diff --git a/course/loginas.php b/course/loginas.php
index 8dff3b70d56..311c04dd4e0 100644
--- a/course/loginas.php
+++ b/course/loginas.php
@@ -5,7 +5,8 @@
require("lib.php");
require_variable($id); // course id
- require_variable($user); // login as this user
+ optional_variable($user); // login as this user
+ optional_variable($return); // return to being the real user again
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
@@ -13,6 +14,17 @@
require_login($course->id);
+ if ($return and $USER->realuser) {
+ $USER = get_user_info_from_db("id", $USER->realuser);
+ $USER->loggedin = true;
+ $USER->site = $CFG->wwwroot;
+ save_session("USER");
+ redirect($HTTP_REFERER);
+ exit;
+ }
+
+ // $user must be defined to go on
+
if (!isteacher($course->id)) {
error("Only teachers can use this page!");
}
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 25aff69ffbd..649f1ec3db3 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -68,42 +68,43 @@ function print_footer ($course=NULL) {
// to the course home page, otherwise the link will go to the site home
global $USER, $CFG, $THEME;
+
+/// Course links
if ($course) {
if ($course == "home") { // special case for site home page - please do not remove
$homelink = "
release ($CFG->version)\" HREF=\"http://moodle.com/\">";
$homelink .= "

";
+
+ $course = get_site();
} else {
$homelink = "wwwroot/course/view.php?id=$course->id\">$course->shortname";
}
} else {
$homelink = "wwwroot\">".get_string("home")."";
+ $course = get_site();
}
+
+/// User links
if ($USER->realuser) {
if ($realuser = get_record("user", "id", $USER->realuser)) {
- $realuserinfo = " [$realuser->firstname $realuser->lastname] ";
+ $realuserinfo = " [wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$realuser->firstname $realuser->lastname] ";
}
}
+
if ($USER->id) {
- if ($course) {
- if ($course == "home") {
- $site = get_site();
- $username = "wwwroot/user/view.php?id=$USER->id&course=$site->id\">$USER->firstname $USER->lastname";
- } else {
- $username = "wwwroot/user/view.php?id=$USER->id&course=$course->id\">$USER->firstname $USER->lastname";
- }
- } else {
- $username = "$USER->firstname $USER->lastname";
- }
+ $username = "wwwroot/user/view.php?id=$USER->id&course=$course->id\">$USER->firstname $USER->lastname";
$loggedinas = $realuserinfo.get_string("loggedinas", "moodle", "$username").
" (wwwroot/login/logout.php\">".get_string("logout").")";
- } else {
+ } else {
$loggedinas = get_string("loggedinnot", "moodle").
" (wwwroot/login/index.php\">".get_string("login").")";
- }
+ }
include ("$CFG->dirroot/theme/$CFG->theme/footer.html");
}
+
+
function print_navigation ($navigation) {
global $CFG;