Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/overridedelete.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 require_once(dirname(__FILE__) . '/../../config.php');
00028 require_once($CFG->dirroot.'/mod/quiz/lib.php');
00029 require_once($CFG->dirroot.'/mod/quiz/locallib.php');
00030 require_once($CFG->dirroot.'/mod/quiz/override_form.php');
00031 
00032 $overrideid = required_param('id', PARAM_INT);  // override ID
00033 $confirm = optional_param('confirm', false, PARAM_BOOL); // already confirmed?
00034 
00035 if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) {
00036     print_error('invalidoverrideid', 'quiz');
00037 }
00038 if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) {
00039     print_error('invalidcoursemodule');
00040 }
00041 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $quiz->course)) {
00042     print_error('invalidcoursemodule');
00043 }
00044 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
00045 
00046 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
00047 
00048 require_login($course, false, $cm);
00049 
00050 // Check the user has the required capabilities to modify an override
00051 require_capability('mod/quiz:manageoverrides', $context);
00052 
00053 $url = new moodle_url('/mod/quiz/overridedelete.php', array('id'=>$override->id));
00054 $confirmurl = new moodle_url($url, array('id'=>$override->id, 'confirm'=>1));
00055 $cancelurl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
00056 
00057 if (!empty($override->userid)) {
00058     $cancelurl->param('mode', 'user');
00059 }
00060 
00061 // If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete
00062 if ($confirm) {
00063     // Confirm the session key to stop CSRF
00064     require_sesskey();
00065 
00066     // Remove the override
00067     quiz_delete_override($quiz, $override->id);
00068 
00069     add_to_log($cm->course, 'quiz', 'delete override',
00070         "overrides.php?cmid=$cm->id", $quiz->id, $cm->id);
00071 
00072     // And redirect
00073     redirect($cancelurl);
00074 }
00075 
00076 // Prepare the page to show the confirmation form
00077 $stroverride = get_string('override', 'quiz');
00078 $title = get_string('deletecheck', null, $stroverride);
00079 
00080 $PAGE->set_url($url);
00081 $PAGE->set_pagelayout('admin');
00082 $PAGE->navbar->add($title);
00083 $PAGE->set_title($title);
00084 $PAGE->set_heading($course->fullname);
00085 
00086 echo $OUTPUT->header();
00087 
00088 if ($override->groupid) {
00089     $group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
00090     $confirmstr = get_string("overridedeletegroupsure", "quiz", $group->name);
00091 } else {
00092     $user = $DB->get_record('user', array('id' => $override->userid),
00093             'id, firstname, lastname');
00094     $confirmstr = get_string("overridedeleteusersure", "quiz", fullname($user));
00095 }
00096 
00097 echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
00098 
00099 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations