Commit | Line | Data |
---|---|---|
a09f21d0 | 1 | <?php |
8f37f7fb 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 | ||
36e413e3 | 17 | /** |
18 | * This page prints a summary of a quiz attempt before it is submitted. | |
19 | * | |
ba643847 | 20 | * @package mod |
8f37f7fb | 21 | * @subpackage quiz |
ba643847 TH |
22 | * @copyright 2009 The Open University |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
36e413e3 | 24 | */ |
25 | ||
ba643847 | 26 | |
78e7a3dd | 27 | require_once(dirname(__FILE__) . '/../../config.php'); |
28 | require_once($CFG->dirroot . '/mod/quiz/locallib.php'); | |
36e413e3 | 29 | |
30 | $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise. | |
a09f21d0 | 31 | |
eb02301a | 32 | $PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid)); |
a09f21d0 | 33 | |
990650f9 | 34 | $attemptobj = quiz_attempt::create($attemptid); |
36e413e3 | 35 | |
8f37f7fb | 36 | // Check login. |
56ed242b | 37 | require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); |
36e413e3 | 38 | |
50c88ad2 | 39 | // Check that this attempt belongs to this user. |
36e413e3 | 40 | if ($attemptobj->get_userid() != $USER->id) { |
50c88ad2 TH |
41 | if ($attemptobj->has_capability('mod/quiz:viewreports')) { |
42 | redirect($attemptobj->review_url(null, $page)); | |
43 | } else { | |
44 | throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); | |
45 | } | |
36e413e3 | 46 | } |
47 | ||
8f37f7fb TH |
48 | // Check capabilites. |
49 | if (!$attemptobj->is_preview_user()) { | |
50 | $attemptobj->require_capability('mod/quiz:attempt'); | |
51 | } | |
52 | ||
eb02301a | 53 | if ($attemptobj->is_preview_user()) { |
73eba4be | 54 | navigation_node::override_active_url($attemptobj->start_attempt_url()); |
eb02301a TH |
55 | } |
56 | ||
8f37f7fb | 57 | // Check access. |
36e413e3 | 58 | $accessmanager = $attemptobj->get_access_manager(time()); |
d205afe6 | 59 | $messages = $accessmanager->prevent_access(); |
4abc5a1a | 60 | $output = $PAGE->get_renderer('mod_quiz'); |
b10c38a3 | 61 | if (!$attemptobj->is_preview_user() && $messages) { |
36e413e3 | 62 | print_error('attempterror', 'quiz', $attemptobj->view_url(), |
7238cd2e | 63 | $output->access_messages($messages)); |
36e413e3 | 64 | } |
987c2d49 TH |
65 | if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { |
66 | redirect($attemptobj->start_attempt_url(null, $page)); | |
67 | } | |
36e413e3 | 68 | |
8f37f7fb TH |
69 | $displayoptions = $attemptobj->get_display_options(false); |
70 | ||
a6866c7e TH |
71 | // If the attempt is now overdue, or abandoned, deal with that. |
72 | $attemptobj->handle_if_time_expired(time(), true); | |
73 | ||
74 | // If the attempt is already closed, redirect them to the review page. | |
75 | if ($attemptobj->is_finished()) { | |
76 | redirect($attemptobj->review_url()); | |
77 | } | |
78 | ||
8f37f7fb | 79 | // Log this page view. |
55ca80ed TH |
80 | add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', |
81 | 'summary.php?attempt=' . $attemptobj->get_attemptid(), | |
36e413e3 | 82 | $attemptobj->get_quizid(), $attemptobj->get_cmid()); |
83 | ||
1b796a27 | 84 | // Arrange for the navigation to be displayed. |
56ed242b SH |
85 | if (empty($attemptobj->get_quiz()->showblocks)) { |
86 | $PAGE->blocks->show_only_fake_blocks(); | |
87 | } | |
88 | ||
0e2274c3 | 89 | $navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', -1); |
34b037de TH |
90 | $regions = $PAGE->blocks->get_regions(); |
91 | $PAGE->blocks->add_fake_block($navbc, reset($regions)); | |
1b796a27 | 92 | |
d755b0f5 TH |
93 | $PAGE->navbar->add(get_string('summaryofattempt', 'quiz')); |
94 | $PAGE->set_title(format_string($attemptobj->get_quiz_name())); | |
95 | $PAGE->set_heading($attemptobj->get_course()->fullname); | |
4abc5a1a | 96 | $accessmanager->setup_attempt_page($PAGE); |
36e413e3 | 97 | |
1b796a27 | 98 | // Display the page. |
babfb615 | 99 | echo $output->summary_page($attemptobj, $displayoptions); |