.
/**
* Edit the htmlcert settings.
*
* @package mod_htmlcert
* @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
$tid = optional_param('tid', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
if ($action) {
$actionid = required_param('aid', PARAM_INT);
}
$confirm = optional_param('confirm', 0, PARAM_INT);
// Edit an existing template.
if ($tid) {
// Create the template object.
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
$template = new \mod_htmlcert\template($template);
// Set the context.
$contextid = $template->get_contextid();
// Set the page url.
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $tid));
} else { // Adding a new template.
// Need to supply the contextid.
$contextid = required_param('contextid', PARAM_INT);
// Set the page url.
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('contextid' => $contextid));
}
$context = context::instance_by_id($contextid);
if ($context->contextlevel == CONTEXT_MODULE) {
$cm = get_coursemodule_from_id('htmlcert', $context->instanceid, 0, false, MUST_EXIST);
require_login($cm->course, false, $cm);
$htmlcert = $DB->get_record('htmlcert', ['id' => $cm->instance], '*', MUST_EXIST);
$title = $htmlcert->name;
$heading = format_string($title);
} else {
require_login();
$title = $SITE->fullname;
$heading = $title;
}
require_capability('mod/htmlcert:manage', $context);
// Set up the page.
\mod_htmlcert\page_helper::page_setup($pageurl, $context, $title);
if ($context->contextlevel == CONTEXT_SYSTEM) {
// We are managing a template - add some navigation.
$PAGE->navbar->add(get_string('managetemplates', 'htmlcert'),
new moodle_url('/mod/htmlcert/manage_templates.php'));
if (!$tid) {
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'));
} else {
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'),
new moodle_url('/mod/htmlcert/edit.php', ['tid' => $tid]));
}
}
if ($tid) {
$mform = new \mod_htmlcert\edit_form($pageurl, array('tid' => $tid));
// Set the name for the form.
$mform->set_data(array('name' => $template->get_name()));
} else {
$mform = new \mod_htmlcert\edit_form($pageurl);
}
if ($data = $mform->get_data()) {
// If there is no id, then we are creating a template.
if (!$tid) {
$template = \mod_htmlcert\template::create($data->name, $contextid);
}
// Save any data for the template.
$template->save($data);
// Check if we want to preview this custom certificate.
if (!empty($data->previewbtn)) {
$template->generate_pdf(true);
exit();
}
// Redirect to the editing page to show form with recent updates.
$url = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $template->get_id()));
redirect($url);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($heading);
$mform->display();
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
$loadtemplateurl = new moodle_url('/mod/htmlcert/load_template.php', array('tid' => $tid));
$loadtemplateform = new \mod_htmlcert\load_template_form($loadtemplateurl, array('context' => $context), 'post',
'', array('id' => 'loadtemplateform'));
$loadtemplateform->display();
}
echo $OUTPUT->footer();