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']; ?>
| = $sort_link('role_name', 'Role') ?> | Access | = $sort_link('agents', 'Agents') ?> | = $sort_link('role_updated_at', 'Updated') ?> | |
|---|---|---|---|---|
|
= $name ?>
Yours
= escapeHtml($row['role_description']) ?>
Archived = date('M j, Y', strtotime($row['role_archived_at'])) ?>
= roleAccessHtml($row) ?>
= $agents_html ?>
|
= roleAccessHtml($row) ?> | = $agents_html ?> | = timeAgo($updated) ?> |
|