diff --git a/classes/forms/gohome.php b/classes/forms/gohome.php new file mode 100644 index 0000000..a457ca5 --- /dev/null +++ b/classes/forms/gohome.php @@ -0,0 +1,43 @@ +. + +namespace auth_outage\forms; + +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. +} + +require_once($CFG->libdir . '/formslib.php'); + +/** + * Home form. Shows a button 'Continue' and moves to home page once clicked. + * + * @package auth_outage + * @author Daniel Thee Roperto + * @copyright Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class gohome extends \moodleform { + const TITLE_MAX_CHARS = 100; + + /** + * {@inheritDoc} + * @see moodleform::definition() + */ + public function definition() { + $this->add_action_buttons(false, get_string('continue')); + } +} \ No newline at end of file diff --git a/classes/outagelib.php b/classes/outagelib.php index d893572..cbe46f5 100644 --- a/classes/outagelib.php +++ b/classes/outagelib.php @@ -39,7 +39,7 @@ class outagelib { public static function pagesetup() { global $PAGE; admin_externalpage_setup('auth_outage_manage'); - $PAGE->set_url(new \moodle_url('/auth/outage/list.php')); + $PAGE->set_url(new \moodle_url('/auth/outage/manage.php')); return self::get_renderer(); } @@ -68,7 +68,7 @@ class outagelib { return; } - $CFG->additionalhtmltopofbody = self::get_renderer()->renderbar($active) + $CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active) . $CFG->additionalhtmltopofbody; } diff --git a/info.php b/info.php new file mode 100644 index 0000000..73783f4 --- /dev/null +++ b/info.php @@ -0,0 +1,52 @@ +. + +/** + * List outages + * + * @package auth_outage + * @author Daniel Thee Roperto + * @copyright Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use auth_outage\outagedb; +use auth_outage\outagelib; + +require_once('../../config.php'); + +$outage = outagedb::get_active(); +if (is_null($outage)) { + redirect(new moodle_url('/')); +} + +$PAGE->set_context(context_system::instance()); +$PAGE->set_title("Outage Warning"); +$PAGE->set_heading("Outage Warning"); +$PAGE->set_url(new \moodle_url('/auth/outage/info.php')); + +$mform = new \auth_outage\forms\gohome(); +if ($mform->get_data()) { + redirect(new moodle_url('/')); +} + + +echo $OUTPUT->header(); + +echo outagelib::get_renderer()->renderoutagepage($outage); +$mform->display(); + +echo $OUTPUT->footer(); diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index 2200137..01fee89 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -24,6 +24,8 @@ */ $string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.'; +$string['defaultlayoutcss'] = 'Layout CSS'; +$string['defaultlayoutcssdescription'] = 'This CSS code will be used to display the Outage Warning Bar.'; $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.'; diff --git a/renderer.php b/renderer.php index d50bc15..3f76b52 100644 --- a/renderer.php +++ b/renderer.php @@ -125,10 +125,23 @@ class auth_outage_renderer extends plugin_renderer_base { ); } - public function renderbar($outage) { - global $PAGE; + public function renderoutagepage(outage $outage) { + $start = userdate($outage->starttime, get_string('strftimedatetimeshort')); + $stop = userdate($outage->stoptime, get_string('strftimedatetimeshort')); - $PAGE->requires->css(new moodle_url('/auth/outage/res/outage.css')); + return html_writer::div( + html_writer::tag('p', + html_writer::tag('b', 'From: ') + . $start + . html_writer::tag('b', ' Until: ') + . $stop + ) + . html_writer::div($outage->description) + ); + } + + public function renderoutagebar(outage $outage) { + global $CFG; $start = userdate($outage->starttime, get_string('strftimedatetimeshort')); $stop = userdate($outage->stoptime, get_string('strftimedatetimeshort')); @@ -140,15 +153,21 @@ class auth_outage_renderer extends plugin_renderer_base { ); return - html_writer::div( + html_writer::tag('style', $CFG->auth_outage_css) + . html_writer::div( html_writer::div( html_writer::div($outage->title, 'auth_outage_warningbar_box_title') - . html_writer::div($message, 'auth_outage_warningbar_box_message'), + . html_writer::div( + $message . ' ' + . html_writer::tag('small', + '[' . html_writer::link(new moodle_url('/auth/outage/info.php'), 'more') . ']' + ), + 'auth_outage_warningbar_box_message' + ), 'auth_outage_warningbar_box' ), 'auth_outage_warningbar' ) - . - html_writer::div(' ', 'auth_outage_warningbar_spacer'); + . html_writer::div(' ', 'auth_outage_warningbar_spacer'); } } diff --git a/res/outage.css b/res/default.css similarity index 79% rename from res/outage.css rename to res/default.css index 1269b0a..67a68b6 100644 --- a/res/outage.css +++ b/res/default.css @@ -1,3 +1,8 @@ +/* +This file is used as default value for the 'auth_outage_css' settings. +If you need to make chances here, remember to update your settings inside Moodle. +*/ + .auth_outage_warningbar { background-color: white; box-sizing: content-box; @@ -33,4 +38,4 @@ .auth_outage_warningbar_spacer { height: 80px; -} \ No newline at end of file +} diff --git a/settings.php b/settings.php index 61dfc18..aca99c7 100644 --- a/settings.php +++ b/settings.php @@ -39,6 +39,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) { get_string('defaultwarningmessagevalue', 'auth_outage'), PARAM_TEXT) ); + $settings->add( + new admin_setting_configtextarea('auth_outage_css', + get_string('defaultlayoutcss', 'auth_outage'), + get_string('defaultlayoutcssdescription', 'auth_outage'), + file_get_contents($CFG->dirroot.'/auth/outage/res/default.css'), + PARAM_TEXT) + ); // Create category for Outage. $ADMIN->add('authsettings', new admin_category('auth_outage', get_string('pluginname', 'auth_outage'))); // Add settings page toconfigure defaults.