set_url('/mod/hotpot/review.php', array('id'=>$id,'attempt'=>$attempt)); if (! $cm = get_coursemodule_from_id('hotpot', $id)) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { print_error('coursemisconf'); } if (! $hotpot = $DB->get_record("hotpot", array("id"=>$cm->instance))) { print_error('invalidcoursemodule'); } } else { $PAGE->set_url('/mod/hotpot/review.php', array('hp'=>$hp,'attempt'=>$attempt)); if (! $hotpot = $DB->get_record("hotpot", array("id"=>$hp))) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$hotpot->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) { print_error('invalidcoursemodule'); } } if (! $attempt = $DB->get_record("hotpot_attempts", array("id"=>$attempt))) { print_error('invalidattemptid', 'hotpot'); } require_login($course, true, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('mod/hotpot:viewreport',$context)) { if (!$hotpot->review) { print_error("noreview", "quiz"); } //if (time() < $hotpot->timeclose) { // print_error("noreviewuntil", "quiz", '', userdate($hotpot->timeclose)); //} if ($attempt->userid != $USER->id) { print_error('notyourattempt', 'hotpot'); } } add_to_log($course->id, "hotpot", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id"); // Print the page header $strmodulenameplural = get_string("modulenameplural", "hotpot"); $strmodulename = get_string("modulename", "hotpot"); // print header $PAGE->requires->js('/lib/overlib/overlib.js', true); $PAGE->requires->js('/lib/overlib/overlib_cssstyle.js', true); $PAGE->set_title(format_string($course->shortname) . ": $hotpot->name"); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); print ''; // for overlib echo $OUTPUT->heading($hotpot->name); hotpot_print_attempt_summary($hotpot, $attempt); hotpot_print_review_buttons($course, $hotpot, $attempt, $context); $action = has_capability('mod/hotpot:viewreport',$context) ? optional_param('action', '', PARAM_ALPHA) : ''; if ($action) { $xml = $DB->get_field('hotpot_details', 'details', array('attempt'=>$attempt->id)); print '
'; switch ($action) { case 'showxmltree': print '
';
                $xml_tree = new hotpot_xml_tree($xml, "['hpjsresult']['#']");
                print_r ($xml_tree->xml_value('fields'));
                print '
'; break; case 'showxmlsource': print htmlspecialchars($xml); break; default: print "Action '$action' not recognized"; } print '
'; } else { hotpot_print_attempt_details($hotpot, $attempt); } hotpot_print_review_buttons($course, $hotpot, $attempt, $context); echo $OUTPUT->footer(); /////////////////////////// // functions /////////////////////////// function hotpot_print_attempt_summary(&$hotpot, &$attempt) { // start table global $OUTPUT; echo $OUTPUT->box_start("generalbox boxaligncenter boxwidthwide"); print ''."\n"; // add attempt properties $fields = array('attempt', 'score', 'penalties', 'status', 'timetaken', 'timerecorded'); foreach ($fields as $field) { switch ($field) { case 'score': $value = hotpot_format_score($attempt); break; case 'status': $value = hotpot_format_status($attempt); break; case 'timerecorded': $value = empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish); break; case 'timetaken': $value = empty($attempt->timefinish) ? '-' : format_time($attempt->timefinish - $attempt->timestart); break; default: $value = isset($attempt->$field) ? $attempt->$field : NULL; } if (isset($value)) { switch ($field) { case 'status': case 'timerecorded': $name = get_string('report'.$field, 'hotpot'); break; case 'penalties': $name = get_string('penalties', 'hotpot'); break; default: $name = get_string($field, 'quiz'); } print ''; } } // finish table print '
'.$name.':'.$value.'
'; echo $OUTPUT->box_end(); } function hotpot_print_review_buttons(&$course, &$hotpot, &$attempt, $context) { global $DB, $OUTPUT; print "\n".''; print "\n\n".'\n".'\n".'\n\n"; print '\n"; print "
'; echo $OUTPUT->single_button(new moodle_url("report.php", array('hp'=>$hotpot->id)), get_string('continue')); if (has_capability('mod/hotpot:viewreport',$context) && $DB->record_exists('hotpot_details', array('attempt'=>$attempt->id))) { print "'; echo $OUTPUT->single_button(new moodle_url("review.php", array('hp'=>$hotpot->id, 'attempt'=>$attempt->id, 'action'=>'showxmlsource')), get_string('showxmlsource', 'hotpot')); print "'; echo $OUTPUT->single_button(new moodle_url("review.php", array('hp'=>$hotpot->id,'attempt'=>$attempt->id, 'action'=>'showxmltree')), get_string('showxmltree', 'hotpot')); $colspan = 3; } else { $colspan = 1; } print "
'; echo $OUTPUT->spacer(array('height'=>4, 'width'=>1)); // should be done with CSS instead print "
\n"; } function hotpot_print_attempt_details(&$hotpot, &$attempt) { global $DB, $OUTPUT; // define fields to print $textfields = array('correct', 'ignored', 'wrong'); $numfields = array('score', 'weighting', 'hints', 'clues', 'checks'); $fields = array_merge($textfields, $numfields); $q = array(); // questions $f = array(); // fields foreach ($fields as $field) { $name = get_string($field, 'hotpot'); $f[$field] = array('count'=>0, 'name'=>$name); } // get questions and responses for this attempt $questions = $DB->get_records('hotpot_questions', array('hotpot'=>$hotpot->id), 'id'); $responses = $DB->get_records('hotpot_responses', array('attempt'=>$attempt->id), 'id'); if ($questions && $responses) { foreach ($responses as $response) { $id = $response->question; foreach ($fields as $field) { if (!isset($f[$field])) { $name = get_string($field, 'hotpot'); $f[$field] = array('count'=>0, 'name'=>$name); } if (isset($response->$field)) { $f[$field]['count']++; if (!isset($q[$id])) { $name = hotpot_get_question_name($questions[$id]); $q[$id] = array('name'=>$name); } $q[$id][$field] = $response->$field; } } } } // count the number of columns required in the table $colspan = 0; foreach ($numfields as $field) { if ($f[$field]['count']) { $colspan += 2; } } $colspan = max(2, $colspan); // start table of questions and responses echo $OUTPUT->box_start("generalbox boxaligncenter boxwidthwide"); print ''."\n"; if (empty($q)) { print '\n"; } else { // flag to ensure separators are only printed before the 2nd and subsequent questions $printseparator = false; foreach ($q as $i=>$question) { // flag to ensure questions are only printed when there is at least one response $printedquestion = false; // add rows of text fields foreach ($textfields as $field) { if (isset($question[$field])) { $text = hotpot_strings($question[$field]); if (trim($text)) { // print question if necessary if (!$printedquestion) { if ($printseparator) { print ''."\n"; } $printseparator = true; print ''."\n"; $printedquestion = true; } // print response print ''."\n"; } } } // add row of numeric fields print ''; foreach ($numfields as $field) { if ($f[$field]['count']) { // print question if necessary if (!$printedquestion) { print '\n"; $printedquestion = true; } // print numeric response $value = isset($question[$field]) ? $question[$field] : '-'; print ''; } } print "\n"; } // foreach $q } // finish table print "
'.get_string("noresponses", "hotpot")."
'.$question['name'].'
'.$f[$field]['name'].':'.$text.'
'.$question['name']."
'.$f[$field]['name'].':'.$value.'
\n"; echo $OUTPUT->box_end(); }