forked from ZwiiCMS-Team/ZwiiCampus
Désincription en masse
This commit is contained in:
parent
44e913a781
commit
b73963d5df
@ -539,7 +539,7 @@ class course extends common
|
|||||||
template::button('userDelete' . $userId, [
|
template::button('userDelete' . $userId, [
|
||||||
'class' => 'userDelete buttonRed',
|
'class' => 'userDelete buttonRed',
|
||||||
'href' => helper::baseUrl() . 'course/userDelete/' . $courseId . '/' . $userId,
|
'href' => helper::baseUrl() . 'course/userDelete/' . $courseId . '/' . $userId,
|
||||||
'value' => template::ico('trash'),
|
'value' => template::ico('user'),
|
||||||
'help' => 'Désinscrire'
|
'help' => 'Désinscrire'
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
@ -711,23 +711,119 @@ class course extends common
|
|||||||
*/
|
*/
|
||||||
public function usersDelete()
|
public function usersDelete()
|
||||||
{
|
{
|
||||||
// Accès refusé
|
|
||||||
|
// Contenu sélectionné
|
||||||
|
$courseId = $this->getUrl(2);
|
||||||
|
|
||||||
|
// Inscription des utilisateurs cochés
|
||||||
if (
|
if (
|
||||||
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
|
isset($_POST['courseUsersDeleteSubmit'])
|
||||||
) {
|
) {
|
||||||
// Valeurs en sortie
|
foreach ($_POST as $keyPost => $valuePost) {
|
||||||
$this->addOutput([
|
// Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits
|
||||||
'access' => false
|
if (
|
||||||
]);
|
$this->getData(['user', $keyPost]) !== null
|
||||||
} else {
|
&& $this->getData(['enrolment', $courseId, $keyPost]) !== null
|
||||||
$this->setData(['enrolment', $this->getUrl(2), array()]);
|
) {
|
||||||
// Valeurs en sortie
|
$this->deleteData(['enrolment', $courseId, $keyPost]);
|
||||||
$this->addOutput([
|
}
|
||||||
'redirect' => helper::baseUrl() . 'course/user/' . $this->getUrl(2),
|
}
|
||||||
'notification' => helper::translate('Contenu réinitialisé'),
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Liste des groupes et des profils
|
||||||
|
$courseGroups = $this->getData(['profil']);
|
||||||
|
foreach ($courseGroups as $groupId => $groupValue) {
|
||||||
|
switch ($groupId) {
|
||||||
|
case "-1":
|
||||||
|
case "0":
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
self::$courseGroups['30'] = 'Administrateur';
|
||||||
|
$profils['30'] = 0;
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
case "2":
|
||||||
|
foreach ($groupValue as $profilId => $profilValue) {
|
||||||
|
if ($profilId) {
|
||||||
|
self::$courseGroups[$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(['enrolment', $courseId]);
|
||||||
|
|
||||||
|
// Tri du tableau par défaut par $userId
|
||||||
|
ksort($users);
|
||||||
|
|
||||||
|
foreach ($users as $userId => $userValue) {
|
||||||
|
|
||||||
|
// Compte les rôles
|
||||||
|
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
|
||||||
|
|
||||||
|
// Filtres
|
||||||
|
if (
|
||||||
|
isset($_POST['courseFilterGroup'])
|
||||||
|
|| isset($_POST['courseFilterFirstName'])
|
||||||
|
|| isset($_POST['courseFilterLastName'])
|
||||||
|
) {
|
||||||
|
|
||||||
|
// 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('courseFilterGroup', helper::FILTER_INT) > 0
|
||||||
|
&& $this->getInput('courseFilterGroup', helper::FILTER_STRING_SHORT) !== $group . $profil
|
||||||
|
)
|
||||||
|
continue;
|
||||||
|
// Première lettre du prénom
|
||||||
|
if (
|
||||||
|
$this->getInput('courseFilterFirstName', helper::FILTER_STRING_SHORT) !== 'all'
|
||||||
|
&& $this->getInput('courseFilterFirstName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($firstName, 0, 1))
|
||||||
|
)
|
||||||
|
continue;
|
||||||
|
// Première lettre du nom
|
||||||
|
if (
|
||||||
|
$this->getInput('courseFilterLastName', helper::FILTER_STRING_SHORT) !== 'all'
|
||||||
|
&& $this->getInput('courseFilterLastName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($lastName, 0, 1))
|
||||||
|
)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construction du tableau
|
||||||
|
self::$courseUsers[] = [
|
||||||
|
$userId,
|
||||||
|
$this->getData(['user', $userId, 'firstname']),
|
||||||
|
$this->getData(['user', $userId, 'lastname']),
|
||||||
|
template::checkbox($userId, true, '', ['class' => 'checkboxSelect'])
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajoute les effectifs aux profils du sélecteur
|
||||||
|
foreach (self::$courseGroups as $groupId => $groupValue) {
|
||||||
|
if ($groupId === 'all') {
|
||||||
|
self::$courseGroups['all'] = self::$courseGroups['all'] . ' (' . array_sum($profils) . ')';
|
||||||
|
} else {
|
||||||
|
self::$courseGroups[$groupId] = self::$courseGroups[$groupId] . ' (' . $profils[$groupId] . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valeurs en sortie
|
||||||
|
$this->addOutput([
|
||||||
|
'title' => helper::translate('Désincription en masse'),
|
||||||
|
'view' => 'usersDelete'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -21,12 +21,6 @@ $(document).ready((function () {
|
|||||||
$(location).attr("href", _this.attr("href"))
|
$(location).attr("href", _this.attr("href"))
|
||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
$(".userDeleteAll").on("click", (function () {
|
|
||||||
var _this = $(this);
|
|
||||||
return message = "<?php echo helper::translate('Confirmer la désinscription de tous les utilisateur');?>", core.confirm(message, (function () {
|
|
||||||
$(location).attr("href", _this.attr("href"))
|
|
||||||
}))
|
|
||||||
}));
|
|
||||||
|
|
||||||
$('#dataTables').DataTable({
|
$('#dataTables').DataTable({
|
||||||
language: {
|
language: {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
<?php echo template::button('userDeleteAll', [
|
<?php echo template::button('userDeleteAll', [
|
||||||
'class' => 'userDeleteAll buttonRed',
|
'class' => 'userDeleteAll buttonRed',
|
||||||
'href' => helper::baseUrl() . 'course/usersDelete/' . $this->getUrl(2),
|
'href' => helper::baseUrl() . 'course/usersDelete/' . $this->getUrl(2),
|
||||||
'value' => template::ico('trash'),
|
'value' => template::ico('users'),
|
||||||
'help' => 'Désinscrire tous les utilisateurs',
|
'help' => 'Désinscrire en masse',
|
||||||
])?>
|
])?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col1">
|
<div class="col1">
|
||||||
@ -26,7 +26,7 @@
|
|||||||
'class' => 'buttonGreen',
|
'class' => 'buttonGreen',
|
||||||
'href' => helper::baseUrl() . 'course/usersAdd/' . $this->getUrl(2),
|
'href' => helper::baseUrl() . 'course/usersAdd/' . $this->getUrl(2),
|
||||||
'value' => template::ico('users'),
|
'value' => template::ico('users'),
|
||||||
'help' => 'Inscription',
|
'help' => 'Inscription en masse',
|
||||||
]) ?>
|
]) ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
18
core/module/course/view/usersDelete/usersDelete.css
Normal file
18
core/module/course/view/usersDelete/usersDelete.css
Normal 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-2023, Frédéric Tempez
|
||||||
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
||||||
|
* @link http://zwiicms.fr/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** NE PAS EFFACER
|
||||||
|
* admin.css
|
||||||
|
*/
|
86
core/module/course/view/usersDelete/usersDelete.js.php
Normal file
86
core/module/course/view/usersDelete/usersDelete.js.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* 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-2023, Frédéric Tempez
|
||||||
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
||||||
|
* @link http://zwiicms.fr/
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(document).ready((function () {
|
||||||
|
|
||||||
|
|
||||||
|
$("#courseFilterGroup, #courseFilterFirstName, #courseFilterLastName").change(function () {
|
||||||
|
saveCheckboxState();
|
||||||
|
$("#courseUsersDeleteForm").submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
var table = $('#dataTables').DataTable({
|
||||||
|
language: {
|
||||||
|
url: "core/vendor/datatables/french.json"
|
||||||
|
},
|
||||||
|
"columnDefs": [
|
||||||
|
{
|
||||||
|
target: 3,
|
||||||
|
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
|
||||||
|
$("#courseUsersDeleteSubmit").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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
42
core/module/course/view/usersDelete/usersDelete.php
Normal file
42
core/module/course/view/usersDelete/usersDelete.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php echo template::formOpen('courseUsersDeleteForm'); ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col1">
|
||||||
|
<?php echo template::button('courseUserAddBack', [
|
||||||
|
'class' => 'buttonGrey',
|
||||||
|
'href' => helper::baseUrl() . 'course/users/' . $this->getUrl(2),
|
||||||
|
'value' => template::ico('left')
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col2 offset10">
|
||||||
|
<?php echo template::submit('courseUsersDeleteSubmit', [
|
||||||
|
'class' => 'buttonRed',
|
||||||
|
'value' => 'Désinscrire'
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
<div class="row" id="Bfrtip">
|
||||||
|
<div class="col3">
|
||||||
|
<?php echo template::select('courseFilterGroup', $module::$courseGroups, [
|
||||||
|
'label' => 'Groupes / Profils',
|
||||||
|
'selected' => isset($_POST['courseFilterGroup']) ? $_POST['courseFilterGroup'] : 'all',
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
<div class="col3">
|
||||||
|
<?php echo template::select('courseFilterFirstName', $module::$alphabet, [
|
||||||
|
'label' => 'Prénom commence par',
|
||||||
|
'selected' => isset($_POST['courseFilterFirstName']) ? $_POST['courseFilterFirstName'] : 'all',
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
<div class="col3">
|
||||||
|
<?php echo template::select('courseFilterLastName', $module::$alphabet, [
|
||||||
|
'label' => 'Nom commence par',
|
||||||
|
'selected' => isset($_POST['courseFilterLastName']) ? $_POST['courseFilterLastName'] : 'all',
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php if ($module::$courseUsers): ?>
|
||||||
|
<?php echo template::table([4, 4, 4, 1], $module::$courseUsers, ['Id', 'Prénom', 'Nom', ''], ['id' => 'dataTables']); ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php echo template::speech('Aucun inscrit'); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php echo template::formClose(); ?>
|
Loading…
Reference in New Issue
Block a user