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");
*
*/
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);
+ }
+ }
}
/**
* 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 {
/// 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";
}
$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 .= ":";
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 {
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 {
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 {
$strrequirespayment = get_string("requirespayment");
$strcost = get_string("cost");
+ if (empty($CFG->enrol_paypalcurrency)) {
+ $CFG->enrol_paypalcurrency = 'USD';
+ }
+
switch ($CFG->enrol_paypalcurrency) {
case 'EUR': $currency = '€'; break;
case 'CAD': $currency = '$'; break;
}
$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>';
}