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 | |
10 | require_once("../../config.php"); |
11 | require_once("locallib.php"); |
12 | require_once("attemptlib.php"); |
13 | |
14 | $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise. |
15 | $attemptobj = new quiz_attempt($attemptid); |
16 | |
17 | /// Check login and get contexts. |
18 | require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm()); |
19 | |
20 | /// If this is not our own attempt, display an error. |
21 | if ($attemptobj->get_userid() != $USER->id) { |
22 | print_error('notyourattempt', 'quiz', $attemptobj->view_url()); |
23 | } |
24 | |
25 | /// If the attempt is already closed, redirect them to the review page. |
26 | if ($attemptobj->is_finished()) { |
27 | redirect($attemptobj->review_url()); |
28 | } |
29 | |
30 | /// Check access. |
31 | $accessmanager = $attemptobj->get_access_manager(time()); |
32 | $messages = $accessmanager->prevent_access(); |
b10c38a3 |
33 | if (!$attemptobj->is_preview_user() && $messages) { |
36e413e3 |
34 | print_error('attempterror', 'quiz', $attemptobj->view_url(), |
35 | $accessmanager->print_messages($messages, true)); |
36 | } |
b10c38a3 |
37 | $accessmanager->do_password_check($attemptobj->is_preview_user()); |
36e413e3 |
38 | |
39 | /// Log this page view. |
40 | add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(), |
41 | $attemptobj->get_quizid(), $attemptobj->get_cmid()); |
42 | |
43 | /// Load the questions and states. |
44 | $attemptobj->load_questions(); |
45 | $attemptobj->load_question_states(); |
46 | |
47 | /// Print the page header |
48 | require_js($CFG->wwwroot . '/mod/quiz/quiz.js'); |
49 | $title = get_string('summaryofattempt', 'quiz'); |
b10c38a3 |
50 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
36e413e3 |
51 | $accessmanager->setup_secure_page($course->shortname.': '.format_string($quiz->name), $headtags); |
52 | } else { |
53 | print_header_simple(format_string($attemptobj->get_quiz_name()), '', |
54 | $attemptobj->navigation($title), '', '', true, $attemptobj->update_module_button()); |
55 | } |
56 | |
57 | /// Print tabs if they should be there. |
b10c38a3 |
58 | if ($attemptobj->is_preview_user()) { |
36e413e3 |
59 | $currenttab = 'preview'; |
60 | include('tabs.php'); |
61 | } |
62 | |
63 | /// Print heading. |
64 | print_heading(format_string($attemptobj->get_quiz_name())); |
b10c38a3 |
65 | if ($attemptobj->is_preview_user()) { |
36e413e3 |
66 | print_restart_preview_button($quiz); |
67 | } |
68 | print_heading($title); |
69 | |
70 | /// Prepare the summary table header |
71 | $table->class = 'generaltable quizsummaryofattempt'; |
72 | $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); |
73 | $table->align = array('left', 'left'); |
74 | $table->size = array('', ''); |
75 | $scorescolumn = $attemptobj->get_review_options()->scores; |
76 | if ($scorescolumn) { |
77 | $table->head[] = get_string('marks', 'quiz'); |
78 | $table->align[] = 'left'; |
79 | $table->size[] = ''; |
80 | } |
81 | $table->data = array(); |
82 | |
83 | /// Get the summary info for each question. |
84 | $questionids = $attemptobj->get_question_ids(); |
85 | foreach ($attemptobj->get_question_iterator() as $number => $question) { |
86 | $row = array($number, $attemptobj->get_question_status($question->id)); |
87 | if ($scorescolumn) { |
88 | $row[] = $attemptobj->get_question_score($question->id); |
89 | } |
90 | $table->data[] = $row; |
91 | } |
92 | |
93 | /// Print the summary table. |
94 | print_table($table); |
95 | |
96 | /// Finish attempt button. |
97 | echo "<div class=\"submitbtns mdl-align\">\n"; |
98 | $options = array( |
99 | 'finishattempt' => 1, |
100 | 'timeup' => 0, |
101 | 'questionids' => '', |
102 | 'sesskey' => sesskey() |
103 | ); |
104 | print_single_button($attemptobj->attempt_url(), $options, get_string('finishattempt', 'quiz'), |
105 | 'post', '', false, '', false, get_string('confirmclose', 'quiz')); |
106 | echo "</div>\n"; |
107 | |
108 | /// Finish the page |
109 | $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time()); |
b10c38a3 |
110 | if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) { |
36e413e3 |
111 | print_footer('empty'); |
112 | } else { |
113 | print_footer($course); |
114 | } |
115 | |
116 | ?> |