|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00026 require_once(dirname(__FILE__) . '/../../config.php'); 00027 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 00028 00029 // Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php 00030 if ($id = optional_param('id', 0, PARAM_INTEGER)) { 00031 redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $id . '&sesskey=' . sesskey()); 00032 } else if ($qid = optional_param('q', 0, PARAM_INTEGER)) { 00033 if (!$cm = get_coursemodule_from_instance('quiz', $qid)) { 00034 print_error('invalidquizid', 'quiz'); 00035 } 00036 redirect(new moodle_url('/mod/quiz/startattempt.php', 00037 array('cmid' => $cm->id, 'sesskey' => sesskey()))); 00038 } 00039 00040 // Get submitted parameters. 00041 $attemptid = required_param('attempt', PARAM_INT); 00042 $page = optional_param('page', 0, PARAM_INT); 00043 00044 $attemptobj = quiz_attempt::create($attemptid); 00045 $PAGE->set_url($attemptobj->attempt_url(null, $page)); 00046 00047 // Check login. 00048 require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); 00049 00050 // Check that this attempt belongs to this user. 00051 if ($attemptobj->get_userid() != $USER->id) { 00052 if ($attemptobj->has_capability('mod/quiz:viewreports')) { 00053 redirect($attemptobj->review_url(null, $page)); 00054 } else { 00055 throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); 00056 } 00057 } 00058 00059 // Check capabilities and block settings 00060 if (!$attemptobj->is_preview_user()) { 00061 $attemptobj->require_capability('mod/quiz:attempt'); 00062 if (empty($attemptobj->get_quiz()->showblocks)) { 00063 $PAGE->blocks->show_only_fake_blocks(); 00064 } 00065 00066 } else { 00067 navigation_node::override_active_url($attemptobj->start_attempt_url()); 00068 } 00069 00070 // If the attempt is already closed, send them to the review page. 00071 if ($attemptobj->is_finished()) { 00072 redirect($attemptobj->review_url(null, $page)); 00073 } 00074 00075 // Check the access rules. 00076 $accessmanager = $attemptobj->get_access_manager(time()); 00077 $messages = $accessmanager->prevent_access(); 00078 $output = $PAGE->get_renderer('mod_quiz'); 00079 if (!$attemptobj->is_preview_user() && $messages) { 00080 print_error('attempterror', 'quiz', $attemptobj->view_url(), 00081 $output->access_messages($messages)); 00082 } 00083 if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { 00084 redirect($attemptobj->start_attempt_url(null, $page)); 00085 } 00086 00087 add_to_log($attemptobj->get_courseid(), 'quiz', 'continue attempt', 00088 'review.php?attempt=' . $attemptobj->get_attemptid(), 00089 $attemptobj->get_quizid(), $attemptobj->get_cmid()); 00090 00091 // Get the list of questions needed by this page. 00092 $slots = $attemptobj->get_slots($page); 00093 00094 // Check. 00095 if (empty($slots)) { 00096 throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound'); 00097 } 00098 00099 // Initialise the JavaScript. 00100 $headtags = $attemptobj->get_html_head_contributions($page); 00101 $PAGE->requires->js_init_call('M.mod_quiz.init_attempt_form', null, false, quiz_get_js_module()); 00102 00103 // Arrange for the navigation to be displayed. 00104 $navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', $page); 00105 $firstregion = reset($PAGE->blocks->get_regions()); 00106 $PAGE->blocks->add_fake_block($navbc, $firstregion); 00107 00108 $title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number()); 00109 $headtags = $attemptobj->get_html_head_contributions($page); 00110 $PAGE->set_title(format_string($attemptobj->get_quiz_name())); 00111 $PAGE->set_heading($attemptobj->get_course()->fullname); 00112 $accessmanager->setup_attempt_page($PAGE); 00113 00114 if ($attemptobj->is_last_page($page)) { 00115 $nextpage = -1; 00116 } else { 00117 $nextpage = $page + 1; 00118 } 00119 00120 $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time(), $output); 00121 echo $output->attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id, $nextpage);