From: skodak Date: Wed, 28 Jun 2006 14:58:30 +0000 (+0000) Subject: minor loginas cleanup; merged from MOODLE_16_STABLE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7c24284126aaf20120ae8d81e7562bb7fa521494;p=moodle.git minor loginas cleanup; merged from MOODLE_16_STABLE --- diff --git a/course/loginas.php b/course/loginas.php index acfabe0713..02b128d23e 100644 --- a/course/loginas.php +++ b/course/loginas.php @@ -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. @@ -33,12 +19,31 @@ 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)) {