grade MDL-19797 Upgraded deprecated function calls
[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 {
03da0c39 53 $attemptobj->navigation($title);
54 $PAGE->set_title(format_string($attemptobj->get_quiz_name()));
55 $PAGE->set_button($attemptobj->update_module_button());
56 echo $OUTPUT->header();
36e413e3 57}
58
59/// Print tabs if they should be there.
b10c38a3 60if ($attemptobj->is_preview_user()) {
36e413e3 61 $currenttab = 'preview';
62 include('tabs.php');
63}
64
65/// Print heading.
90cd54cb 66echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name()));
b10c38a3 67if ($attemptobj->is_preview_user()) {
78e7a3dd 68 $attemptobj->print_restart_preview_button();
36e413e3 69}
90cd54cb 70echo $OUTPUT->heading($title);
36e413e3 71
72/// Prepare the summary table header
39e37019 73$table = new html_table();
74$table->add_class('generaltable quizsummaryofattempt boxaligncenter');
36e413e3 75$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
76$table->align = array('left', 'left');
77$table->size = array('', '');
78$scorescolumn = $attemptobj->get_review_options()->scores;
79if ($scorescolumn) {
80 $table->head[] = get_string('marks', 'quiz');
81 $table->align[] = 'left';
82 $table->size[] = '';
83}
84$table->data = array();
85
86/// Get the summary info for each question.
87$questionids = $attemptobj->get_question_ids();
88foreach ($attemptobj->get_question_iterator() as $number => $question) {
b9b3aa94 89 if ($question->length == 0) {
90 continue;
91 }
e41a7d28 92 $flag = '';
93 if ($attemptobj->is_question_flagged($question->id)) {
f2a1963c 94 $flag = ' <img src="' . $OUTPUT->old_icon_url('i/flagged') . '" alt="' .
e41a7d28 95 get_string('flagged', 'question') . '" class="questionflag" />';
96 }
d4ad9adf 97 $row = array('<a href="' . s($attemptobj->attempt_url($question->id)) . '">' . $number . $flag . '</a>',
78e7a3dd 98 get_string($attemptobj->get_question_status($question->id), 'quiz'));
36e413e3 99 if ($scorescolumn) {
100 $row[] = $attemptobj->get_question_score($question->id);
101 }
102 $table->data[] = $row;
103}
104
105/// Print the summary table.
39e37019 106echo $OUTPUT->table($table);
36e413e3 107
692e0c33 108/// countdown timer
109echo $attemptobj->get_timer_html();
110
36e413e3 111/// Finish attempt button.
39e37019 112echo $OUTPUT->container_start('submitbtns mdl-align');
36e413e3 113$options = array(
9f9eec1e 114 'attempt' => $attemptobj->get_attemptid(),
36e413e3 115 'finishattempt' => 1,
116 'timeup' => 0,
117 'questionids' => '',
9f9eec1e 118 'sesskey' => sesskey(),
36e413e3 119);
39e37019 120
121$form = html_form::make_button($attemptobj->processattempt_url(), $options, get_string('finishattempt', 'quiz'));
122$form->id = 'responseform';
123$form->button->add_confirm_action(get_string('confirmclose', 'quiz'));
124
125echo $OUTPUT->button($form);
126echo $OUTPUT->container_end();
36e413e3 127
128/// Finish the page
129$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
867847e3 130echo $OUTPUT->footer();
36e413e3 131
132?>