From b1f318a67f37d3f0878afae78c43c01e48212da8 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 23 Oct 2006 06:38:15 +0000 Subject: [PATCH] Merged guest key enrolment fix from stable MDL-6881 --- course/enrol.php | 2 +- enrol/manual/enrol.php | 3 +++ lib/moodlelib.php | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/course/enrol.php b/course/enrol.php index 976a0b3e78..25cf3dbe38 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -32,7 +32,7 @@ /// thus got to this script by mistake. This might occur if enrolments /// changed during this session or something - if (has_capability('moodle/course:view', $context)) { + if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context)) { if ($SESSION->wantsurl) { $destination = $SESSION->wantsurl; unset($SESSION->wantsurl); diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 0673fd9339..0f53667127 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -137,9 +137,12 @@ function check_entry($form, $course) { $groupid = $this->check_group_entry($course->id, $form->password); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + if (($form->password == $course->password) or ($groupid !== false) ) { if (has_capability('moodle/legacy:guest', $context, $USER->id, false)) { + $USER->enrolkey[$course->id] = true; add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr()); } else { /// Update or add new enrolment diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 05d798ee58..a810e153fd 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1631,7 +1631,11 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) { break; - case 2: /// Guests allowed with key (drop through to logic below) + case 2: /// Guests allowed with key + if (!empty($USER->enrolkey[$course->id])) { // Set by enrol/manual/enrol.php + return true; + } + // otherwise drop through to logic below (--> enrol.php) break; default: /// Guests not allowed -- 2.39.5