Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / hotpot / review.php
blob57bc10d031cf073e0998226c9345045ac5d4affc
1 <?PHP // $Id$
2 // This page prints a review of a particular quiz attempt
3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
7 $hp = optional_param('hp', 0, PARAM_INT); // hotpot ID
8 $attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review
10 if ($id) {
11 if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
12 error("Course Module ID was incorrect");
14 if (! $course = get_record("course", "id", $cm->course)) {
15 error("Course is misconfigured");
17 if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
18 error("Course module is incorrect");
20 } else {
21 if (! $hotpot = get_record("hotpot", "id", $hp)) {
22 error("Course module is incorrect");
24 if (! $course = get_record("course", "id", $hotpot->course)) {
25 error("Course is misconfigured");
27 if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
28 error("Course Module ID was incorrect");
31 if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
32 error("Attempt ID was incorrect");
35 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
36 require_login($course->id);
37 if (!has_capability('mod/hotpot:viewreport',$context)) {
38 if (!$hotpot->review) {
39 error(get_string("noreview", "quiz"));
41 //if (time() < $hotpot->timeclose) {
42 // error(get_string("noreviewuntil", "quiz", userdate($hotpot->timeclose)));
43 //}
44 if ($attempt->userid != $USER->id) {
45 error("This is not your attempt!");
48 add_to_log($course->id, "hotpot", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
49 // Print the page header
50 $strmodulenameplural = get_string("modulenameplural", "hotpot");
51 $strmodulename = get_string("modulename", "hotpot");
52 // print header
53 $title = format_string($course->shortname) . ": $hotpot->name";
54 $heading = $course->fullname;
56 $navlinks = array();
57 $navlinks[] = array('name' => $strmodulenameplural, 'link' => 'index.php?id='.$course->id, 'type' => 'activity');
58 $navlinks[] = array('name' => get_string("review", "quiz"), 'link' => '', 'type' => 'activityinstance');
59 $navigation = build_navigation($navlinks);
62 $button = update_module_button($cm->id, $course->id, $strmodulename);
63 print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
64 print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
65 print_heading($hotpot->name);
66 hotpot_print_attempt_summary($hotpot, $attempt);
67 hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
68 $action = has_capability('mod/hotpot:viewreport',$context) ? optional_param('action', '', PARAM_ALPHA) : '';
69 if ($action) {
70 $xml = get_field('hotpot_details', 'details', 'attempt', $attempt->id);
71 print '<hr>';
72 switch ($action) {
73 case 'showxmltree':
74 print '<pre id="contents">';
75 $xml_tree = new hotpot_xml_tree($xml, "['hpjsresult']['#']");
76 print_r ($xml_tree->xml_value('fields'));
77 print '</pre>';
78 break;
79 case 'showxmlsource':
80 print htmlspecialchars($xml);
81 break;
82 default:
83 print "Action '$action' not recognized";
85 print '<hr>';
86 } else {
87 hotpot_print_attempt_details($hotpot, $attempt);
89 hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
90 print_footer($course);
91 ///////////////////////////
92 // functions
93 ///////////////////////////
94 function hotpot_print_attempt_summary(&$hotpot, &$attempt) {
95 // start table
96 print_simple_box_start("center", "80%", "#ffffff", 0);
97 print '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
98 // add attempt properties
99 $fields = array('attempt', 'score', 'penalties', 'status', 'timetaken', 'timerecorded');
100 foreach ($fields as $field) {
101 switch ($field) {
102 case 'score':
103 $value = hotpot_format_score($attempt);
104 break;
105 case 'status':
106 $value = hotpot_format_status($attempt);
107 break;
108 case 'timerecorded':
109 $value = empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish);
110 break;
111 case 'timetaken':
112 $value = empty($attempt->timefinish) ? '-' : format_time($attempt->timefinish - $attempt->timestart);
113 break;
114 default:
115 $value = isset($attempt->$field) ? $attempt->$field : NULL;
117 if (isset($value)) {
118 switch ($field) {
119 case 'status':
120 case 'timerecorded':
121 $name = get_string('report'.$field, 'hotpot');
122 break;
123 case 'penalties':
124 $name = get_string('penalties', 'hotpot');
125 break;
126 default:
127 $name = get_string($field, 'quiz');
129 print '<tr><th align="right" width="100" class="generaltableheader" scope="row">'.$name.':</th><td class="generaltablecell">'.$value.'</td></tr>';
132 // finish table
133 print '</table>';
134 print_simple_box_end();
136 function hotpot_print_review_buttons(&$course, &$hotpot, &$attempt, $context) {
137 print "\n".'<table border="0" align="center" cellpadding="2" cellspacing="2" class="generaltable">';
138 print "\n<tr>\n".'<td align="center">';
139 print_single_button("report.php?hp=$hotpot->id", NULL, get_string('continue'), 'post');
140 if (has_capability('mod/hotpot:viewreport',$context) && record_exists('hotpot_details', 'attempt', $attempt->id)) {
141 print "</td>\n".'<td align="center">';
142 print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmlsource", NULL, get_string('showxmlsource', 'hotpot'), 'post');
143 print "</td>\n".'<td align="center">';
144 print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmltree", NULL, get_string('showxmltree', 'hotpot'), 'post');
145 $colspan = 3;
146 } else {
147 $colspan = 1;
149 print "</td>\n</tr>\n";
150 print '<tr><td colspan="'.$colspan.'">';
151 print_spacer(4, 1, false); // height=4, width=1, no <br />
152 print "</td></tr>\n";
153 print "</table>\n";
155 function hotpot_print_attempt_details(&$hotpot, &$attempt) {
156 // define fields to print
157 $textfields = array('correct', 'ignored', 'wrong');
158 $numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
159 $fields = array_merge($textfields, $numfields);
160 $q = array(); // questions
161 $f = array(); // fields
162 foreach ($fields as $field) {
163 $name = get_string($field, 'hotpot');
164 $f[$field] = array('count'=>0, 'name'=>$name);
166 // get questions and responses for this attempt
167 $questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
168 $responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
169 if ($questions && $responses) {
170 foreach ($responses as $response) {
171 $id = $response->question;
172 foreach ($fields as $field) {
173 if (!isset($f[$field])) {
174 $name = get_string($field, 'hotpot');
175 $f[$field] = array('count'=>0, 'name'=>$name);
177 if (isset($response->$field)) {
178 $f[$field]['count']++;
179 if (!isset($q[$id])) {
180 $name = hotpot_get_question_name($questions[$id]);
181 $q[$id] = array('name'=>$name);
183 $q[$id][$field] = $response->$field;
188 // count the number of columns required in the table
189 $colspan = 0;
190 foreach ($numfields as $field) {
191 if ($f[$field]['count']) {
192 $colspan += 2;
195 $colspan = max(2, $colspan);
196 // start table of questions and responses
197 print_simple_box_start("center", "80%", "#ffffff", 0);
198 print '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
199 if (empty($q)) {
200 print '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot")."</b></td></tr>\n";
201 } else {
202 // flag to ensure separators are only printed before the 2nd and subsequent questions
203 $printseparator = false;
204 foreach ($q as $i=>$question) {
205 // flag to ensure questions are only printed when there is at least one response
206 $printedquestion = false;
207 // add rows of text fields
208 foreach ($textfields as $field) {
209 if (isset($question[$field])) {
210 $text = hotpot_strings($question[$field]);
211 if (trim($text)) {
212 // print question if necessary
213 if (!$printedquestion) {
214 if ($printseparator) {
215 print '<tr><td colspan="'.$colspan.'"><div class="tabledivider"></div></td></tr>'."\n";
217 $printseparator = true;
218 print '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>'."\n";
219 $printedquestion = true;
221 // print response
222 print '<tr><th align="right" width="100" class="generaltableheader" scope="row">'.$f[$field]['name'].':</th><td colspan="'.($colspan-1).'" class="generaltablecell">'.$text.'</td></tr>'."\n";
226 // add row of numeric fields
227 print '<tr>';
228 foreach ($numfields as $field) {
229 if ($f[$field]['count']) {
230 // print question if necessary
231 if (!$printedquestion) {
232 print '<td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name']."</b></td></tr>\n<tr>";
233 $printedquestion = true;
235 // print numeric response
236 $value = isset($question[$field]) ? $question[$field] : '-';
237 print '<th align="right" width="100" class="generaltableheader" scope="row">'.$f[$field]['name'].':</th><td class="generaltablecell">'.$value.'</td>';
240 print "</tr>\n";
241 } // foreach $q
243 // finish table
244 print "</table>\n";
245 print_simple_box_end();