コード例 #1
0
/**
 * Callback function for preg_replace_callback.
 * Returns replacement code by MIME type.
 * @param $matches (string) array containing matches: $matches[0] is the complete match, $matches[1] the match for the first subpattern enclosed in '(...)' and so on
 * @return string replacement string by file extension
 */
function F_objects_callback($matches)
{
    $width = 0;
    $height = 0;
    $alt = '';
    if (isset($matches[3]) and $matches[3] > 0) {
        $width = $matches[3];
    }
    if (isset($matches[4]) and $matches[4] > 0) {
        $height = $matches[4];
    }
    if (isset($matches[5]) and !empty($matches[5])) {
        $alt = F_tcecodeToTitle($matches[5]);
    }
    return F_objects_replacement($matches[1], $matches[2], $width, $height, $alt);
}
コード例 #2
0
/**
 * Returns a questions menu and navigator buttons.
 * @param $testdata (array) test data
 * @param $testuser_id (int) user's test ID
 * @param $testlog_id (int) test log ID
 * @param $disable (boolean) if TRUE disable the questions list.
 * @return string XHTML code
 */
function F_questionsMenu($testdata, $testuser_id, $testlog_id = 0, $disable = false)
{
    require_once '../config/tce_config.php';
    require_once '../../shared/code/tce_functions_tcecode.php';
    global $db, $l;
    $testuser_id = intval($testuser_id);
    $testlog_id = intval($testlog_id);
    $str = '';
    $testlog_id_prev = 0;
    // previous question ID
    $testlog_id_next = 0;
    // next question ID
    $testlog_id_last = 0;
    // temp variable
    $sql = 'SELECT question_description, question_difficulty, question_timer, testlog_id, testlog_answer_text, testlog_display_time, testlog_change_time
		FROM ' . K_TABLE_QUESTIONS . ', ' . K_TABLE_TESTS_LOGS . '
		WHERE question_id=testlog_question_id
			AND testlog_testuser_id=' . $testuser_id . '
		ORDER BY testlog_id';
    if ($r = F_db_query($sql, $db)) {
        while ($m = F_db_fetch_array($r)) {
            if ($m['testlog_id'] != $testlog_id) {
                $str .= '<li>';
                $str .= '<input type="submit" name="jumpquestion_' . $m['testlog_id'] . '" id="jumpquestion_' . $m['testlog_id'] . '" value="&gt;" title="' . F_tcecodeToTitle($m['question_description']) . '" /> ';
                if ($testlog_id_last == $testlog_id) {
                    $testlog_id_next = $m['testlog_id'];
                }
            } else {
                $str .= '<li class="selected">';
                $str .= '<input type="button" name="jumpquestion_' . $m['testlog_id'] . '" id="jumpquestion_' . $m['testlog_id'] . '" value="&gt;" title="' . F_tcecodeToTitle($m['question_description']) . '" disabled="disabled"/> ';
                $testlog_id_prev = $testlog_id_last;
                $question_timer = F_getBoolean($m['question_timer']);
            }
            // display mark when the current question has been displayed
            $str .= '<acronym';
            if (!empty($m['testlog_display_time'])) {
                $str .= ' class="onbox"';
                $str .= ' title="' . $l['h_question_displayed'] . '">+';
            } else {
                $str .= ' class="offbox"';
                $str .= ' title="' . $l['h_question_not_displayed'] . '">-';
            }
            $str .= '</acronym>';
            $str .= '&nbsp;';
            // show mark when the current question has been answered
            $str .= '<acronym';
            if (!empty($m['testlog_change_time'])) {
                $str .= ' class="onbox"';
                $str .= ' title="' . $l['h_question_answered'] . '">+';
            } else {
                $str .= ' class="offbox"';
                $str .= ' title="' . $l['h_question_not_answered'] . '">-';
            }
            $str .= '</acronym>';
            $str .= '&nbsp;';
            // show question score
            $n_question_score = $testdata['test_score_right'] * $m['question_difficulty'];
            $str .= '<acronym class="offbox" title="' . $l['w_max_score'] . ': ' . $n_question_score . '">';
            $str .= sprintf('% 5.1f', $n_question_score);
            $str .= '</acronym>';
            $str .= '&nbsp;';
            if ($testlog_id == 0) {
                $testlog_id = $m['testlog_id'];
                $testlog_id_last = $testlog_id;
            }
            $testlog_id_last = $m['testlog_id'];
            $str .= F_tcecodeToLine($m['question_description']);
            $str .= '</li>' . K_NEWLINE;
        }
    } else {
        F_display_db_error();
    }
    // build quick navigator links (previous - next)
    $navlink = '';
    // button for previous question
    if (!$question_timer) {
        $navlink .= '<input type="submit" name="prevquestion" id="prevquestion" value="&lt; ' . $l['w_previous'] . '" title="' . $l['w_previous'] . '"';
        if ($testlog_id_prev <= 0 or $testlog_id_prev > $testlog_id) {
            $navlink .= ' disabled="disabled"';
        }
        $navlink .= ' />';
        // button for confirm current question
        $navlink .= '<input type="submit" name="confirmanswer" id="confirmanswer" value="' . $l['w_confirm'] . '" />';
    }
    // button for next question
    $navlink .= '<input type="submit" name="nextquestion" id="nextquestion" value="' . $l['w_next'] . ' &gt;" title="' . $l['w_next'] . '"';
    if ($testlog_id_next <= 0) {
        $navlink .= ' disabled="disabled"';
    }
    $navlink .= ' />' . K_NEWLINE;
    if (($question_timer or $disable) and $testlog_id_next <= 0) {
        // force test termination
        $navlink .= '<input type="hidden" name="forceterminate" id="forceterminate" value="lasttimedquestion" />' . K_NEWLINE;
    }
    $navlink .= '<input type="hidden" name="prevquestionid" id="prevquestionid" value="' . $testlog_id_prev . '" />' . K_NEWLINE;
    $navlink .= '<input type="hidden" name="nextquestionid" id="nextquestionid" value="' . $testlog_id_next . '" />' . K_NEWLINE;
    $navlink .= '<input type="hidden" name="autonext" id="autonext" value="" />' . K_NEWLINE;
    $navlink = '<div class="navlink">' . $navlink . '</div>' . K_NEWLINE;
    $rstr = '';
    $rstr .= '<br />' . K_NEWLINE;
    $rstr .= $navlink;
    $rstr .= '<br />' . K_NEWLINE;
    if (F_getBoolean($testdata['test_menu_enabled']) and !$disable) {
        // display questions menu
        $rstr .= '<a name="questionssection" id="questionssection"></a>' . K_NEWLINE;
        $rstr .= '<div class="tcecontentbox">' . K_NEWLINE;
        //fieldset
        //$rstr .= '<legend>';
        $rstr .= $l['w_questions'];
        //$rstr .= '</legend>'.K_NEWLINE;
        $rstr .= '<ol class="qlist">' . K_NEWLINE . $str . '</ol>' . K_NEWLINE;
        $rstr .= '</div>' . K_NEWLINE;
        //fieldset
        $rstr .= '<br />' . K_NEWLINE;
    }
    return $rstr;
}