Ordre des profils

This commit is contained in:
Fred Tempez 2023-08-05 14:50:05 +02:00
parent b13a5a5043
commit d2e3dfe700
2 changed files with 139 additions and 83 deletions

View File

@ -71,6 +71,8 @@ class user extends common
public static $listModules = []; public static $listModules = [];
public static $profils = [];
/** /**
* Ajout * Ajout
*/ */
@ -508,23 +510,23 @@ class user extends common
$groupId == self::GROUP_EDITOR $groupId == self::GROUP_EDITOR
) { ) {
// Enumérer les sous groupes MEMBER et MODERATOR // Enumérer les sous groupes MEMBER et MODERATOR
foreach ($groupData as $subGroupId => $subGroupData) { foreach ($groupData as $profilId => $profilData) {
self::$userGroups[$groupId . '.' . $subGroupId] = [ self::$userGroups[$groupId . '.' . $profilId] = [
$groupId . '-' . $subGroupId, $groupId . '-' . $profilId,
self::$groups[$groupId] . '<br />Profil : ' . $subGroupData['name'], self::$groups[$groupId] . '<br />Profil : ' . $profilData['name'],
nl2br($subGroupData['comment']), nl2br($profilData['comment']),
template::button('profilEdit' . $groupId . $subGroupId, [ template::button('profilEdit' . $groupId . $profilId, [
'href' => helper::baseUrl() . 'user/profilEdit/' . $groupId . '/' . $subGroupId, 'href' => helper::baseUrl() . 'user/profilEdit/' . $groupId . '/' . $profilId,
'value' => template::ico('pencil'), 'value' => template::ico('pencil'),
'help' => 'Éditer', 'help' => 'Éditer',
'disabled' => $subGroupData['readonly'], 'disabled' => $profilId === 1 ? true : $profilData['readonly'],
]), ]),
template::button('profilDelete' . $groupId . $subGroupId, [ template::button('profilDelete' . $groupId . $profilId, [
'class' => 'userDelete buttonRed', 'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/profilDelete/' . $groupId . '/' . $subGroupId, 'href' => helper::baseUrl() . 'user/profilDelete/' . $groupId . '/' . $profilId,
'value' => template::ico('trash'), 'value' => template::ico('trash'),
'help' => 'Supprimer', 'help' => 'Supprimer',
'disabled' => $subGroupData['permanent'], 'disabled' => $profilData['permanent'],
]) ])
]; ];
} }
@ -548,6 +550,15 @@ class user extends common
$this->getUser('permission', __CLASS__, __FUNCTION__) === true && $this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost() $this->isPost()
) { ) {
// Effacer les données du numéro de profil ancien
$group = $this->getInput('profilEditGroup', helper::FILTER_STRING_SHORT, true);
$profil = $this->getInput('profilEditProfil', helper::FILTER_STRING_SHORT, true);
$oldProfil = $this->getInput('profilEditOldProfil', helper::FILTER_STRING_SHORT);
if ($profil !== $profil) {
$this->deleteData(['profil', $group, $oldProfil]);
}
// Données du formulaire // Données du formulaire
$data = [ $data = [
'name' => $this->getInput('profilEditName', helper::FILTER_STRING_SHORT, true), 'name' => $this->getInput('profilEditName', helper::FILTER_STRING_SHORT, true),
@ -606,14 +617,14 @@ class user extends common
//Sauvegarder le données //Sauvegarder le données
$this->setData([ $this->setData([
'profil', 'profil',
$this->getInput('profilEditGroup', helper::FILTER_STRING_LONG, true), $group,
$this->getInput('profilEditProfil', helper::FILTER_STRING_LONG, true), $profil,
$data $data
]); ]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'user/profilEdit/' . $this->getUrl(2) . '/' . $this->getUrl(3), 'redirect' => helper::baseUrl() . 'user/profil',
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
'state' => true 'state' => true
]); ]);
@ -630,6 +641,27 @@ class user extends common
self::$listModules = array_keys(self::$listModules); self::$listModules = array_keys(self::$listModules);
sort(self::$listModules); sort(self::$listModules);
/**
* Génération des profils disponibles
* Tableau des profils attribués
* Extraire les numéros de profils
* Générer un tableau $p des profils possibles selon le plafond
* Ne garder que la différence sauf le profil de l'utilisateur édité que l'on ajoute
*/
self::$profils = $this->getData(['profil', $this->getUrl(2)]);
// Supprime le profil utilisateur
unset(self::$profils[$this->getUrl(3)]);
self::$profils = array_keys(self::$profils);
$p = range(1, self::MAX_PROFILS - 1);
self::$profils = array_diff($p, self::$profils);
sort(self::$profils);
// Restructure le tableau pour faire correspondre la clé et la valeur
$p = array();
foreach (self::$profils as $key => $value) {
$p[$value] = $value;
}
self::$profils = $p;
// Valeurs en sortie; // Valeurs en sortie;
$this->addOutput([ $this->addOutput([
'title' => sprintf(helper::translate('Édition du profil %s'), $this->getData(['profil', $this->getUrl(2), $this->getUrl(3), 'name'])), 'title' => sprintf(helper::translate('Édition du profil %s'), $this->getData(['profil', $this->getUrl(2), $this->getUrl(3), 'name'])),
@ -650,76 +682,89 @@ class user extends common
) { ) {
// Nombre de profils de ce groupe // Nombre de profils de ce groupe
$group = $this->getInput('profilAddGroup'); $group = $this->getInput('profilAddGroup');
$profil = (string) (count($this->getData(['profil', $group])) + 1); $profil = count($this->getData(['profil', $group]));
// Vérifier le quota du nombre de profils dans le groupe
var_dump($profil < self::MAX_PROFILS);
// Données du formulaire if ($profil < self::MAX_PROFILS) {
$data = [ $profil = (string) ($profil + 1);
'name' => $this->getInput('profilAddName', helper::FILTER_STRING_SHORT, true), // Données du formulaire
'readonly' => false, $data = [
'permanent' => false, 'name' => $this->getInput('profilAddName', helper::FILTER_STRING_SHORT, true),
'comment' => $this->getInput('profilAddComment', helper::FILTER_STRING_SHORT, true), 'readonly' => false,
'filemanager' => $this->getInput('profilAddFileManager', helper::FILTER_BOOLEAN), 'permanent' => false,
'file' => [ 'comment' => $this->getInput('profilAddComment', helper::FILTER_STRING_SHORT, true),
'download' => $this->getInput('profilAddDownload', helper::FILTER_BOOLEAN), 'filemanager' => $this->getInput('profilAddFileManager', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilAddEdit', helper::FILTER_BOOLEAN), 'file' => [
'create' => $this->getInput('profilAddCreate', helper::FILTER_BOOLEAN), 'download' => $this->getInput('profilAddDownload', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('profilAddRename', helper::FILTER_BOOLEAN), 'edit' => $this->getInput('profilAddEdit', helper::FILTER_BOOLEAN),
'upload' => $this->getInput('profilAddUpload', helper::FILTER_BOOLEAN), 'create' => $this->getInput('profilAddCreate', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilAddDelete', helper::FILTER_BOOLEAN), 'rename' => $this->getInput('profilAddRename', helper::FILTER_BOOLEAN),
'preview' => $this->getInput('profilAddPreview', helper::FILTER_BOOLEAN), 'upload' => $this->getInput('profilAddUpload', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('profilAddDuplicate', helper::FILTER_BOOLEAN), 'delete' => $this->getInput('profilAddDelete', helper::FILTER_BOOLEAN),
'extract' => $this->getInput('profilAddExtract', helper::FILTER_BOOLEAN), 'preview' => $this->getInput('profilAddPreview', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilAddCopycut', helper::FILTER_BOOLEAN), 'duplicate' => $this->getInput('profilAddDuplicate', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilAddChmod', helper::FILTER_BOOLEAN), 'extract' => $this->getInput('profilAddExtract', helper::FILTER_BOOLEAN),
], 'copycut' => $this->getInput('profilAddCopycut', helper::FILTER_BOOLEAN),
'folder' => [ 'chmod' => $this->getInput('profilAddChmod', helper::FILTER_BOOLEAN),
'create' => $this->getInput('profilAddFolderCreate', helper::FILTER_BOOLEAN), ],
'delete' => $this->getInput('profilAddFolderDelete', helper::FILTER_BOOLEAN), 'folder' => [
'rename' => $this->getInput('profilAddFolderRename', helper::FILTER_BOOLEAN), 'create' => $this->getInput('profilAddFolderCreate', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilAddFolderCopycut', helper::FILTER_BOOLEAN), 'delete' => $this->getInput('profilAddFolderDelete', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilAddFolderChmod', helper::FILTER_BOOLEAN), 'rename' => $this->getInput('profilAddFolderRename', helper::FILTER_BOOLEAN),
'path' => $this->getInput('profilAddPath'), 'copycut' => $this->getInput('profilAddFolderCopycut', helper::FILTER_BOOLEAN),
], 'chmod' => $this->getInput('profilAddFolderChmod', helper::FILTER_BOOLEAN),
'page' => [ 'path' => $this->getInput('profilAddPath'),
'add' => $this->getInput('profilAddPageAdd', helper::FILTER_BOOLEAN), ],
'edit' => $this->getInput('profilAddPageEdit', helper::FILTER_BOOLEAN), 'page' => [
'delete' => $this->getInput('profilAddPageDelete', helper::FILTER_BOOLEAN), 'add' => $this->getInput('profilAddPageAdd', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('profilAddPageDuplicate', helper::FILTER_BOOLEAN), 'edit' => $this->getInput('profilAddPageEdit', helper::FILTER_BOOLEAN),
'module' => $this->getInput('profilAddPageModule', helper::FILTER_BOOLEAN), 'delete' => $this->getInput('profilAddPageDelete', helper::FILTER_BOOLEAN),
'cssEditor' => $this->getInput('profilAddPagecssEditor', helper::FILTER_BOOLEAN), 'duplicate' => $this->getInput('profilAddPageDuplicate', helper::FILTER_BOOLEAN),
'jsEditor' => $this->getInput('profilAddPagejsEditor', helper::FILTER_BOOLEAN), 'module' => $this->getInput('profilAddPageModule', helper::FILTER_BOOLEAN),
], 'cssEditor' => $this->getInput('profilAddPagecssEditor', helper::FILTER_BOOLEAN),
'user' => [ 'jsEditor' => $this->getInput('profilAddPagejsEditor', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilAddUserEdit', helper::FILTER_BOOLEAN), ],
] 'user' => [
]; 'edit' => $this->getInput('profilAddUserEdit', helper::FILTER_BOOLEAN),
]
];
// Données des modules // Données des modules
$dataModules = helper::getModules(); $dataModules = helper::getModules();
if (is_array($dataModules)) { if (is_array($dataModules)) {
foreach ($dataModules as $moduleId => $moduleValue) { foreach ($dataModules as $moduleId => $moduleValue) {
if (file_exists('module/' . $moduleId . '/profil/main/add.inc.php')) { if (file_exists('module/' . $moduleId . '/profil/main/add.inc.php')) {
include('module/' . $moduleId . '/profil/main/add.inc.php'); include('module/' . $moduleId . '/profil/main/add.inc.php');
if (is_array($moduleData[$moduleId])) { if (is_array($moduleData[$moduleId])) {
$data = array_merge($data, [$moduleId => $moduleData[$moduleId]]); $data = array_merge($data, [$moduleId => $moduleData[$moduleId]]);
}
} }
} }
} }
}
// Sauvegarder les données // Sauvegarder les données
$this->setData([ $this->setData([
'profil', 'profil',
$group, $group,
$profil, $profil,
$data $data
]); ]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'user/profil', 'redirect' => helper::baseUrl() . 'user/profil',
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
'state' => true 'state' => true
]); ]);
} else {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user/profil',
'notification' => helper::translate('Nombre de profils maximum : ') . self::MAX_PROFILS,
'state' => false
]);
}
} }
// Chemin vers les dossiers du gestionnaire de fichier // Chemin vers les dossiers du gestionnaire de fichier

View File

@ -21,10 +21,21 @@
<div class="col6"> <div class="col6">
<div class="row"> <div class="row">
<div class="col12"> <div class="col12">
<?php echo template::text('profilEditName', [ <div class="row">
'label' => 'Nom du profil', <div class="col6">
'value' => $this->getData(['profil', $this->getUrl(2), $this->getUrl(3), 'name']) <?php echo template::text('profilEditName', [
]); ?> 'label' => 'Nom du profil',
'value' => $this->getData(['profil', $this->getUrl(2), $this->getUrl(3), 'name'])
]); ?>
</div>
<div class="col6">
<?php echo template::select('profilEditProfil', $module::$profils, [
'label' => 'Hiérarchie du profil',
'help' => 'Les profils d\'ordre supérieurs sont de rang plus élevés que les profils d\'ordre inférieur',
'selected' => $this->getUrl(3)
]); ?>
</div>
</div>
</div> </div>
<div class="col12"> <div class="col12">
<?php echo template::text('profilEditDisplayGroup', [ <?php echo template::text('profilEditDisplayGroup', [
@ -35,7 +46,7 @@
<?php echo template::hidden('profilEditGroup', [ <?php echo template::hidden('profilEditGroup', [
'value' => $this->getUrl(2), 'value' => $this->getUrl(2),
]); ?> ]); ?>
<?php echo template::hidden('profilEditProfil', [ <?php echo template::hidden('profilEditOldProfil', [
'value' => $this->getUrl(3), 'value' => $this->getUrl(3),
]); ?> ]); ?>
</div> </div>