2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This page handles deleting lesson overrides
21 * @copyright 2015 Jean-Michel vedrine
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once(__DIR__
. '/../../config.php');
27 require_once($CFG->dirroot
.'/mod/lesson/lib.php');
28 require_once($CFG->dirroot
.'/mod/lesson/locallib.php');
29 require_once($CFG->dirroot
.'/mod/lesson/override_form.php');
31 $overrideid = required_param('id', PARAM_INT
);
32 $confirm = optional_param('confirm', false, PARAM_BOOL
);
34 if (! $override = $DB->get_record('lesson_overrides', array('id' => $overrideid))) {
35 print_error('invalidoverrideid', 'lesson');
38 $lesson = new lesson($DB->get_record('lesson', array('id' => $override->lessonid
), '*', MUST_EXIST
));
40 if (! $cm = get_coursemodule_from_instance("lesson", $lesson->id
, $lesson->course
)) {
41 print_error('invalidcoursemodule');
43 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
45 $context = context_module
::instance($cm->id
);
47 require_login($course, false, $cm);
49 // Check the user has the required capabilities to modify an override.
50 require_capability('mod/lesson:manageoverrides', $context);
52 $url = new moodle_url('/mod/lesson/overridedelete.php', array('id' => $override->id
));
53 $confirmurl = new moodle_url($url, array('id' => $override->id
, 'confirm' => 1));
54 $cancelurl = new moodle_url('/mod/lesson/overrides.php', array('cmid' => $cm->id
));
56 if (!empty($override->userid
)) {
57 $cancelurl->param('mode', 'user');
60 // If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
64 $lesson->delete_override($override->id
);
69 // Prepare the page to show the confirmation form.
70 $stroverride = get_string('override', 'lesson');
71 $title = get_string('deletecheck', null, $stroverride);
74 $PAGE->set_pagelayout('admin');
75 $PAGE->navbar
->add($title);
76 $PAGE->set_title($title);
77 $PAGE->set_heading($course->fullname
);
79 echo $OUTPUT->header();
80 echo $OUTPUT->heading(format_string($lesson->name
, true, array('context' => $context)));
82 if ($override->groupid
) {
83 $group = $DB->get_record('groups', array('id' => $override->groupid
), 'id, name');
84 $confirmstr = get_string("overridedeletegroupsure", "lesson", $group->name
);
86 $namefields = get_all_user_name_fields(true);
87 $user = $DB->get_record('user', array('id' => $override->userid
),
88 'id, ' . $namefields);
89 $confirmstr = get_string("overridedeleteusersure", "lesson", fullname($user));
92 echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
94 echo $OUTPUT->footer();