3 require("../config.php");
6 require_variable($id); // course id
7 require_variable($user); // login as this user
9 if (! $course = get_record("course", "id", $id)) {
10 error("Course ID was incorrect");
13 require_login($course->id);
15 if (!isteacher($course->id)) {
16 error("Only teachers can use this page!");
19 if (!isstudent($course->id, $user)) {
20 error("This student is not in your course!");
23 // Login as this student and return to course home page.
25 $teacher_name = "$USER->firstname $USER->lastname";
27 $USER = get_user_info_from_db("id", $user);
28 $USER->loggedin = true;
30 set_moodle_cookie($USER->username);
32 $student_name = "$USER->firstname $USER->lastname";
34 add_to_log($course->id, "course", "loginas", "loginas.php?id=$course->id&user=$user", "$teacher_name");
36 notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");