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 $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)));
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");
53 $title = format_string($course->shortname
) . ": $hotpot->name";
54 $heading = $course->fullname
;
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
) : '';
70 $xml = get_field('hotpot_details', 'details', 'attempt', $attempt->id
);
74 print '<pre id="contents">';
75 $xml_tree = new hotpot_xml_tree($xml, "['hpjsresult']['#']");
76 print_r ($xml_tree->xml_value('fields'));
80 print htmlspecialchars($xml);
83 print "Action '$action' not recognized";
87 hotpot_print_attempt_details($hotpot, $attempt);
89 hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
90 print_footer($course);
91 ///////////////////////////
93 ///////////////////////////
94 function hotpot_print_attempt_summary(&$hotpot, &$attempt) {
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) {
103 $value = hotpot_format_score($attempt);
106 $value = hotpot_format_status($attempt);
109 $value = empty($attempt->timefinish
) ?
'-' : userdate($attempt->timefinish
);
112 $value = empty($attempt->timefinish
) ?
'-' : format_time($attempt->timefinish
- $attempt->timestart
);
115 $value = isset($attempt->$field) ?
$attempt->$field : NULL;
121 $name = get_string('report'.$field, 'hotpot');
124 $name = get_string('penalties', 'hotpot');
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>';
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');
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";
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
190 foreach ($numfields as $field) {
191 if ($f[$field]['count']) {
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";
200 print '<tr><td align="center" class="generaltablecell"><b>'.get_string("noresponses", "hotpot")."</b></td></tr>\n";
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]);
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;
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
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>';
245 print_simple_box_end();