[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 script deals with starting a new attempt at a quiz. 19 * 20 * Normally, it will end up redirecting to attempt.php - unless a password form is displayed. 21 * 22 * This code used to be at the top of attempt.php, if you are looking for CVS history. 23 * 24 * @package mod_quiz 25 * @copyright 2009 The Open University 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 29 require_once(__DIR__ . '/../../config.php'); 30 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 31 32 // Get submitted parameters. 33 $id = required_param('cmid', PARAM_INT); // Course module id 34 $forcenew = optional_param('forcenew', false, PARAM_BOOL); // Used to force a new preview 35 $page = optional_param('page', -1, PARAM_INT); // Page to jump to in the attempt. 36 37 if (!$cm = get_coursemodule_from_id('quiz', $id)) { 38 print_error('invalidcoursemodule'); 39 } 40 if (!$course = $DB->get_record('course', array('id' => $cm->course))) { 41 print_error("coursemisconf"); 42 } 43 44 $quizobj = quiz::create($cm->instance, $USER->id); 45 // This script should only ever be posted to, so set page URL to the view page. 46 $PAGE->set_url($quizobj->view_url()); 47 48 // Check login and sesskey. 49 require_login($quizobj->get_course(), false, $quizobj->get_cm()); 50 require_sesskey(); 51 $PAGE->set_heading($quizobj->get_course()->fullname); 52 53 // If no questions have been set up yet redirect to edit.php or display an error. 54 if (!$quizobj->has_questions()) { 55 if ($quizobj->has_capability('mod/quiz:manage')) { 56 redirect($quizobj->edit_url()); 57 } else { 58 print_error('cannotstartnoquestions', 'quiz', $quizobj->view_url()); 59 } 60 } 61 62 // Create an object to manage all the other (non-roles) access rules. 63 $timenow = time(); 64 $accessmanager = $quizobj->get_access_manager($timenow); 65 66 // Validate permissions for creating a new attempt and start a new preview attempt if required. 67 list($currentattemptid, $attemptnumber, $lastattempt, $messages, $page) = 68 quiz_validate_new_attempt($quizobj, $accessmanager, $forcenew, $page, true); 69 70 // Check access. 71 if (!$quizobj->is_preview_user() && $messages) { 72 $output = $PAGE->get_renderer('mod_quiz'); 73 print_error('attempterror', 'quiz', $quizobj->view_url(), 74 $output->access_messages($messages)); 75 } 76 77 if ($accessmanager->is_preflight_check_required($currentattemptid)) { 78 // Need to do some checks before allowing the user to continue. 79 $mform = $accessmanager->get_preflight_check_form( 80 $quizobj->start_attempt_url($page), $currentattemptid); 81 82 if ($mform->is_cancelled()) { 83 $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz')); 84 85 } else if (!$mform->get_data()) { 86 87 // Form not submitted successfully, re-display it and stop. 88 $PAGE->set_url($quizobj->start_attempt_url($page)); 89 $PAGE->set_title($quizobj->get_quiz_name()); 90 $accessmanager->setup_attempt_page($PAGE); 91 $output = $PAGE->get_renderer('mod_quiz'); 92 if (empty($quizobj->get_quiz()->showblocks)) { 93 $PAGE->blocks->show_only_fake_blocks(); 94 } 95 96 echo $output->start_attempt_page($quizobj, $mform); 97 die(); 98 } 99 100 // Pre-flight check passed. 101 $accessmanager->notify_preflight_check_passed($currentattemptid); 102 } 103 if ($currentattemptid) { 104 if ($lastattempt->state == quiz_attempt::OVERDUE) { 105 redirect($quizobj->summary_url($lastattempt->id)); 106 } else { 107 redirect($quizobj->attempt_url($currentattemptid, $page)); 108 } 109 } 110 111 $attempt = quiz_prepare_and_start_new_attempt($quizobj, $attemptnumber, $lastattempt); 112 113 // Redirect to the attempt page. 114 redirect($quizobj->attempt_url($attempt->id, $page));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |