-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplates.php
More file actions
133 lines (117 loc) · 4.78 KB
/
templates.php
File metadata and controls
133 lines (117 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// This file is part of 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
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Template list and management.
*
* @package local_bbcomailing
* @copyright 2026 David Herney @ BambuCo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\output\html_writer;
use core_table\output\html_table;
use core\url as moodle_url;
use core\context\system as context_system;
require_once('../../config.php');
require_login();
$context = context_system::instance();
require_capability('local/bbcomailing:manage', $context);
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/local/bbcomailing/templates.php'));
$PAGE->set_title(get_string('pluginname', 'local_bbcomailing'));
$PAGE->set_heading(get_string('pluginname', 'local_bbcomailing'));
$PAGE->set_pagelayout('admin');
// Handle template copy.
$copy = optional_param('copy', 0, PARAM_INT);
if ($copy && confirm_sesskey()) {
$newid = \local_bbcomailing\manager::copy_template($copy);
\local_bbcomailing\event\template_created::create([
'context' => $context,
'objectid' => $newid,
])->trigger();
redirect($PAGE->url, get_string('templatecopied', 'local_bbcomailing'));
}
// Handle template deletion.
$delete = optional_param('delete', 0, PARAM_INT);
if ($delete && confirm_sesskey()) {
\local_bbcomailing\manager::delete_template($delete);
\local_bbcomailing\event\template_deleted::create([
'context' => $context,
'objectid' => $delete,
])->trigger();
redirect($PAGE->url, get_string('templatedeleted', 'local_bbcomailing'));
}
echo $OUTPUT->header();
// Navigation tabs.
echo \local_bbcomailing\manager::render_tabs('templates');
// Button to create new template.
$newurl = new moodle_url('/local/bbcomailing/template.php');
$newtpllabel = $OUTPUT->pix_icon('t/add', get_string('newtemplate', 'local_bbcomailing'));
$newtpllabel .= ' ' . get_string('newtemplate', 'local_bbcomailing');
echo html_writer::link(
$newurl,
$newtpllabel,
['class' => 'btn btn-primary mb-3']
);
// Templates table.
echo $OUTPUT->heading(get_string('templates', 'local_bbcomailing'), 3);
$templates = \local_bbcomailing\manager::get_templates();
if (empty($templates)) {
echo html_writer::tag('p', get_string('notemplates', 'local_bbcomailing'));
} else {
$table = new html_table();
$table->head = [
get_string('name', 'local_bbcomailing'),
get_string('timecreated', 'local_bbcomailing'),
get_string('actions', 'local_bbcomailing'),
];
$table->attributes['class'] = 'generaltable';
foreach ($templates as $tpl) {
$editurl = new moodle_url('/local/bbcomailing/template.php', ['id' => $tpl->id]);
$copyurl = new moodle_url('/local/bbcomailing/templates.php', ['copy' => $tpl->id, 'sesskey' => sesskey()]);
$previewurl = new moodle_url('/local/bbcomailing/template.php', ['id' => $tpl->id, 'preview' => 1]);
$deleteurl = new moodle_url('/local/bbcomailing/templates.php', ['delete' => $tpl->id, 'sesskey' => sesskey()]);
$useurl = new moodle_url('/local/bbcomailing/send.php', ['tplid' => $tpl->id]);
$actions = html_writer::link($editurl, $OUTPUT->pix_icon('t/edit', get_string('edit')));
$actions .= ' ';
$actions .= html_writer::link(
$copyurl,
$OUTPUT->pix_icon('t/copy', get_string('copytemplate', 'local_bbcomailing'))
);
$actions .= ' ';
$actions .= html_writer::link(
$useurl,
$OUTPUT->pix_icon('t/email', get_string('usetemplate', 'local_bbcomailing'))
);
$actions .= ' ';
$actions .= html_writer::link(
$previewurl,
$OUTPUT->pix_icon('t/preview', get_string('preview', 'local_bbcomailing'))
);
$actions .= ' ';
$actions .= html_writer::link(
$deleteurl,
$OUTPUT->pix_icon('t/delete', get_string('delete')),
['onclick' => 'return confirm("' . get_string('deletetemplate_confirm', 'local_bbcomailing') . '")']
);
$table->data[] = [
s($tpl->name),
userdate($tpl->timecreated),
$actions,
];
}
echo html_writer::table($table);
}
echo $OUTPUT->footer();