From b85327491d46e0dfa906002f11c0f525e94f6f42 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Sat, 7 Oct 2023 18:30:43 +0200 Subject: [PATCH] =?UTF-8?q?v26=20d=C3=A9sinscription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 2 +- core/module/course/course.php | 74 ++++++++++++++++++------ core/module/course/view/user/user.js.php | 13 +++++ core/module/course/view/user/user.php | 4 +- 4 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 core/module/course/view/user/user.js.php diff --git a/core/core.php b/core/core.php index e10cb9c..d67b868 100644 --- a/core/core.php +++ b/core/core.php @@ -50,7 +50,7 @@ class common const ACCESS_TIMER = 1800; // Numéro de version - const ZWII_VERSION = '1.0.25'; + const ZWII_VERSION = '1.0.26'; // URL autoupdate const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/update/raw/branch/master/lms/'; diff --git a/core/module/course/course.php b/core/module/course/course.php index 59c9ffc..0911cb6 100644 --- a/core/module/course/course.php +++ b/core/module/course/course.php @@ -28,6 +28,7 @@ class course extends common 'categoryDelete' => self::GROUP_ADMIN, 'user' => self::GROUP_ADMIN, 'userAdd' => self::GROUP_ADMIN, + 'userDelete' => self::GROUP_ADMIN, ]; public static $courseAccess = [ @@ -340,23 +341,34 @@ class course extends common public function categoryDelete() { - $categories = helper::arrayColumn($this->getData(['course']), 'category', 'SORT_ASC'); - $courseId = $this->getUrl(2); - $message = helper::translate('Une catégorie affectée ne peut pas être effacée'); - $state = false; - if (in_array($courseId, $categories) === false) { - $this->deleteData(['category', $this->getUrl(2)]); + // Accès refusé + if ( + $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { // Valeurs en sortie - $message = helper::translate('Catégorie effacée'); - $state = true; + $this->addOutput([ + 'access' => false + ]); + } else { + $categories = helper::arrayColumn($this->getData(['course']), 'category', 'SORT_ASC'); + $courseId = $this->getUrl(2); + $message = helper::translate('Une catégorie affectée ne peut pas être effacée'); + $state = false; + if (in_array($courseId, $categories) === false) { + $this->deleteData(['category', $this->getUrl(2)]); + // Valeurs en sortie + $message = helper::translate('Catégorie effacée'); + $state = true; + } + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'course/category', + 'notification' => $message, + 'state' => $state + ]); } - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'course/category', - 'notification' => $message, - 'state' => $state - ]); } public function user() @@ -369,11 +381,11 @@ class course extends common $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']), $userValue['lastPageId'], helper::dateUTF8('%d %B %Y - %H:%M', $userValue['dateVisit']), - template::button('courseDelete' . $userId, [ - 'class' => 'categoryDelete buttonRed', - 'href' => helper::baseUrl() . 'course/userDelete/' . $userId, - 'value' => template::ico('trash'), - 'help' => 'Supprimer' + template::button('userDelete' . $userId, [ + 'class' => 'userDelete buttonRed', + 'href' => helper::baseUrl() . 'course/userDelete/'. $this->getUrl(2) . '/' . $userId, + 'value' => template::ico('minus'), + 'help' => 'Désinscrire' ]) ]; } @@ -394,6 +406,30 @@ class course extends common ]); } + /** + * Désinscription d'un utilisateur + */ + public function userDelete() + { + // Accès refusé + if ( + $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + $this->deleteData(['enrolment', $this->getUrl(2), $this->getUrl(3)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'course/user/' . $this->getUrl(2), + 'notification' => sprintf(helper::translate('%s est désinscrit'), $this->getUrl(3)), + 'state' => true + ]); + } + } + /* * Traitement du changement de langue */ diff --git a/core/module/course/view/user/user.js.php b/core/module/course/view/user/user.js.php new file mode 100644 index 0000000..edc1f1f --- /dev/null +++ b/core/module/course/view/user/user.js.php @@ -0,0 +1,13 @@ +/** + * 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 + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2023, Frédéric Tempez + * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International + * @link http://zwiicms.fr/ + */ +$(".userDelete").on("click", (function () { var _this = $(this); return message = "", core.confirm(message, (function () { $(location).attr("href", _this.attr("href")) })) })); \ No newline at end of file diff --git a/core/module/course/view/user/user.php b/core/module/course/view/user/user.php index 50836d9..a543ccb 100644 --- a/core/module/course/view/user/user.php +++ b/core/module/course/view/user/user.php @@ -7,11 +7,11 @@ ]); ?>
- 'buttonGreen', 'href' => helper::baseUrl() . 'course/userAdd', 'value' => template::ico('plus') - ]); ?> + ]); */?>