1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Handles loading a customcert template.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_customcert
|
|
|
21 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../../config.php');
|
|
|
26 |
|
|
|
27 |
$tid = required_param('tid', PARAM_INT);
|
|
|
28 |
$ltid = required_param('ltid', PARAM_INT); // The template to load.
|
|
|
29 |
$confirm = optional_param('confirm', 0, PARAM_INT);
|
|
|
30 |
|
|
|
31 |
$template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST);
|
|
|
32 |
$template = new \mod_customcert\template($template);
|
|
|
33 |
|
|
|
34 |
$loadtemplate = $DB->get_record('customcert_templates', ['id' => $ltid], '*', MUST_EXIST);
|
|
|
35 |
$loadtemplate = new \mod_customcert\template($loadtemplate);
|
|
|
36 |
|
|
|
37 |
if ($cm = $template->get_cm()) {
|
|
|
38 |
require_login($cm->course, false, $cm);
|
|
|
39 |
} else {
|
|
|
40 |
require_login();
|
|
|
41 |
}
|
|
|
42 |
$template->require_manage();
|
|
|
43 |
|
|
|
44 |
if ($template->get_context()->contextlevel == CONTEXT_MODULE) {
|
|
|
45 |
$customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
|
|
46 |
$title = $customcert->name;
|
|
|
47 |
} else {
|
|
|
48 |
$title = $SITE->fullname;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
// Check that they have confirmed they wish to load the template.
|
|
|
52 |
if ($confirm && confirm_sesskey()) {
|
|
|
53 |
// First, remove all the existing elements and pages.
|
|
|
54 |
if ($pages = $DB->get_records('customcert_pages', ['templateid' => $template->get_id()])) {
|
|
|
55 |
foreach ($pages as $page) {
|
|
|
56 |
$template->delete_page($page->id, false);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
// Copy the items across.
|
|
|
61 |
$loadtemplate->copy_to_template($template);
|
|
|
62 |
|
|
|
63 |
// Redirect.
|
|
|
64 |
$url = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]);
|
|
|
65 |
redirect($url);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
// Create the link options.
|
|
|
69 |
$nourl = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]);
|
|
|
70 |
$yesurl = new moodle_url('/mod/customcert/load_template.php', ['tid' => $tid,
|
|
|
71 |
'ltid' => $ltid,
|
|
|
72 |
'confirm' => 1,
|
|
|
73 |
'sesskey' => sesskey()]);
|
|
|
74 |
|
|
|
75 |
$pageurl = new moodle_url('/mod/customcert/load_template.php', ['tid' => $tid, 'ltid' => $ltid]);
|
|
|
76 |
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
|
|
77 |
$PAGE->activityheader->set_attrs(['hidecompletion' => true,
|
|
|
78 |
'description' => '']);
|
|
|
79 |
|
|
|
80 |
$str = get_string('editcustomcert', 'customcert');
|
|
|
81 |
$link = new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]);
|
|
|
82 |
$PAGE->navbar->add($str, new \action_link($link, $str));
|
|
|
83 |
$PAGE->navbar->add(get_string('loadtemplate', 'customcert'));
|
|
|
84 |
|
|
|
85 |
// Show a confirmation page.
|
|
|
86 |
echo $OUTPUT->header();
|
|
|
87 |
echo $OUTPUT->confirm(get_string('loadtemplatemsg', 'customcert'), $yesurl, $nourl);
|
|
|
88 |
echo $OUTPUT->footer();
|