From: moodler Date: Thu, 29 Jul 2004 14:52:59 +0000 (+0000) Subject: Various fixes, especially related to using timestart and timeend X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=76b60bb897e95a44a41a79cdcd3d5f868103e496;p=moodle.git Various fixes, especially related to using timestart and timeend for new enrolments --- diff --git a/enrol/enrol.class.php b/enrol/enrol.class.php index cc1a20af46..602f25a93b 100644 --- a/enrol/enrol.class.php +++ b/enrol/enrol.class.php @@ -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); + } + } } diff --git a/enrol/flatfile/enrol.php b/enrol/flatfile/enrol.php index d43440d226..73f58f7ddb 100644 --- a/enrol/flatfile/enrol.php +++ b/enrol/flatfile/enrol.php @@ -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 { diff --git a/enrol/flatfile/example.txt b/enrol/flatfile/example.txt index 256a67626e..3e5fa8bb61 100644 --- a/enrol/flatfile/example.txt +++ b/enrol/flatfile/example.txt @@ -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 diff --git a/enrol/paypal/enrol.php b/enrol/paypal/enrol.php index d1981dd91d..5c0790f762 100644 --- a/enrol/paypal/enrol.php +++ b/enrol/paypal/enrol.php @@ -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 = '€'; break; case 'CAD': $currency = '$'; break; @@ -87,7 +91,7 @@ function get_access_icons($course) { } $str .= "

$strcost: wwwroot/course/view.php?id=$course->id\">"; - $str .= "$currency $cost

"; + $str .= "$currency".format_float($cost,2).'

'; }