]> git.mjollnir.org Git - moodle.git/commitdiff
minor loginas cleanup; merged from MOODLE_16_STABLE
authorskodak <skodak>
Wed, 28 Jun 2006 14:58:30 +0000 (14:58 +0000)
committerskodak <skodak>
Wed, 28 Jun 2006 14:58:30 +0000 (14:58 +0000)
course/loginas.php

index acfabe0713d619f5a7a432c82124872076c374a3..02b128d23ea606505a5d75593b97ffb34ac4246a 100644 (file)
@@ -4,24 +4,10 @@
     require_once("../config.php");
     require_once("lib.php");
 
-    $id       = required_param('id', PARAM_INT);           // course id
-    $user     = optional_param('user', 0, PARAM_INT);      // login as this user
+/// Reset user back to their real self if needed
     $return   = optional_param('return', 0, PARAM_BOOL);   // return to the page we came from
-    $password = optional_param('password', '', PARAM_RAW); // site wide password
-
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
 
-    if (! $course = get_record("course", "id", $id)) {
-        error("Course ID was incorrect");
-    }
-
-    if ($course->category) {
-        require_login($course->id);
-    }
-
-    if (isset($USER->realuser)) {   /// Reset user back to their real self
+    if (!empty($USER->realuser)) {
         $USER = get_complete_user_data('id', $USER->realuser);
 
         if (isset($SESSION->oldcurrentgroup)) {      // Restore previous "current group" cache.
             unset($SESSION->oldtimeaccess);
         }
 
-        if ($return) {       /// That's all we wanted to do, so let's go back
+        if ($return and isset($_SERVER["HTTP_REFERER"])) { // That's all we wanted to do, so let's go back
             redirect($_SERVER["HTTP_REFERER"]);
-            exit;
+        } else {
+            redirect($CFG->wwwroot);
         }
     }
 
+///-------------------------------------
+/// try to login as student if allowed
+    $id       = required_param('id', PARAM_INT);           // course id
+    $user     = required_param('user', PARAM_INT);         // login as this user
+    $password = optional_param('password', '', PARAM_RAW); // site wide password
+
+    if (!$site = get_site()) {
+        error("Site isn't defined!");
+    }
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID was incorrect");
+    }
+
+    if ($course->category) {
+        require_login($course->id);
+    }
+
     // $user must be defined to go on
 
     if (!isteacher($course->id)) {