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 |
* Prints an instance of mod_custommailing.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_custommailing
|
|
|
21 |
* @author olivier@cblue.be
|
|
|
22 |
* @copyright 2021 CBlue SPRL
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
use core\output\notification;
|
|
|
27 |
use mod_custommailing\Mailing;
|
|
|
28 |
|
|
|
29 |
require_once __DIR__ . '/../../config.php';
|
|
|
30 |
|
|
|
31 |
global $CFG, $DB, $PAGE, $OUTPUT;
|
|
|
32 |
|
|
|
33 |
require_once $CFG->dirroot . '/mod/custommailing/lib.php';
|
|
|
34 |
|
|
|
35 |
$id = required_param('id', PARAM_INT);
|
|
|
36 |
$mailing_id = required_param('mailingid', PARAM_INT);
|
|
|
37 |
$delete = optional_param('delete', false, PARAM_BOOL);
|
|
|
38 |
$confirm = optional_param('confirm', '', PARAM_ALPHANUM);
|
|
|
39 |
|
|
|
40 |
[$course, $cm] = get_course_and_cm_from_cmid($id, 'custommailing');
|
|
|
41 |
$custommailing = $DB->get_record("custommailing", ['id' => $cm->instance], '*', MUST_EXIST);
|
|
|
42 |
$context = context_module::instance($cm->id);
|
|
|
43 |
$mailing = $DB->get_record("custommailing_mailing", ['id' => $mailing_id], '*', MUST_EXIST);
|
|
|
44 |
|
|
|
45 |
require_login($course, false, $cm);
|
|
|
46 |
require_capability('mod/custommailing:manage', $context);
|
|
|
47 |
|
|
|
48 |
$url = new moodle_url('/mod/custommailing/delete.php', ['id' => $id, 'mailingid' => $mailing_id]);
|
|
|
49 |
$return_url = new moodle_url('/mod/custommailing/view.php', ['id' => $cm->id]);
|
|
|
50 |
|
|
|
51 |
$PAGE->set_url($url);
|
|
|
52 |
$PAGE->set_title(format_string($course->shortname . ': ' . $custommailing->name));
|
|
|
53 |
$PAGE->set_heading(format_string($course->fullname));
|
|
|
54 |
$PAGE->set_context($context);
|
|
|
55 |
|
|
|
56 |
if ($delete == true && $confirm == md5($mailing_id) && confirm_sesskey()) {
|
|
|
57 |
Mailing::delete($mailing_id);
|
|
|
58 |
redirect($return_url, get_string('mailingdeleted', 'mod_custommailing'), null, notification::NOTIFY_SUCCESS);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
echo $OUTPUT->header();
|
|
|
62 |
echo $OUTPUT->heading(format_string($custommailing->name));
|
|
|
63 |
|
|
|
64 |
echo $OUTPUT->confirm(
|
|
|
65 |
get_string('confirmdelete', 'mod_custommailing', $mailing->mailingname),
|
|
|
66 |
new single_button(
|
|
|
67 |
new moodle_url($url, ['delete' => true, 'confirm' => md5($mailing_id), 'sesskey' => sesskey()]),
|
|
|
68 |
get_string('delete'),
|
|
|
69 |
'post'
|
|
|
70 |
),
|
|
|
71 |
$return_url
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
echo $OUTPUT->footer();
|