]> git.mjollnir.org Git - moodle.git/commitdiff
Various fixes, especially related to using timestart and timeend
authormoodler <moodler>
Thu, 29 Jul 2004 14:52:59 +0000 (14:52 +0000)
committermoodler <moodler>
Thu, 29 Jul 2004 14:52:59 +0000 (14:52 +0000)
for new enrolments

enrol/enrol.class.php
enrol/flatfile/enrol.php
enrol/flatfile/example.txt
enrol/paypal/enrol.php

index cc1a20af46d61f12b0cdd00dae828b3124af7619..602f25a93bbd7693f1f218c2912df36d3c0fce17 100644 (file)
@@ -138,8 +138,15 @@ function print_entry($course) {
             exit;
 
         } else {
+            if ($course->enrolperiod == 0) {
+                $timestart = 0;
+                $timeend = 0;
+            } else {
+                $timestart = time();
+                $timeend = time() + $course->enrolperiod;
+            }
 
-            if (! enrol_student($USER->id, $course->id)) {
+            if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
                 error("An error occurred while trying to enrol you.");
             }
             add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
@@ -268,6 +275,20 @@ function process_config($config) {
 *
 */
 function cron() {
+    // Delete students from all courses where their enrolment period has expired
+    
+    $select = "timeend > '0' AND timeend < '" . time() . "'";
+    
+    if ($students = get_records_select('user_students', $select)) {
+        foreach ($students as $student) {
+            unenrol_student($student->userid, $student->course);
+        }
+    }
+    if ($teachers = get_records_select('user_teachers', $select)) {
+        foreach ($teachers as $teacher) {
+            remove_teacher($teacher->userid, $teacher->course);
+        }
+    }
 }
 
 
index d43440d226b696201be59b090a6b37f5ddba7a7b..73f58f7ddb5e7b5c4d21934eb402142a86c3425b 100644 (file)
@@ -41,17 +41,22 @@ function check_entry($form, $course) {
 /**
 * Override the base cron() function to read in a file
 *
-* Comma separated file assumed to have four fields per line:
-*   operation, role, idnumber(user), idnumber(course)
+* Comma separated file assumed to have four or six fields per line:
+*   operation, role, idnumber(user), idnumber(course) [, starttime, endtime]
 * where:
 *   operation        = add | del
 *   role             = student | teacher | teacheredit
 *   idnumber(user)   = idnumber in the user table NB not id
 *   idnumber(course) = idnumber in the course table NB not id
+*   starttime        = start time (in seconds since epoch) - optional
+*   endtime          = end time (in seconds since epoch) - optional
 */
     function cron() {
         global $CFG;
 
+        /// call the base class
+        parent::cron();
+
         if (empty($CFG->enrol_flatfilelocation)) {
             $filename = "$CFG->dataroot/1/enrolments.txt";  // Default location
         } else {
@@ -73,7 +78,7 @@ function check_entry($form, $course) {
 
 
                 /// If a line is incorrectly formatted ie does not have 4 comma separated fields then ignore it
-                    if ( count($fields) != 4) {
+                    if (count($fields) != 4 and count($fields) !=6) {
                         if ( count($fields) > 1 or strlen($fields[0]) > 1) { // no error for blank lines
                             $this->log .= "$line: Line incorrectly formatted - ignoring\n";
                         }
@@ -85,9 +90,19 @@ function check_entry($form, $course) {
                     $fields[1] = trim(strtolower($fields[1]));
                     $fields[2] = trim($fields[2]);
                     $fields[3] = trim($fields[3]);
+                    
+                    $this->log .= "$line: $fields[0] $fields[1] $fields[2] $fields[3] ";
+                    
+                    if (!empty($fields[5])) {
+                        $fields[4] = (int)trim($fields[4]);
+                        $fields[5] = (int)trim($fields[5]);
+                        $this->log .= "$fields[4] $fields[5]";
+                    } else {
+                        $fields[4] = 0;
+                        $fields[5] = 0;
+                    } 
 
-
-                    $this->log .= "$line: $fields[0] $fields[1] $fields[2] $fields[3]: ";
+                    $this->log .= ":";
 
 
 
@@ -116,12 +131,17 @@ function check_entry($form, $course) {
                         continue;
                     }
 
+                    if ($fields[4] > $fields[5]) {
+                        $this->log .= "Start time was later than end time - ignoring line\n";
+                        continue;
+                    }
+
 
                     unset($elog);
                     switch ($fields[1]) {
                         case "student":
                             if ($fields[0] == "add") {
-                                if (! enrol_student($user->id, $course->id)) {
+                                if (! enrol_student($user->id, $course->id, $fields[4], $fields[5])) {
                                     $elog = "Error enrolling in course\n";
                                 }
                             } else {
@@ -133,7 +153,7 @@ function check_entry($form, $course) {
 
                         case "teacher":
                             if ($fields[0] == "add") {
-                                if (! add_teacher($user->id, $course->id, 0)) {
+                                if (! add_teacher($user->id, $course->id, 0, '', $fields[4], $fields[5])) {
                                     $elog = "Error adding teacher to course\n";
                                 }
                             } else {
@@ -145,7 +165,7 @@ function check_entry($form, $course) {
 
                         case "teacheredit":
                             if ($fields[0] == "add") {
-                                if (! add_teacher($user->id, $course->id, 1)) {
+                                if (! add_teacher($user->id, $course->id, 1, '', $fields[4], $fields[5])) {
                                     $elog = "Error adding teacher to course\n";
                                 }
                             } else {
index 256a67626ee70fb3eee734f24dbc83150f9e4474..3e5fa8bb616daee189abae453fd63af3a1cba198 100644 (file)
@@ -3,3 +3,4 @@ add, teacher, 6, CF101
 add, teacheredit, 7, CF101
 del, student, 8, CF101
 del, student, 17, CF101
+add, student, 21, CF101, 1091115000, 1091215000
index d1981dd91d7d6f646c703fe5715691952cad4338..5c0790f762b7266845a978b1c498b341f5c646d5 100644 (file)
@@ -78,6 +78,10 @@ function get_access_icons($course) {
         $strrequirespayment = get_string("requirespayment");
         $strcost = get_string("cost");
 
+        if (empty($CFG->enrol_paypalcurrency)) {
+            $CFG->enrol_paypalcurrency = 'USD';
+        }
+
         switch ($CFG->enrol_paypalcurrency) {
            case 'EUR': $currency = '&euro;'; break;
            case 'CAD': $currency = '$'; break;
@@ -87,7 +91,7 @@ function get_access_icons($course) {
         }
         
         $str .= "<p>$strcost: <a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
-        $str .= "$currency $cost</a></p>";
+        $str .= "$currency".format_float($cost,2).'</a></p>';
         
     }