diff --git a/classes/forms/outage/edit.php b/classes/forms/outage/edit.php
index 9c511e4..3419b48 100644
--- a/classes/forms/outage/edit.php
+++ b/classes/forms/outage/edit.php
@@ -31,6 +31,8 @@ require_once($CFG->libdir . '/formslib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit extends \moodleform {
+ const TITLE_MAX_CHARS = 100;
+
/**
* {@inheritDoc}
* @see moodleform::definition()
@@ -47,7 +49,12 @@ class edit extends \moodleform {
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
- $mform->addElement('text', 'title', get_string('title', 'auth_outage'));
+ $mform->addElement(
+ 'text',
+ 'title',
+ get_string('title', 'auth_outage'),
+ 'maxlength="'.self::TITLE_MAX_CHARS.'"'
+ );
$mform->setType('title', PARAM_TEXT);
$mform->addElement('editor', 'description', get_string('description', 'auth_outage'));
@@ -65,6 +72,24 @@ class edit extends \moodleform {
public function validation($data, $files) {
$errors = parent::validation($data, $files);
+ if ($data['starttime'] <= time()) {
+ $errors['starttime'] = get_string('starttimeerrornotinfuture', 'auth_outage');
+ }
+ if ($data['stoptime'] <= $data['starttime']) {
+ $errors['stoptime'] = get_string('stoptimeerrornotafterstart', 'auth_outage');
+ }
+ if ($data['warningduration'] <= 0) {
+ $errors['warningduration'] = get_string('warningdurationerrorinvalid', 'auth_outage');
+ }
+
+ $titlelen = strlen(trim($data['title']));
+ if ($titlelen == 0) {
+ $errors['title'] = get_string('titleerrorinvalid', 'auth_outage');
+ }
+ if ($titlelen > self::TITLE_MAX_CHARS) {
+ $errors['title'] = get_string('titleerrortoolong', 'auth_outage', self::TITLE_MAX_CHARS);
+ }
+
return $errors;
}
diff --git a/classes/outagedb.php b/classes/outagedb.php
index 2fcaf75..59e2821 100644
--- a/classes/outagedb.php
+++ b/classes/outagedb.php
@@ -98,7 +98,7 @@ final class outagedb {
['objectid' => $outage->id, 'other' => (array)$outage]
)->trigger();
} else {
- // Not new, clean up the class (remove creator field) then update.
+ // Remove the createdby field so it does not get updated.
unset($outage->createdby);
$DB->update_record('auth_outage', $outage);
// Log it.
diff --git a/db/install.xml b/db/install.xml
index 4f2297e..f375742 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php
index f232f1b..0febcae 100644
--- a/lang/en/auth_outage.php
+++ b/lang/en/auth_outage.php
@@ -24,25 +24,27 @@
*/
$string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.';
-$string['pluginname'] = 'Outage';
-
-$string['menudefaults'] = 'Default Settings';
-$string['menumanage'] = 'Manage';
-
-$string['defaultwarningtime'] = 'Default Warning Time';
-$string['defaultwarningtimedescription'] = 'Default warning time (in minutes) for outages.';
$string['defaultwarningmessage'] = 'Default Warning Message';
$string['defaultwarningmessagedescription'] = 'Default warning message for outages. Use [from] and [until] placeholders as required.';
$string['defaultwarningmessagevalue'] = 'There is an scheduled maintenance from [from] to [until] and our system will not be available during that time.';
-
-$string['starttime'] = 'Start date and time';
-$string['stoptime'] = 'Stop date and time';
-$string['warningduration'] = 'Warning duration';
-$string['title'] = 'Title';
+$string['defaultwarningtime'] = 'Default Warning Time';
+$string['defaultwarningtimedescription'] = 'Default warning time (in minutes) for outages.';
$string['description'] = 'Public description';
-$string['modifyoutage'] = 'Modify Outage';
-$string['removeoutage'] = 'Remove Outage';
-$string['removeoutagewarning'] = 'You are about to permanently remove the outage below. This cannot be undone.';
-$string['outageslist'] = 'Outages List';
-$string['createoutage'] = 'Create Outage';
+$string['menudefaults'] = 'Default Settings';
+$string['menumanage'] = 'Manage';
$string['modify'] = 'Modify';
+$string['modifyoutage'] = 'Modify Outage';
+$string['outagecreate'] = 'Create Outage';
+$string['outageremove'] = 'Remove Outage';
+$string['outageremovewarning'] = 'You are about to permanently remove the outage below. This cannot be undone.';
+$string['outageslist'] = 'Outages List';
+$string['pluginname'] = 'Outage';
+$string['starttimeerrornotinfuture'] = 'Start time must be in the future.';
+$string['starttime'] = 'Start date and time';
+$string['stoptimeerrornotafterstart'] = 'Stop time must be after start time.';
+$string['stoptime'] = 'Stop date and time';
+$string['titleerrorinvalid'] = 'Title cannot be left blank.';
+$string['titleerrortoolong'] = 'Title cannot have more than {$a} characters.';
+$string['title'] = 'Title';
+$string['warningdurationerrorinvalid'] = 'Warning duration cannot be zero.';
+$string['warningduration'] = 'Warning duration';
diff --git a/renderer.php b/renderer.php
index f95945d..d6848b1 100644
--- a/renderer.php
+++ b/renderer.php
@@ -39,8 +39,8 @@ class auth_outage_renderer extends plugin_renderer_base
}
public function renderdeleteconfirmation(outage $outage) {
- return $this->rendersubtitle('removeoutage')
- . html_writer::tag('p', get_string('removeoutagewarning', 'auth_outage'))
+ return $this->rendersubtitle('outageremove')
+ . html_writer::tag('p', get_string('outageremovewarning', 'auth_outage'))
. $this->renderoutage($outage, false);
}
@@ -61,7 +61,7 @@ class auth_outage_renderer extends plugin_renderer_base
$html .= html_writer::empty_tag('br')
. html_writer::link(
$url,
- $img . ' ' . get_string('createoutage', 'auth_outage'),
+ $img . ' ' . get_string('outagecreate', 'auth_outage'),
['title' => get_string('remove')])
. html_writer::empty_tag('br');
diff --git a/version.php b/version.php
index 0f174e7..6a77e7d 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@ if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
-$plugin->version = 2016090100; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2016090500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = $plugin->version; // Same as version
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
$plugin->component = "auth_outage";