From 43e93a07565a28f96f8f9cbda86ef6af62a4f6b8 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 23 Jan 2004 08:30:15 +0000 Subject: [PATCH] FIxes to cope with this case: - student authenticates - teacher enrols the student manually - student tries to enter course http://moodle.org/mod/forum/discuss.php?d=4529#20493 --- course/enrol.php | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/course/enrol.php b/course/enrol.php index cc9797673d..6f7fb62b84 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -8,10 +8,20 @@ require_login(); + $strloginto = get_string("loginto", "", $course->shortname); + $strcourses = get_string("courses"); + if (! $course = get_record("course", "id", $id) ) { error("That's an invalid course id"); } + if (! $site = get_site()) { + error("Could not find a site!"); + } + + +/// Check the submitted enrollment key if there is one + if ($form = data_submitted()) { if ($form->password == $course->password) { @@ -39,13 +49,13 @@ add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id"); } - $USER->student["$id"] = true; + $USER->student[$course->id] = true; if ($SESSION->wantsurl) { $destination = $SESSION->wantsurl; unset($SESSION->wantsurl); } else { - $destination = "$CFG->wwwroot/course/view.php?id=$id"; + $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; } redirect($destination); @@ -55,13 +65,26 @@ } } - $strloginto = get_string("loginto", "", $course->shortname); - $strcourses = get_string("courses"); - if (! $site = get_site()) { - error("Could not find a site!"); +/// Double check just in case they are actually enrolled already +/// This might occur if they were manually enrolled during this session + + if (record_exists("user_students", "userid", $USER->id, "course", $course->id)) { + $USER->student[$course->id] = true; + + if ($SESSION->wantsurl) { + $destination = $SESSION->wantsurl; + unset($SESSION->wantsurl); + } else { + $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; + } + + redirect($destination); } + +/// Automatically enrol into courses without password + if ($course->password == "") { // no password, so enrol if (isguest()) { @@ -82,13 +105,13 @@ } add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id"); - $USER->student["$id"] = true; + $USER->student[$course->id] = true; if ($SESSION->wantsurl) { $destination = $SESSION->wantsurl; unset($SESSION->wantsurl); } else { - $destination = "$CFG->wwwroot/course/view.php?id=$id"; + $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; } redirect($destination); -- 2.39.5