From 727f8123c0bfd6e08ecb62a8b281dd654e4946e6 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Thu, 21 Sep 2023 19:32:30 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=B4les=20renomm=C3=A9s,=20fonctions=20pour?= =?UTF-8?q?=20d=C3=A9terminer=20les=20droits=20d'acc=C3=A8s=20=C3=A0=20un?= =?UTF-8?q?=20cours,=20le=20sous=20ensembles=20teacher=20et=20students=20s?= =?UTF-8?q?ont=20supprim=C3=A9s=20dans=20enrolment,=20le=20profil=20et=20l?= =?UTF-8?q?e=20groupe=20moodle=20comptent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/layout.class.php | 6 +- core/class/router.class.php | 4 +- core/core.php | 82 +++++++------------ core/layout/main.php | 4 +- core/module/course/course.php | 32 +++----- core/module/course/view/change/change.php | 3 +- core/module/install/install.php | 4 +- core/module/install/ressource/defaultdata.php | 16 ++-- core/module/maintenance/maintenance.php | 2 +- core/module/page/page.php | 4 +- core/module/page/view/edit/edit.php | 4 +- core/module/sitemap/sitemap.php | 2 +- core/module/user/user.php | 24 +++--- core/module/user/view/add/add.php | 12 +-- core/module/user/view/edit/edit.php | 10 +-- module/blog/blog.php | 4 +- module/form/form.php | 2 +- module/gallery/gallery.php | 2 +- module/news/news.php | 4 +- module/redirection/redirection.php | 2 +- module/search/search.php | 2 +- module/slider/slider.php | 2 +- notes.txt | 11 +-- 23 files changed, 104 insertions(+), 134 deletions(-) diff --git a/core/class/layout.class.php b/core/class/layout.class.php index 1fc299e..da1e482 100644 --- a/core/class/layout.class.php +++ b/core/class/layout.class.php @@ -345,7 +345,7 @@ class layout extends common } // Affichage de la barre de membre simple if ( - $this->getUser('group') >= self::GROUP_STUDENT && $this->getUser('group') < self::GROUP_ADMIN + $this->getUser('group') >= self::GROUP_TUTOR && $this->getUser('group') < self::GROUP_ADMIN && $this->getData(['theme', 'footer', 'memberBar']) === true ) { $items .= 'getUser('group') >= self::GROUP_STUDENT && $this->getUser('group') < self::GROUP_ADMIN + $this->getUser('group') >= self::GROUP_TUTOR && $this->getUser('group') < self::GROUP_ADMIN && $this->getData(['theme', 'menu', 'memberBar']) === true ) { if ( - $this->getUser('group') >= self::GROUP_STUDENT && + $this->getUser('group') >= self::GROUP_TUTOR && $this->getUser('permission', 'filemanager') === true ) { $itemsRight .= '
  • ' . template::ico('folder', [ diff --git a/core/class/router.class.php b/core/class/router.class.php index 42d1723..7d306d2 100644 --- a/core/class/router.class.php +++ b/core/class/router.class.php @@ -527,7 +527,7 @@ class core extends common $access = null; if ($this->getData(['page', $this->getUrl(0)]) !== null) { if ( - $this->getData(['page', $this->getUrl(0), 'group']) === self::GROUP_VISITOR + $this->getData(['page', $this->getUrl(0), 'group']) === self::GROUP_STUDENT or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') // and $this->getUser('group') >= $this->getData(['page', $this->getUrl(0), 'group']) // Modification qui tient compte du profil de la page @@ -705,7 +705,7 @@ class core extends common $output = $module->output; // Check le groupe de l'utilisateur if ( - ($module::$actions[$action] === self::GROUP_VISITOR + ($module::$actions[$action] === self::GROUP_STUDENT or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') and $this->getUser('group') >= $module::$actions[$action] and $this->getUser('permission', $moduleId, $action) diff --git a/core/core.php b/core/core.php index 8b35cda..0050cf4 100644 --- a/core/core.php +++ b/core/core.php @@ -25,8 +25,8 @@ class common const DISPLAY_LAYOUT_MAIN = 4; const DISPLAY_LAYOUT_LIGHT = 5; const GROUP_BANNED = -1; - const GROUP_VISITOR = 0; - const GROUP_STUDENT = 1; + const GROUP_STUDENT = 0; + const GROUP_TUTOR = 1; const GROUP_TEACHER = 2; // Groupe MODERATOR, compatibilité avec les anciens modules : const GROUP_ADMIN = 3; @@ -94,14 +94,6 @@ class common 'theme', 'user' ]; - /* - Cette variable est supprimée du test dans le routeur. - public static $accessExclude = [ - 'login', - 'logout', - 'maintenance', - ]; - */ private $data = []; private $hierarchy = [ 'all' => [], @@ -153,25 +145,25 @@ class common ]; public static $groups = [ self::GROUP_BANNED => 'Banni', - self::GROUP_VISITOR => 'Visiteur', self::GROUP_STUDENT => 'Apprenant', + self::GROUP_TUTOR => 'Tuteur', self::GROUP_TEACHER => 'Enseignant', self::GROUP_ADMIN => 'Administrateur' ]; public static $groupEdits = [ self::GROUP_BANNED => 'Banni', - self::GROUP_STUDENT => 'Apprenant', + self::GROUP_TUTOR => 'Tuteur', self::GROUP_TEACHER => 'Enseignant', self::GROUP_ADMIN => 'Administrateur' ]; public static $groupNews = [ - self::GROUP_STUDENT => 'Apprenant', + self::GROUP_TUTOR => 'Tuteur', self::GROUP_TEACHER => 'Enseignant', self::GROUP_ADMIN => 'Administrateur' ]; public static $groupPublics = [ - self::GROUP_VISITOR => 'Visiteur', self::GROUP_STUDENT => 'Apprenant', + self::GROUP_TUTOR => 'Tuteur', self::GROUP_TEACHER => 'Enseignant', self::GROUP_ADMIN => 'Administrateur' ]; @@ -453,7 +445,6 @@ class common // Mise à jour des données core include('core/include/update.inc.php'); - } @@ -720,7 +711,7 @@ class common // Page parent $this->getData(['page', $pageId, 'parentPageId']) === '' // Ignore les pages dont l'utilisateur n'a pas accès - and ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR + and ($this->getData(['page', $pageId, 'group']) === self::GROUP_STUDENT or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') //and $this->getUser('group') >= $this->getData(['page', $pageId, 'group']) // Modification qui tient compte du profil de la page @@ -745,8 +736,8 @@ class common $parentId = $this->getData(['page', $pageId, 'parentPageId']) // Ignore les pages dont l'utilisateur n'a pas accès and ( - ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR - and $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR + ($this->getData(['page', $pageId, 'group']) === self::GROUP_STUDENT + and $this->getData(['page', $parentId, 'group']) === self::GROUP_STUDENT ) or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') //and $this->getUser('group') >= $this->getData(['page', $parentId, 'group']) @@ -1439,11 +1430,12 @@ class common return $c; case self::GROUP_TEACHER: foreach ($c as $courseId => $value) { - if ($this->getData(['enrolment', $courseId, 'teacher']) !== $userId) { + if ($this->getData(['enrolment', $courseId]) !== $userId) { unset($c[$courseId]); } } return $c; + case self::GROUP_TUTOR: case self::GROUP_STUDENT: foreach ($c as $courseId => $value) { $students = $this->getData(['enrolment', $courseId, 'students']); @@ -1463,45 +1455,31 @@ class common * @param string $userId identifiant de l'utilisateur * @param string $courseId identifiant du cours sollicité */ - public function courseUserEnrolment($courseId, $userId) + public function courseUserEnrolment($courseId, $userId = null) { - // Modalité d'ouverture du cours - // L'utilisateur n'est pas admin - switch ($this->getData(['user', $userId, 'group'])) { + $group = $userId ? $this->getData(['user', $userId, 'group']) : false; + switch ($group) { case self::GROUP_ADMIN: - return true; + $r = true; + break; case self::GROUP_TEACHER: - return ($userId === $this->getData(['enrolment', $courseId, 'teacher'])); + $r = in_array($userId, array_keys($this->getData(['enrolment', $courseId]))); + break; + case self::GROUP_TUTOR: case self::GROUP_STUDENT: - return ( - // Le cours est-il ouvert ? - $this->courseIsAvailable($courseId) && - // L'étudiant est inscrit ? - array_search($userId, $this->getData(['enrolment', $courseId, 'students'])) - ); - case self::GROUP_VISITOR: - // Le cours est-il ouvert ? - return ( - $this->courseIsAvailable($courseId) && - $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST - ); + $r = $this->courseIsAvailable($courseId) && + (in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) || + $this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF); + break; + // Visiteur non connecté + case false: + $r = $this->courseIsAvailable($courseId) && + $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST; + break; default: - return false; - } - if ($this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN) { - if ( - // le cours est fermé - $this->getData(['course', $courseId, 'access']) === self::COURSE_ACCESS_CLOSE - || - // Le cours ets ouvert entre deux dates - ($this->getData(['course', $courseId, 'access']) && - ($this->getData(['course', $courseId, 'openingDate']) >= time() || - $this->getData(['course', $courseId, 'clodingDate']) <= time()) - ) - ) { - return; - } + $r = false; } + return $r; } /** diff --git a/core/layout/main.php b/core/layout/main.php index 1a82d9a..508bf18 100644 --- a/core/layout/main.php +++ b/core/layout/main.php @@ -32,7 +32,7 @@ - getUser('group') > self::GROUP_STUDENT) : ?> + getUser('group') > self::GROUP_TUTOR) : ?> showBar(); ?> @@ -45,7 +45,7 @@ $this->getData(['theme', 'menu', 'position']) === 'top' and $this->getData(['theme', 'menu', 'fixed']) === true and $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') - and $this->getUser('group') > self::GROUP_STUDENT + and $this->getUser('group') > self::GROUP_TUTOR ) { echo '