Commit | Line | Data |
---|---|---|
a09f21d0 | 1 | <?php |
8f37f7fb TH |
2 | |
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
36e413e3 | 18 | /** |
19 | * This page prints a summary of a quiz attempt before it is submitted. | |
20 | * | |
8f37f7fb TH |
21 | * @package mod |
22 | * @subpackage quiz | |
23 | * @copyright 2009 Tim Hunt | |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
36e413e3 | 25 | */ |
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 | |
8f37f7fb | 39 | // If this is not our own attempt, display an error. |
36e413e3 | 40 | if ($attemptobj->get_userid() != $USER->id) { |
41 | print_error('notyourattempt', 'quiz', $attemptobj->view_url()); | |
42 | } | |
43 | ||
8f37f7fb TH |
44 | // Check capabilites. |
45 | if (!$attemptobj->is_preview_user()) { | |
46 | $attemptobj->require_capability('mod/quiz:attempt'); | |
47 | } | |
48 | ||
49 | // If the attempt is already closed, redirect them to the review page. | |
36e413e3 | 50 | if ($attemptobj->is_finished()) { |
51 | redirect($attemptobj->review_url()); | |
52 | } | |
53 | ||
eb02301a | 54 | if ($attemptobj->is_preview_user()) { |
73eba4be | 55 | navigation_node::override_active_url($attemptobj->start_attempt_url()); |
eb02301a TH |
56 | } |
57 | ||
8f37f7fb | 58 | // Check access. |
36e413e3 | 59 | $accessmanager = $attemptobj->get_access_manager(time()); |
60 | $messages = $accessmanager->prevent_access(); | |
b10c38a3 | 61 | if (!$attemptobj->is_preview_user() && $messages) { |
36e413e3 | 62 | print_error('attempterror', 'quiz', $attemptobj->view_url(), |
63 | $accessmanager->print_messages($messages, true)); | |
64 | } | |
b10c38a3 | 65 | $accessmanager->do_password_check($attemptobj->is_preview_user()); |
36e413e3 | 66 | |
8f37f7fb TH |
67 | $displayoptions = $attemptobj->get_display_options(false); |
68 | ||
69 | // Log this page view. | |
36e413e3 | 70 | add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(), |
71 | $attemptobj->get_quizid(), $attemptobj->get_cmid()); | |
72 | ||
8f37f7fb | 73 | // Print the page header |
56ed242b SH |
74 | if (empty($attemptobj->get_quiz()->showblocks)) { |
75 | $PAGE->blocks->show_only_fake_blocks(); | |
76 | } | |
77 | ||
36e413e3 | 78 | $title = get_string('summaryofattempt', 'quiz'); |
b10c38a3 | 79 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
78e7a3dd | 80 | $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' . |
81 | format_string($attemptobj->get_quiz_name()), ''); | |
7d4dfc48 | 82 | } elseif ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) { |
a09f21d0 | 83 | $PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name())); |
56ed242b | 84 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
a09f21d0 | 85 | $PAGE->set_cacheable(false); |
86 | echo $OUTPUT->header(); | |
36e413e3 | 87 | } else { |
8f37f7fb | 88 | $PAGE->navbar->add($title); |
03da0c39 | 89 | $PAGE->set_title(format_string($attemptobj->get_quiz_name())); |
56ed242b | 90 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
03da0c39 | 91 | echo $OUTPUT->header(); |
36e413e3 | 92 | } |
93 | ||
8f37f7fb | 94 | // Print heading. |
90cd54cb | 95 | echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name())); |
b10c38a3 | 96 | if ($attemptobj->is_preview_user()) { |
78e7a3dd | 97 | $attemptobj->print_restart_preview_button(); |
36e413e3 | 98 | } |
90cd54cb | 99 | echo $OUTPUT->heading($title); |
36e413e3 | 100 | |
8f37f7fb | 101 | // Prepare the summary table header |
39e37019 | 102 | $table = new html_table(); |
16be8974 | 103 | $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter'; |
36e413e3 | 104 | $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); |
105 | $table->align = array('left', 'left'); | |
106 | $table->size = array('', ''); | |
8f37f7fb TH |
107 | $markscolumn = $displayoptions->marks; |
108 | if ($markscolumn) { | |
36e413e3 | 109 | $table->head[] = get_string('marks', 'quiz'); |
110 | $table->align[] = 'left'; | |
111 | $table->size[] = ''; | |
112 | } | |
113 | $table->data = array(); | |
114 | ||
8f37f7fb TH |
115 | // Get the summary info for each question. |
116 | $slots = $attemptobj->get_slots(); | |
117 | foreach ($slots as $slot) { | |
118 | if (!$attemptobj->is_real_question($slot)) { | |
b9b3aa94 | 119 | continue; |
120 | } | |
e41a7d28 | 121 | $flag = ''; |
8f37f7fb | 122 | if ($attemptobj->is_question_flagged($slot)) { |
b5d0cafc | 123 | $flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' . |
e41a7d28 | 124 | get_string('flagged', 'question') . '" class="questionflag" />'; |
125 | } | |
a13d4fbd | 126 | $row = array('<a href="' . $attemptobj->attempt_url($slot) . '">' . |
8f37f7fb TH |
127 | $attemptobj->get_question_number($slot) . $flag . '</a>', |
128 | $attemptobj->get_question_status($slot, $displayoptions->correctness)); | |
129 | if ($markscolumn) { | |
b2607ccc | 130 | $row[] = $attemptobj->get_question_mark($slot); |
36e413e3 | 131 | } |
132 | $table->data[] = $row; | |
133 | } | |
134 | ||
8f37f7fb | 135 | // Print the summary table. |
16be8974 | 136 | echo html_writer::table($table); |
36e413e3 | 137 | |
8f37f7fb | 138 | // countdown timer |
692e0c33 | 139 | echo $attemptobj->get_timer_html(); |
140 | ||
8f37f7fb | 141 | // Finish attempt button. |
39e37019 | 142 | echo $OUTPUT->container_start('submitbtns mdl-align'); |
36e413e3 | 143 | $options = array( |
9f9eec1e | 144 | 'attempt' => $attemptobj->get_attemptid(), |
36e413e3 | 145 | 'finishattempt' => 1, |
146 | 'timeup' => 0, | |
8f37f7fb | 147 | 'slots' => '', |
9f9eec1e | 148 | 'sesskey' => sesskey(), |
36e413e3 | 149 | ); |
39e37019 | 150 | |
8f37f7fb TH |
151 | $button = new single_button( |
152 | new moodle_url($attemptobj->processattempt_url(), $options), | |
153 | get_string('submitallandfinish', 'quiz')); | |
3ba60ee1 PS |
154 | $button->id = 'responseform'; |
155 | $button->add_confirm_action(get_string('confirmclose', 'quiz')); | |
39e37019 | 156 | |
d8011b7b | 157 | echo $OUTPUT->container_start('controls'); |
3ba60ee1 | 158 | echo $OUTPUT->render($button); |
39e37019 | 159 | echo $OUTPUT->container_end(); |
d8011b7b | 160 | echo $OUTPUT->container_end(); |
36e413e3 | 161 | |
8f37f7fb | 162 | // Finish the page |
36e413e3 | 163 | $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time()); |
867847e3 | 164 | echo $OUTPUT->footer(); |
36e413e3 | 165 |