29d5d0b4 |
1 | <?PHP // $Id$ |
2 | |
3 | // This page prints a review of a particular quiz attempt |
4 | |
5 | require_once("../../config.php"); |
6 | require_once("lib.php"); |
7 | |
8 | optional_variable($id); // Course Module ID, or |
9 | optional_variable($q); // quiz ID |
10 | |
11 | require_variable($attempt); // A particular attempt ID for review |
12 | |
13 | if ($id) { |
14 | if (! $cm = get_record("course_modules", "id", $id)) { |
15 | error("Course Module ID was incorrect"); |
16 | } |
17 | |
18 | if (! $course = get_record("course", "id", $cm->course)) { |
19 | error("Course is misconfigured"); |
20 | } |
21 | |
22 | if (! $quiz = get_record("quiz", "id", $cm->instance)) { |
23 | error("Course module is incorrect"); |
24 | } |
25 | |
26 | } else { |
27 | if (! $quiz = get_record("quiz", "id", $q)) { |
28 | error("Course module is incorrect"); |
29 | } |
30 | if (! $course = get_record("course", "id", $quiz->course)) { |
31 | error("Course is misconfigured"); |
32 | } |
33 | if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { |
34 | error("Course Module ID was incorrect"); |
35 | } |
36 | } |
37 | |
38 | if (! $attempt = get_record("quiz_attempts", "id", $attempt)) { |
39 | error("No such attempt ID exists"); |
40 | } |
41 | |
42 | |
43 | require_login($course->id); |
44 | |
45 | if (!isteacher($course->id)) { |
46 | if (!$quiz->review) { |
47 | error(get_string("noreview", "quiz")); |
48 | } |
49 | if (time() < $quiz->timeclose) { |
50 | error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose))); |
51 | } |
52 | if ($attempt->userid != $USER->id) { |
53 | error("This is not your attempt!"); |
54 | } |
55 | } |
56 | |
eaefa1c0 |
57 | add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", "$cm->id"); |
29d5d0b4 |
58 | |
59 | |
60 | // Print the page header |
61 | |
62 | if ($course->category) { |
63 | $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->"; |
64 | } |
65 | |
66 | $strquizzes = get_string("modulenameplural", "quiz"); |
67 | $strquiz = get_string("modulename", "quiz"); |
68 | $strreport = get_string("report", "quiz"); |
69 | $strreview = get_string("review", "quiz"); |
70 | $strname = get_string("name"); |
71 | $strattempts = get_string("attempts", "quiz"); |
72 | $strscore = get_string("score", "quiz"); |
73 | $strgrade = get_string("grade"); |
74 | $strbestgrade = get_string("bestgrade", "quiz"); |
75 | $strtimetaken = get_string("timetaken", "quiz"); |
76 | $strtimecompleted = get_string("timecompleted", "quiz"); |
77 | |
78 | print_header("$course->shortname: $quiz->name", "$course->fullname", |
79 | "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> |
80 | -> <a href=\"view.php?id=$cm->id\">$quiz->name</a> -> $strreview", |
81 | "", "", true); |
82 | |
b7f35820 |
83 | echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib |
84 | |
29d5d0b4 |
85 | print_heading($quiz->name); |
86 | |
87 | |
8966a111 |
88 | if (!($questions = quiz_get_attempt_questions($quiz, $attempt))) { |
89 | error("Unable to get questions from database for quiz $quiz->id attempt $attempt->id number $attempt->attempt"); |
29d5d0b4 |
90 | } |
91 | |
8966a111 |
92 | if (!$result = quiz_grade_responses($quiz, $questions)) { |
29d5d0b4 |
93 | error("Could not re-grade this quiz attempt!"); |
94 | } |
95 | |
96 | if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { |
97 | $timetaken = format_time($timetaken); |
98 | } else { |
99 | $timetaken = "-"; |
100 | } |
101 | |
102 | $table->align = array("right", "left"); |
103 | $table->data[] = array("$strtimetaken:", $timetaken); |
104 | $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish)); |
ed1daaa9 |
105 | if ($quiz->grade) { |
081bf74f |
106 | $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)"); |
ed1daaa9 |
107 | $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade"); |
108 | } |
29d5d0b4 |
109 | |
110 | print_table($table); |
111 | |
112 | if (isteacher($course->id)) { |
113 | print_continue("report.php?q=$quiz->id"); |
114 | } else { |
115 | print_continue("view.php?q=$quiz->id"); |
116 | } |
117 | |
118 | $quiz->feedback = true; |
119 | $quiz->correctanswers = true; |
120 | $quiz->shuffleanswers = false; |
121 | $quiz->shufflequestions = false; |
8966a111 |
122 | quiz_print_quiz_questions($quiz, $questions, $result); |
29d5d0b4 |
123 | |
124 | if (isteacher($course->id)) { |
125 | print_continue("report.php?q=$quiz->id"); |
126 | } else { |
127 | print_continue("view.php?q=$quiz->id"); |
128 | } |
129 | |
130 | print_footer($course); |
131 | |
132 | ?> |