diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 86bc7a043bb..5c04cc220d0 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -128,10 +128,20 @@ switch ($action) { $roleid = null; } + if (empty($startdate)) { + if (!$startdate = get_config('enrol_manual', 'enrolstart')) { + // Default to now if there is no system setting. + $startdate = 4; + } + } + switch($startdate) { case 2: $timestart = $course->startdate; break; + case 4: + $timestart = time(); + break; case 3: default: $today = time(); diff --git a/enrol/manual/db/upgrade.php b/enrol/manual/db/upgrade.php index 3e58900497e..db7d1829c96 100644 --- a/enrol/manual/db/upgrade.php +++ b/enrol/manual/db/upgrade.php @@ -66,6 +66,12 @@ function xmldb_enrol_manual_upgrade($oldversion) { // Moodle v2.9.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2015091500) { + // We keep today as default enrolment start time on upgrades. + set_config('enrolstart', 3, 'enrol_manual'); + upgrade_plugin_savepoint(true, 2015091500, 'enrol', 'manual'); + } + return true; } diff --git a/enrol/manual/lang/en/enrol_manual.php b/enrol/manual/lang/en/enrol_manual.php index 7c5f941e291..b325f4aacdb 100644 --- a/enrol/manual/lang/en/enrol_manual.php +++ b/enrol/manual/lang/en/enrol_manual.php @@ -29,6 +29,7 @@ $string['assignrole'] = 'Assign role'; $string['browseusers'] = 'Browse users'; $string['browsecohorts'] = 'Browse cohorts'; $string['confirmbulkdeleteenrolment'] = 'Are you sure you want to delete these users enrolments?'; +$string['defaultstart'] = 'Default enrolment start'; $string['defaultperiod'] = 'Default enrolment duration'; $string['defaultperiod_desc'] = 'Default length of time that the enrolment is valid. If set to zero, the enrolment duration will be unlimited by default.'; $string['defaultperiod_help'] = 'Default length of time that the enrolment is valid, starting with the moment the user is enrolled. If disabled, the enrolment duration will be unlimited by default.'; @@ -56,6 +57,7 @@ $string['manual:manage'] = 'Manage user enrolments'; $string['manual:unenrol'] = 'Unenrol users from the course'; $string['manual:unenrolself'] = 'Unenrol self from the course'; $string['messageprovider:expiry_notification'] = 'Manual enrolment expiry notifications'; +$string['now'] = 'Now'; $string['pluginname'] = 'Manual enrolments'; $string['pluginname_desc'] = 'The manual enrolments plugin allows users to be enrolled manually via a link in the course administration settings, by a user with appropriate permissions such as a teacher. The plugin should normally be enabled, since certain other enrolment plugins, such as self enrolment, require it.'; $string['status'] = 'Enable manual enrolments'; @@ -71,4 +73,4 @@ $string['unenrolusers'] = 'Unenrol users'; $string['wscannotenrol'] = 'Plugin instance cannot manually enrol a user in the course id = {$a->courseid}'; $string['wsnoinstance'] = 'Manual enrolment plugin instance doesn\'t exist or is disabled for the course (id = {$a->courseid})'; $string['wsusercannotassign'] = 'You don\'t have the permission to assign this role ({$a->roleid}) to this user ({$a->userid}) in this course({$a->courseid}).'; -$string['manualpluginnotinstalled'] = 'The "Manual" plugin has not yet been installed'; \ No newline at end of file +$string['manualpluginnotinstalled'] = 'The "Manual" plugin has not yet been installed'; diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 464d76b19fb..b50e3cc1a0d 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -226,14 +226,19 @@ class enrol_manual_plugin extends enrol_plugin { $button->class .= ' enrol_manual_plugin'; $startdate = $manager->get_course()->startdate; - $startdateoptions = array(); - $timeformat = get_string('strftimedatefullshort'); - if ($startdate > 0) { - $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $timeformat) . ')'; + if (!$defaultstart = get_config('enrol_manual', 'enrolstart')) { + // Default to now if there is no system setting. + $defaultstart = 4; } - $today = time(); - $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); - $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; + $startdateoptions = array(); + $dateformat = get_string('strftimedatefullshort'); + if ($startdate > 0) { + $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $dateformat) . ')'; + } + $now = time(); + $today = make_timestamp(date('Y', $now), date('m', $now), date('d', $now), 0, 0, 0); + $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $dateformat) . ')'; + $startdateoptions[4] = get_string('now', 'enrol_manual') . ' (' . userdate($now, get_string('strftimedatetimeshort')) . ')'; $defaultduration = $instance->enrolperiod > 0 ? $instance->enrolperiod / 86400 : ''; $modules = array('moodle-enrol_manual-quickenrolment', 'moodle-enrol_manual-quickenrolment-skin'); @@ -245,6 +250,7 @@ class enrol_manual_plugin extends enrol_plugin { 'optionsStartDate' => $startdateoptions, 'defaultRole' => $instance->roleid, 'defaultDuration' => $defaultduration, + 'defaultStartDate' => (int)$defaultstart, 'disableGradeHistory' => $CFG->disablegradehistory, 'recoverGradesDefault'=> '', 'cohortsAvailable' => cohort_get_available_cohorts($manager->get_context(), COHORT_WITH_NOTENROLLED_MEMBERS_ONLY, 0, 1) ? true : false diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 6c86e6fb45d..744be862a2c 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -28,7 +28,7 @@ require_once($CFG->dirroot.'/enrol/manual/locallib.php'); $enrolid = required_param('enrolid', PARAM_INT); $roleid = optional_param('roleid', -1, PARAM_INT); $extendperiod = optional_param('extendperiod', 0, PARAM_INT); -$extendbase = optional_param('extendbase', 3, PARAM_INT); +$extendbase = optional_param('extendbase', 0, PARAM_INT); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); @@ -83,24 +83,31 @@ for ($i=1; $i<=365; $i++) { $seconds = $i * 86400; $periodmenu[$seconds] = get_string('numdays', '', $i); } -// Work out the apropriate default setting. +// Work out the apropriate default settings. if ($extendperiod) { $defaultperiod = $extendperiod; } else { $defaultperiod = $instance->enrolperiod; } +if (empty($extendbase)) { + if (!$extendbase = get_config('enrol_manual', 'enrolstart')) { + // Default to now if there is no system setting. + $extendbase = 4; + } +} // Build the list of options for the starting from dropdown. -$timeformat = get_string('strftimedatefullshort'); -$today = time(); -$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); +$now = time(); +$today = make_timestamp(date('Y', $now), date('m', $now), date('d', $now), 0, 0, 0); +$dateformat = get_string('strftimedatefullshort'); // Enrolment start. $basemenu = array(); if ($course->startdate > 0) { - $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')'; + $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $dateformat) . ')'; } -$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; +$basemenu[3] = get_string('today') . ' (' . userdate($today, $dateformat) . ')'; +$basemenu[4] = get_string('now', 'enrol_manual') . ' (' . userdate($now, get_string('strftimedatetimeshort')) . ')'; // Process add and removes. if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { @@ -111,6 +118,9 @@ if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) case 2: $timestart = $course->startdate; break; + case 4: + $timestart = $now; + break; case 3: default: $timestart = $today; diff --git a/enrol/manual/settings.php b/enrol/manual/settings.php index dbfc766938a..2056c196dc3 100644 --- a/enrol/manual/settings.php +++ b/enrol/manual/settings.php @@ -66,6 +66,11 @@ if ($ADMIN->fulltree) { get_string('defaultrole', 'role'), '', $student->id, $options)); } + $options = array(2 => get_string('coursestart'), 3 => get_string('today'), 4 => get_string('now', 'enrol_manual')); + $settings->add( + new admin_setting_configselect('enrol_manual/enrolstart', get_string('defaultstart', 'enrol_manual'), '', 4, $options) + ); + $settings->add(new admin_setting_configduration('enrol_manual/enrolperiod', get_string('defaultperiod', 'enrol_manual'), get_string('defaultperiod_desc', 'enrol_manual'), 0)); diff --git a/enrol/manual/version.php b/enrol/manual/version.php index bb592b3aa9d..ebb6db19407 100644 --- a/enrol/manual/version.php +++ b/enrol/manual/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2015051100; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2015091500; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2015050500; // Requires this Moodle version $plugin->component = 'enrol_manual'; // Full name of the plugin (used for diagnostics) $plugin->cron = 600; diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index f3de1bfdfc6..d05b1cb22a9 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -215,12 +215,12 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { var options = this.get(UEP.OPTIONSTARTDATE); var index = 0, count = 0; for (var i in options) { - count++; var option = create(''); if (i == defaultvalue) { index = count; } select.append(option); + count++; } select.set('selectedIndex', index); }, @@ -608,7 +608,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { value : 0 }, defaultStartDate : { - value : 2, + value : 4, validator : Y.Lang.isNumber }, defaultDuration : {