Edition des tags

This commit is contained in:
Fred Tempez 2024-09-04 18:03:50 +02:00
parent 4444c58902
commit 1aca92b1c7
6 changed files with 332 additions and 45 deletions

View File

@ -32,6 +32,7 @@ class user extends common
'profilEdit' => self::GROUP_ADMIN,
'profilAdd' => self::GROUP_ADMIN,
'profilDelete' => self::GROUP_ADMIN,
'tag' => self::GROUP_ADMIN,
];
public static $users = [];
@ -262,9 +263,9 @@ class user extends common
if (
$this->getData(['user', $keyPost]) !== null
) {
if ($keyPost === $this->getUser('id')) {
$notification = helper::translate('Votre compte n\'a pas été supprimé !') . '<br />' . $notification ;
$notification = helper::translate('Votre compte n\'a pas été supprimé !') . '<br />' . $notification;
$success = 1;
} else {
$this->deleteData(['user', $keyPost]);
@ -275,7 +276,7 @@ class user extends common
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user/usersDelete',
'notification' => sprintf($count > 1 ? $notification . 's': $notification , $count),
'notification' => sprintf($count > 1 ? $notification . 's' : $notification, $count),
'state' => $success
]);
@ -1146,12 +1147,12 @@ class user extends common
// Exclure les espaces des cours
/*
foreach (array_keys($this->getData(['course'])) as $courseId) {
self::$sharePath = array_filter(self::$sharePath, function ($key) use ($courseId) {
return strpos($key, $courseId) === false;
});
}
*/
foreach (array_keys($this->getData(['course'])) as $courseId) {
self::$sharePath = array_filter(self::$sharePath, function ($key) use ($courseId) {
return strpos($key, $courseId) === false;
});
}
*/
self::$sharePath = array_flip(self::$sharePath);
self::$sharePath = array_merge(['none' => 'Aucun Accès'], self::$sharePath);
@ -1302,7 +1303,7 @@ class user extends common
// RAZ
$this->setData(['user', $userId, 'connectFail', 0]);
$this->setData(['user', $userId, 'connectTimeout', 0]);
// Validité du cookie
$expire = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? strtotime("+1 year") : 0;
switch ($this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN)) {
@ -1648,6 +1649,125 @@ class user extends common
}
public function tag()
{
// Contenu sélectionné
$courseId = $this->getUrl(2);
// Accès limité aux admins, à l'auteur ou éditeurs inscrits
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
}
// Liste des groupes et des profils
$usersGroups = $this->getData(['profil']);
foreach ($usersGroups as $groupId => $groupValue) {
switch ($groupId) {
case "-1":
case "0":
break;
case "3":
self::$usersGroups['30'] = 'Administrateur';
$profils['30'] = 0;
break;
case "1":
case "2":
foreach ($groupValue as $profilId => $profilValue) {
if ($profilId) {
self::$usersGroups[$groupId . $profilId] = sprintf(helper::translate('Groupe %s - Profil %s'), self::$groupPublics[$groupId], $profilValue['name']);
$profils[$groupId . $profilId] = 0;
}
}
}
}
// Liste alphabétique
self::$alphabet = range('A', 'Z');
$alphabet = range('A', 'Z');
self::$alphabet = array_combine($alphabet, self::$alphabet);
self::$alphabet = array_merge(['all' => 'Tout'], self::$alphabet);
// Liste des inscrits dans le contenu sélectionné.
$users = $this->getData(['user']);
if (is_array($users)) {
// Tri du tableau par défaut par $userId
ksort($users);
foreach ($users as $userId => $userValue) {
// Compte les rôles
if (isset($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) {
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
}
// Filtres
if (
isset($_POST['usersFilterGroup'])
|| isset($_POST['usersFilterFirstName'])
|| isset($_POST['usersFilterLastName'])
) {
// Groupe et profils
$group = (string) $this->getData(['user', $userId, 'group']);
$profil = (string) $this->getData(['user', $userId, 'profil']);
$firstName = $this->getData(['user', $userId, 'firstname']);
$lastName = $this->getData(['user', $userId, 'lastname']);
if (
$this->getInput('usersFilterGroup', helper::FILTER_INT) > 0
&& $this->getInput('usersFilterGroup', helper::FILTER_STRING_SHORT) !== $group . $profil
)
continue;
// Première lettre du prénom
if (
$this->getInput('usersFilterFirstName', helper::FILTER_STRING_SHORT) !== 'all'
&& $this->getInput('usersFilterFirstName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($firstName, 0, 1))
)
continue;
// Première lettre du nom
if (
$this->getInput('usersFilterLastName', helper::FILTER_STRING_SHORT) !== 'all'
&& $this->getInput('usersFilterLastName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($lastName, 0, 1))
)
continue;
}
// Construction du tableau
self::$users[] = [
template::checkbox($userId, true, '', ['class' => 'checkboxSelect']),
$userId,
$this->getData(['user', $userId, 'firstname']),
$this->getData(['user', $userId, 'lastname']),
$this->getData(['user', $userId, 'tags']),
];
}
}
// Ajoute les effectifs aux profils du sélecteur
foreach (self::$usersGroups as $groupId => $groupValue) {
if ($groupId === 'all') {
self::$usersGroups['all'] = self::$usersGroups['all'] . ' (' . array_sum($profils) . ')';
} else {
self::$usersGroups[$groupId] = self::$usersGroups[$groupId] . ' (' . $profils[$groupId] . ')';
}
}
// Valeurs en sortie
$this->addOutput([
'view' => 'tag',
'title' => 'Étiquettes',
'vendor' => [
'datatables'
]
]);
}
/**
* Liste les dossier contenus dans RFM
*/

View File

@ -6,38 +6,7 @@
'value' => template::ico('home')
]); ?>
</div>
<div class="col1">
<?php /**echo template::button('userHelp', [
'href' => 'https://doc.zwiicms.fr/gestion-des-utilisateurs',
'target' => '_blank',
'value' => template::ico('help'),
'class' => 'buttonHelp',
'help' => 'Consulter l\'aide en ligne'
]);*/ ?>
</div>
<div class="col1 offset6">
<?php echo template::button('userImport', [
'href' => helper::baseUrl() . 'user/import',
'value' => template::ico('users'),
'help' => 'Importer des utilisateurs en masse'
]); ?>
</div>
<div class="col1">
<?php echo template::button('userDeleteAll', [
'class' => 'userDeleteAll buttonRed',
'href' => helper::baseUrl() . 'user/usersDelete/' . $this->getUrl(2),
'value' => template::ico('users'),
'help' => 'Désinscrire en masse',
]) ?>
</div>
<div class="col1">
<?php echo template::button('userGroup', [
'href' => helper::baseUrl() . 'user/profil',
'value' => template::ico('lock'),
'help' => 'Profils'
]); ?>
</div>
<div class="col1">
<div class="col1 offset2">
<?php echo template::button('userAdd', [
'href' => helper::baseUrl() . 'user/add',
'value' => template::ico('plus'),
@ -45,6 +14,35 @@
'help' => 'Ajouter un utilisateur'
]); ?>
</div>
<div class="col2 ">
<?php echo template::button('userImport', [
'href' => helper::baseUrl() . 'user/import',
'ico' => 'users',
'value' => 'Importer en masse'
]); ?>
</div>
<div class="col2">
<?php echo template::button('userDeleteAll', [
'class' => 'userDeleteAll buttonRed',
'href' => helper::baseUrl() . 'user/usersDelete/' . $this->getUrl(2),
'ico' => 'users',
'value' => 'Désinscrire en masse',
]) ?>
</div>
<div class="col2">
<?php echo template::button('userTag', [
'href' => helper::baseUrl() . 'user/tag',
'ico' => '#',
'value' => 'Étiquettes'
]); ?>
</div>
<div class="col2">
<?php echo template::button('userGroup', [
'href' => helper::baseUrl() . 'user/profil',
'ico' => 'lock',
'value' => 'Profils'
]); ?>
</div>
</div>
<?php echo template::formOpen('userFilterUserForm'); ?>
<div class="row">

View File

@ -0,0 +1,18 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
*/

View File

@ -0,0 +1,100 @@
/**
* This file is part of Zwii.
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
$(document).ready((function () {
$('tr').click(function () {
// Cochez ou décochez la case à cocher dans cette ligne
$(this).find('input[type="checkbox"]').prop('checked', function (i, val) {
return !val; // Inverse l'état actuel de la case à cocher
});
});
$('#usersTagSelectAll').on('click', function () {
$('.checkboxSelect').prop('checked', true);
saveCheckboxState();
});
$('#usersTagSelectNone').on('click', function () {
$('.checkboxSelect').prop('checked', false);
saveCheckboxState();
});
$("#usersFilterGroup, #usersFilterFirstName, #usersFilterLastName").change(function () {
saveCheckboxState();
$("#usersTagForm").submit();
});
var table = $('#dataTables').DataTable({
language: {
url: "core/vendor/datatables/french.json"
},
locale: 'fr',
"columnDefs": [
{
target: 0,
orderable: false,
searchable: false,
}
]
});
// Handle checkbox change event
$('.checkboxSelect').on('change', function () {
// Save checkbox state to cookies or local storage
saveCheckboxState();
});
// Handle checkbox state on DataTables draw event
table.on('draw', function () {
// Restore checkbox state from cookies or local storage
restoreCheckboxState();
});
// Empty local storage after submit
$("#usersTagSubmit").on("click", function () {
localStorage.setItem('checkboxState', JSON.stringify({}));
});
// Restore checkbox state on page load
restoreCheckboxState();
function saveCheckboxState() {
// Récupérer d'abord les données existantes dans le localStorage
var existingData = JSON.parse(localStorage.getItem('checkboxState')) || {};
// Ajouter ou mettre à jour les données actuelles
$('.checkboxSelect').each(function () {
var checkboxId = $(this).attr('id');
var checked = $(this).prop('checked');
existingData[checkboxId] = checked;
});
// Sauvegarder les données mises à jour dans le localStorage
localStorage.setItem('checkboxState', JSON.stringify(existingData));
}
// Function to restore checkbox state
function restoreCheckboxState() {
var checkboxState = JSON.parse(localStorage.getItem('checkboxState')) || {};
// console.log(checkboxState);
for (var checkboxId in checkboxState) {
if (checkboxState.hasOwnProperty(checkboxId)) {
var checked = checkboxState[checkboxId];
// Update checkbox state based on stored information
$('#' + checkboxId).prop('checked', checked);
}
}
}
}));

View File

@ -0,0 +1,51 @@
<?php echo template::formOpen('usersTagForm'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('userDeleteBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'user/' . $this->getUrl(2),
'value' => template::ico('left')
]); ?>
</div>
<div class="col1 offset7">
<?php echo template::button('usersTagSelectAll', [
'value' => template::ico('square-check'),
'help' => 'Tout sélectionner'
]); ?>
</div>
<div class="col1">
<?php echo template::button('usersTagSelectNone', [
'value' => template::ico('square-check-empty'),
'help' => 'Tout désélectionner'
]); ?>
</div>
<div class="col2">
<?php echo template::submit('usersTagSubmit'); ?>
</div>
</div>
<div class="row" id="Bfrtip">
<div class="col3">
<?php echo template::select('usersFilterGroup', $module::$usersGroups, [
'label' => 'Groupes / Profils',
'selected' => isset($_POST['usersFilterGroup']) ? $_POST['usersFilterGroup'] : 'all',
]); ?>
</div>
<div class="col3">
<?php echo template::select('usersFilterFirstName', $module::$alphabet, [
'label' => 'Prénom commence par',
'selected' => isset($_POST['usersFilterFirstName']) ? $_POST['usersFilterFirstName'] : 'all',
]); ?>
</div>
<div class="col3">
<?php echo template::select('usersFilterLastName', $module::$alphabet, [
'label' => 'Nom commence par',
'selected' => isset($_POST['usersFilterLastName']) ? $_POST['usersFilterLastName'] : 'all',
]); ?>
</div>
</div>
<?php if ($module::$users): ?>
<?php echo template::table([1, 2, 3, 3, 3], $module::$users, ['', 'Id', 'Prénom', 'Nom', 'Étiquettes'], ['id' => 'dataTables']); ?>
<?php else: ?>
<?php echo template::speech('Aucun inscrit'); ?>
<?php endif; ?>
<?php echo template::formClose(); ?>

View File

@ -19,14 +19,14 @@
'help' => 'Tout désélectionner'
]); ?>
</div>
<div class="col1">
<div class="col1">
<?php echo template::submit('usersDeleteSubmit', [
'class' => 'buttonRed',
'ico' => '',
'value' => template::ico('minus'),
]); ?>
</div>
</div>
</div>
<div class="row" id="Bfrtip">
<div class="col3">
<?php echo template::select('usersFilterGroup', $module::$usersGroups, [
@ -48,7 +48,7 @@
</div>
</div>
<?php if ($module::$users): ?>
<?php echo template::table([1, 2, 3, 3, 3], $module::$users, ['', 'Id', 'Prénom', 'Nom', 'Étiquettes'], ['id' => 'dataTables']); ?>
<?php echo template::table([1, 2, 3, 3, 3], $module::$users, ['', 'Id', 'Prénom', 'Nom', 'Étiquettes'], ['id' => 'dataTables']); ?>
<?php else: ?>
<?php echo template::speech('Aucun inscrit'); ?>
<?php endif; ?>