diff --git a/core/class/layout.class.php b/core/class/layout.class.php index 59c3561..91192d9 100644 --- a/core/class/layout.class.php +++ b/core/class/layout.class.php @@ -499,10 +499,10 @@ class layout extends common $this->getUser('group') <= self::GROUP_MEMBER && $this->getData(['theme', 'menu', 'selectSpace']) === true ) { - if ($this->getCoursesByUser($this->getUser('id'), $this->getUser('group'))) { + if ($this->getCoursesByUser()) { $itemsRight .= '
  • '; @@ -922,10 +922,10 @@ class layout extends common * Les enseignants les contenus dont ils sont auteurs */ if ($this->getUser('group') >= self::GROUP_EDITOR) { - if ($this->getCoursesByUser($this->getUser('id'), $this->getUser('group'))) { + if ($this->getCoursesByUser()) { $leftItems .= '
  • '; diff --git a/core/core.php b/core/core.php index 21fc23b..675f122 100644 --- a/core/core.php +++ b/core/core.php @@ -1424,50 +1424,50 @@ class common * CETTE FONCTION N'EST PAS UTILISEE * */ - public function getCoursesByUser($userId, $userStatus) + public function getCoursesByUser() { - $c = $this->getData([('course')]); - $c = helper::arraycolumn($c, 'title', 'SORT_ASC'); - switch ($userStatus) { + $courses = $this->getData([('course')]); + $courses = helper::arraycolumn($courses, 'title', 'SORT_ASC'); + $filter = array(); + $userId = $this->getUser('id'); + switch ($this->getUser('group')) { case self::GROUP_ADMIN: // Affiche tout - return $c; + return $courses; case self::GROUP_EDITOR: - /* - foreach ($c as $courseId => $value) { + foreach ($courses as $courseId => $value) { $students = $this->getData(['enrolment', $courseId]); // Affiche les espaces gérés par l'éditeur, les espaces où il participe et les espaces ouverts if ( - isset($students[$userId]) === false || - $this->getData(['course', $courseId, 'author']) !== $userId || - $this->getData(['course', $courseId, 'access']) !== self::COURSE_ENROLMENT_GUEST + isset($students[$userId]) === true || + $this->getData(['course', $courseId, 'author']) === $userId || + $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST ) { - unset($c[$courseId]); + $filter[$courseId] = $courses[$courseId]; } - } */ - return $c; + } + return $courses; case self::GROUP_MEMBER: - /* - foreach ($c as $courseId => $value) { - // Affiche les espaces où le membre participe et les espaces ouverts + foreach ($courses as $courseId => $value) { + // Affiche les espaces du participant et les espaces anonymes $students = $this->getData(['enrolment', $courseId]); if ( - isset($students[$userId]) === false || - $this->getData(['course', $courseId, 'access']) !== self::COURSE_ENROLMENT_GUEST + isset($students[$userId]) === true || + $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST ) { - unset($c[$courseId]); + $filter[$courseId] = $courses[$courseId]; } } - */ - return $c; + return $filter; case self::GROUP_VISITOR: - foreach ($c as $courseId => $value) { - // Affiche les espaces ouverts - if ($this->getData(['course', $courseId, 'access']) !== self::COURSE_ENROLMENT_GUEST) { - unset($c[$courseId]); + foreach ($courses as $courseId => $value) { + // Affiche les espaces anonymes + if ($this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST) { + echo $this->getData(['course', $courseId, 'access']) ; + $filter[$courseId] = $courses[$courseId]; } } - return $c; + return $filter; default: return null; } diff --git a/core/module/course/course.php b/core/module/course/course.php index c6551ef..c9759a9 100644 --- a/core/module/course/course.php +++ b/core/module/course/course.php @@ -88,6 +88,21 @@ class course extends common && $this->getCoursesByUser() ) { foreach ($this->getCoursesByUser() as $courseId => $courseValue) { + + /** + * Filtres : + * Groupes acceptés : + * admin : tous les espaces + * editor : gère son espace + */ + + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $courseId, 'author']) + ) { + continue; + } + $author = $this->getData(['course', $courseId, 'author']) ? sprintf('%s %s', $this->getData(['user', $this->getData(['course', $courseId, 'author']), 'firstname']), $this->getData(['user', $this->getData(['course', $courseId, 'author']), 'lastname'])) : ''; @@ -215,6 +230,17 @@ class course extends common public function edit() { + // Profil limité au propriétaire ou admis + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Soumission du formulaire if ( $this->getUser('permission', __CLASS__, __FUNCTION__) === true && @@ -284,6 +310,18 @@ class course extends common public function manage() { + // Profil limité au propriétaire ou admis + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Liste des enseignants pour le sélecteur d'auteurs $teachers = $this->getData(['user']); foreach ($teachers as $teacherId => $teacherInfo) { @@ -319,6 +357,19 @@ class course extends common */ public function clone () { + + // Profil limité au propriétaire ou admis + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Cours à dupliquer $courseId = $this->getUrl(2); @@ -503,6 +554,18 @@ class course extends common public function users() { + // Profil limité au propriétaire ou admis + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Contenu sélectionné $courseId = $this->getUrl(2); @@ -652,6 +715,18 @@ class course extends common public function usersAdd() { + // Profil limité au propriétaire ou admis + if ( + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Contenu sélectionné $courseId = $this->getUrl(2); @@ -783,9 +858,12 @@ class course extends common */ public function userDelete() { - // Accès refusé + + // Profil limité au propriétaire ou admis if ( - $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true ) { // Valeurs en sortie $this->addOutput([ @@ -802,7 +880,7 @@ class course extends common } } - /** + /** * Désinscription de tous les utilisateurs */ public function usersDelete() @@ -1300,8 +1378,7 @@ class course extends common ]); break; case self::COURSE_ENROLMENT_SELF_KEY: - if ($this->getInput('courseSwapEnrolmentKey', helper::FILTER_STRING_SHORT, true) === $this->getData(['course', $courseId, 'enrolmentKey'])) - { + if ($this->getInput('courseSwapEnrolmentKey', helper::FILTER_STRING_SHORT, true) === $this->getData(['course', $courseId, 'enrolmentKey'])) { $this->courseEnrolUser($courseId, $userId); // Stocker la sélection $_SESSION['ZWII_SITE_CONTENT'] = $courseId; @@ -1388,9 +1465,11 @@ class course extends common public function backup() { - // Accès refusé + // Profil limité au propriétaire ou admis if ( - $this->getUser('permission', __CLASS__, __FUNCTION__) !== true + $this->getUser('group') === self::GROUP_EDITOR + && $this->getUser('id') != $this->getData(['course', $this->getUrl(2), 'author']) + || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true ) { // Valeurs en sortie $this->addOutput([