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 |
* This page handles deleting quiz overrides
|
|
|
19 |
*
|
|
|
20 |
* @package mod_quiz
|
|
|
21 |
* @copyright 2010 Matt Petro
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use mod_quiz\form\edit_override_form;
|
|
|
26 |
use mod_quiz\quiz_settings;
|
|
|
27 |
|
|
|
28 |
require_once(__DIR__ . '/../../config.php');
|
|
|
29 |
require_once($CFG->dirroot.'/mod/quiz/lib.php');
|
|
|
30 |
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
|
|
|
31 |
|
|
|
32 |
$overrideid = required_param('id', PARAM_INT);
|
|
|
33 |
$confirm = optional_param('confirm', false, PARAM_BOOL);
|
|
|
34 |
|
|
|
35 |
$override = $DB->get_record('quiz_overrides', ['id' => $overrideid], '*', MUST_EXIST);
|
|
|
36 |
$quizobj = quiz_settings::create($override->quiz);
|
|
|
37 |
$quiz = $quizobj->get_quiz();
|
|
|
38 |
$cm = $quizobj->get_cm();
|
|
|
39 |
$course = $quizobj->get_course();
|
|
|
40 |
$context = $quizobj->get_context();
|
|
|
41 |
$manager = $quizobj->get_override_manager();
|
|
|
42 |
|
|
|
43 |
require_login($course, false, $cm);
|
|
|
44 |
|
|
|
45 |
// Check the user has the required capabilities to modify an override.
|
|
|
46 |
$manager->require_manage_capability();
|
11 |
efrain |
47 |
if (!$manager->can_view_override($override, $course, $cm)) {
|
|
|
48 |
throw new \moodle_exception('invalidoverrideid', 'quiz');
|
1 |
efrain |
49 |
}
|
|
|
50 |
|
|
|
51 |
$url = new moodle_url('/mod/quiz/overridedelete.php', ['id' => $override->id]);
|
|
|
52 |
$confirmurl = new moodle_url($url, ['id' => $override->id, 'confirm' => 1]);
|
|
|
53 |
$cancelurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $cm->id]);
|
|
|
54 |
|
|
|
55 |
if (!empty($override->userid)) {
|
|
|
56 |
$cancelurl->param('mode', 'user');
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
|
|
|
60 |
if ($confirm) {
|
|
|
61 |
require_sesskey();
|
|
|
62 |
$manager->delete_overrides(overrides: [$override]);
|
|
|
63 |
redirect($cancelurl);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// Prepare the page to show the confirmation form.
|
|
|
67 |
$stroverride = get_string('override', 'quiz');
|
|
|
68 |
$title = get_string('deletecheck', null, $stroverride);
|
|
|
69 |
|
|
|
70 |
$PAGE->set_url($url);
|
|
|
71 |
$PAGE->set_pagelayout('admin');
|
|
|
72 |
$PAGE->add_body_class('limitedwidth');
|
|
|
73 |
$PAGE->navbar->add($title);
|
|
|
74 |
$PAGE->set_title($title);
|
|
|
75 |
$PAGE->set_heading($course->fullname);
|
|
|
76 |
$PAGE->activityheader->set_attrs([
|
|
|
77 |
"title" => format_string($quiz->name, true, ['context' => $context]),
|
|
|
78 |
"description" => "",
|
|
|
79 |
"hidecompletion" => true
|
|
|
80 |
]);
|
|
|
81 |
echo $OUTPUT->header();
|
|
|
82 |
|
|
|
83 |
if ($override->groupid) {
|
|
|
84 |
$group = $DB->get_record('groups', ['id' => $override->groupid], 'id, name');
|
|
|
85 |
$confirmstr = get_string("overridedeletegroupsure", "quiz", format_string($group->name, true, ['context' => $context]));
|
|
|
86 |
} else {
|
|
|
87 |
$user = $DB->get_record('user', ['id' => $override->userid]);
|
|
|
88 |
profile_load_custom_fields($user);
|
|
|
89 |
|
|
|
90 |
$confirmstr = get_string('overridedeleteusersure', 'quiz',
|
|
|
91 |
edit_override_form::display_user_name($user,
|
|
|
92 |
\core_user\fields::get_identity_fields($context)));
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
|
|
|
96 |
|
|
|
97 |
echo $OUTPUT->footer();
|