2013-06-06 10:59:08 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2013-07-22 05:06:18 +00:00
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2013-06-06 10:59:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a customcert element.
|
|
|
|
*
|
|
|
|
* @package mod_customcert
|
2013-07-22 05:06:18 +00:00
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
2013-06-06 10:59:08 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('../../config.php');
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
$tid = required_param('tid', PARAM_INT);
|
2013-06-06 10:59:08 +00:00
|
|
|
$action = required_param('action', PARAM_ALPHA);
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
|
|
|
|
|
|
|
// Set the template object.
|
|
|
|
$template = new \mod_customcert\template($template);
|
|
|
|
|
|
|
|
// Perform checks.
|
|
|
|
if ($cm = $template->get_cm()) {
|
|
|
|
require_login($cm->course, false, $cm);
|
|
|
|
} else {
|
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
// Make sure the user has the required capabilities.
|
|
|
|
$template->require_manage();
|
2013-06-06 10:59:08 +00:00
|
|
|
|
|
|
|
if ($action == 'edit') {
|
|
|
|
// The id of the element must be supplied if we are currently editing one.
|
|
|
|
$id = required_param('id', PARAM_INT);
|
|
|
|
$element = $DB->get_record('customcert_elements', array('id' => $id), '*', MUST_EXIST);
|
2016-02-16 09:03:34 +00:00
|
|
|
$pageurl = new moodle_url('/mod/customcert/edit_element.php', array('id' => $id, 'tid' => $tid, 'action' => $action));
|
2013-06-06 10:59:08 +00:00
|
|
|
} else { // Must be adding an element.
|
2016-02-16 09:03:34 +00:00
|
|
|
// We need to supply what element we want added to what page.
|
2013-06-06 10:59:08 +00:00
|
|
|
$pageid = required_param('pageid', PARAM_INT);
|
|
|
|
$element = new stdClass();
|
|
|
|
$element->element = required_param('element', PARAM_ALPHA);
|
2016-02-16 09:03:34 +00:00
|
|
|
$pageurl = new moodle_url('/mod/customcert/edit_element.php', array('tid' => $tid, 'element' => $element->element,
|
|
|
|
'pageid' => $pageid, 'action' => $action));
|
2013-06-06 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
// Set up the page.
|
|
|
|
$title = get_string('editelement', 'customcert');
|
|
|
|
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
2013-06-06 10:59:08 +00:00
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
// Additional page setup.
|
|
|
|
if ($template->get_context()->contextlevel == CONTEXT_SYSTEM) {
|
|
|
|
$PAGE->navbar->add(get_string('managetemplates', 'customcert'),
|
|
|
|
new moodle_url('/mod/customcert/manage_templates.php'));
|
|
|
|
}
|
|
|
|
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php',
|
|
|
|
array('tid' => $tid)));
|
|
|
|
$PAGE->navbar->add($title);
|
2013-06-06 10:59:08 +00:00
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
$mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element));
|
2013-06-06 10:59:08 +00:00
|
|
|
|
|
|
|
// Check if they cancelled.
|
|
|
|
if ($mform->is_cancelled()) {
|
2016-02-16 09:03:34 +00:00
|
|
|
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
2013-07-23 07:19:55 +00:00
|
|
|
redirect($url);
|
2013-06-06 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($data = $mform->get_data()) {
|
|
|
|
// Set the id, or page id depending on if we are editing an element, or adding a new one.
|
|
|
|
if ($action == 'edit') {
|
|
|
|
$data->id = $id;
|
|
|
|
} else {
|
|
|
|
$data->pageid = $pageid;
|
|
|
|
}
|
|
|
|
// Set the element variable.
|
|
|
|
$data->element = $element->element;
|
|
|
|
// Get an instance of the element class.
|
2017-08-26 05:27:19 +00:00
|
|
|
if ($e = \mod_customcert\element_factory::get_element_instance($data)) {
|
2013-06-06 10:59:08 +00:00
|
|
|
$e->save_form_elements($data);
|
|
|
|
}
|
2013-07-23 07:19:55 +00:00
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
2013-07-23 07:19:55 +00:00
|
|
|
redirect($url);
|
2013-06-06 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2016-02-16 09:03:34 +00:00
|
|
|
echo $OUTPUT->heading(get_string('editelement', 'customcert'));
|
2013-06-06 10:59:08 +00:00
|
|
|
$mform->display();
|
|
|
|
echo $OUTPUT->footer();
|