diff options
author | Valentin Popov <info@valentineus.link> | 2017-11-22 12:59:02 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2017-11-22 12:59:02 +0300 |
commit | 57cac60ab3cab5c65fdf92e986da110863d02de4 (patch) | |
tree | f69ad54173d34fd0f5b577d2dc5a57018fa94fdd | |
parent | d4d105c0180e1a02396f00f924679ac0a84a8654 (diff) | |
download | local_webhooks-57cac60ab3cab5c65fdf92e986da110863d02de4.tar.xz local_webhooks-57cac60ab3cab5c65fdf92e986da110863d02de4.zip |
Code refactoring
-rw-r--r-- | editservice.php | 18 | ||||
-rw-r--r-- | managerservice.php | 28 | ||||
-rw-r--r-- | restorebackup.php | 15 |
3 files changed, 19 insertions, 42 deletions
diff --git a/editservice.php b/editservice.php index 4564909..907a41d 100644 --- a/editservice.php +++ b/editservice.php @@ -26,8 +26,6 @@ require_once(__DIR__ . "/../../config.php"); require_once(__DIR__ . "/classes/editform.php"); require_once($CFG->libdir . "/adminlib.php"); -admin_externalpage_setup("local_webhooks"); - /* Optional parameters */ $serviceid = optional_param("serviceid", 0, PARAM_INT); @@ -35,15 +33,10 @@ $serviceid = optional_param("serviceid", 0, PARAM_INT); $urlparameters = array("serviceid" => $serviceid); $managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters); $baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters); -$PAGE->set_url($baseurl, $urlparameters); /* Configure the context of the page */ +admin_externalpage_setup("local_webhooks", "", null, $baseurl, array()); $context = context_system::instance(); -$PAGE->set_context($context); - -/* Preparing a template for data */ -$titlepage = new lang_string("externalservice", "webservice"); -$servicerecord = new stdClass; /* Create an editing form */ $mform = new \local_webhooks\service_edit_form($PAGE->url); @@ -54,6 +47,7 @@ if ($mform->is_cancelled()) { } /* 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); @@ -88,13 +82,11 @@ if ($data = $mform->get_data()) { } } -/* Page template */ -$PAGE->set_pagelayout("admin"); -$PAGE->set_heading($titlepage); -$PAGE->set_title($titlepage); - /* 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 */ diff --git a/managerservice.php b/managerservice.php index f15ef21..a27db1d 100644 --- a/managerservice.php +++ b/managerservice.php @@ -26,28 +26,23 @@ require_once(__DIR__ . "/../../config.php"); require_once($CFG->libdir . "/tablelib.php"); require_once($CFG->libdir . "/adminlib.php"); -admin_externalpage_setup("local_webhooks"); - /* Optional parameters */ $backupservices = optional_param("getbackup", 0, PARAM_BOOL); $deleteid = optional_param("deleteid", 0, PARAM_INT); $hideshowid = optional_param("hideshowid", 0, PARAM_INT); -/* Used references */ +/* Link generation */ $editservice = "/local/webhooks/editservice.php"; $managerservice = "/local/webhooks/managerservice.php"; $restorebackup = "/local/webhooks/restorebackup.php"; - -/* Link generation */ -$baseurl = new moodle_url($managerservice); -$PAGE->set_url($baseurl); +$baseurl = new moodle_url($managerservice); /* Configure the context of the page */ +admin_externalpage_setup("local_webhooks", "", null, $baseurl, array()); $context = context_system::instance(); -$PAGE->set_context($context); /* Delete the service */ -if (boolval($deleteid) && confirm_sesskey()) { +if (boolval($deleteid)) { $DB->delete_records("local_webhooks_service", array("id" => $deleteid)); /* Run the event */ @@ -73,7 +68,7 @@ if (boolval($backupservices)) { } /* Switching the status of the service */ -if (boolval($hideshowid) && confirm_sesskey()) { +if (boolval($hideshowid)) { $callback = $callbacks[$hideshowid]; if (!empty($callback)) { @@ -88,13 +83,10 @@ if (boolval($hideshowid) && confirm_sesskey()) { } } -/* Page template */ +/* The page title */ $titlepage = new lang_string("pluginname", "local_webhooks"); -$PAGE->set_pagelayout("admin"); -$PAGE->set_title($titlepage); $PAGE->set_heading($titlepage); - -/* The page title */ +$PAGE->set_title($titlepage); echo $OUTPUT->header(); /* Table declaration */ @@ -120,7 +112,7 @@ foreach ($callbacks as $callback) { } /* Link to enable / disable the service */ - $hideshowlink = new moodle_url($managerservice, array("hideshowid" => $callback->id, "sesskey" => sesskey())); + $hideshowlink = new moodle_url($managerservice, array("hideshowid" => $callback->id)); $hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring)); /* Link for editing */ @@ -128,7 +120,7 @@ foreach ($callbacks as $callback) { $edititem = $OUTPUT->action_icon($editlink, new pix_icon("t/edit", new lang_string("edit", "moodle"))); /* Link to remove */ - $deletelink = new moodle_url($managerservice, array("deleteid" => $callback->id, "sesskey" => sesskey())); + $deletelink = new moodle_url($managerservice, array("deleteid" => $callback->id)); $deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon("t/delete", new lang_string("delete", "moodle"))); /* Adding data to the table */ @@ -147,7 +139,7 @@ $backupurl = new moodle_url($managerservice, array("getbackup" => true)); echo $OUTPUT->single_button($backupurl, new lang_string("backup", "moodle"), "get"); /* Button for restoring settings */ -$restorebackupurl = new moodle_url($restorebackup, array("sesskey" => sesskey())); +$restorebackupurl = new moodle_url($restorebackup); echo $OUTPUT->single_button($restorebackupurl, new lang_string("restore", "moodle"), "get"); echo $OUTPUT->footer();
\ No newline at end of file diff --git a/restorebackup.php b/restorebackup.php index 75a6fb7..453e25c 100644 --- a/restorebackup.php +++ b/restorebackup.php @@ -26,16 +26,13 @@ require_once(__DIR__ . "/../../config.php"); require_once(__DIR__ . "/classes/editform.php"); require_once($CFG->libdir . "/adminlib.php"); -admin_externalpage_setup("local_webhooks"); - /* Link generation */ $managerservice = new moodle_url("/local/webhooks/managerservice.php"); $baseurl = new moodle_url("/local/webhooks/restorebackup.php"); -$PAGE->set_url($baseurl); /* Configure the context of the page */ +admin_externalpage_setup("local_webhooks", "", null, $baseurl, array()); $context = context_system::instance(); -$PAGE->set_context($context); /* Create an editing form */ $mform = new \local_webhooks\service_backup_form($PAGE->url); @@ -46,8 +43,7 @@ if ($mform->is_cancelled()) { } /* Processing the received file */ -$data = $mform->get_data(); -if (boolval($data) && confirm_sesskey()) { +if ($data = $mform->get_data() && confirm_sesskey()) { $content = $mform->get_file_content("backupfile"); $callbacks = unserialize(gzuncompress(base64_decode($content))); @@ -63,14 +59,11 @@ if (boolval($data) && confirm_sesskey()) { redirect($managerservice, new lang_string("restorefinished", "moodle")); } -/* Page template */ +/* The page title */ $titlepage = new lang_string("backup", "moodle"); -$PAGE->set_pagelayout("admin"); +$PAGE->navbar->add($titlepage); $PAGE->set_heading($titlepage); $PAGE->set_title($titlepage); - -/* The page title */ -$PAGE->navbar->add($titlepage); echo $OUTPUT->header(); /* Displays the form */ |