]> git.mjollnir.org Git - moodle.git/commitdiff
FIxes to cope with this case:
authormoodler <moodler>
Fri, 23 Jan 2004 08:30:15 +0000 (08:30 +0000)
committermoodler <moodler>
Fri, 23 Jan 2004 08:30:15 +0000 (08:30 +0000)
  - 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

index cc9797673dd738952ef93a768f6951aee4272811..6f7fb62b842367bfd04489ad1c93265f4f71f6ef 100644 (file)
@@ -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) {
                 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);
         }
     }
 
-    $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()) {
             }
             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);