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");
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