示例#1
0
$navigation = build_navigation('', $cm);
$button = update_module_button($cm->id, $course->id, $strmodulename);
print_header($title, $heading, $navigation, "", "", true, $button, user_login_string($course) . '<hr style="width:95%">' . navmenu($course, $cm));
print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>';
// for overlib
print_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 = get_field('hotpot_details', 'details', 'attempt', $attempt->id);
    print '<hr>';
    switch ($action) {
        case 'showxmltree':
            print '<pre id="contents">';
            $xml_tree = new hotpot_xml_tree($xml, "['hpjsresult']['#']");
            print_r($xml_tree->xml_value('fields'));
            print '</pre>';
            break;
        case 'showxmlsource':
            print htmlspecialchars($xml);
            break;
        default:
            print "Action '{$action}' not recognized";
    }
    print '<hr>';
} else {
    hotpot_print_attempt_details($hotpot, $attempt);
}
hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
print_footer($course);
示例#2
0
function hotpot_add_attempt_details(&$attempt)
{
    // encode ampersands so that HTML entities are preserved in the XML parser
    // N.B. ampersands inside <![CDATA[ ]]> blocks do NOT need to be encoded
    $old =& $attempt->details;
    // shortcut to "old" details
    $new = '';
    $str_start = 0;
    while (($cdata_start = strpos($old, '<![CDATA[', $str_start)) && ($cdata_end = strpos($old, ']]>', $cdata_start))) {
        $cdata_end += 3;
        $new .= str_replace('&', '&amp;', substr($old, $str_start, $cdata_start - $str_start)) . substr($old, $cdata_start, $cdata_end - $cdata_start);
        $str_start = $cdata_end;
    }
    $new .= str_replace('&', '&amp;', substr($old, $str_start));
    unset($old);
    // parse the attempt details as xml
    $details = new hotpot_xml_tree($new, "['hpjsresult']['#']");
    $num = -1;
    $q_num = -1;
    $question = NULL;
    $reponse = NULL;
    $i = 0;
    $tags = 'fields,field';
    while (($field = "[{$i}]['#']") && $details->xml_value($tags, $field)) {
        $name = $details->xml_value($tags, $field . "['fieldname'][0]['#']");
        $data = $details->xml_value($tags, $field . "['fielddata'][0]['#']");
        // parse the field name into $matches
        //  [1] quiz type
        //  [2] attempt detail name
        if (preg_match('/^(\\w+?)_(\\w+)$/', $name, $matches)) {
            $quiztype = strtolower($matches[1]);
            $name = strtolower($matches[2]);
            // parse the attempt detail $name into $matches
            //  [1] question number
            //  [2] question detail name
            if (preg_match('/^q(\\d+)_(\\w+)$/', $name, $matches)) {
                $num = $matches[1];
                $name = strtolower($matches[2]);
                $data = addslashes($data);
                // adjust JCross question numbers
                if (preg_match('/^(across|down)(.*)$/', $name, $matches)) {
                    $num .= '_' . $matches[1];
                    // e.g. 01_across, 02_down
                    $name = $matches[2];
                    if (substr($name, 0, 1) == '_') {
                        $name = substr($name, 1);
                        // remove leading '_'
                    }
                }
                // is this a new question (or the first one)?
                if ($q_num != $num) {
                    // add previous question and response, if any
                    hotpot_add_response($attempt, $question, $response);
                    // initialize question object
                    $question = NULL;
                    $question->name = '';
                    $question->text = '';
                    $question->hotpot = $attempt->hotpot;
                    // initialize response object
                    $response = NULL;
                    $response->attempt = $attempt->id;
                    // update question number
                    $q_num = $num;
                }
                // adjust field name and value, and set question type
                // (may not be necessary one day)
                hotpot_adjust_response_field($quiztype, $question, $num, $name, $data);
                // add $data to the question/response details
                switch ($name) {
                    case 'name':
                    case 'type':
                        $question->{$name} = $data;
                        break;
                    case 'text':
                        $question->{$name} = hotpot_string_id($data);
                        break;
                    case 'correct':
                    case 'ignored':
                    case 'wrong':
                        $response->{$name} = hotpot_string_ids($data);
                        break;
                    case 'score':
                    case 'weighting':
                    case 'hints':
                    case 'clues':
                    case 'checks':
                        $response->{$name} = intval($data);
                        break;
                }
            } else {
                // attempt details
                // adjust field name and value
                hotpot_adjust_response_field($quiztype, $question, $num = '', $name, $data);
                // add $data to the attempt details
                if ($name == 'penalties') {
                    $attempt->{$name} = intval($data);
                }
            }
        }
        $i++;
    }
    // end while
    // add the final question and response, if any
    hotpot_add_response($attempt, $question, $response);
}