Merge branch 'MDL-74441-400' of https://github.com/cameron1729/moodle into MOODLE_400...
[moodle.git] / mod / quiz / overridedelete.php
blob5f8004642f8f283b28e510a29eb4060da3b7a7b5
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.
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/>.
17 /**
18 * This page handles deleting quiz overrides
20 * @package mod_quiz
21 * @copyright 2010 Matt Petro
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/quiz/lib.php');
28 require_once($CFG->dirroot.'/mod/quiz/locallib.php');
29 require_once($CFG->dirroot.'/mod/quiz/override_form.php');
31 $overrideid = required_param('id', PARAM_INT);
32 $confirm = optional_param('confirm', false, PARAM_BOOL);
34 if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) {
35 print_error('invalidoverrideid', 'quiz');
37 if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) {
38 print_error('invalidcoursemodule');
40 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $quiz->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/quiz:manageoverrides', $context);
52 if ($override->groupid) {
53 if (!groups_group_visible($override->groupid, $course, $cm)) {
54 print_error('invalidoverrideid', 'quiz');
56 } else {
57 if (!groups_user_groups_visible($course, $override->userid, $cm)) {
58 print_error('invalidoverrideid', 'quiz');
62 $url = new moodle_url('/mod/quiz/overridedelete.php', array('id'=>$override->id));
63 $confirmurl = new moodle_url($url, array('id'=>$override->id, 'confirm'=>1));
64 $cancelurl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
66 if (!empty($override->userid)) {
67 $cancelurl->param('mode', 'user');
70 // If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
71 if ($confirm) {
72 require_sesskey();
74 // Set the course module id before calling quiz_delete_override().
75 $quiz->cmid = $cm->id;
76 quiz_delete_override($quiz, $override->id);
78 redirect($cancelurl);
81 // Prepare the page to show the confirmation form.
82 $stroverride = get_string('override', 'quiz');
83 $title = get_string('deletecheck', null, $stroverride);
85 $PAGE->set_url($url);
86 $PAGE->set_pagelayout('admin');
87 $PAGE->navbar->add($title);
88 $PAGE->set_title($title);
89 $PAGE->set_heading($course->fullname);
90 $PAGE->activityheader->set_attrs([
91 "title" => format_string($quiz->name, true, ['context' => $context]),
92 "description" => "",
93 "hidecompletion" => true
94 ]);
95 echo $OUTPUT->header();
97 if ($override->groupid) {
98 $group = $DB->get_record('groups', ['id' => $override->groupid], 'id, name');
99 $confirmstr = get_string("overridedeletegroupsure", "quiz", $group->name);
100 } else {
101 $user = $DB->get_record('user', ['id' => $override->userid]);
102 profile_load_custom_fields($user);
104 $confirmstr = get_string('overridedeleteusersure', 'quiz',
105 quiz_override_form::display_user_name($user,
106 \core_user\fields::get_identity_fields($context)));
109 echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
111 echo $OUTPUT->footer();