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