Exemplo n.º 1
0
     echo '<head>' . K_NEWLINE;
     echo '<title>REDIRECT</title>' . K_NEWLINE;
     echo '<meta http-equiv="refresh" content="0;url=index.php" />' . K_NEWLINE;
     //reload page
     echo '</head>' . K_NEWLINE;
     echo '<body>' . K_NEWLINE;
     echo '<a href="index.php">INDEX...</a>' . K_NEWLINE;
     echo '</body>' . K_NEWLINE;
     echo '</html>' . K_NEWLINE;
     exit;
 }
 // the user is authorized to execute the selected test
 $thispage_title .= ': ' . F_getTestName($test_id);
 require_once '../code/tce_page_header.php';
 echo '<div class="container">' . K_NEWLINE;
 echo '<span class="infolink">' . F_testInfoLink($test_id, $l['w_info']) . '<br /><br /></span>' . K_NEWLINE;
 if (!isset($_REQUEST['terminationform'])) {
     if (F_isRightTestlogUser($test_id, $testlog_id)) {
         // the form has been submitted, update testlogid data
         F_updateQuestionLog($test_id, $testlog_id, $answer_id, $answer_text, $reaction_time);
         // update user's test comment
         if (isset($_REQUEST['testcomment']) and !empty($_REQUEST['testcomment'])) {
             $test_comment = $_REQUEST['testcomment'];
             F_updateTestComment($test_id, $test_comment);
         }
         if ((isset($_REQUEST['nextquestion']) or isset($_REQUEST['autonext']) and $_REQUEST['autonext'] == 1) and $_REQUEST['nextquestionid'] > 0) {
             // go to next question
             $testlog_id = 0 + intval($_REQUEST['nextquestionid']);
         } elseif (isset($_REQUEST['prevquestion']) and $_REQUEST['prevquestionid'] > 0) {
             // go to previous question
             $testlog_id = intval($_REQUEST['prevquestionid']);
/**
 * Returns an XHTML table of user's tests.
 * @return string containing an XHTML table of user's tests.
 */
function F_getUserTests()
{
    require_once '../config/tce_config.php';
    require_once '../../shared/code/tce_functions_tcecode.php';
    require_once '../../shared/code/tce_functions_test_stats.php';
    global $db, $l;
    $user_id = intval($_SESSION['session_user_id']);
    $str = '';
    // temp string
    // get current date-time
    $current_time = date(K_TIMESTAMP_FORMAT);
    // select tests
    $sql = 'SELECT * FROM ' . K_TABLE_TESTS . ' WHERE (test_id IN (SELECT tsubset_test_id FROM ' . K_TABLE_TEST_SUBJSET . ') AND (test_begin_time < \'' . $current_time . '\')';
    if (K_HIDE_EXPIRED_TESTS) {
        $sql .= ' AND (test_end_time > \'' . $current_time . '\')';
    }
    $sql .= ') ORDER BY test_begin_time DESC';
    if ($r = F_db_query($sql, $db)) {
        while ($m = F_db_fetch_array($r)) {
            // for each active test
            // check user's authorization
            if (F_isValidTestUser($m['test_id'], $_SESSION['session_user_ip'], $m['test_ip_range'])) {
                // the user's IP is valid, check test status
                $test_status = F_checkTestStatus($user_id, $m['test_id'], $m['test_duration_time']);
                if (strtotime($current_time) >= strtotime($m['test_end_time'])) {
                    // the test is expired.
                    $test_status = 5;
                    $datestyle = ' style="color:#666666;"';
                } else {
                    $datestyle = '';
                }
                $str .= '<tr>' . K_NEWLINE;
                $str .= '<td><strong>' . F_testInfoLink($m['test_id'], $m['test_name']) . '</strong></td>' . K_NEWLINE;
                $str .= '<td' . $datestyle . '>' . $m['test_begin_time'] . '</td>' . K_NEWLINE;
                $str .= '<td' . $datestyle . '>' . $m['test_end_time'] . '</td>' . K_NEWLINE;
                // status
                $str .= '<td';
                if ($test_status >= 4 and F_getBoolean($m['test_results_to_users'])) {
                    $usrtestdata = F_getUserTestStat($m['test_id'], $user_id);
                    $passmsg = '';
                    if (isset($usrtestdata['score']) and isset($usrtestdata['score_threshold']) and $usrtestdata['score_threshold'] > 0) {
                        if ($usrtestdata['score'] >= $usrtestdata['score_threshold']) {
                            $str .= ' style="background-color:#ddffdd;"';
                            $passmsg = ' - ' . $l['w_passed'];
                        } else {
                            $str .= ' style="background-color:#ffdddd;"';
                            $passmsg = ' - ' . $l['w_not_passed'];
                        }
                    }
                    $str .= '>';
                    if (isset($usrtestdata['score']) and strlen('' . $usrtestdata['score']) > 0) {
                        $str .= '<a href="tce_test_results.php?testid=' . $m['test_id'] . '" title="' . $l['h_result'] . '">' . $usrtestdata['score'] . ' / ' . $usrtestdata['max_score'] . ' (' . round(100 * $usrtestdata['score'] / $usrtestdata['max_score']) . '%)' . $passmsg . '</a>';
                    } else {
                        $str .= '&nbsp;';
                    }
                } else {
                    $str .= '>&nbsp;';
                }
                $str .= '</td>' . K_NEWLINE;
                // display various action links by status case
                $str .= '<td>';
                switch ($test_status) {
                    case 0:
                        // 0 = the test generation process is started but not completed
                        // print execute test link
                        $str .= '<a href="';
                        if (!defined('K_DISPLAY_TEST_DESCRIPTION') or !K_DISPLAY_TEST_DESCRIPTION) {
                            // directly execute test
                            $str .= 'tce_test_execute.php';
                        } else {
                            // display test description before starting
                            $str .= 'tce_test_start.php';
                        }
                        $str .= '?testid=' . $m['test_id'] . '" title="' . $l['h_execute'] . '" class="buttongreen">' . $l['w_execute'] . '</a>';
                        break;
                    case 1:
                        // 1 = the test has been successfully created
                    // 1 = the test has been successfully created
                    case 2:
                        // 2 = all questions have been displayed to the user
                    // 2 = all questions have been displayed to the user
                    case 3:
                        // 3 = all questions have been answered
                        // continue test
                        $str .= '<a href="tce_test_execute.php?testid=' . $m['test_id'] . '" title="' . $l['h_continue'] . '" class="xmlbutton">' . $l['w_continue'] . '</a>';
                        break;
                    case 4:
                        // 4 = test locked (for timeout)
                        if (F_getBoolean($m['test_repeatable'])) {
                            $str .= '<a href="index.php?testid=' . $m['test_id'] . '&amp;repeat=1" title="' . $l['h_repeat_test'] . '" class="buttonred">' . $l['w_repeat'] . '</a>';
                        }
                        break;
                }
                $str .= '</td>' . K_NEWLINE;
                $str .= '</tr>' . K_NEWLINE;
            }
        }
    } else {
        F_display_db_error();
    }
    if (strlen($str) > 0) {
        $out = '<table class="testlist">' . K_NEWLINE;
        $out .= '<tr>' . K_NEWLINE;
        $out .= '<th>' . $l['w_test'] . '</th>' . K_NEWLINE;
        $out .= '<th>' . $l['w_from'] . '</th>' . K_NEWLINE;
        $out .= '<th>' . $l['w_to'] . '</th>' . K_NEWLINE;
        $out .= '<th>' . $l['w_status'] . '</th>' . K_NEWLINE;
        $out .= '<th>' . $l['w_action'] . '</th>' . K_NEWLINE;
        $out .= '</tr>' . K_NEWLINE;
        $out .= $str;
        $out .= '</table>' . K_NEWLINE;
    } else {
        $out = $l['m_no_test_available'];
    }
    return $out;
}