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 | |
a6855934 | 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 | ||
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 | ||
56ed242b SH |
49 | if (empty($attemptobj->get_quiz()->showblocks)) { |
50 | $PAGE->blocks->show_only_fake_blocks(); | |
51 | } | |
52 | ||
36e413e3 | 53 | /// Print the page header |
36e413e3 | 54 | $title = get_string('summaryofattempt', 'quiz'); |
b10c38a3 | 55 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
78e7a3dd | 56 | $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' . |
57 | format_string($attemptobj->get_quiz_name()), ''); | |
7d4dfc48 | 58 | } elseif ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) { |
a09f21d0 | 59 | $PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name())); |
56ed242b | 60 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
a09f21d0 | 61 | $PAGE->set_cacheable(false); |
62 | echo $OUTPUT->header(); | |
36e413e3 | 63 | } else { |
03da0c39 | 64 | $attemptobj->navigation($title); |
65 | $PAGE->set_title(format_string($attemptobj->get_quiz_name())); | |
56ed242b | 66 | $PAGE->set_heading($attemptobj->get_course()->fullname); |
03da0c39 | 67 | echo $OUTPUT->header(); |
36e413e3 | 68 | } |
69 | ||
36e413e3 | 70 | /// Print heading. |
90cd54cb | 71 | echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name())); |
b10c38a3 | 72 | if ($attemptobj->is_preview_user()) { |
78e7a3dd | 73 | $attemptobj->print_restart_preview_button(); |
36e413e3 | 74 | } |
90cd54cb | 75 | echo $OUTPUT->heading($title); |
36e413e3 | 76 | |
77 | /// Prepare the summary table header | |
39e37019 | 78 | $table = new html_table(); |
16be8974 | 79 | $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter'; |
36e413e3 | 80 | $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); |
81 | $table->align = array('left', 'left'); | |
82 | $table->size = array('', ''); | |
83 | $scorescolumn = $attemptobj->get_review_options()->scores; | |
84 | if ($scorescolumn) { | |
85 | $table->head[] = get_string('marks', 'quiz'); | |
86 | $table->align[] = 'left'; | |
87 | $table->size[] = ''; | |
88 | } | |
89 | $table->data = array(); | |
90 | ||
91 | /// Get the summary info for each question. | |
92 | $questionids = $attemptobj->get_question_ids(); | |
93 | foreach ($attemptobj->get_question_iterator() as $number => $question) { | |
b9b3aa94 | 94 | if ($question->length == 0) { |
95 | continue; | |
96 | } | |
e41a7d28 | 97 | $flag = ''; |
98 | if ($attemptobj->is_question_flagged($question->id)) { | |
b5d0cafc | 99 | $flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' . |
e41a7d28 | 100 | get_string('flagged', 'question') . '" class="questionflag" />'; |
101 | } | |
d4ad9adf | 102 | $row = array('<a href="' . s($attemptobj->attempt_url($question->id)) . '">' . $number . $flag . '</a>', |
78e7a3dd | 103 | get_string($attemptobj->get_question_status($question->id), 'quiz')); |
36e413e3 | 104 | if ($scorescolumn) { |
105 | $row[] = $attemptobj->get_question_score($question->id); | |
106 | } | |
107 | $table->data[] = $row; | |
108 | } | |
109 | ||
110 | /// Print the summary table. | |
16be8974 | 111 | echo html_writer::table($table); |
36e413e3 | 112 | |
692e0c33 | 113 | /// countdown timer |
114 | echo $attemptobj->get_timer_html(); | |
115 | ||
36e413e3 | 116 | /// Finish attempt button. |
39e37019 | 117 | echo $OUTPUT->container_start('submitbtns mdl-align'); |
36e413e3 | 118 | $options = array( |
9f9eec1e | 119 | 'attempt' => $attemptobj->get_attemptid(), |
36e413e3 | 120 | 'finishattempt' => 1, |
121 | 'timeup' => 0, | |
122 | 'questionids' => '', | |
9f9eec1e | 123 | 'sesskey' => sesskey(), |
36e413e3 | 124 | ); |
39e37019 | 125 | |
3ba60ee1 PS |
126 | $button = new single_button(new moodle_url($attemptobj->processattempt_url(), $options), get_string('finishattempt', 'quiz')); |
127 | $button->id = 'responseform'; | |
128 | $button->add_confirm_action(get_string('confirmclose', 'quiz')); | |
39e37019 | 129 | |
d8011b7b | 130 | echo $OUTPUT->container_start('controls'); |
3ba60ee1 | 131 | echo $OUTPUT->render($button); |
39e37019 | 132 | echo $OUTPUT->container_end(); |
d8011b7b | 133 | echo $OUTPUT->container_end(); |
36e413e3 | 134 | |
135 | /// Finish the page | |
136 | $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time()); | |
867847e3 | 137 | echo $OUTPUT->footer(); |
36e413e3 | 138 | |
83192608 | 139 |