Step 2 of Bug 1223 done.
[moodle.git] / mod / quiz / review.php
CommitLineData
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
83 print_heading($quiz->name);
84
85
586b2c82 86 if (! $questions = quiz_get_attempt_responses($attempt)) {
dbb49192 87 if ($user = get_record("user", "id", $attempt->userid)) {
88 $fullname = fullname($user);
89 } else {
90 $fullname = "????";
91 }
92 print_heading(get_string("attemptincomplete", "quiz", $fullname));
93 print_footer($course);
94 exit;
29d5d0b4 95 }
96
97 quiz_remove_unwanted_questions($questions, $quiz);
98
99 if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
100 error("Could not re-grade this quiz attempt!");
101 }
102
103 if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
104 $timetaken = format_time($timetaken);
105 } else {
106 $timetaken = "-";
107 }
108
109 $table->align = array("right", "left");
110 $table->data[] = array("$strtimetaken:", $timetaken);
111 $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish));
ed1daaa9 112 if ($quiz->grade) {
081bf74f 113 $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)");
ed1daaa9 114 $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade");
115 }
29d5d0b4 116
117 print_table($table);
118
119 if (isteacher($course->id)) {
120 print_continue("report.php?q=$quiz->id");
121 } else {
122 print_continue("view.php?q=$quiz->id");
123 }
124
125 $quiz->feedback = true;
126 $quiz->correctanswers = true;
127 $quiz->shuffleanswers = false;
128 $quiz->shufflequestions = false;
129 quiz_print_quiz_questions($quiz, $result, $questions);
130
131 if (isteacher($course->id)) {
132 print_continue("report.php?q=$quiz->id");
133 } else {
134 print_continue("view.php?q=$quiz->id");
135 }
136
137 print_footer($course);
138
139?>