. /** * Edit an outage. * * @package auth_outage * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use auth_outage\dml\outagedb; use auth_outage\form\outage\edit; use auth_outage\local\outage; use auth_outage\local\outagelib; use auth_outage\output\renderer; require_once(__DIR__.'/../../config.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/formslib.php'); admin_externalpage_setup('auth_outage_manage'); $PAGE->set_url(new moodle_url('/auth/outage/manage.php')); $mform = new edit(); if ($mform->is_cancelled()) { redirect(new moodle_url('/auth/outage/manage.php')); } else if ($outage = $mform->get_data()) { $id = outagedb::save($outage); redirect($CFG->wwwroot. '/auth/outage/manage.php#auth_outage_id_'.$id); } $clone = optional_param('clone', 0, PARAM_INT); $edit = optional_param('edit', 0, PARAM_INT); if ($clone && $edit) { throw new invalid_parameter_exception('Cannot provide both clone and edit ids.'); } if ($clone) { // Remove outage id to force creating a new one. $outage = outagedb::get_by_id($clone); $outage->id = null; $action = 'outageclone'; } else if ($edit) { $outage = outagedb::get_by_id($edit); $action = 'outageedit'; } else { $config = outagelib::get_config(); $time = time(); $outage = new outage([ 'autostart' => $config->default_autostart, 'starttime' => $time, 'stoptime' => $time + $config->default_duration, 'warntime' => $time - $config->default_warning_duration, 'title' => $config->default_title, 'description' => $config->default_description, ]); $action = 'outagecreate'; } if ($outage == null) { throw new invalid_parameter_exception('Outage not found.'); } $mform->set_data($outage); $PAGE->navbar->add(get_string($action.'crumb', 'auth_outage')); echo $OUTPUT->header(); echo renderer::get()->rendersubtitle($action); $mform->display(); echo $OUTPUT->footer();