Skip to content
Browse files

Bypass enrolment if guest shortcut for courses that allow guests.

  • Loading branch information...
1 parent 3d9717e commit 9ca3b4f313f2b012c6bb0ccd22d1fa91c0941301 fiedorow committed Feb 5, 2005
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/moodlelib.php
View
19 lib/moodlelib.php
@@ -1015,6 +1015,25 @@ function require_login($courseid=0, $autologinguest=true) {
}
}
+ //User is not enrolled in the course, wants to access course content
+ //as a guest, and course setting allow unlimited guest access
+ //Code cribbed from course/loginas.php
+ if (strstr($FULLME,"username=guest") && ($course->guest==1)) {
+ $realuser = $USER->id;
+ $realname = fullname($USER, true);
+ $USER = guest_user();
+ $USER->loggedin = true;
+ $USER->site = $CFG->wwwroot;
+ $USER->realuser = $realuser;
+ if (isset($SESSION->currentgroup[$course->id])) { // Remember current setting for later
+ $SESSION->oldcurrentgroup = $SESSION->currentgroup[$course->id];
+ unset($SESSION->currentgroup[$course->id]);
+ }
+ $guest_name = fullname($USER, true);
+ add_to_log($course->id, "course", "loginas", "../user/view.php?id=$course->id&$USER->id$", "$realname -> $guest_name");
+ return;
+ }
+
// Currently not enrolled in the course, so see if they want to enrol
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot .'/course/enrol.php?id='. $courseid);

0 comments on commit 9ca3b4f

Please sign in to comment.
Something went wrong with that request. Please try again.