Roles - what each role lets its agents open: an admin role opens * everything, any other a level of each module. Each shows its access at a * glance and its agents (opening Users filtered to them). A role can be * changed, copied as the start of another, archived - kept for the agents * archived with it, not offered for new ones - or, while nobody has it, * deleted. The work is in functions/roles.php; the handlers are * admin/post/roles.php. */ // Default Column Sortby Filter $sort = "role_name"; $order = "ASC"; require_once "includes/inc_all_admin.php"; // ?archived=1 is how older links asked for the archived ones $show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']); // Only these sort - an unknown column would take the page down. Admin roles stay first, as on Users $sortable_columns = [ 'role_name' => "role_is_admin DESC, role_name $order", 'agents' => "agents $order, role_name ASC", 'role_updated_at' => "COALESCE(role_updated_at, role_created_at) $order", ]; if (!isset($sortable_columns[$sort])) { $sort = 'role_name'; } $search = "role_type = 1 AND (role_name LIKE '%$q%' OR role_description LIKE '%$q%')"; $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS role_id, role_name, role_description, role_is_admin, role_created_at, role_updated_at, role_archived_at, (SELECT COUNT(*) FROM users WHERE user_role_id = role_id AND user_type = 1 AND user_archived_at IS NULL) AS agents, (SELECT COUNT(*) FROM users WHERE user_role_id = role_id AND user_type = 1 AND user_archived_at IS NOT NULL) AS agents_archived FROM user_roles WHERE $search AND role_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . " ORDER BY {$sortable_columns[$sort]}, role_id ASC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); // Each with its levels, as roleRows() gives them $roles = []; while ($row = mysqli_fetch_assoc($sql)) { $roles[intval($row['role_id'])] = $row; } $levels = roleLevels(array_keys($roles)); foreach ($roles as $role_id => $row) { $roles[$role_id]['levels'] = $levels[$role_id] ?? []; } $agents = roleAgents(array_keys($roles), 5); $counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(role_archived_at IS NULL), 0), COALESCE(SUM(role_archived_at IS NOT NULL), 0) FROM user_roles WHERE $search")); $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $csrf = $_SESSION['csrf_token']; ?>

Roles

"> $row) { $name = escapeHtml($row['role_name']); $is_admin = intval($row['role_is_admin']) === 1; $is_mine = $role_id === intval($session_user_role); $edit_url = "modals/role/role_edit.php?id=$role_id"; $agent_count = intval($row['agents']); $archive_blocker = roleArchiveBlocker($row); $delete_blocker = roleDeleteBlocker($row); $updated = $row['role_updated_at'] ?: $row['role_created_at']; // The agents with it - a few faces and how many, opening Users filtered to them ob_start(); if ($agent_count) { ?> agent Nobody
archived
Access
Yours
Archived
'roles', 'icon' => 'fa-user-shield', 'filtered' => $q !== '', 'archived' => $show_archived, 'views' => ['show'], 'text' => 'A role sets what its agents can open - an admin role everything, including Admin; any other a level of each part of ITFlow.', 'actions' => [['label' => 'New Role', 'modal' => 'modals/role/role_add.php', 'size' => 'lg']], ]; require_once "../includes/filter_footer.php"; ?>