From 9b223669df8b17669013d0e94c4278bc3a1666e6 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 29 Nov 2017 01:40:44 +0400 Subject: Template editor --- editor.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 editor.php diff --git a/editor.php b/editor.php new file mode 100644 index 0000000..efa129e --- /dev/null +++ b/editor.php @@ -0,0 +1,81 @@ +. + +/** + * The token editor. + * + * @package tool_managertokens + * @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/editor_form.php"); +require_once(__DIR__ . "/lib.php"); + +require_once($CFG->libdir . "/adminlib.php"); + +/* Optional parameters */ +$tokenid = optional_param("tokenid", 0, PARAM_INT); + +/* Link generation */ +$urlparameters = array("tokenid" => $tokenid); +$baseurl = new moodle_url("/admin/tool/managertokens/editor.php", $urlparameters); +$managertokens = new moodle_url("/admin/tool/managertokens/index.php"); + +/* Configure the context of the page */ +admin_externalpage_setup("tool_managertokens", "", null, $baseurl, array()); +$context = context_system::instance(); + +/* Create an editing form */ +$mform = new token_editor_form($PAGE->url); + +/* Cancel processing */ +if ($mform->is_cancelled()) { + redirect($managertokens); +} + +/* Getting the data */ +$tokenrecord = new stdClass(); +if ($editing = boolval($tokenid)) { + $tokenrecord = tool_managertokens_find_record($tokenid); + $mform->set_data($tokenrecord); +} + +/* Processing of received data */ +if ($data = $mform->get_data()) { + if ($editing) { + $data->id = $tokenid; + tool_managertokens_update_record($data); + redirect($managertokens, new lang_string("update", "moodle")); + } else { + tool_managertokens_create_record($data); + redirect($managertokens, new lang_string("create", "moodle")); + } +} + +/* The page title */ +$titlepage = new lang_string("editsettings", "moodle"); +$PAGE->navbar->add($titlepage); +$PAGE->set_heading($titlepage); +$PAGE->set_title($titlepage); +echo $OUTPUT->header(); + +/* Displays the form */ +$mform->display(); + +/* Footer */ +echo $OUTPUT->footer(); \ No newline at end of file -- cgit v1.2.3