2012-12-07 09:34:46 +00:00
|
|
|
<?php
|
2021-11-24 07:29:43 +00:00
|
|
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
2012-12-07 09:34:46 +00:00
|
|
|
//
|
|
|
|
// 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/>.
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Edit the htmlcert settings.
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @package mod_htmlcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
2012-12-07 09:34:46 +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 = optional_param('tid', 0, PARAM_INT);
|
2016-02-20 09:12:32 +00:00
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
if ($action) {
|
|
|
|
$actionid = required_param('aid', PARAM_INT);
|
|
|
|
}
|
2012-12-07 09:34:46 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_INT);
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
// Edit an existing template.
|
|
|
|
if ($tid) {
|
|
|
|
// Create the template object.
|
2021-11-24 07:29:43 +00:00
|
|
|
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
|
|
|
$template = new \mod_htmlcert\template($template);
|
2016-02-16 09:03:34 +00:00
|
|
|
// Set the context.
|
|
|
|
$contextid = $template->get_contextid();
|
|
|
|
// Set the page url.
|
2021-11-24 07:29:43 +00:00
|
|
|
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $tid));
|
2016-02-16 09:03:34 +00:00
|
|
|
} else { // Adding a new template.
|
|
|
|
// Need to supply the contextid.
|
|
|
|
$contextid = required_param('contextid', PARAM_INT);
|
|
|
|
// Set the page url.
|
2021-11-24 07:29:43 +00:00
|
|
|
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('contextid' => $contextid));
|
2016-02-16 09:03:34 +00:00
|
|
|
}
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
$context = context::instance_by_id($contextid);
|
|
|
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$cm = get_coursemodule_from_id('htmlcert', $context->instanceid, 0, false, MUST_EXIST);
|
2016-02-16 09:03:34 +00:00
|
|
|
require_login($cm->course, false, $cm);
|
2018-06-26 10:50:21 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$htmlcert = $DB->get_record('htmlcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
|
|
|
$title = $htmlcert->name;
|
2018-06-26 10:50:21 +00:00
|
|
|
$heading = format_string($title);
|
2016-02-16 09:03:34 +00:00
|
|
|
} else {
|
|
|
|
require_login();
|
2018-06-26 10:50:21 +00:00
|
|
|
$title = $SITE->fullname;
|
|
|
|
$heading = $title;
|
2016-02-16 09:03:34 +00:00
|
|
|
}
|
2018-06-26 10:50:21 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
require_capability('mod/htmlcert:manage', $context);
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
// Set up the page.
|
2021-11-24 07:29:43 +00:00
|
|
|
\mod_htmlcert\page_helper::page_setup($pageurl, $context, $title);
|
2016-02-16 09:03:34 +00:00
|
|
|
|
|
|
|
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
|
|
|
// We are managing a template - add some navigation.
|
2021-11-24 07:29:43 +00:00
|
|
|
$PAGE->navbar->add(get_string('managetemplates', 'htmlcert'),
|
|
|
|
new moodle_url('/mod/htmlcert/manage_templates.php'));
|
2018-06-26 10:50:21 +00:00
|
|
|
if (!$tid) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'));
|
2018-06-26 10:50:21 +00:00
|
|
|
} else {
|
2021-11-24 07:29:43 +00:00
|
|
|
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'),
|
|
|
|
new moodle_url('/mod/htmlcert/edit.php', ['tid' => $tid]));
|
2018-06-26 10:50:21 +00:00
|
|
|
}
|
2013-05-03 10:51:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
if ($tid) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$mform = new \mod_htmlcert\edit_form($pageurl, array('tid' => $tid));
|
2016-02-16 09:03:34 +00:00
|
|
|
// Set the name for the form.
|
2021-11-24 12:32:08 +00:00
|
|
|
$mform->set_data(array('name' => $template->get_name(), 'html' => ''));
|
2016-02-16 09:03:34 +00:00
|
|
|
} else {
|
2021-11-24 07:29:43 +00:00
|
|
|
$mform = new \mod_htmlcert\edit_form($pageurl);
|
2016-02-16 09:03:34 +00:00
|
|
|
}
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
if ($data = $mform->get_data()) {
|
2016-02-16 09:03:34 +00:00
|
|
|
// If there is no id, then we are creating a template.
|
|
|
|
if (!$tid) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$template = \mod_htmlcert\template::create($data->name, $contextid);
|
2016-02-16 09:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save any data for the template.
|
|
|
|
$template->save($data);
|
|
|
|
|
2013-05-17 03:05:42 +00:00
|
|
|
// Check if we want to preview this custom certificate.
|
|
|
|
if (!empty($data->previewbtn)) {
|
2016-02-16 09:03:34 +00:00
|
|
|
$template->generate_pdf(true);
|
2017-05-31 08:08:42 +00:00
|
|
|
exit();
|
2013-05-17 03:05:42 +00:00
|
|
|
}
|
|
|
|
|
2012-12-07 09:34:46 +00:00
|
|
|
// Redirect to the editing page to show form with recent updates.
|
2021-11-24 07:29:43 +00:00
|
|
|
$url = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $template->get_id()));
|
2013-05-06 10:22:55 +00:00
|
|
|
redirect($url);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2018-06-26 10:50:21 +00:00
|
|
|
echo $OUTPUT->heading($heading);
|
2012-12-07 09:34:46 +00:00
|
|
|
$mform->display();
|
2017-09-03 09:30:04 +00:00
|
|
|
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$loadtemplateurl = new moodle_url('/mod/htmlcert/load_template.php', array('tid' => $tid));
|
|
|
|
$loadtemplateform = new \mod_htmlcert\load_template_form($loadtemplateurl, array('context' => $context), 'post',
|
2017-08-09 11:05:57 +00:00
|
|
|
'', array('id' => 'loadtemplateform'));
|
2013-05-03 10:51:41 +00:00
|
|
|
$loadtemplateform->display();
|
|
|
|
}
|
2012-12-07 09:34:46 +00:00
|
|
|
echo $OUTPUT->footer();
|