mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
111 lines
7.4 KiB
PHP
111 lines
7.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* A role's fields - for role_add.php (new, or a copy) and role_edit.php,
|
|
* which set $role (a roleRow() to fill from, or null) and $role_admin_blocker
|
|
* (why it can't stop being an admin role, '' when it can). Two tabs:
|
|
* Details (name, description, Admin) and What it can open. An admin role
|
|
* opens everything; any other has a level of each module, one line each, with
|
|
* what the level picked allows under it and what each level adds on its
|
|
* button. js/role_form.js hides the levels for an admin role and says what a
|
|
* level allows as it is picked.
|
|
*/
|
|
|
|
isset($mysqli) || die("Direct file access is not allowed");
|
|
|
|
$r = $role ?? null;
|
|
$r_admin = $r ? intval($r['role_is_admin']) : 0;
|
|
$r_levels = $r['levels'] ?? [];
|
|
$r_admin_locked = ($role_admin_blocker ?? '') !== '';
|
|
|
|
?>
|
|
|
|
<div data-role-form>
|
|
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" data-bs-toggle="pill" href="#roleFormDetails<?= intval($r['role_id'] ?? 0) ?>"><i class="fas fa-fw fa-user-tag me-2 d-none d-lg-inline"></i>Details</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" data-bs-toggle="pill" href="#roleFormModules<?= intval($r['role_id'] ?? 0) ?>"><i class="fas fa-fw fa-th-large me-2 d-none d-lg-inline"></i>What it can open</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content">
|
|
|
|
<!-- Its name, and whether it is an admin role -->
|
|
<div class="tab-pane fade show active" id="roleFormDetails<?= intval($r['role_id'] ?? 0) ?>">
|
|
<div class="mb-3">
|
|
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-user-tag"></i></span>
|
|
<input type="text" class="form-control" name="name" maxlength="200" placeholder="Help Desk, Billing, Field Tech" value="<?= escapeHtml($r['role_name'] ?? '') ?>" required autofocus>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Description</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
|
<input type="text" class="form-control" name="description" maxlength="200" placeholder="Who it is for" value="<?= escapeHtml($r['role_description'] ?? '') ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<div class="form-check form-switch">
|
|
<input class="form-check-input" type="checkbox" role="switch" name="admin" value="1" id="roleAdmin" data-role-admin<?= $r_admin ? ' checked' : '' ?><?= $r_admin_locked ? ' disabled' : '' ?>>
|
|
<label class="form-check-label fw-semibold" for="roleAdmin"><i class="fas fa-fw fa-user-shield me-1"></i>Admin</label>
|
|
<div class="form-text mt-0">Every part of ITFlow, every client, and Admin - users, roles and settings.</div>
|
|
<?php if ($r_admin_locked) { ?>
|
|
<input type="hidden" name="admin" value="1">
|
|
<div class="form-text mt-0 text-warning-emphasis"><i class="fas fa-fw fa-lock me-1"></i>It stays an admin role: <?= escapeHtml($role_admin_blocker) ?></div>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- A level of each module - one line each, with what the level picked allows under it -->
|
|
<div class="tab-pane fade" id="roleFormModules<?= intval($r['role_id'] ?? 0) ?>">
|
|
<div data-role-levels<?= $r_admin ? ' hidden' : '' ?>>
|
|
<?php
|
|
// Each client's pages need Clients - most of the rest is on them
|
|
$r_by_name = [];
|
|
foreach (roleModules() as $module_id => $module) {
|
|
$r_by_name[$module['module_name']] = intval($r_levels[$module_id] ?? 0);
|
|
}
|
|
$r_needs_clients = empty($r_by_name['module_client'])
|
|
&& max($r_by_name['module_support'] ?? 0, $r_by_name['module_credential'] ?? 0, $r_by_name['module_sales'] ?? 0, $r_by_name['module_financial'] ?? 0) > 0;
|
|
?>
|
|
<div class="alert alert-warning small py-2" data-role-needs-clients<?= $r_needs_clients ? '' : ' hidden' ?>><i class="fas fa-fw fa-exclamation-triangle me-1"></i>Each client's pages need Clients at Read, and most of what is picked here is on them - with Clients at None, its agents are turned away from most of it.</div>
|
|
<div class="list-group">
|
|
<?php foreach (roleModules() as $module_id => $module) {
|
|
$level = min(intval($r_levels[$module_id] ?? 0), $module['max']);
|
|
$label = escapeHtml($module['label']);
|
|
$allows = array_slice($module['levels'], 0, $level); ?>
|
|
<div class="list-group-item d-flex align-items-center gap-2 py-2 itflow-role-module" data-role-module="<?= escapeHtml($module['module_name']) ?>" data-role-allows="<?= escapeHtml(json_encode($module['levels'])) ?>">
|
|
<span class="itflow-asset-icon itflow-asset-icon-sm itflow-asset-tone-other" aria-hidden="true"><i class="fas fa-fw <?= $module['icon'] ?>"></i></span>
|
|
<div class="flex-grow-1 min-w-0">
|
|
<div class="text-truncate"><span class="fw-semibold"><?= $label ?></span> <span class="small text-secondary" title="<?= escapeHtml($module['about']) ?>"><?= escapeHtml($module['about']) ?></span></div>
|
|
<div class="small text-truncate <?= $level ? 'text-body' : 'text-secondary' ?>" data-role-can title="<?= escapeHtml($allows ? implode(' · ', $allows) : 'Nothing') ?>"><i class="fas fa-fw <?= $level ? 'fa-check text-success' : 'fa-times' ?> me-1" aria-hidden="true"></i><?= escapeHtml($allows ? implode(' · ', $allows) : 'Nothing') ?></div>
|
|
</div>
|
|
<div class="btn-group btn-group-sm flex-shrink-0" role="group" aria-label="<?= $label ?>">
|
|
<?php foreach (ROLE_LEVELS as $value => $level_label) {
|
|
if ($value > $module['max']) {
|
|
break;
|
|
}
|
|
$id = "roleLevel{$module_id}_$value"; ?>
|
|
<input class="btn-check" type="radio" name="levels[<?= $module_id ?>]" id="<?= $id ?>" value="<?= $value ?>" autocomplete="off"<?= $level === $value ? ' checked' : '' ?>>
|
|
<label class="btn btn-outline-<?= ROLE_LEVEL_TONES[$value] ?>" for="<?= $id ?>" title="<?= escapeHtml($value ? $module['levels'][$value] : 'Nothing - its agents can\'t open it') ?>"><?= $level_label ?></label>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
<div class="small text-secondary" data-role-admin-note<?= $r_admin ? '' : ' hidden' ?>><i class="fas fa-fw fa-info-circle me-1"></i>An admin role opens every part of ITFlow, so there are no levels to set. Its levels are kept, for if it stops being one.</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script src="<?= staticFileUrl('/js/role_form.js') ?>"></script>
|