MDL-45071 mod_quiz: retrieve all the name fields when deleting a user override
[moodle.git] / mod / quiz / overridedelete.php
CommitLineData
990650f9 1<?php
990650f9
TH
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
990650f9
TH
17/**
18 * This page handles deleting quiz overrides
19 *
9e83f3d1 20 * @package mod_quiz
ba643847
TH
21 * @copyright 2010 Matt Petro
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
990650f9
TH
23 */
24
ba643847 25
990650f9
TH
26require_once(dirname(__FILE__) . '/../../config.php');
27require_once($CFG->dirroot.'/mod/quiz/lib.php');
28require_once($CFG->dirroot.'/mod/quiz/locallib.php');
29require_once($CFG->dirroot.'/mod/quiz/override_form.php');
30
9e83f3d1
TH
31$overrideid = required_param('id', PARAM_INT);
32$confirm = optional_param('confirm', false, PARAM_BOOL);
990650f9
TH
33
34if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) {
35 print_error('invalidoverrideid', 'quiz');
36}
37if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) {
38 print_error('invalidcoursemodule');
39}
40if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $quiz->course)) {
41 print_error('invalidcoursemodule');
42}
74df2951 43$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
990650f9 44
c492a78e 45$context = context_module::instance($cm->id);
990650f9 46
56ed242b 47require_login($course, false, $cm);
990650f9 48
9e83f3d1 49// Check the user has the required capabilities to modify an override.
990650f9
TH
50require_capability('mod/quiz:manageoverrides', $context);
51
52$url = new moodle_url('/mod/quiz/overridedelete.php', array('id'=>$override->id));
53$confirmurl = new moodle_url($url, array('id'=>$override->id, 'confirm'=>1));
54$cancelurl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
55
56if (!empty($override->userid)) {
57 $cancelurl->param('mode', 'user');
58}
59
9e83f3d1 60// If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
990650f9 61if ($confirm) {
990650f9
TH
62 require_sesskey();
63
990650f9
TH
64 quiz_delete_override($quiz, $override->id);
65
990650f9
TH
66 redirect($cancelurl);
67}
68
9e83f3d1 69// Prepare the page to show the confirmation form.
990650f9
TH
70$stroverride = get_string('override', 'quiz');
71$title = get_string('deletecheck', null, $stroverride);
72
73$PAGE->set_url($url);
e07cccfc 74$PAGE->set_pagelayout('admin');
990650f9
TH
75$PAGE->navbar->add($title);
76$PAGE->set_title($title);
56ed242b 77$PAGE->set_heading($course->fullname);
990650f9
TH
78
79echo $OUTPUT->header();
c544ee92 80echo $OUTPUT->heading(format_string($quiz->name, true, array('context' => $context)));
990650f9
TH
81
82if ($override->groupid) {
25a03faa 83 $group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
990650f9 84 $confirmstr = get_string("overridedeletegroupsure", "quiz", $group->name);
55ca80ed 85} else {
4e651893 86 $namefields = get_all_user_name_fields(true);
25a03faa 87 $user = $DB->get_record('user', array('id' => $override->userid),
4e651893 88 'id, ' . $namefields);
990650f9
TH
89 $confirmstr = get_string("overridedeleteusersure", "quiz", fullname($user));
90}
91
92echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
93
94echo $OUTPUT->footer();