. /** * Service editor. * * @package local_webhooks * @copyright 2017 "Valentin Popov" * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once(__DIR__ . "/../../config.php"); require_once(__DIR__ . "/classes/editform.php"); require_once($CFG->libdir . "/adminlib.php"); /* Optional parameters */ $serviceid = optional_param("serviceid", 0, PARAM_INT); /* Link generation */ $urlparameters = array("serviceid" => $serviceid); $managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters); $baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters); /* Configure the context of the page */ admin_externalpage_setup("local_webhooks", "", null, $baseurl, array()); $context = context_system::instance(); /* Create an editing form */ $mform = new \local_webhooks\service_edit_form($PAGE->url); /* Cancel processing */ if ($mform->is_cancelled()) { redirect($managerservice); } /* Getting the data */ $servicerecord = new stdClass(); if ($editing = boolval($serviceid)) { $servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST); $mform->set_data($servicerecord); } /* Processing of received data */ if ($data = $mform->get_data()) { if (empty($data->events)) { $data->events = array(); } /* Pack the list of events */ $data->events = base64_encode(gzcompress(serialize($data->events), 9)); if ($editing) { $data->id = $serviceid; $DB->update_record("local_webhooks_service", $data); /* Run the event */ $event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $data->id)); $event->trigger(); redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice")); } else { $servicenewid = $DB->insert_record("local_webhooks_service", $data); /* Run the event */ $event = \local_webhooks\event\service_added::create(array("context" => $context, "objectid" => $servicenewid)); $event->trigger(); redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice")); } } /* The page title */ $titlepage = new lang_string("externalservice", "webservice"); $PAGE->navbar->add($titlepage); $PAGE->set_heading($titlepage); $PAGE->set_title($titlepage); echo $OUTPUT->header(); /* Displays the form */ $mform->display(); echo $OUTPUT->footer();