diff --git a/course/enrol.php b/course/enrol.php index 0b86684c5d6..61419cccf24 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -8,12 +8,15 @@ require_once("$CFG->dirroot/enrol/enrol.class.php"); $id = required_param('id', PARAM_INT); - $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); + $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed? - require_login(); - - if ($USER->username == 'guest') { // Guests can't enrol in anything! - redirect($CFG->wwwroot.'/login/index.php'); + if (!isloggedin()) { + $wwwroot = $CFG->wwwroot; + if (!empty($CFG->loginhttps)) { + $wwwroot = str_replace('http:','https:', $wwwroot); + } + // do not use require_login here because we are usually comming from it + redirect($wwwroot.'/login/index.php'); } if (! $course = get_record('course', 'id', $id) ) { @@ -34,7 +37,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) and !has_capability('moodle/legacy:guest', $context)) { + if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) { if ($SESSION->wantsurl) { $destination = $SESSION->wantsurl; unset($SESSION->wantsurl); diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index c32e22c9e32..a5a60c9b4ad 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -64,7 +64,7 @@ class enrolment_plugin_authorize } print_simple_box_start('center', '80%'); - if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), $USER->id, false)) { + if ($USER->username == 'guest') { // only real guest user, not for users with guest role $curcost = get_course_cost($course); echo '
'; echo '

'.get_string('paymentrequired').'

'; diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 0f53667127f..7bbe82fc4ad 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -137,11 +137,9 @@ 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)) { + if ($USER->username == 'guest') { // only real user guest, do not use this for users with guest role $USER->enrolkey[$course->id] = true; add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr()); diff --git a/enrol/paypal/enrol.php b/enrol/paypal/enrol.php index 5ea01b01b02..e571851a1dd 100644 --- a/enrol/paypal/enrol.php +++ b/enrol/paypal/enrol.php @@ -42,7 +42,7 @@ function print_entry($course) { print_simple_box_start("center"); - if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM, SITEID), NULL, false)) { + if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role if (empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; } else {