]> git.mjollnir.org Git - moodle.git/commitdiff
Merged bug 2114 fix from STABLE
authormoodler <moodler>
Thu, 21 Oct 2004 15:50:58 +0000 (15:50 +0000)
committermoodler <moodler>
Thu, 21 Oct 2004 15:50:58 +0000 (15:50 +0000)
course/loginas.php

index 0563fbdb603c688a036df6e4546264e3cc17adcf..b638ace36f5036257ef1073e34511f681f3de8ec 100644 (file)
@@ -4,9 +4,10 @@
     require_once("../config.php");
     require_once("lib.php");
 
-    require_variable($id);     // course id
+    require_variable($id);      // course id
     optional_variable($user);   // login as this user
-    optional_variable($return); // return to being the real user again
+    optional_variable($return); // return to the page we came from
+
 
     if (! $course = get_record("course", "id", $id)) {
         error("Course ID was incorrect");
@@ -16,7 +17,7 @@
         require_login($course->id);
     }
 
-    if ($return and $USER->realuser) {
+    if ($USER->realuser) {   /// Reset user back to their real self
         $USER = get_user_info_from_db("id", $USER->realuser);
         $USER->loggedin = true;
         $USER->site = $CFG->wwwroot;
             unset($SESSION->oldtimeaccess);
         }
 
-        redirect($_SERVER["HTTP_REFERER"]);
-        exit;
+        if ($return) {       /// That's all we wanted to do, so let's go back
+            redirect($_SERVER["HTTP_REFERER"]);
+            exit;
+        }
     }
 
     // $user must be defined to go on