Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / hotpot / review.php
blob0bc34a7f68ad4f5e31eed47bbb42d216a00833ae
1 <?PHP // $Id$
3 // This page prints a review of a particular quiz attempt
5 require_once("../../config.php");
6 require_once("lib.php");
8 $id = optional_param("id"); // Course Module ID, or
9 $hp = optional_param("hp"); // hotpot ID
11 $attempt = required_param("attempt"); // A particular attempt ID for review
13 if ($id) {
14 if (! $cm = get_record("course_modules", "id", $id)) {
15 error("Course Module ID was incorrect");
17 if (! $course = get_record("course", "id", $cm->course)) {
18 error("Course is misconfigured");
20 if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
21 error("Course module is incorrect");
24 } else {
25 if (! $hotpot = get_record("hotpot", "id", $hp)) {
26 error("Course module is incorrect");
28 if (! $course = get_record("course", "id", $hotpot->course)) {
29 error("Course is misconfigured");
31 if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
32 error("Course Module ID was incorrect");
36 if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
37 error("No such attempt ID exists");
40 require_login($course->id);
42 if (!isteacher($course->id)) {
43 if (!$hotpot->review) {
44 error(get_string("noreview", "quiz"));
46 //if (time() < $hotpot->timeclose) {
47 // error(get_string("noreviewuntil", "quiz", userdate($hotpot->timeclose)));
48 //}
49 if ($attempt->userid != $USER->id) {
50 error("This is not your attempt!");
54 add_to_log($course->id, "hotpot", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
57 // Print the page header
59 $strmodulenameplural = get_string("modulenameplural", "hotpot");
60 $strmodulename = get_string("modulename", "hotpot");
62 // print header
63 $title = "$course->shortname: $hotpot->name";
64 $heading = "$course->fullname";
65 $navigation = "<a href=\"index.php?id=$course->id\">$strmodulenameplural</a> -> ".get_string("review", "quiz");
66 if ($course->category) {
67 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
69 $button = update_module_button($cm->id, $course->id, $strmodulename);
71 print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
74 echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
76 print_heading($hotpot->name);
78 // format attempt properties
79 if (!empty($attempt->timefinish)) {
80 $attempt->timecompleted = userdate($attempt->timefinish);
81 $attempt->timetaken = format_time($attempt->timefinish - $attempt->timestart);
82 } else {
83 $attempt->timecompleted = '-';
84 $attempt->timetaken = '-';
86 $attempt->score = hotpot_format_score($attempt);
88 $html = '';
90 // start table
91 $html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
93 // add attempt properties
94 $fields = array('attempt', 'score', 'penalties', 'timetaken', 'timecompleted');
95 foreach ($fields as $field) {
96 if (isset($attempt->$field)) {
97 $module = ($field=='penalties') ? 'hotpot' : 'quiz';
98 $html .= '<tr><th align="right" width="100" class="generaltableheader">'.get_string($field, $module).':</th><td class="generaltablecell">'.$attempt->$field.'</td></tr>';
102 // finish table
103 $html .= '</table>';
105 print_simple_box_start("center", "80%", "#ffffff", 0);
106 print $html;
107 print_simple_box_end();
109 print_continue("report.php?id=$cm->id");
110 hotpot_print_attempt_details($hotpot, $attempt);
111 print_continue("report.php?id=$cm->id");
113 print_footer($course);
115 ///////////////////////////
116 // functions
117 ///////////////////////////
119 function hotpot_print_attempt_details(&$hotpot, &$attempt) {
121 // define fields to print
122 $textfields = array('correct', 'ignored', 'wrong');
123 $numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
125 $fields = array_merge($textfields, $numfields);
127 $q = array(); // questions
128 $f = array(); // fields
129 foreach ($fields as $field) {
130 $name = get_string($field, 'hotpot');
131 $f[$field] = array('count'=>0, 'name'=>$name);
134 // get questions and responses for this attempt
135 $questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
136 $responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
138 if ($questions && $responses) {
139 foreach ($responses as $response) {
140 $id = $response->question;
141 foreach ($fields as $field) {
142 if (!isset($f[$field])) {
143 $name = get_string($field, 'hotpot');
144 $f[$field] = array('count'=>0, 'name'=>$name);
146 if (isset($response->$field)) {
147 $f[$field]['count']++;
149 if (!isset($q[$id])) {
150 $name = hotpot_get_question_name($questions[$id]);
151 $q[$id] = array('name'=>$name);
154 $q[$id][$field] = $response->$field;
160 // count the number of columns required in the table
161 $colspan = 0;
162 foreach ($numfields as $field) {
163 if ($f[$field]['count']) {
164 $colspan += 2;
167 $colspan = max(2, $colspan);
169 $html = '';
171 // start table of questions and responses
172 $html .= '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
174 if (empty($q)) {
175 $html .= '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot").'</b></td></tr>';
177 } else {
178 foreach ($q as $question) {
180 // flag to ensure questions are only printed when there is at least one response
181 $printedquestion = false;
183 // add rows of text fields
184 foreach ($textfields as $field) {
185 if (isset($question[$field])) {
186 $text = hotpot_strings($question[$field]);
187 if (trim($text)) {
189 // print question if necessary
190 if (!$printedquestion) {
191 $html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
192 $printedquestion = true;
195 // print response
196 $html .= '<tr><th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td colspan="'.($colspan-1).'" class="generaltablecell">'.$text.'</td></tr>';
201 // add row of numeric fields
202 $html .= '<tr>';
203 foreach ($numfields as $field) {
204 if ($f[$field]['count']) {
206 // print question if necessary
207 if (!$printedquestion) {
208 $html .= '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>';
209 $printedquestion = true;
212 // print numeric response
213 $value = isset($question[$field]) ? $question[$field] : '-';
214 $html .= '<th align="right" width="100" class="generaltableheader">'.$f[$field]['name'].':</th><td class="generaltablecell">'.$value.'</td>';
217 $html .= '</tr>';
219 // add separator
220 if ($printedquestion) {
221 $html .= '<tr><td colspan="'.$colspan.'"><div class="tabledivider"></div></td></tr>';
224 } // foreach $q
227 // finish table
228 $html .= '</table>';
230 print_simple_box_start("center", "80%", "#ffffff", 0);
231 print $html;
232 print_simple_box_end();