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) ) {
/// 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);
}
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 '<div align="center">';
echo '<p>'.get_string('paymentrequired').'</p>';
$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());
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 {