1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of 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 |
* Manage the various templates available
|
|
|
19 |
*
|
|
|
20 |
* @author Peter Dias
|
|
|
21 |
* @copyright 2021 Peter Dias
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
23 |
* @package mod_feedback
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once("../../config.php");
|
|
|
27 |
require_once("lib.php");
|
|
|
28 |
|
|
|
29 |
$id = required_param('id', PARAM_INT);
|
|
|
30 |
$templateid = optional_param('deletetemplate', 0, PARAM_INT);
|
|
|
31 |
|
|
|
32 |
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
|
|
|
33 |
$context = context_module::instance($cm->id);
|
|
|
34 |
|
|
|
35 |
require_login($course, true, $cm);
|
|
|
36 |
require_capability('mod/feedback:edititems', $context);
|
|
|
37 |
|
|
|
38 |
$feedback = $PAGE->activityrecord;
|
|
|
39 |
$systemcontext = context_system::instance();
|
|
|
40 |
|
|
|
41 |
$params = ['id' => $id];
|
|
|
42 |
$url = new moodle_url('/mod/feedback/manage_templates.php', $params);
|
|
|
43 |
|
|
|
44 |
$PAGE->set_url($url);
|
|
|
45 |
|
|
|
46 |
$PAGE->set_heading($course->fullname);
|
|
|
47 |
|
1441 |
ariadna |
48 |
/** @var \mod_feedback\output\renderer $renderer */
|
|
|
49 |
$renderer = $PAGE->get_renderer('mod_feedback');
|
|
|
50 |
$renderer->set_title(
|
|
|
51 |
[format_string($feedback->name), format_string($course->fullname)],
|
|
|
52 |
get_string('templates', 'feedback')
|
|
|
53 |
);
|
|
|
54 |
|
|
|
55 |
$PAGE->add_body_class('limitedwidth');
|
|
|
56 |
|
1 |
efrain |
57 |
// Process template deletion.
|
|
|
58 |
if ($templateid) {
|
|
|
59 |
require_sesskey();
|
|
|
60 |
require_capability('mod/feedback:deletetemplate', $context);
|
|
|
61 |
$template = $DB->get_record('feedback_template', ['id' => $templateid], '*', MUST_EXIST);
|
|
|
62 |
|
|
|
63 |
if ($template->ispublic) {
|
|
|
64 |
require_capability('mod/feedback:createpublictemplate', $systemcontext);
|
|
|
65 |
require_capability('mod/feedback:deletetemplate', $systemcontext);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
feedback_delete_template($template);
|
|
|
69 |
$successurl = new moodle_url('/mod/feedback/manage_templates.php', ['id' => $id]);
|
|
|
70 |
redirect($url, get_string('template_deleted', 'feedback'), null, \core\output\notification::NOTIFY_SUCCESS);
|
|
|
71 |
}
|
|
|
72 |
$PAGE->activityheader->set_attrs([
|
|
|
73 |
"hidecompletion" => true,
|
|
|
74 |
"description" => ''
|
|
|
75 |
]);
|
|
|
76 |
echo $OUTPUT->header();
|
1441 |
ariadna |
77 |
echo $OUTPUT->heading(get_string('templates', 'mod_feedback'));
|
1 |
efrain |
78 |
|
|
|
79 |
// First we get the course templates.
|
|
|
80 |
$templates = feedback_get_template_list($course, 'own');
|
|
|
81 |
echo $OUTPUT->box_start('coursetemplates');
|
1441 |
ariadna |
82 |
echo $OUTPUT->heading(get_string('coursetemplates', 'mod_feedback'), 3);
|
1 |
efrain |
83 |
|
|
|
84 |
$baseurl = new moodle_url('/mod/feedback/use_templ.php', $params);
|
1441 |
ariadna |
85 |
$tablecourse = new mod_feedback_templates_table('feedback_template_course_table', $baseurl);
|
1 |
efrain |
86 |
$tablecourse->display($templates);
|
|
|
87 |
echo $OUTPUT->box_end();
|
|
|
88 |
|
|
|
89 |
$templates = feedback_get_template_list($course, 'public');
|
|
|
90 |
echo $OUTPUT->box_start('publictemplates');
|
1441 |
ariadna |
91 |
echo $OUTPUT->heading(get_string('sitetemplates', 'mod_feedback'), 3);
|
|
|
92 |
$tablepublic = new mod_feedback_templates_table('feedback_template_public_table', $baseurl);
|
1 |
efrain |
93 |
$tablepublic->display($templates);
|
|
|
94 |
echo $OUTPUT->box_end();
|
|
|
95 |
echo $OUTPUT->footer();
|