a09f21d0 |
1 | <?php |
36e413e3 |
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. |
a09f21d0 |
14 | |
15 | $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/quiz/summary.php', array('attempt'=>$attemptid))); |
16 | |
36e413e3 |
17 | $attemptobj = new quiz_attempt($attemptid); |
18 | |
78e7a3dd |
19 | /// Check login. |
36e413e3 |
20 | require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm()); |
21 | |
22 | /// If this is not our own attempt, display an error. |
23 | if ($attemptobj->get_userid() != $USER->id) { |
24 | print_error('notyourattempt', 'quiz', $attemptobj->view_url()); |
25 | } |
26 | |
78e7a3dd |
27 | /// If the attempt is alreadyuj closed, redirect them to the review page. |
36e413e3 |
28 | if ($attemptobj->is_finished()) { |
29 | redirect($attemptobj->review_url()); |
30 | } |
31 | |
32 | /// Check access. |
33 | $accessmanager = $attemptobj->get_access_manager(time()); |
34 | $messages = $accessmanager->prevent_access(); |
b10c38a3 |
35 | if (!$attemptobj->is_preview_user() && $messages) { |
36e413e3 |
36 | print_error('attempterror', 'quiz', $attemptobj->view_url(), |
37 | $accessmanager->print_messages($messages, true)); |
38 | } |
b10c38a3 |
39 | $accessmanager->do_password_check($attemptobj->is_preview_user()); |
36e413e3 |
40 | |
41 | /// Log this page view. |
42 | add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(), |
43 | $attemptobj->get_quizid(), $attemptobj->get_cmid()); |
44 | |
45 | /// Load the questions and states. |
46 | $attemptobj->load_questions(); |
47 | $attemptobj->load_question_states(); |
48 | |
49 | /// Print the page header |
25ddb7ef |
50 | $PAGE->requires->js('mod/quiz/quiz.js'); |
36e413e3 |
51 | $title = get_string('summaryofattempt', 'quiz'); |
b10c38a3 |
52 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
78e7a3dd |
53 | $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' . |
54 | format_string($attemptobj->get_quiz_name()), ''); |
7d4dfc48 |
55 | } elseif ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) { |
a09f21d0 |
56 | $PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name())); |
57 | $PAGE->set_cacheable(false); |
58 | echo $OUTPUT->header(); |
36e413e3 |
59 | } else { |
03da0c39 |
60 | $attemptobj->navigation($title); |
61 | $PAGE->set_title(format_string($attemptobj->get_quiz_name())); |
03da0c39 |
62 | echo $OUTPUT->header(); |
36e413e3 |
63 | } |
64 | |
65 | /// Print tabs if they should be there. |
b10c38a3 |
66 | if ($attemptobj->is_preview_user()) { |
36e413e3 |
67 | $currenttab = 'preview'; |
68 | include('tabs.php'); |
69 | } |
70 | |
71 | /// Print heading. |
90cd54cb |
72 | echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name())); |
b10c38a3 |
73 | if ($attemptobj->is_preview_user()) { |
78e7a3dd |
74 | $attemptobj->print_restart_preview_button(); |
36e413e3 |
75 | } |
90cd54cb |
76 | echo $OUTPUT->heading($title); |
36e413e3 |
77 | |
78 | /// Prepare the summary table header |
39e37019 |
79 | $table = new html_table(); |
80 | $table->add_class('generaltable quizsummaryofattempt boxaligncenter'); |
36e413e3 |
81 | $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); |
82 | $table->align = array('left', 'left'); |
83 | $table->size = array('', ''); |
84 | $scorescolumn = $attemptobj->get_review_options()->scores; |
85 | if ($scorescolumn) { |
86 | $table->head[] = get_string('marks', 'quiz'); |
87 | $table->align[] = 'left'; |
88 | $table->size[] = ''; |
89 | } |
90 | $table->data = array(); |
91 | |
92 | /// Get the summary info for each question. |
93 | $questionids = $attemptobj->get_question_ids(); |
94 | foreach ($attemptobj->get_question_iterator() as $number => $question) { |
b9b3aa94 |
95 | if ($question->length == 0) { |
96 | continue; |
97 | } |
e41a7d28 |
98 | $flag = ''; |
99 | if ($attemptobj->is_question_flagged($question->id)) { |
b5d0cafc |
100 | $flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' . |
e41a7d28 |
101 | get_string('flagged', 'question') . '" class="questionflag" />'; |
102 | } |
d4ad9adf |
103 | $row = array('<a href="' . s($attemptobj->attempt_url($question->id)) . '">' . $number . $flag . '</a>', |
78e7a3dd |
104 | get_string($attemptobj->get_question_status($question->id), 'quiz')); |
36e413e3 |
105 | if ($scorescolumn) { |
106 | $row[] = $attemptobj->get_question_score($question->id); |
107 | } |
108 | $table->data[] = $row; |
109 | } |
110 | |
111 | /// Print the summary table. |
39e37019 |
112 | echo $OUTPUT->table($table); |
36e413e3 |
113 | |
692e0c33 |
114 | /// countdown timer |
115 | echo $attemptobj->get_timer_html(); |
116 | |
36e413e3 |
117 | /// Finish attempt button. |
39e37019 |
118 | echo $OUTPUT->container_start('submitbtns mdl-align'); |
36e413e3 |
119 | $options = array( |
9f9eec1e |
120 | 'attempt' => $attemptobj->get_attemptid(), |
36e413e3 |
121 | 'finishattempt' => 1, |
122 | 'timeup' => 0, |
123 | 'questionids' => '', |
9f9eec1e |
124 | 'sesskey' => sesskey(), |
36e413e3 |
125 | ); |
39e37019 |
126 | |
d894edd4 |
127 | $form = new single_button(new moodle_url($attemptobj->processattempt_url(), $options), get_string('finishattempt', 'quiz')); |
39e37019 |
128 | $form->id = 'responseform'; |
129 | $form->button->add_confirm_action(get_string('confirmclose', 'quiz')); |
130 | |
5c2ed7e2 |
131 | echo $OUTPUT->single_button($form); |
39e37019 |
132 | echo $OUTPUT->container_end(); |
36e413e3 |
133 | |
134 | /// Finish the page |
135 | $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time()); |
867847e3 |
136 | echo $OUTPUT->footer(); |
36e413e3 |
137 | |
83192608 |
138 | |