]> git.mjollnir.org Git - moodle.git/commitdiff
Merged enrolment fixes frm stable
authormoodler <moodler>
Thu, 9 Sep 2004 09:43:51 +0000 (09:43 +0000)
committermoodler <moodler>
Thu, 9 Sep 2004 09:43:51 +0000 (09:43 +0000)
course/enrol.php
enrol/enrol.class.php
lib/moodlelib.php

index bd2d7ee8ccec5f9f2606ac256af8d98d158c4b5c..43596f6d8bd27d1b5b102ddfbed102eedba078b5 100644 (file)
 /// Double check just in case they are enrolled to start in the future 
 
     if ($student = get_record('user_students', 'userid', $USER->id, 'course', $course->id)) { 
-        $message = get_string('enrolmentnotyet', '', userdate($student->timestart));
-        print_header();
-        notice($message, $CFG->wwwroot);
+        if ($course->enrolperiod and $student->timestart and ($student->timestart >= time())) {
+            $message = get_string('enrolmentnotyet', '', userdate($student->timestart));
+            print_header();
+            notice($message, $CFG->wwwroot);
+        }
     }
 
 /// Check the submitted enrollment key if there is one
index 96ef28444737c3b2803020ea01ed92eff2c7c5c9..1c4261d9c15feda49fe55b4c68108c9ed5f2102b 100644 (file)
@@ -138,12 +138,11 @@ function print_entry($course) {
             exit;
 
         } else {
-            if ($course->enrolperiod == 0) {
-                $timestart = 0;
-                $timeend = 0;
-            } else {
+            if ($course->enrolperiod) {
                 $timestart = time();
                 $timeend = time() + $course->enrolperiod;
+            } else {
+                $timestart = $timeend = 0;
             }
 
             if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
@@ -200,9 +199,16 @@ function check_entry($form, $course) {
         
             add_to_log($course->id, "course", "guest", "view.php?id=$course->id", $_SERVER['REMOTE_ADDR']);
             
-        } else if (!record_exists("user_students", "userid", $USER->id, "course", $course->id)) {
+        } else {  /// Update or add new enrolment
 
-            if (! enrol_student($USER->id, $course->id)) {
+            if ($course->enrolperiod) {
+                $timestart = time();
+                $timeend   = $timestart + $course->enrolperiod;
+            } else {
+                $timestart = $timeend = 0;
+            }
+
+            if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
                 error("An error occurred while trying to enrol you.");
             }
             
index 643047585b99649c6372a611a2ace59fdde979ce..2468cc9de9099fca560007f62658e3fbb1547d61 100644 (file)
@@ -858,27 +858,28 @@ function authenticate_user_login($username, $password) {
 }
 
 function enrol_student($userid, $courseid, $timestart=0, $timeend=0) {
-/// Enrols a student in a given course
-    global $CFG;
-
-    $course = get_record("course", "id", $courseid);
-
-    if (!record_exists("user_students", "userid", $userid, "course", $courseid)) {
-        if (record_exists("user", "id", $userid)) {
+/// Enrols (or re-enrols) a student in a given course
 
-            require_once('../mod/forum/lib.php');
-            forum_add_user($userid, $courseid);
-             
-            $student->userid = $userid;
-            $student->course = $courseid;
-            $student->timestart = $timestart;
-            $student->timeend = $timeend;
-            $student->time = time();
-            return insert_record("user_students", $student);
-        }
+    if (!$course = get_record("course", "id", $courseid)) {  // Check course
         return false;
     }
-    return true;
+    if (!$user = get_record("user", "id", $userid)) {        // Check user
+        return false;
+    }
+    if ($student = get_record("user_students", "userid", $userid, "course", $courseid)) {
+        $student->timestart = $timestart;
+        $student->timeend = $timeend;
+        $student->time = time();
+        return update_record("user_students", $student);
+        
+    } else {
+        $student->userid = $userid;
+        $student->course = $courseid;
+        $student->timestart = $timestart;
+        $student->timeend = $timeend;
+        $student->time = time();
+        return insert_record("user_students", $student);
+    }
 }
 
 function unenrol_student($userid, $courseid=0) {