question MDL-19797 Updated print_header_simple and build_navigation to OUTPUT and...
[moodle.git] / mod / quiz / summary.php
CommitLineData
36e413e3 1<?php // $Id$
2/**
3 * This page prints a summary of a quiz attempt before it is submitted.
4 *
5 * @author Tim Hunt others.
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package quiz
8 */
9
78e7a3dd 10require_once(dirname(__FILE__) . '/../../config.php');
11require_once($CFG->dirroot . '/mod/quiz/locallib.php');
36e413e3 12
13$attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
14$attemptobj = new quiz_attempt($attemptid);
15
78e7a3dd 16/// Check login.
36e413e3 17require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
18
19/// If this is not our own attempt, display an error.
20if ($attemptobj->get_userid() != $USER->id) {
21 print_error('notyourattempt', 'quiz', $attemptobj->view_url());
22}
23
78e7a3dd 24/// If the attempt is alreadyuj closed, redirect them to the review page.
36e413e3 25if ($attemptobj->is_finished()) {
26 redirect($attemptobj->review_url());
27}
28
29/// Check access.
30$accessmanager = $attemptobj->get_access_manager(time());
31$messages = $accessmanager->prevent_access();
b10c38a3 32if (!$attemptobj->is_preview_user() && $messages) {
36e413e3 33 print_error('attempterror', 'quiz', $attemptobj->view_url(),
34 $accessmanager->print_messages($messages, true));
35}
b10c38a3 36$accessmanager->do_password_check($attemptobj->is_preview_user());
36e413e3 37
38/// Log this page view.
39add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(),
40 $attemptobj->get_quizid(), $attemptobj->get_cmid());
41
42/// Load the questions and states.
43$attemptobj->load_questions();
44$attemptobj->load_question_states();
45
46/// Print the page header
25ddb7ef 47$PAGE->requires->js('mod/quiz/quiz.js');
36e413e3 48$title = get_string('summaryofattempt', 'quiz');
b10c38a3 49if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
78e7a3dd 50 $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
51 format_string($attemptobj->get_quiz_name()), '');
36e413e3 52} else {
53 print_header_simple(format_string($attemptobj->get_quiz_name()), '',
54 $attemptobj->navigation($title), '', '', true, $attemptobj->update_module_button());
55}
56
57/// Print tabs if they should be there.
b10c38a3 58if ($attemptobj->is_preview_user()) {
36e413e3 59 $currenttab = 'preview';
60 include('tabs.php');
61}
62
63/// Print heading.
90cd54cb 64echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name()));
b10c38a3 65if ($attemptobj->is_preview_user()) {
78e7a3dd 66 $attemptobj->print_restart_preview_button();
36e413e3 67}
90cd54cb 68echo $OUTPUT->heading($title);
36e413e3 69
70/// Prepare the summary table header
39e37019 71$table = new html_table();
72$table->add_class('generaltable quizsummaryofattempt boxaligncenter');
36e413e3 73$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
74$table->align = array('left', 'left');
75$table->size = array('', '');
76$scorescolumn = $attemptobj->get_review_options()->scores;
77if ($scorescolumn) {
78 $table->head[] = get_string('marks', 'quiz');
79 $table->align[] = 'left';
80 $table->size[] = '';
81}
82$table->data = array();
83
84/// Get the summary info for each question.
85$questionids = $attemptobj->get_question_ids();
86foreach ($attemptobj->get_question_iterator() as $number => $question) {
b9b3aa94 87 if ($question->length == 0) {
88 continue;
89 }
e41a7d28 90 $flag = '';
91 if ($attemptobj->is_question_flagged($question->id)) {
f2a1963c 92 $flag = ' <img src="' . $OUTPUT->old_icon_url('i/flagged') . '" alt="' .
e41a7d28 93 get_string('flagged', 'question') . '" class="questionflag" />';
94 }
d4ad9adf 95 $row = array('<a href="' . s($attemptobj->attempt_url($question->id)) . '">' . $number . $flag . '</a>',
78e7a3dd 96 get_string($attemptobj->get_question_status($question->id), 'quiz'));
36e413e3 97 if ($scorescolumn) {
98 $row[] = $attemptobj->get_question_score($question->id);
99 }
100 $table->data[] = $row;
101}
102
103/// Print the summary table.
39e37019 104echo $OUTPUT->table($table);
36e413e3 105
692e0c33 106/// countdown timer
107echo $attemptobj->get_timer_html();
108
36e413e3 109/// Finish attempt button.
39e37019 110echo $OUTPUT->container_start('submitbtns mdl-align');
36e413e3 111$options = array(
9f9eec1e 112 'attempt' => $attemptobj->get_attemptid(),
36e413e3 113 'finishattempt' => 1,
114 'timeup' => 0,
115 'questionids' => '',
9f9eec1e 116 'sesskey' => sesskey(),
36e413e3 117);
39e37019 118
119$form = html_form::make_button($attemptobj->processattempt_url(), $options, get_string('finishattempt', 'quiz'));
120$form->id = 'responseform';
121$form->button->add_confirm_action(get_string('confirmclose', 'quiz'));
122
123echo $OUTPUT->button($form);
124echo $OUTPUT->container_end();
36e413e3 125
126/// Finish the page
127$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
867847e3 128echo $OUTPUT->footer();
36e413e3 129
130?>