New modular plugin structure for quiz reports.
[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
57 add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id");
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
86 if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) {
87 error("Could not reconstruct quiz results for attempt $attempt->id!");
88 }
89
90 quiz_remove_unwanted_questions($questions, $quiz);
91
92 if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
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));
105 $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)");
106 $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade");
107
108 print_table($table);
109
110 if (isteacher($course->id)) {
111 print_continue("report.php?q=$quiz->id");
112 } else {
113 print_continue("view.php?q=$quiz->id");
114 }
115
116 $quiz->feedback = true;
117 $quiz->correctanswers = true;
118 $quiz->shuffleanswers = false;
119 $quiz->shufflequestions = false;
120 quiz_print_quiz_questions($quiz, $result, $questions);
121
122 if (isteacher($course->id)) {
123 print_continue("report.php?q=$quiz->id");
124 } else {
125 print_continue("view.php?q=$quiz->id");
126 }
127
128 print_footer($course);
129
130?>