Permalink
Browse files

New feature: Course enrollable control with date range

  • Loading branch information...
1 parent 1910d66 commit f89033b111ed1283f9154c8fd7cdfe4b6e7de841 patrickslee committed Oct 4, 2005
Showing with 107 additions and 2 deletions.
  1. +55 −0 course/edit.html
  2. +16 −0 course/edit.php
  3. +9 −0 course/enrol.php
  4. +1 −0 lang/en/help/courseenrollable.html
  5. +6 −0 lang/en/moodle.php
  6. +6 −0 lib/db/mysql.php
  7. +3 −0 lib/db/mysql.sql
  8. +6 −0 lib/db/postgres7.php
  9. +4 −1 lib/db/postgres7.sql
  10. +1 −1 version.php
View
@@ -15,6 +15,21 @@
if (!isset($form->theme)) {
$form->theme = '';
}
+ if (!isset($form->enrollable)) {
+ $form->enrollable = 1;
+ }
+ if (!isset($form->enrolstartdate)) {
+ $form->enrolstartdate = 0;
+ }
+ if (!$form->enrolstartdate) {
+ $form->enrolstartdisabled = 1;
+ }
+ if (!isset($form->enrolenddate)) {
+ $form->enrolenddate = 0;
+ }
+ if (!$form->enrolenddate) {
+ $form->enrolenddisabled = 1;
+ }
if (!isset($form->enrolperiod)) {
$form->enrolperiod = 0;
}
@@ -95,6 +110,46 @@
?></td>
</tr>
<tr valign="top">
+ <td align="right"><?php print_string("enrollable") ?>:</td>
+ <td><?php
+ unset($choices);
+ $choices["0"] = get_string("no");
+ $choices["1"] = get_string("yes");
+ $choices["2"] = get_string("enroldate");
+ choose_from_radio ($choices, "enrollable", "$form->enrollable", "");
+ helpbutton("courseenrollable", get_string("enrollable"));
+ ?></td>
+</tr>
+<tr valign="top" id="daterange">
+ <td align="right"><?php print_string("enroldate") ?>:</td>
+ <td>
+ <table cellpadding="0" cellspacing="0">
+ <tr>
+ <td align="right"><?php print_string('enrolstartdate') ?>: </td>
+ <td><?php
+ print_date_selector("enrolstartday", "enrolstartmonth", "enrolstartyear", $form->enrolstartdate);
+ print_string('disable');
+ echo ': ';
+ print_checkbox('enrolstartdisabled', 1, "$form->enrolstartdisabled");
+ ?></td>
+ </tr>
+ <tr>
+ <td height="18" colspan="2"> </td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string('enrolenddate') ?>: </td>
+ <td><?php
+ print_date_selector("enrolendday", "enrolendmonth", "enrolendyear", $form->enrolenddate);
+ print_string('disable');
+ echo ': ';
+ print_checkbox('enrolenddisabled', 1, "$form->enrolenddisabled");
+ if (isset($err["enroldate"])) formerr($err["enroldate"]);
+ ?></td>
+ </tr>
+ </table>
+ </td>
+</tr>
+<tr valign="top">
<td align="right"><?php print_string("enrolperiod") ?>:</td>
<td>
<?php
View
@@ -60,6 +60,18 @@
$form->startdate = make_timestamp($form->startyear, $form->startmonth, $form->startday);
+ if (empty($form->enrolstartdisabled)) {
+ $form->enrolstartdate = make_timestamp($form->enrolstartyear, $form->enrolstartmonth, $form->enrolstartday);
+ } else {
+ $form->enrolstartdate = 0;
+ }
+
+ if (empty($form->enrolenddisabled)) {
+ $form->enrolenddate = make_timestamp($form->enrolendyear, $form->enrolendmonth, $form->enrolendday);
+ } else {
+ $form->enrolenddate = 0;
+ }
+
$form->format = optional_param('format', 'social', PARAM_ALPHA);
validate_form($course, $form, $err);
@@ -267,6 +279,10 @@
function validate_form($course, &$form, &$err) {
+ if (empty($form->enrolenddisabled) && $form->enrolenddate <= $form->enrolstartdate) {
+ $err["enroldate"] = get_string("enrolenddaterror");
+ }
+
if (empty($form->fullname))
$err["fullname"] = get_string("missingfullname");
View
@@ -59,6 +59,15 @@
}
}
+/// Check if the course is enrollable
+ if (!$course->enrollable ||
+ ($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) ||
+ ($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time())
+ ) {
+ print_header_simple();
+ notice(get_string('notenrollable'), $CFG->wwwroot);
+ }
+
/// Check the submitted enrollment key if there is one
if ($form = data_submitted()) {
@@ -0,0 +1 @@
+<p>Whether this course is enrollable or not. With a third option of allowing enrolment within a range of date.</p>
View
@@ -427,6 +427,8 @@
$string['messageselectadd'] = 'Add / send message';
$string['enable'] = 'Enable';
$string['encryptedcode'] = 'Encrypted code';
+$string['enroldate'] = 'Date range';
+$string['enrollable'] = 'Course enrollable';
$string['enrolledincourse'] = 'Enrolled in course \"$a\"';
$string['enrolledincoursenot'] = 'Not enrolled in course \"$a\"';
$string['enrollfirst'] = 'You have to enrol in one of the courses before you can use the site activities';
@@ -445,6 +447,9 @@
$string['enrolments'] = 'Enrolments';
$string['enrolmentstart'] = 'Enrolment Started';
$string['enrolperiod'] = 'Enrolment duration';
+$string['enrolenddate'] = 'End date';
+$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date';
+$string['enrolstartdate'] = 'Start date';
$string['entercourse'] = 'Click to enter this course';
$string['enteremailaddress'] = 'Enter in your email address to reset your
password and have the new password sent to you via email.';
@@ -863,6 +868,7 @@
$string['nosuchemail'] = 'No such email address';
$string['notavailable'] = 'Not available';
$string['noteachersyet'] = 'No teachers in this course yet';
+$string['notenrollable'] = 'This course is not enrollable at the moment.';
$string['notenrolled'] = '$a is not enrolled in this course.';
$string['noteuserschangednonetocourse'] = 'Note: course users need to be restored when restoring user data (in activities, files or messages). This setting has been changed for you.';
$string['nothingnew'] = 'Nothing new since your last login';
View
@@ -1643,6 +1643,12 @@ function main_upgrade($oldversion=0) {
insert_record('config', $new);
}
+ if ($oldversion < 2005100400) {
+ table_column('course','','enrollable','tinyint','1','unsigned','1');
+ table_column('course','','enrolstartdate','int');
+ table_column('course','','enrolenddate','int');
+ }
+
return $result;
}
View
@@ -82,6 +82,9 @@ CREATE TABLE `prefix_course` (
`expirynotify` tinyint(1) unsigned NOT NULL default '0',
`expirythreshold` int(10) unsigned NOT NULL default '0',
`notifystudents` tinyint(1) unsigned NOT NULL default '0',
+ `enrollable` tinyint(1) unsigned NOT NULL default '1',
+ `enrolstartdate` int(10) unsigned NOT NULL default '0',
+ `enrolenddate` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `category` (`category`),
KEY `idnumber` (`idnumber`),
View
@@ -1384,6 +1384,12 @@ function main_upgrade($oldversion=0) {
$new->value = 0;
insert_record('config', $new);
}
+
+ if ($oldversion < 2005100400) {
+ table_column('course','','enrollable','integer','1','unsigned','1');
+ table_column('course','','enrolstartdate','integer');
+ table_column('course','','enrolenddate','integer');
+ }
return $result;
}
View
@@ -52,7 +52,10 @@ CREATE TABLE prefix_course (
restrictmodules integer NOT NULL default '0',
expirynotify integer NOT NULL default '0',
expirythreshold integer NOT NULL default '0',
- notifystudents integer NOT NULL default '0'
+ notifystudents integer NOT NULL default '0',
+ enrollable integer NOT NULL default '1',
+ enrolstartdate integer NOT NULL default '0',
+ enrolenddate integer NOT NULL default '0'
);
CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
View
@@ -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 = 2005100300; // YYYYMMDD = date
+ $version = 2005100400; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.6 development'; // Human-friendly version name

0 comments on commit f89033b

Please sign in to comment.