Fix Role Archiving, Roles can only be archived if no users are assigned to the role

This commit is contained in:
johnnyq 2026-01-11 16:46:53 -05:00
parent 5815ef2f75
commit 1de023f9df
2 changed files with 15 additions and 17 deletions

View File

@ -34,7 +34,7 @@ if (isset($_POST['edit_role'])) {
$name = sanitizeInput($_POST['role_name']); $name = sanitizeInput($_POST['role_name']);
$description = sanitizeInput($_POST['role_description']); $description = sanitizeInput($_POST['role_description']);
$admin = intval($_POST['role_is_admin']); $admin = intval($_POST['role_is_admin']);
mysqli_query($mysqli, "UPDATE user_roles SET role_name = '$name', role_description = '$description', role_is_admin = $admin WHERE role_id = $role_id"); mysqli_query($mysqli, "UPDATE user_roles SET role_name = '$name', role_description = '$description', role_is_admin = $admin WHERE role_id = $role_id");
// Update role access levels // Update role access levels
@ -70,18 +70,18 @@ if (isset($_GET['archive_role'])) {
$role_user_count = mysqli_fetch_row($sql_role_user_count)[0]; $role_user_count = mysqli_fetch_row($sql_role_user_count)[0];
if ($role_user_count != 0) { if ($role_user_count != 0) {
flash_alert("Role must not in use to archive it", 'error'); flash_alert("Role must not in use to archive it", 'error');
redirect(); redirect();
} }
mysqli_query($mysqli, "UPDATE user_roles SET role_archived_at = NOW() WHERE role_id = $role_id"); mysqli_query($mysqli, "UPDATE user_roles SET role_archived_at = NOW() WHERE role_id = $role_id");
$role_name = sanitizeInput(getFieldById('roles', $role_id, 'role_name')); $role_name = sanitizeInput(getFieldById('user_roles', $role_id, 'role_name'));
logAction("User Role", "Archive", "$session_name archived user role $role_name", 0, $role_id); logAction("User Role", "Archive", "$session_name archived user role $role_name", 0, $role_id);
flash_alert("User Role <strong>$role_name</strong> archived", 'error'); flash_alert("User Role <strong>$role_name</strong> archived", 'error');
redirect(); redirect();
} }

View File

@ -19,7 +19,7 @@ ob_start();
?> ?>
<div class="modal-header bg-dark"> <div class="modal-header bg-dark">
<h5 class="modal-title"><i class='fas fa-bell mr-2'></i>Notifications<span class='badge badge-secondary badge-pill px-3 ml-3'><?php echo $num_notifications; ?><span></h5> <h5 class="modal-title"><i class='fas fa-bell mr-2'></i>Notifications<span class='badge badge-secondary badge-pill px-3 ml-3'><?= $num_notifications ?><span></h5>
<button type="button" class="close text-white" data-dismiss="modal"> <button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span> <span>&times;</span>
</button> </button>
@ -28,9 +28,9 @@ ob_start();
<div class="modal-body"> <div class="modal-body">
<?php if ($num_notifications) { ?> <?php if ($num_notifications) { ?>
<table class="table table-sm table-hover table-borderless"> <table class="table table-sm table-hover table-borderless">
<?php while ($row = mysqli_fetch_array($sql)) {
<?php while ($row = mysqli_fetch_assoc($sql)) {
$notification_id = intval($row["notification_id"]); $notification_id = intval($row["notification_id"]);
$notification_type = nullable_htmlentities($row["notification_type"]); $notification_type = nullable_htmlentities($row["notification_type"]);
@ -47,16 +47,16 @@ ob_start();
$notification_action = "#"; $notification_action = "#";
} }
?> ?>
<tr class="notification-item"> <tr class="notification-item">
<th> <th>
<a class="text-dark" href="<?php echo $notification_action; ?>"> <a class="text-dark" href="<?= $notification_action ?>">
<i class="fas fa-bullhorn mr-2"></i><?php echo $notification_type; ?> <i class="fas fa-bullhorn mr-2"></i><?= $notification_type ?>
<small class="text-muted float-right"> <small class="text-muted float-right">
<?php echo $notification_timestamp_formated; ?> <?= $notification_timestamp_formated ?>
</small> </small>
<br> <br>
<small class="text-secondary text-wrap"><?php echo $notification_details; ?></small> <small class="text-secondary text-wrap"><?= $notification_details ?></small>
</a> </a>
</th> </th>
</tr> </tr>
@ -78,10 +78,8 @@ ob_start();
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<?php if ($num_notifications) { ?> <?php if ($num_notifications) { ?>
<a href="/agent/post.php?dismiss_all_notifications&csrf_token=<?php echo $_SESSION[ <a href="/agent/post.php?dismiss_all_notifications&csrf_token=<?= $_SESSION["csrf_token"] ?>" class="btn btn-primary">
"csrf_token"
]; ?>" class="btn btn-primary">
<span class="text-white text-bold"><i class="fas fa-check mr-2"></i>Dismiss all</span> <span class="text-white text-bold"><i class="fas fa-check mr-2"></i>Dismiss all</span>
</a> </a>
<a href="/agent/notifications.php" class="btn btn-secondary"> <a href="/agent/notifications.php" class="btn btn-secondary">