Ajout du profil d'un membre

This commit is contained in:
Fred Tempez 2023-05-02 23:37:51 +02:00
parent ef8c10fae7
commit 21a903b1e5
6 changed files with 207 additions and 117 deletions

View File

@ -46,6 +46,8 @@ class user extends common
public static $userGroups = [];
public static $userProfils = [];
public static $userLongtime = false;
public static $separators = [
@ -89,6 +91,13 @@ class user extends common
$userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true);
$userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true);
// Profil
$group = $this->getInput('userAddGroup', helper::FILTER_INT, true);
$profil = null;
if ($group < 1 || $group > 2 ) {
$profil = $this->getInput('userAddProfil' . $group, helper::FILTER_INT);
}
// Stockage des données
$this->setData([
'user',
@ -96,18 +105,18 @@ class user extends common
[
'firstname' => $userFirstname,
'forgot' => 0,
'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true),
'group' => $group,
'profil' => $profil,
'lastname' => $userLastname,
'pseudo' => $this->getInput('userAddPseudo', helper::FILTER_STRING_SHORT, true),
'signature' => $this->getInput('userAddSignature', helper::FILTER_INT, true),
'mail' => $userMail,
'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true),
"connectFail" => null,
"connectTimeout" => null,
"accessUrl" => null,
"accessTimer" => null,
"accessCsrf" => null,
"files" => $this->getInput('userAddFiles', helper::FILTER_BOOLEAN),
'connectFail' => null,
'connectTimeout' => null,
'accessUrl' => null,
'accessTimer' => null,
'accessCsrf' => null,
'language' => $this->getInput('userEditLanguage', helper::FILTER_STRING_SHORT),
]
]);
@ -133,19 +142,26 @@ class user extends common
'state' => $sent === true ? true : null
]);
}
// Langues disponibles pour l'interface de l'utilisateur
if (is_dir(self::I18N_DIR)) {
$dir = getcwd();
chdir(self::I18N_DIR);
$files = glob('*.json');
chdir($dir);
}
foreach ($files as $file) {
// La langue est-elle référencée ?
if (array_key_exists(basename($file, '.json'), self::$languages)) {
self::$languagesInstalled[basename($file, '.json')] = self::$languages[basename($file, '.json')];
self::$languagesInstalled = $this->getData(['language']);
if (self::$languagesInstalled) {
foreach (self::$languagesInstalled as $lang => $datas) {
self::$languagesInstalled[$lang] = self::$languages[$lang];
}
}
// Profils disponibles
foreach ($this->getData(['profil']) as $profilId => $profilData) {
if ($profilId < 1 || $profilId > 2) {
continue;
}
foreach ($profilData as $key => $value) {
self::$userProfils[$profilId][$key] = $profilData[$key]['name'];
}
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Nouvel utilisateur'),
@ -316,7 +332,6 @@ class user extends common
}
// Langues disponibles pour l'interface de l'utilisateur
self::$languagesInstalled = $this->getData(['language']);
if (self::$languagesInstalled) {
foreach (self::$languagesInstalled as $lang => $datas) {
@ -324,6 +339,17 @@ class user extends common
}
}
// Profils disponibles
foreach ($this->getData(['profil']) as $profilId => $profilData) {
if ($profilId < 1 || $profilId > 2) {
continue;
}
echo $profilId;
foreach ($profilData as $key => $value) {
self::$userProfils[$profilId][$key] = $profilData[$key]['name'];
}
}
// Valeurs en sortie
$this->addOutput([
'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']),
@ -405,6 +431,7 @@ class user extends common
];
}
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Utilisateurs'),
@ -449,17 +476,17 @@ class user extends common
) {
// Enumérer les sous groupes MEMBER et MODERATOR
foreach ($groupData as $subGroupId => $subGroupData) {
self::$userGroups[$groupId.'.'.$subGroupId] = [
self::$userGroups[$groupId . '.' . $subGroupId] = [
$groupId . '-' . $subGroupId,
self::$groups[$groupId] .'<br />Profil : '. $subGroupData['name'],
self::$groups[$groupId] . '<br />Profil : ' . $subGroupData['name'],
nl2br($subGroupData['comment']),
template::button('profilEdit' . $groupId.$subGroupId, [
template::button('profilEdit' . $groupId . $subGroupId, [
'href' => helper::baseUrl() . 'user/profilEdit/' . $groupId . '/' . $subGroupId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil'),
'help' => 'Éditer',
'disabled' => $subGroupData['readonly'],
]),
template::button('profilDelete' . $groupId.$subGroupId, [
template::button('profilDelete' . $groupId . $subGroupId, [
'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/profilDelete/' . $groupId . '/' . $subGroupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
@ -503,10 +530,8 @@ class user extends common
$this->deleteData(['profil', $oldGroup, $profil]);
$profil = helper::increment($profil, $this->getData(['profil', $group]));
}
echo "groupe " . $group;
echo "profil " . $profil;
exit();
$this->setData([
'profil',
$group,
@ -540,8 +565,6 @@ class user extends common
]
]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user/profil',
@ -565,7 +588,8 @@ class user extends common
* Ajouter un profil de permission
*/
public function profilAdd() {
public function profilAdd()
{
// Valeurs en sortie;
$this->addOutput([

View File

@ -17,3 +17,8 @@
/** NE PAS EFFACER
* admin.css
*/
#userAddProfil1Wrapper,
#userAddProfil2Wrapper {
padding: 0;
}

View File

@ -10,4 +10,39 @@
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
$("#userAddId").on("change keydown keyup",(function(event){var userId=$(this).val();if(8!==event.keyCode&&37!==event.keyCode&&39!==event.keyCode&&46!==event.keyCode&&window.getSelection().toString()!==userId){var searchReplace={"á":"a","à":"a","â":"a","ä":"a","ã":"a","å":"a","ç":"c","é":"e","è":"e","ê":"e","ë":"e","í":"i","ì":"i","î":"i","ï":"i","ñ":"n","ó":"o","ò":"o","ô":"o","ö":"o","õ":"o","ú":"u","ù":"u","û":"u","ü":"u","ý":"y","ÿ":"y","Á":"A","À":"A","Â":"A","Ä":"A","Ã":"A","Å":"A","Ç":"C","É":"E","È":"E","Ê":"E","Ë":"E","Í":"I","Ì":"I","Î":"I","Ï":"I","Ñ":"N","Ó":"O","Ò":"O","Ô":"O","Ö":"O","Õ":"O","Ú":"U","Ù":"U","Û":"U","Ü":"U","Ý":"Y","Ÿ":"Y","'":"-",'"':"-"," ":"-"};userId=(userId=userId.replace(/[áàâäãåçéèêëíìîïñóòôöõúùûüýÿ'" ]/gi,(function(match){return searchReplace[match]}))).replace(/[^a-z0-9-]/gi,""),$(this).val(userId)}})),$("#userAddGroup").on("change",(function(){$(".userAddGroupDescription").hide(),$("#userAddGroupDescription"+$(this).val()).show()})).trigger("change"),$(document).ready((function(){"1"===$("#userAddGroup").val()?$("#userAddMemberFiles").slideDown():$("#userAddMemberFiles").slideUp((function(){$("#userAddtFiles").prop("checked",!1).trigger("change")}))})),$("#userAddGroup").on("change",(function(){"1"===$("#userAddGroup").val()?$("#userAddMemberFiles").slideDown():$("#userAddMemberFiles").slideUp((function(){$("#userAddFiles").prop("checked",!1).trigger("change")}))})).trigger("change");
/**
* Affichage de l'id en simulant FILTER_ID
*/
$("#userAddId").on("change keydown keyup", function(event) {
var userId = $(this).val();
if(
event.keyCode !== 8 // BACKSPACE
&& event.keyCode !== 37 // LEFT
&& event.keyCode !== 39 // RIGHT
&& event.keyCode !== 46 // DELETE
&& window.getSelection().toString() !== userId // Texte sélectionné
) {
var searchReplace = {
"á": "a", "à": "a", "â": "a", "ä": "a", "ã": "a", "å": "a", "ç": "c", "é": "e", "è": "e", "ê": "e", "ë": "e", "í": "i", "ì": "i", "î": "i", "ï": "i", "ñ": "n", "ó": "o", "ò": "o", "ô": "o", "ö": "o", "õ": "o", "ú": "u", "ù": "u", "û": "u", "ü": "u", "ý": "y", "ÿ": "y",
"Á": "A", "À": "A", "Â": "A", "Ä": "A", "Ã": "A", "Å": "A", "Ç": "C", "É": "E", "È": "E", "Ê": "E", "Ë": "E", "Í": "I", "Ì": "I", "Î": "I", "Ï": "I", "Ñ": "N", "Ó": "O", "Ò": "O", "Ô": "O", "Ö": "O", "Õ": "O", "Ú": "U", "Ù": "U", "Û": "U", "Ü": "U", "Ý": "Y", "Ÿ": "Y",
"'": "-", "\"": "-", " ": "-"
};
userId = userId.replace(/[áàâäãåçéèêëíìîïñóòôöõúùûüýÿ'" ]/ig, function(match) {
return searchReplace[match];
});
userId = userId.replace(/[^a-z0-9-]/ig, "");
$(this).val(userId);
}
});
/**
* Droits des groupes
*/
$("#userAddGroup").on("change", function() {
$(".userAddGroupDescription").hide();
$("#userAddGroupDescription" + $(this).val()).show();
}).trigger("change");

View File

@ -14,7 +14,8 @@
<div class="row">
<div class="col6">
<div class="block">
<h4><?php echo helper::translate('Identité'); ?>
<h4>
<?php echo helper::translate('Identité'); ?>
</h4>
<div class="row">
<div class="col6">
@ -30,23 +31,34 @@
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::text('userAddPseudo', [
'autocomplete' => 'off',
'label' => 'Pseudo'
]); ?>
</div>
<div class="col6">
<?php echo template::select('userAddSignature', $module::$signature, [
'label' => 'Signature',
'selected' => 1
]); ?>
</div>
</div>
<?php echo template::mail('userAddMail', [
'autocomplete' => 'off',
'label' => 'Adresse électronique'
]); ?>
<?php echo template::select('userAddLanguage', $module::$languagesInstalled, [
'label' => 'Langues'
]); ?>
</div>
</div>
<div class="col6">
<div class="block">
<h4><?php echo helper::translate('Authentification'); ?>
<h4>
<?php echo helper::translate('Authentification'); ?>
</h4>
<?php echo template::text('userAddId', [
'autocomplete' => 'off',
@ -72,39 +84,29 @@
<div class="row">
<div class="col12">
<div class="block">
<h4><?php echo helper::translate('Paramètres'); ?>
<h4>
<?php echo helper::translate('Permissions'); ?>
</h4>
<div class="row">
<div class="col6">
<?php echo template::select('userAddLanguage', $module::$languagesInstalled, [
'label' => 'Langues'
]); ?>
</div>
<div class="row ">
<div class="col6">
<?php echo template::select('userAddGroup', self::$groupNews, [
'label' => 'Groupe',
'selected' => self::GROUP_MEMBER
]); ?>
<div id="userAddMemberFiles" class="displayNone">
<?php echo template::checkbox('userAddFiles', true, 'Partage de fichiers autorisé', [
'checked' => false,
'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers'
</div>
<div class="col3">
<div class="userAddGroupDescription displayNone" id="userAddGroupDescription<?php echo self::GROUP_MEMBER; ?>">
<?php echo template::select('userAddProfil' . self::GROUP_MEMBER, $module::$userProfils[self::GROUP_MEMBER], [
'label' => 'Profil',
]); ?>
</div>
<div id="userAddLabelAuth">
<?php echo helper::translate('Permissions :'); ?>
</div>
<ul id="userAddGroupDescription<?php echo self::GROUP_MEMBER; ?>" class="userAddGroupDescription displayNone">
<li><?php echo helper::translate('Accès aux pages privées'); ?></li>
</ul>
<ul id="userAddGroupDescription<?php echo self::GROUP_MODERATOR; ?>" class="userAddGroupDescription displayNone">
<li><?php echo helper::translate('Accès aux pages privées'); ?></li>
<li><?php echo helper::translate('Ajout - Édition - Suppression de pages'); ?></li>
<li><?php echo helper::translate('Ajout - Édition - Suppression de fichiers'); ?></li>
</ul>
<ul id="userAddGroupDescription<?php echo self::GROUP_ADMIN; ?>" class="userAddGroupDescription displayNone">
<li><?php echo helper::translate('Administration complète du site'); ?></li>
</ul>
<div class="col3">
<div class="userAddGroupDescription displayNone" id="userAddGroupDescription<?php echo self::GROUP_MODERATOR; ?>">
<?php echo template::select('userAddProfil' . self::GROUP_MODERATOR, $module::$userProfils[self::GROUP_MODERATOR], [
'label' => 'Profil',
]); ?>
</div>
</div>
</div>
</div>

View File

@ -10,4 +10,41 @@
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
$("#userEditGroup").on("change",(function(){$(".userEditGroupDescription").hide(),$("#userEditGroupDescription"+$(this).val()).show(),$("#userEditGroup option:selected").val()<0?$("#userEditLabelAuth").css("display","none"):$("#userEditLabelAuth").css("display","inline-block")})).trigger("change"),$(document).ready((function(){"1"===$("#userEditGroup").val()?$("#userEditMemberFiles").slideDown():$("#userEditMemberFiles").slideUp((function(){$("#userEditFiles").prop("checked",!1).trigger("change")}))})),$("#userEditGroup").on("change",(function(){"1"===$("#userEditGroup").val()?$("#userEditMemberFiles").slideDown():$("#userEditMemberFiles").slideUp((function(){$("#userEditFiles").prop("checked",!1).trigger("change")}))})).trigger("change");
/**
* Droits des groupes
*/
$("#userEditGroup").on("change", function() {
$(".userEditGroupDescription").hide();
$("#userEditGroupDescription" + $(this).val()).show();
if ($("#userEditGroup option:selected").val() < 0) {
$("#userEditLabelAuth").css("display","none");
} else {
$("#userEditLabelAuth").css("display","inline-block");
}
}).trigger("change");
$(document).ready(function(){
// Membre avec ou sans gestion de fichiers
if($("#userEditGroup").val() === '1') {
$("#userEditMemberFiles").slideDown();
}
else {
$("#userEditMemberFiles").slideUp(function() {
$("#userEditFiles").prop("checked", false).trigger("change");
});
}
});
$("#userEditGroup").on("change", function() {
// Membre avec ou sans gestion de fichiers
if($("#userEditGroup").val() === '1') {
$("#userEditMemberFiles").slideDown();
}
else {
$("#userEditMemberFiles").slideUp(function() {
$("#userEditFiles").prop("checked", false).trigger("change");
});
}
}).trigger("change");

View File

@ -43,20 +43,30 @@
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::text('userEditPseudo', [
'autocomplete' => 'off',
'label' => 'Pseudo',
'value' => $this->getData(['user', $this->getUrl(2), 'pseudo'])
]); ?>
</div>
<div class="col6">
<?php echo template::select('userEditSignature', $module::$signature, [
'label' => 'Signature',
'selected' => $this->getData(['user', $this->getUrl(2), 'signature'])
]); ?>
</div>
</div>
<?php echo template::mail('userEditMail', [
'autocomplete' => 'off',
'label' => 'Adresse électronique',
'value' => $this->getData(['user', $this->getUrl(2), 'mail'])
]); ?>
<?php echo template::select('userEditLanguage', $module::$languagesInstalled, [
'label' => 'Langue',
'selected' => $this->getData(['user', $this->getUser('id'), 'language'])
]); ?>
</div>
</div>
<div class="col6">
@ -91,15 +101,9 @@
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Paramètres'); ?>
<?php echo helper::translate('Permissions'); ?>
</h4>
<div class="row">
<div class="col6">
<?php echo template::select('userEditLanguage', $module::$languagesInstalled, [
'label' => 'Langues',
'selected' => $this->getData(['user', $this->getUser('id'), 'language'])
]); ?>
</div>
<div class="col6">
<?php if ($this->getUser('group') === self::GROUP_ADMIN): ?>
<?php echo template::select('userEditGroup', self::$groupEdits, [
@ -108,40 +112,23 @@
'label' => 'Groupe',
'selected' => $this->getData(['user', $this->getUrl(2), 'group'])
]); ?>
<div id="userEditMemberFiles" class="displayNone">
<?php echo template::checkbox('userEditFiles', true, 'Partage de fichiers autorisé', [
'checked' => $this->getData(['user', $this->getUrl(2), 'files']),
'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers'
<?php if ($this->getData(['user', $this->getUrl(2), 'group']) === self::GROUP_MEMBER): ?>
<div class="col6">
<?php echo template::select('userEditProfil', $module::$userProfils[self::GROUP_MEMBER], [
'label' => 'Profil',
'selected' => $this->getData(['user', $this->getUser('id'), 'profil'])
]); ?>
</div>
<div id="userEditLabelAuth">
<?php echo helper::translate('Permissions :'); ?>
</div>
<ul id="userEditGroupDescription<?php echo self::GROUP_MEMBER; ?>"
class="userEditGroupDescription displayNone">
<li>
<?php echo helper::translate('Accès aux pages privées'); ?>
</li>
</ul>
<ul id="userEditGroupDescription<?php echo self::GROUP_MODERATOR; ?>"
class="userEditGroupDescription displayNone">
<li>
<?php echo helper::translate('Accès aux pages privées'); ?>
</li>
<li>
<?php echo helper::translate('Ajout - Édition - Suppression de pages'); ?>
</li>
<li>
<?php echo helper::translate('Ajout - Édition - Suppression de fichiers'); ?>
</li>
</ul>
<ul id="userEditGroupDescription<?php echo self::GROUP_ADMIN; ?>"
class="userEditGroupDescription displayNone">
<li>
<?php echo helper::translate('Administration complète du site'); ?>
</li>
</ul>
<?php endif; ?>
<?php if ($this->getData(['user', $this->getUrl(2), 'group']) === self::GROUP_MEMBER): ?>
<div class="col6">
<?php echo template::select('userEditProfil', $module::$userProfils[self::GROUP_MODERATOR], [
'label' => 'Profil',
'selected' => $this->getData(['user', $this->getUser('id'), 'profil'])
]); ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>