579ddad5 |
1 | <?PHP // $Id$ |
2 | |
3 | // This page prints a particular instance of quiz |
4 | |
5 | require("../../config.php"); |
6 | require("lib.php"); |
7 | |
8 | optional_variable($id); // Course Module ID, or |
9 | optional_variable($q); // quiz ID |
10 | |
e1c91df0 |
11 | optional_variable($attempt); // A particular attempt ID |
12 | |
579ddad5 |
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 | require_login($course->id); |
39 | |
40 | if (!isteacher($course->id)) { |
41 | error("Only teachers can see this page"); |
42 | } |
43 | |
44 | add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id"); |
45 | |
46 | // Print the page header |
47 | |
48 | if ($course->category) { |
49 | $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->"; |
50 | } |
51 | |
52 | $strquizzes = get_string("modulenameplural", "quiz"); |
53 | $strquiz = get_string("modulename", "quiz"); |
54 | $strreport = get_string("report", "quiz"); |
55 | $strname = get_string("name"); |
56 | $strattempts = get_string("attempts", "quiz"); |
6d86b5dc |
57 | $strscore = get_string("score", "quiz"); |
8d94f5a0 |
58 | $strgrade = get_string("grade"); |
6d86b5dc |
59 | $strtimetaken = get_string("timetaken", "quiz"); |
60 | $strtimecompleted = get_string("timecompleted", "quiz"); |
579ddad5 |
61 | |
62 | print_header("$course->shortname: $quiz->name", "$course->fullname", |
63 | "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> |
64 | -> <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strreport", |
65 | "", "", true); |
66 | |
67 | print_heading($quiz->name); |
68 | |
6d86b5dc |
69 | if ($attempt) { // Show a particular attempt |
70 | |
71 | if (! $attempt = get_record("quiz_attempts", "id", $attempt)) { |
72 | error("No such attempt ID exists"); |
73 | } |
74 | |
75 | if (! $questions = quiz_get_attempt_responses($attempt)) { |
76 | error("Could not reconstruct quiz results for attempt $attempt->id!"); |
77 | } |
78 | |
79 | if (!$result = quiz_grade_attempt_results($quiz, $questions)) { |
80 | error("Could not re-grade this quiz attempt!"); |
81 | } |
82 | |
83 | $table->align = array("RIGHT", "LEFT"); |
84 | $table->data[] = array("$strtimetaken:", format_time($attempt->timefinish - $attempt->timestart)); |
85 | $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish)); |
86 | $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)"); |
87 | $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade"); |
88 | print_table($table); |
89 | |
90 | print_continue("report.php?q=$quiz->id"); |
91 | |
92 | $quiz->feedback = true; |
93 | $quiz->correctanswers = true; |
94 | quiz_print_quiz_questions($quiz, $result); |
95 | |
96 | print_continue("report.php?q=$quiz->id"); |
97 | print_footer($course); |
98 | exit; |
99 | } |
100 | |
579ddad5 |
101 | if (!$grades = quiz_get_grade_records($quiz)) { |
102 | print_footer($course); |
103 | exit; |
104 | } |
105 | |
106 | $table->head = array("", $strname, $strattempts, $strgrade); |
107 | $table->align = array("CENTER", "LEFT", "LEFT", "RIGHT"); |
108 | $table->width = array(10, "*", "*", 20); |
109 | |
110 | foreach ($grades as $grade) { |
111 | $picture = print_user_picture($grade->user, $course->id, $grade->picture, false, true); |
112 | |
113 | if ($attempts = quiz_get_user_attempts($quiz->id, $grade->user)) { |
8d94f5a0 |
114 | $userattempts = quiz_get_user_attempts_string($quiz, $attempts, $grade->grade); |
579ddad5 |
115 | } |
116 | |
117 | $table->data[] = array ($picture, |
118 | "<A HREF=\"$CFG->wwwroot/user/view.php?id=$grade->user&course=$course->id\">$grade->firstname $grade->lastname</A>", |
e1c91df0 |
119 | "$userattempts", round($grade->grade,0)); |
579ddad5 |
120 | } |
121 | |
122 | print_table($table); |
123 | |
124 | // Finish the page |
125 | print_footer($course); |
126 | |
127 | ?> |