Add role deletion functionality in admin interface

This commit introduces the ability to delete roles within the admin interface. It adds new functions to check if a role can be deleted based on active assignments and historical data. The UI is updated to include delete buttons with confirmation prompts, enhancing user interaction and management capabilities. The version code is updated to reflect these changes.
This commit is contained in:
2026-07-01 12:41:10 -04:00
parent 0b3ea4811a
commit 4d3260b2ca
2 changed files with 88 additions and 0 deletions

View File

@ -43,6 +43,19 @@ if (isset($_GET['action'])) {
$strQ = ($arrResult['state'] === 'ok') ? 'ok=' . urlencode($arrResult['message']) : 'err=' . urlencode($arrResult['message']);
header('Location: eve_acces.php?p=kits&' . $strQ);
exit;
case 'delete':
if ($intRoleId <= 0) {
header('Location: eve_acces.php?p=kits');
exit;
}
$arrResult = fxEveAccesAdminDeleteRole($intRoleId);
if ($arrResult['state'] === 'ok') {
header('Location: eve_acces.php?p=kits&ok=' . urlencode($arrResult['message']));
} else {
header('Location: eve_acces.php?p=kits&err=' . urlencode($arrResult['message']));
}
exit;
}
}

View File

@ -169,6 +169,61 @@ function fxEveAccesAdminCountActiveAssignments($intRoleId)
return intval($objDatabase->fxGetVar($sql));
}
function fxEveAccesAdminCountAllAssignments($intRoleId)
{
global $objDatabase;
$sql = "SELECT COUNT(*) FROM inscriptions_eve_acces
WHERE role_id = " . intval($intRoleId);
return intval($objDatabase->fxGetVar($sql));
}
function fxEveAccesAdminCanDeleteRole($intRoleId)
{
$row = fxEveAccesAdminGetRoleById($intRoleId);
if ($row === null) {
return array('can' => false, 'message' => 'Kit introuvable.');
}
if (intval($row['role_systeme']) === 1) {
return array('can' => false, 'message' => 'Un kit système ne peut pas être supprimé.');
}
$intActive = fxEveAccesAdminCountActiveAssignments($intRoleId);
if ($intActive > 0) {
return array(
'can' => false,
'message' => 'Ce kit est assigné à ' . $intActive . ' compte(s). Retirez les assignations avant de supprimer.',
);
}
if (fxEveAccesAdminCountAllAssignments($intRoleId) > 0) {
return array(
'can' => false,
'message' => 'Ce kit a déjà été assigné (historique). Suppression impossible.',
);
}
return array('can' => true, 'message' => '');
}
function fxEveAccesAdminDeleteRole($intRoleId)
{
global $objDatabase;
$arrCheck = fxEveAccesAdminCanDeleteRole($intRoleId);
if (!$arrCheck['can']) {
return array('state' => 'error', 'message' => $arrCheck['message']);
}
$intRoleId = intval($intRoleId);
$objDatabase->fxQuery('DELETE FROM inscriptions_eve_role_permissions WHERE role_id = ' . $intRoleId);
$objDatabase->fxQuery('DELETE FROM inscriptions_eve_roles WHERE role_id = ' . $intRoleId);
return array('state' => 'ok', 'message' => 'Kit supprimé.');
}
function fxEveAccesAdminSaveRole($arrData, $arrPermKeys)
{
global $objDatabase;
@ -413,6 +468,7 @@ function fxEveAccesAdminRenderKitsList($strFlash = '')
} else {
foreach ($arrRoles as $row) {
$strIcon = trim((string)($row['role_icone'] ?? ''));
$arrDelete = fxEveAccesAdminCanDeleteRole(intval($row['role_id']));
?>
<tr>
<td class="text-center text-muted">
@ -461,6 +517,13 @@ function fxEveAccesAdminRenderKitsList($strFlash = '')
onclick="return confirm('Changer le statut de ce kit ?');">
<i class="fa fa-power-off"></i>
</a>
<?php if ($arrDelete['can']) { ?>
<a class="btn btn-sm btn-outline-danger" href="eve_acces.php?action=delete&amp;id=<?= intval($row['role_id']) ?>"
title="Supprimer"
onclick="return confirm('Supprimer définitivement ce kit ?');">
<i class="fa fa-trash"></i>
</a>
<?php } ?>
</td>
</tr>
<?php
@ -494,6 +557,7 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
}
$blnSysteme = ($row !== null && intval($row['role_systeme']) === 1);
$arrDelete = ($intRoleId > 0) ? fxEveAccesAdminCanDeleteRole($intRoleId) : array('can' => false, 'message' => '');
$arrCatalog = fxEveAccesGetCatalogPermissions(null, true);
$arrByGroup = array();
if ($arrCatalog != null) {
@ -662,6 +726,17 @@ function fxEveAccesAdminRenderKitForm($intRoleId, $strError = '')
<button type="submit" class="btn btn-success">
<i class="fa fa-save"></i> Enregistrer
</button>
<?php if ($arrDelete['can']) { ?>
<a class="btn btn-outline-danger ml-2"
href="eve_acces.php?action=delete&amp;id=<?= intval($intRoleId) ?>"
onclick="return confirm('Supprimer définitivement ce kit ?');">
<i class="fa fa-trash"></i> Supprimer
</a>
<?php } elseif ($intRoleId > 0 && $arrDelete['message'] !== '' && intval($row['role_systeme'] ?? 0) !== 1) { ?>
<span class="text-muted small ml-2" title="<?= htmlspecialchars($arrDelete['message'], ENT_QUOTES, 'UTF-8') ?>">
<i class="fa fa-info-circle"></i> Suppression impossible tant qu'une assignation existe.
</span>
<?php } ?>
</form>
<script>
(function () {