Skip to content
Browse files

New feature: Notify teachers/students of expirying enrolments

  • Loading branch information...
1 parent 3de938d commit 7246c2d14285a43e8945ab7eb2388eaba2e66f1e patrickslee committed Oct 2, 2005
View
36 course/edit.html
@@ -18,6 +18,15 @@
if (!isset($form->enrolperiod)) {
$form->enrolperiod = 0;
}
+ if (!isset($form->expirynotify)) {
+ $form->expirynotify = 1;
+ }
+ if (!isset($form->notifystudents)) {
+ $form->notifystudents = 0;
+ }
+ if (!isset($form->expirythreshold)) {
+ $form->expirythreshold = 10 * 86400;
+ }
if (!isset($form->metacourse)) {
$form->metacourse = 0;
}
@@ -98,6 +107,33 @@
helpbutton("enrolperiod", get_string("enrolperiod"));
?>
</td>
+</tr><tr valign="top">
+ <td align="right"><?php print_string("expirynotify") ?>:</td>
+ <td>
+ <?php
+ unset($choices);
+ $choices["0"] = get_string("no");
+ $choices["1"] = get_string("yes");
+ choose_from_menu ($choices, "expirynotify", "$form->expirynotify", "");
+ helpbutton("expirynotify", get_string("expirynotify"));
+
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;';
+ print_string('expirynotifystudents');
+ echo ': ';
+ choose_from_menu ($choices, "notifystudents", "$form->notifystudents", "");
+ helpbutton("expirynotifystudents", get_string("expirynotifystudents"));
+
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;';
+ print_string('expirythreshold');
+ echo ': ';
+ for ($i=1; $i<=30; $i++) {
+ $seconds = $i * 86400;
+ $thresholdmenu[$seconds] = get_string('numdays', '', $i);
+ }
+ choose_from_menu ($thresholdmenu, "expirythreshold", "$form->expirythreshold", "");
+ helpbutton("expirythreshold", get_string("expirythreshold"));
+ ?>
+ </td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("numberweeks") ?>:</td>
View
54 enrol/enrol.class.php
@@ -350,6 +350,60 @@ function cron() {
remove_teacher($teacher->userid, $teacher->course);
}
}
+
+ // Notify teachers/students about students who's enrolment are going to expire
+ global $CFG;
+ if ($CFG->lastexpirynotify < date('Ymd') && ($courses = get_records_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0'))) {
+ $site = get_site();
+ $admin = get_admin();
+ $strexpirynotify = get_string('expirynotify');
+ foreach ($courses as $course) {
+ $a = new stdClass();
+ $a->course = $course->shortname .' '. $course->fullname;
+ $a->threshold = $course->expirythreshold / 86400;
+ $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id;
+ $a->current = array();
+ $a->past = array();
+ $a->current = $a->past = array();
+ $expiry = time() + $course->expirythreshold;
+ $sql = "SELECT * FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}user_students s ON u.id=s.userid WHERE s.course = $course->id AND s.timeend > 0 AND s.timeend <= $expiry";
+ if ($students = get_records_sql($sql)) {
+ $teacher = get_teacher($course->id);
+ $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a);
+ foreach ($students as $student) {
+ if ($student->timeend < ($expiry - 86400)) {
+ $a->past[] = fullname($student) . " <$student->email>";
+ } else {
+ $a->current[] = fullname($student) . " <$student->email>";
+ if ($course->notifystudents) {
+ // Send this guy notice
+ email_to_user($student, $teacher, $site->fullname .' '. $strexpirynotify, $strexpirynotifystudentsemail);
+ }
+ }
+ }
+ }
+ $a->current = implode("\n", $a->current);
+ $a->past = implode("\n", $a->past);
+ $strexpirynotifyemail = get_string('expirynotifyemail', '', $a);
+ if ($a->current || $a->past) {
+ $sql = "SELECT u.* FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}user_teachers t ON u.id=t.userid WHERE t.course = $course->id";
+ if ($teachers = get_records_sql($sql)) {
+ foreach ($teachers as $teacher) {
+ email_to_user($teacher, $admin, $a->course .' '. $strexpirynotify, $strexpirynotifyemail);
+ }
+ }
+ }
+ if ($lastexpirynotify = get_record('config', 'name', 'lastexpirynotify')) {
+ $lastexpirynotify->value = date('Ymd');
+ update_record('config', $lastexpirynotify);
+ } else {
+ $lastexpirynotify = new stdClass();
+ $lastexpirynotify->name = 'lastexpirynotify';
+ $lastexpirynotify->value = date('Ymd');
+ insert_record('config', $lastexpirynotify);
+ }
+ }
+ }
}
View
1 lang/en/help/expirynotify.html
@@ -0,0 +1 @@
+<p>Enrolment expiry notification</p>
View
1 lang/en/help/expirynotifystudents.html
@@ -0,0 +1 @@
+<p>Notify students as well</p>
View
1 lang/en/help/expirythreshold.html
@@ -0,0 +1 @@
+<p>Enrolment expiry notification threshold</p>
View
22 lang/en/moodle.php
@@ -463,6 +463,28 @@
$string['existingstudents'] = 'Enrolled students';
$string['existingteachers'] = 'Existing teachers';
$string['explanation'] = 'Explanation';
+$string['expirynotify'] = 'Enrolment expiry notification';
+$string['expirynotifyemail'] = 'The following students in this course are expiring after exact $a->threshold days:
+
+$a->current
+
+
+The following students in this course are expiring in less than $a->threshold days:
+
+$a->past
+
+
+You may go to the following page to extend their enrolment period:
+$a->extendurl
+';
+$string['expirynotifystudents'] = 'Notify students';
+$string['expirynotifystudentsemail'] = 'Dear student:
+
+This is a notification that your enrolment for course $a->course will be expired in $a->threshold days.
+
+Please contact your tutor for any further enqiries.
+';
+$string['expirythreshold'] = 'Threshold';
$string['extendenrol'] = 'Extend enrolment';
$string['extendperiod'] = 'Extended period';
$string['failedloginattempts'] = '$a->attempts failed logins since your last login';
View
10 lib/db/mysql.php
@@ -1633,6 +1633,16 @@ function main_upgrade($oldversion=0) {
}
+ if ($oldversion < 2005100300) {
+ table_column('course','','expirynotify','tinyint','1');
+ table_column('course','','expirythreshold','int','10');
+ table_column('course','','notifystudents','tinyint','1');
+ $new = new stdClass();
+ $new->name = 'lastexpirynotify';
+ $new->value = 0;
+ insert_record('config', $new);
+ }
+
return $result;
}
View
3 lib/db/mysql.sql
@@ -79,6 +79,9 @@ CREATE TABLE `prefix_course` (
`metacourse` int(1) unsigned NOT NULL default '0',
`requested` int(1) unsigned NOT NULL default '0',
`restrictmodules` int(1) unsigned NOT NULL default '0',
+ `expirynotify` tinyint(1) unsigned NOT NULL default '0',
+ `expirythreshold` int(10) unsigned NOT NULL default '0',
+ `notifystudents` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `category` (`category`),
KEY `idnumber` (`idnumber`),
View
10 lib/db/postgres7.php
@@ -1375,6 +1375,16 @@ function main_upgrade($oldversion=0) {
modify_database("","CREATE INDEX prefix_stats_user_monthly_timeend_idx ON prefix_stats_user_monthly (timeend);");
}
+ if ($oldversion < 2005100300) {
+ table_column('course','','expirynotify','integer','1');
+ table_column('course','','expirythreshold','integer');
+ table_column('course','','notifystudents','integer','1');
+ $new = new stdClass();
+ $new->name = 'lastexpirynotify';
+ $new->value = 0;
+ insert_record('config', $new);
+ }
+
return $result;
}
View
5 lib/db/postgres7.sql
@@ -49,7 +49,10 @@ CREATE TABLE prefix_course (
timemodified integer NOT NULL default '0',
metacourse integer NOT NULL default '0',
requested integer NOT NULL default '0',
- restrictmodules integer NOT NULL default '0'
+ restrictmodules integer NOT NULL default '0',
+ expirynotify integer NOT NULL default '0',
+ expirythreshold integer NOT NULL default '0',
+ notifystudents integer NOT NULL default '0'
);
CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
View
2 version.php
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2005090100; // YYYYMMDD = date
+ $version = 2005100300; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.6 development'; // Human-friendly version name

0 comments on commit 7246c2d

Please sign in to comment.
Something went wrong with that request. Please try again.