2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This page prints a summary of a quiz attempt before it is submitted.
22 * @copyright 2009 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once(dirname(__FILE__) . '/../../config.php');
28 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
30 $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
32 $PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
34 $attemptobj = quiz_attempt::create($attemptid);
37 require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
39 // If this is not our own attempt, display an error.
40 if ($attemptobj->get_userid() != $USER->id) {
41 print_error('notyourattempt', 'quiz', $attemptobj->view_url());
45 if (!$attemptobj->is_preview_user()) {
46 $attemptobj->require_capability('mod/quiz:attempt');
49 if ($attemptobj->is_preview_user()) {
50 navigation_node::override_active_url($attemptobj->start_attempt_url());
54 $accessmanager = $attemptobj->get_access_manager(time());
55 $messages = $accessmanager->prevent_access();
56 $output = $PAGE->get_renderer('mod_quiz');
57 if (!$attemptobj->is_preview_user() && $messages) {
58 print_error('attempterror', 'quiz', $attemptobj->view_url(),
59 $output->access_messages($messages));
61 if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) {
62 redirect($attemptobj->start_attempt_url(null, $page));
65 $displayoptions = $attemptobj->get_display_options(false);
67 // If the attempt is now overdue, or abandoned, deal with that.
68 $attemptobj->handle_if_time_expired(time(), true);
70 // If the attempt is already closed, redirect them to the review page.
71 if ($attemptobj->is_finished()) {
72 redirect($attemptobj->review_url());
75 // Log this page view.
76 add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary',
77 'summary.php?attempt=' . $attemptobj->get_attemptid(),
78 $attemptobj->get_quizid(), $attemptobj->get_cmid());
80 // Arrange for the navigation to be displayed.
81 if (empty($attemptobj->get_quiz()->showblocks)) {
82 $PAGE->blocks->show_only_fake_blocks();
85 $navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', -1);
86 $regions = $PAGE->blocks->get_regions();
87 $PAGE->blocks->add_fake_block($navbc, reset($regions));
89 $PAGE->navbar->add(get_string('summaryofattempt', 'quiz'));
90 $PAGE->set_title(format_string($attemptobj->get_quiz_name()));
91 $PAGE->set_heading($attemptobj->get_course()->fullname);
92 $accessmanager->setup_attempt_page($PAGE);
95 echo $output->summary_page($attemptobj, $displayoptions);