]> git.mjollnir.org Git - moodle.git/commitdiff
moodlelib MDL-21060 Editing require_course_login to properly set page vars for the...
authorSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 01:57:01 +0000 (01:57 +0000)
committerSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 01:57:01 +0000 (01:57 +0000)
lib/moodlelib.php

index 8ecf1953ede0c1193a3511656e3a39e65c977b59..e11b6f51b2eb96bd2ee7713482fb136a4ef78789 100644 (file)
@@ -2357,7 +2357,7 @@ function require_logout() {
  *             in order to keep redirects working properly. MDL-14495
  */
 function require_course_login($courseorid, $autologinguest=true, $cm=null, $setwantsurltome=true) {
-    global $CFG;
+    global $CFG, $PAGE, $SITE;
     if (!empty($CFG->forcelogin)) {
         // login required for both SITE and courses
         require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
@@ -2376,6 +2376,24 @@ function require_course_login($courseorid, $autologinguest=true, $cm=null, $setw
             // not-logged-in users do not have any group membership
             require_login($courseorid, $autologinguest, $cm, $setwantsurltome);
         } else {
+            // We still need to instatiate PAGE vars properly so that things
+            // that rely on it like navigation function correctly.
+            if (!empty($courseorid)) {
+                if (is_object($courseorid)) {
+                    $course = $courseorid;
+                } else {
+                    $course = clone($SITE);
+                }
+                if ($cm) {
+                    $PAGE->set_cm($cm, $course);
+                } else {
+                    $PAGE->set_course($course);
+                }
+            } else {
+                // If $PAGE->course, and hence $PAGE->context, have not already been set
+                // up properly, set them up now.
+                $PAGE->set_course($PAGE->course);
+            }
             //TODO: verify conditional activities here
             user_accesstime_log(SITEID);
             return;