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
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");
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 require_login($course);
37 // check user can access this hotpot activity
38 if (!hotpot_is_visible($cm)) {
39 print_error("activityiscurrentlyhidden");
42 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
43 if (!has_capability('mod/hotpot:viewreport',$context)) {
44 if (!$hotpot->review
) {
45 print_error("noreview", "quiz");
47 //if (time() < $hotpot->timeclose) {
48 // print_error("noreviewuntil", "quiz", '', userdate($hotpot->timeclose));
50 if ($attempt->userid
!= $USER->id
) {
51 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");
55 // Print the page header
56 $strmodulenameplural = get_string("modulenameplural", "hotpot");
57 $strmodulename = get_string("modulename", "hotpot");
59 $title = format_string($course->shortname
) . ": $hotpot->name";
60 $heading = $course->fullname
;
62 $navigation = build_navigation('', $cm);
63 $button = update_module_button($cm->id
, $course->id
, $strmodulename);
64 print_header($title, $heading, $navigation, "", "", true, $button, navmenu($course, $cm));
65 print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
66 print_heading($hotpot->name
);
67 hotpot_print_attempt_summary($hotpot, $attempt);
68 hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
69 $action = has_capability('mod/hotpot:viewreport',$context) ?
optional_param('action', '', PARAM_ALPHA
) : '';
71 $xml = get_field('hotpot_details', 'details', 'attempt', $attempt->id
);
75 print '<pre id="contents">';
76 $xml_tree = new hotpot_xml_tree($xml, "['hpjsresult']['#']");
77 print_r ($xml_tree->xml_value('fields'));
81 print htmlspecialchars($xml);
84 print "Action '$action' not recognized";
88 hotpot_print_attempt_details($hotpot, $attempt);
90 hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
91 print_footer($course);
92 ///////////////////////////
94 ///////////////////////////
95 function hotpot_print_attempt_summary(&$hotpot, &$attempt) {
97 print_simple_box_start("center", "80%", "#ffffff", 0);
98 print '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
99 // add attempt properties
100 $fields = array('attempt', 'score', 'penalties', 'status', 'timetaken', 'timerecorded');
101 foreach ($fields as $field) {
104 $value = hotpot_format_score($attempt);
107 $value = hotpot_format_status($attempt);
110 $value = empty($attempt->timefinish
) ?
'-' : userdate($attempt->timefinish
);
113 $value = empty($attempt->timefinish
) ?
'-' : format_time($attempt->timefinish
- $attempt->timestart
);
116 $value = isset($attempt->$field) ?
$attempt->$field : NULL;
122 $name = get_string('report'.$field, 'hotpot');
125 $name = get_string('penalties', 'hotpot');
128 $name = get_string($field, 'quiz');
130 print '<tr><th align="right" width="100" class="generaltableheader" scope="row">'.$name.':</th><td class="generaltablecell">'.$value.'</td></tr>';
135 print_simple_box_end();
137 function hotpot_print_review_buttons(&$course, &$hotpot, &$attempt, $context) {
138 print "\n".'<table border="0" align="center" cellpadding="2" cellspacing="2" class="generaltable">';
139 print "\n<tr>\n".'<td align="center">';
140 print_single_button("report.php?hp=$hotpot->id", NULL, get_string('continue'), 'post');
141 if (has_capability('mod/hotpot:viewreport',$context) && record_exists('hotpot_details', 'attempt', $attempt->id
)) {
142 print "</td>\n".'<td align="center">';
143 print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmlsource", NULL, get_string('showxmlsource', 'hotpot'), 'post');
144 print "</td>\n".'<td align="center">';
145 print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmltree", NULL, get_string('showxmltree', 'hotpot'), 'post');
150 print "</td>\n</tr>\n";
151 print '<tr><td colspan="'.$colspan.'">';
152 print_spacer(4, 1, false); // height=4, width=1, no <br />
153 print "</td></tr>\n";
156 function hotpot_print_attempt_details(&$hotpot, &$attempt) {
157 // define fields to print
158 $textfields = array('correct', 'ignored', 'wrong');
159 $numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
160 $fields = array_merge($textfields, $numfields);
161 $q = array(); // questions
162 $f = array(); // fields
163 foreach ($fields as $field) {
164 $name = get_string($field, 'hotpot');
165 $f[$field] = array('count'=>0, 'name'=>$name);
167 // get questions and responses for this attempt
168 $questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
169 $responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
170 if ($questions && $responses) {
171 foreach ($responses as $response) {
172 $id = $response->question
;
173 foreach ($fields as $field) {
174 if (!isset($f[$field])) {
175 $name = get_string($field, 'hotpot');
176 $f[$field] = array('count'=>0, 'name'=>$name);
178 if (isset($response->$field)) {
179 $f[$field]['count']++
;
180 if (!isset($q[$id])) {
181 $name = hotpot_get_question_name($questions[$id]);
182 $q[$id] = array('name'=>$name);
184 $q[$id][$field] = $response->$field;
189 // count the number of columns required in the table
191 foreach ($numfields as $field) {
192 if ($f[$field]['count']) {
196 $colspan = max(2, $colspan);
197 // start table of questions and responses
198 print_simple_box_start("center", "80%", "#ffffff", 0);
199 print '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">'."\n";
201 print '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot")."</b></td></tr>\n";
203 // flag to ensure separators are only printed before the 2nd and subsequent questions
204 $printseparator = false;
205 foreach ($q as $i=>$question) {
206 // flag to ensure questions are only printed when there is at least one response
207 $printedquestion = false;
208 // add rows of text fields
209 foreach ($textfields as $field) {
210 if (isset($question[$field])) {
211 $text = hotpot_strings($question[$field]);
213 // print question if necessary
214 if (!$printedquestion) {
215 if ($printseparator) {
216 print '<tr><td colspan="'.$colspan.'"><div class="tabledivider"></div></td></tr>'."\n";
218 $printseparator = true;
219 print '<tr><td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name'].'</b></td></tr>'."\n";
220 $printedquestion = true;
223 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";
227 // add row of numeric fields
229 foreach ($numfields as $field) {
230 if ($f[$field]['count']) {
231 // print question if necessary
232 if (!$printedquestion) {
233 print '<td colspan="'.$colspan.'" class="generaltablecell"><b>'.$question['name']."</b></td></tr>\n<tr>";
234 $printedquestion = true;
236 // print numeric response
237 $value = isset($question[$field]) ?
$question[$field] : '-';
238 print '<th align="right" width="100" class="generaltableheader" scope="row">'.$f[$field]['name'].':</th><td class="generaltablecell">'.$value.'</td>';
246 print_simple_box_end();