Commit | Line | Data |
---|---|---|
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 | |
eb02301a | 15 | $PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid)); |
a09f21d0 | 16 | |
990650f9 | 17 | $attemptobj = quiz_attempt::create($attemptid); |
36e413e3 | 18 | |
78e7a3dd | 19 | /// Check login. |
56ed242b | 20 | require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); |
36e413e3 | 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 | ||
eb02301a | 32 | if ($attemptobj->is_preview_user()) { |
73eba4be | 33 | navigation_node::override_active_url($attemptobj->start_attempt_url()); |
eb02301a TH |
34 | } |
35 | ||
36e413e3 | 36 | /// Check access. |
37 | $accessmanager = $attemptobj->get_access_manager(time()); | |
38 | $messages = $accessmanager->prevent_access(); | |
b10c38a3 | 39 | if (!$attemptobj->is_preview_user() && $messages) { |
36e413e3 | 40 | print_error('attempterror', 'quiz', $attemptobj->view_url(), |
41 | $accessmanager->print_messages($messages, true)); | |
42 | } | |
b10c38a3 | 43 | $accessmanager->do_password_check($attemptobj->is_preview_user()); |
36e413e3 | 44 | |
45 | /// Log this page view. | |
46 | add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(), | |
47 | $attemptobj->get_quizid(), $attemptobj->get_cmid()); | |
48 | ||
49 | /// Load the questions and states. | |
50 | $attemptobj->load_questions(); | |
51 | $attemptobj->load_question_states(); | |
52 | ||
56ed242b SH |
53 | if (empty($attemptobj->get_quiz()->showblocks)) { |
54 | $PAGE->blocks->show_only_fake_blocks(); | |
55 | } | |
56 | ||
36e413e3 | 57 | /// Print the page header |
36e413e3 | 58 | $title = get_string('summaryofattempt', 'quiz'); |
b10c38a3 | 59 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
78e7a3dd | 60 | $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' . |
61 | format_string($attemptobj->get_quiz_name()), ''); | |
7d4dfc48 | 62 | } elseif ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) { |
a09f21d0 | 63 | $PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name())); |
56ed242b | 64 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
a09f21d0 | 65 | $PAGE->set_cacheable(false); |
66 | echo $OUTPUT->header(); | |
36e413e3 | 67 | } else { |
03da0c39 | 68 | $attemptobj->navigation($title); |
69 | $PAGE->set_title(format_string($attemptobj->get_quiz_name())); | |
56ed242b | 70 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
03da0c39 | 71 | echo $OUTPUT->header(); |
36e413e3 | 72 | } |
73 | ||
36e413e3 | 74 | /// Print heading. |
90cd54cb | 75 | echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name())); |
b10c38a3 | 76 | if ($attemptobj->is_preview_user()) { |
78e7a3dd | 77 | $attemptobj->print_restart_preview_button(); |
36e413e3 | 78 | } |
90cd54cb | 79 | echo $OUTPUT->heading($title); |
36e413e3 | 80 | |
81 | /// Prepare the summary table header | |
39e37019 | 82 | $table = new html_table(); |
16be8974 | 83 | $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter'; |
36e413e3 | 84 | $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); |
85 | $table->align = array('left', 'left'); | |
86 | $table->size = array('', ''); | |
1be49904 TH |
87 | $scorescolumn = $attemptobj->get_review_options()->scores && |
88 | ($attemptobj->get_quiz()->optionflags & QUESTION_ADAPTIVE); | |
36e413e3 | 89 | if ($scorescolumn) { |
90 | $table->head[] = get_string('marks', 'quiz'); | |
91 | $table->align[] = 'left'; | |
92 | $table->size[] = ''; | |
93 | } | |
94 | $table->data = array(); | |
95 | ||
96 | /// Get the summary info for each question. | |
97 | $questionids = $attemptobj->get_question_ids(); | |
98 | foreach ($attemptobj->get_question_iterator() as $number => $question) { | |
b9b3aa94 | 99 | if ($question->length == 0) { |
100 | continue; | |
101 | } | |
e41a7d28 | 102 | $flag = ''; |
103 | if ($attemptobj->is_question_flagged($question->id)) { | |
b5d0cafc | 104 | $flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' . |
e41a7d28 | 105 | get_string('flagged', 'question') . '" class="questionflag" />'; |
106 | } | |
d4ad9adf | 107 | $row = array('<a href="' . s($attemptobj->attempt_url($question->id)) . '">' . $number . $flag . '</a>', |
78e7a3dd | 108 | get_string($attemptobj->get_question_status($question->id), 'quiz')); |
36e413e3 | 109 | if ($scorescolumn) { |
110 | $row[] = $attemptobj->get_question_score($question->id); | |
111 | } | |
112 | $table->data[] = $row; | |
113 | } | |
114 | ||
115 | /// Print the summary table. | |
16be8974 | 116 | echo html_writer::table($table); |
36e413e3 | 117 | |
692e0c33 | 118 | /// countdown timer |
119 | echo $attemptobj->get_timer_html(); | |
120 | ||
36e413e3 | 121 | /// Finish attempt button. |
39e37019 | 122 | echo $OUTPUT->container_start('submitbtns mdl-align'); |
36e413e3 | 123 | $options = array( |
9f9eec1e | 124 | 'attempt' => $attemptobj->get_attemptid(), |
36e413e3 | 125 | 'finishattempt' => 1, |
126 | 'timeup' => 0, | |
127 | 'questionids' => '', | |
9f9eec1e | 128 | 'sesskey' => sesskey(), |
36e413e3 | 129 | ); |
39e37019 | 130 | |
48c19b25 | 131 | $button = new single_button(new moodle_url($attemptobj->processattempt_url(), $options), get_string('submitallandfinish', 'quiz')); |
3ba60ee1 PS |
132 | $button->id = 'responseform'; |
133 | $button->add_confirm_action(get_string('confirmclose', 'quiz')); | |
39e37019 | 134 | |
d8011b7b | 135 | echo $OUTPUT->container_start('controls'); |
3ba60ee1 | 136 | echo $OUTPUT->render($button); |
39e37019 | 137 | echo $OUTPUT->container_end(); |
d8011b7b | 138 | echo $OUTPUT->container_end(); |
36e413e3 | 139 | |
140 | /// Finish the page | |
141 | $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time()); | |
867847e3 | 142 | echo $OUTPUT->footer(); |
36e413e3 | 143 | |
83192608 | 144 |