/** * Export user results in XML format. * @param $user_id (int) user ID - if greater than zero, filter stats for the specified user. * @param $startdate (string) start date ID - if greater than zero, filter stats for the specified starting date * @param $enddate (string) end date ID - if greater than zero, filter stats for the specified ending date * @param $order_field (string) Ordering fields for SQL query. * @author Nicola Asuni * @return XML data */ function F_xml_export_user_results($user_id, $startdate, $enddate, $order_field) { global $l, $db; require_once '../config/tce_config.php'; // define symbols for answers list $qtype = array('S', 'M', 'T', 'O'); // question types $type = array('single', 'multiple', 'text', 'ordering'); $boolean = array('false', 'true'); $xml = ''; // XML data to be returned $xml .= '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . K_NEWLINE; $xml .= '<tcexamuserresults version="' . K_TCEXAM_VERSION . '">' . K_NEWLINE; $xml .= K_TAB . '<header'; $xml .= ' lang="' . K_USER_LANG . '"'; $xml .= ' date="' . date(K_TIMESTAMP_FORMAT) . '">' . K_NEWLINE; $xml .= K_TAB . K_TAB . '<user_id>' . $user_id . '</user_id>' . K_NEWLINE; $sql = 'SELECT user_name, user_lastname, user_firstname FROM ' . K_TABLE_USERS . ' WHERE user_id=' . $user_id . ''; if ($r = F_db_query($sql, $db)) { if ($m = F_db_fetch_array($r)) { $xml .= K_TAB . K_TAB . '<user_name>' . $m['user_name'] . '</user_name>' . K_NEWLINE; $xml .= K_TAB . K_TAB . '<user_lastname>' . $m['user_lastname'] . '</user_lastname>' . K_NEWLINE; $xml .= K_TAB . K_TAB . '<user_firstname>' . $m['user_firstname'] . '</user_firstname>' . K_NEWLINE; } } else { F_display_db_error(); } $xml .= K_TAB . K_TAB . '<date_from>' . $startdate . '</date_from>' . K_NEWLINE; $xml .= K_TAB . K_TAB . '<date_to>' . $enddate . '</date_to>' . K_NEWLINE; $xml .= K_TAB . '</header>' . K_NEWLINE; $xml .= K_TAB . '<body>' . K_NEWLINE; $statsdata = array(); $statsdata['score'] = array(); $statsdata['right'] = array(); $statsdata['wrong'] = array(); $statsdata['unanswered'] = array(); $statsdata['undisplayed'] = array(); $statsdata['unrated'] = array(); $sql = 'SELECT testuser_id, test_id, test_name, testuser_creation_time, testuser_status, SUM(testlog_score) AS total_score, MAX(testlog_change_time) AS testuser_end_time FROM ' . K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_TESTS . ' WHERE testuser_status>0 AND testuser_creation_time>=\'' . F_escape_sql($db, $startdate) . '\' AND testuser_creation_time<=\'' . F_escape_sql($db, $enddate) . '\' AND testuser_user_id=' . $user_id . ' AND testlog_testuser_id=testuser_id AND testuser_test_id=test_id'; if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) { $sql .= ' AND test_user_id IN (' . F_getAuthorizedUsers($_SESSION['session_user_id']) . ')'; } $sql .= ' GROUP BY testuser_id, test_id, test_name, testuser_creation_time, testuser_status ORDER BY ' . F_escape_sql($db, $order_field) . ''; if ($r = F_db_query($sql, $db)) { $passed = 0; while ($m = F_db_fetch_array($r)) { $testuser_id = $m['testuser_id']; $usrtestdata = F_getUserTestStat($m['test_id'], $user_id); $halfscore = $usrtestdata['max_score'] / 2; $xml .= K_TAB . K_TAB . '<test id=\'' . $m['test_id'] . '\'>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<start_time>' . $m['testuser_creation_time'] . '</start_time>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<end_time>' . $m['testuser_end_time'] . '</end_time>' . K_NEWLINE; $time_diff = strtotime($m['testuser_end_time']) - strtotime($m['testuser_creation_time']); //sec $time_diff = gmdate('H:i:s', $time_diff); $xml .= K_TAB . K_TAB . K_TAB . '<time>' . $time_diff . '</time>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<name>' . F_text_to_xml($m['test_name']) . '</name>' . K_NEWLINE; if ($usrtestdata['score_threshold'] > 0) { if ($usrtestdata['score'] >= $usrtestdata['score_threshold']) { $xml .= K_TAB . K_TAB . K_TAB . '<passed>true</passed>' . K_NEWLINE; $passed++; } else { $xml .= K_TAB . K_TAB . K_TAB . '<passed>false</passed>' . K_NEWLINE; } } elseif ($usrtestdata['score'] > $halfscore) { $passed++; } $xml .= K_TAB . K_TAB . K_TAB . '<score>' . round($m['total_score'], 3) . '</score>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<score_percent>' . round(100 * $usrtestdata['score'] / $usrtestdata['max_score']) . '</score_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<right>' . $usrtestdata['right'] . '</right>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<right_percent>' . round(100 * $usrtestdata['right'] / $usrtestdata['all']) . '</right_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<wrong>' . $usrtestdata['wrong'] . '</wrong>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<wrong_percent>' . round(100 * $usrtestdata['wrong'] / $usrtestdata['all']) . '</wrong_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<unanswered>' . $usrtestdata['unanswered'] . '</unanswered>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<unanswered_percent>' . round(100 * $usrtestdata['unanswered'] / $usrtestdata['all']) . '</unanswered_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<undisplayed>' . $usrtestdata['undisplayed'] . '</undisplayed>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<undisplayed_percent>' . round(100 * $usrtestdata['undisplayed'] / $usrtestdata['all']) . '</undisplayed_percent>' . K_NEWLINE; if ($m['testuser_status'] == 4) { $status = $l['w_locked']; } else { $status = $l['w_unlocked']; } $xml .= K_TAB . K_TAB . K_TAB . '<status>' . $status . '</status>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<comment>' . F_text_to_xml($usrtestdata['comment']) . '</comment>' . K_NEWLINE; $xml .= K_TAB . K_TAB . '</test>' . K_NEWLINE; // collects data for descriptive statistics $statsdata['score'][] = $m['total_score'] / $usrtestdata['max_score']; $statsdata['right'][] = $usrtestdata['right'] / $usrtestdata['all']; $statsdata['wrong'][] = $usrtestdata['wrong'] / $usrtestdata['all']; $statsdata['unanswered'][] = $usrtestdata['unanswered'] / $usrtestdata['all']; $statsdata['undisplayed'][] = $usrtestdata['undisplayed'] / $usrtestdata['all']; $statsdata['unrated'][] = $usrtestdata['unrated'] / $usrtestdata['all']; } } else { F_display_db_error(); } // calculate statistics $stats = F_getArrayStatistics($statsdata); $excludestat = array('sum', 'variance'); $calcpercent = array('mean', 'median', 'mode', 'minimum', 'maximum', 'range', 'standard_deviation'); $xml .= K_TAB . K_TAB . '<teststatistics>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . '<passed>' . $passed . '</passed>' . K_NEWLINE; $passed_perc = 0; if ($itemcount > 0) { $passed_perc = $passed / $stats['number']['score']; } $xml .= K_TAB . K_TAB . K_TAB . '<passed_percent>' . round(100 * $passed_perc) . '</passed_percent>' . K_NEWLINE; foreach ($stats as $row => $columns) { if (!in_array($row, $excludestat)) { $xml .= K_TAB . K_TAB . K_TAB . '<' . $row . '>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<score>' . round($columns['score'], 3) . '</score>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<right>' . round($columns['right'], 3) . '</right>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<wrong>' . round($columns['wrong'], 3) . '</wrong>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<unanswered>' . round($columns['unanswered'], 3) . '</unanswered>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<undisplayed>' . round($columns['undisplayed'], 3) . '</undisplayed>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<unrated>' . round($columns['unrated'], 3) . '</unrated>' . K_NEWLINE; if (in_array($row, $calcpercent)) { $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<score_percent>' . round(100 * ($columns['score'] / $usrtestdata['max_score'])) . '</score_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<right_percent>' . round(100 * ($columns['right'] / $usrtestdata['all'])) . '</right_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<wrong_percent>' . round(100 * ($columns['wrong'] / $usrtestdata['all'])) . '</wrong_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<unanswered_percent>' . round(100 * ($columns['unanswered'] / $usrtestdata['all'])) . '</unanswered_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<undisplayed_percent>' . round(100 * ($columns['undisplayed'] / $usrtestdata['all'])) . '</undisplayed_percent>' . K_NEWLINE; $xml .= K_TAB . K_TAB . K_TAB . K_TAB . '<unrated_percent>' . round(100 * ($columns['unrated'] / $usrtestdata['all'])) . '</unrated_percent>' . K_NEWLINE; } $xml .= K_TAB . K_TAB . K_TAB . '</' . $row . '>' . K_NEWLINE; } } $xml .= K_TAB . K_TAB . '</teststatistics>' . K_NEWLINE; $xml .= K_TAB . '</body>' . K_NEWLINE; $xml .= '</tcexamuserresults>' . K_NEWLINE; return $xml; }
/** * Returns a SQL string to select executed tests accounting for user authorizations. * @author Nicola Asuni * @since 2006-06-26 * @return string sql statement */ function F_select_executed_tests_sql() { global $l; require_once '../config/tce_config.php'; $sql = 'SELECT * FROM ' . K_TABLE_TESTS . ' WHERE test_id IN ( SELECT testuser_test_id FROM ' . K_TABLE_TEST_USER . ' WHERE testuser_status>0 )'; if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) { $sql .= ' AND test_user_id IN (' . F_getAuthorizedUsers($_SESSION['session_user_id']) . ')'; } $sql .= ' ORDER BY test_begin_time DESC, test_name'; return $sql; }
test_id, test_name, test_duration_time, testuser_creation_time, testuser_status, SUM(testlog_score) AS total_score, MAX(testlog_change_time) AS testuser_end_time FROM ' . K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_TESTS . ' WHERE testuser_status>0 AND testuser_creation_time>=\'' . $startdate . '\' AND testuser_creation_time<=\'' . $enddate . '\' AND testuser_user_id=' . $user_id . ' AND testlog_testuser_id=testuser_id AND testuser_test_id=test_id'; if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) { $sqlr .= ' AND test_user_id IN (' . F_getAuthorizedUsers($_SESSION['session_user_id']) . ')'; } $sqlr .= ' GROUP BY testuser_id, test_id, test_name, test_duration_time, testuser_creation_time, testuser_status ORDER BY ' . $full_order_field . ''; if ($rr = F_db_query($sqlr, $db)) { $itemcount = 0; $passed = 0; $statsdata = array(); $statsdata['score'] = array(); $statsdata['right'] = array(); $statsdata['wrong'] = array(); $statsdata['unanswered'] = array(); $statsdata['undisplayed'] = array(); $statsdata['unrated'] = array(); while ($mr = F_db_fetch_array($rr)) { $itemcount++; $usrtestdata = F_getUserTestStat($mr['test_id'], $user_id);
/** * Export all user's test results to CSV. * @author Nicola Asuni * @since 2008-12-26 * @param $user_id (int) user ID * @param $startdate (string) start date in yyyy-mm-dd hh:mm:ss format * @param $enddate (string) end date in yyyy-mm-dd hh:mm:ss format * @param $order_field (string) ORDER BY portion of the SQL query * @return CSV data */ function F_csv_export_allresults_user($user_id, $startdate, $enddate, $order_field = '') { global $l, $db; require_once '../config/tce_config.php'; require_once '../../shared/code/tce_authorization.php'; require_once '../../shared/code/tce_functions_test_stats.php'; require_once 'tce_functions_user_select.php'; require_once '../code/tce_functions_statistics.php'; $user_id = intval($user_id); $startdate = F_escape_sql($startdate); $enddate = F_escape_sql($enddate); $order_field = F_escape_sql($order_field); if (!F_isAuthorizedEditorForUser($user_id)) { return ''; } // statistical data $statsdata = array(); $statsdata['score'] = array(); $statsdata['right'] = array(); $statsdata['wrong'] = array(); $statsdata['unanswered'] = array(); $statsdata['undisplayed'] = array(); $statsdata['unrated'] = array(); $csv = ''; // CSV data to be returned // general data $csv .= 'TCExam User Results' . K_NEWLINE . K_NEWLINE; $csv .= 'version' . K_TAB . K_TCEXAM_VERSION . K_NEWLINE; $csv .= 'lang' . K_TAB . K_USER_LANG . K_NEWLINE; $csv .= 'date' . K_TAB . date(K_TIMESTAMP_FORMAT) . K_NEWLINE; $csv .= 'user_id' . K_TAB . $user_id . K_NEWLINE; $sql = 'SELECT user_name, user_lastname, user_firstname FROM ' . K_TABLE_USERS . ' WHERE user_id=' . $user_id . ''; if ($r = F_db_query($sql, $db)) { if ($m = F_db_fetch_array($r)) { $csv .= $l['w_user'] . K_TAB . $m['user_name'] . K_NEWLINE; $csv .= $l['w_lastname'] . K_TAB . $m['user_lastname'] . K_NEWLINE; $csv .= $l['w_firstname'] . K_TAB . $m['user_firstname'] . K_NEWLINE; } } else { F_display_db_error(); } $csv .= $l['w_time_begin'] . K_TAB . $startdate . K_NEWLINE; $csv .= $l['w_time_end'] . K_TAB . $enddate . K_NEWLINE; $csv .= K_NEWLINE . K_NEWLINE; // separator // print column names $csv .= '#'; $csv .= K_TAB . $l['w_time_begin']; $csv .= K_TAB . $l['w_time_end']; $csv .= K_TAB . $l['w_time']; $csv .= K_TAB . $l['w_test']; $csv .= K_TAB . $l['w_passed']; $csv .= K_TAB . $l['w_score']; $csv .= K_TAB . $l['w_answers_right']; $csv .= K_TAB . $l['w_answers_wrong']; $csv .= K_TAB . $l['w_questions_unanswered']; $csv .= K_TAB . $l['w_questions_undisplayed']; $csv .= K_TAB . $l['w_questions_unrated']; $csv .= K_TAB . $l['w_status']; $csv .= K_TAB . $l['w_comment']; $passed = 0; // output users stats $sqlr = 'SELECT testuser_id, test_id, test_name, test_duration_time, testuser_creation_time, testuser_status, SUM(testlog_score) AS total_score, MAX(testlog_change_time) AS testuser_end_time FROM ' . K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_TESTS . ' WHERE testuser_status>0 AND testuser_creation_time>=\'' . $startdate . '\' AND testuser_creation_time<=\'' . $enddate . '\' AND testuser_user_id=' . $user_id . ' AND testlog_testuser_id=testuser_id AND testuser_test_id=test_id'; if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) { $sqlr .= ' AND test_user_id IN (' . F_getAuthorizedUsers($_SESSION['session_user_id']) . ')'; } $sqlr .= ' GROUP BY testuser_id, test_id, test_name, test_duration_time, testuser_creation_time, testuser_status ORDER BY ' . $order_field . ''; if ($rr = F_db_query($sqlr, $db)) { $itemcount = 0; while ($mr = F_db_fetch_array($rr)) { $itemcount++; $usrtestdata = F_getUserTestStat($mr['test_id'], $user_id); $halfscore = $usrtestdata['max_score'] / 2; $csv .= K_NEWLINE . $itemcount; $csv .= K_TAB . $mr['testuser_creation_time']; $csv .= K_TAB . $mr['testuser_end_time']; $time_diff = strtotime($mr['testuser_end_time']) - strtotime($mr['testuser_creation_time']); //sec $time_diff = gmdate('H:i:s', $time_diff); $csv .= K_TAB . $time_diff; $csv .= K_TAB . $mr['test_name']; if ($usrtestdata['score_threshold'] > 0) { if ($usrtestdata['score'] >= $usrtestdata['score_threshold']) { $csv .= K_TAB . 'true'; $passed++; } else { $csv .= K_TAB . 'false'; } } else { $csv .= K_TAB; if ($usrtestdata['score'] > $halfscore) { $passed++; } } $csv .= K_TAB . $mr['total_score']; $csv .= K_TAB . $usrtestdata['right']; $csv .= K_TAB . $usrtestdata['wrong']; $csv .= K_TAB . $usrtestdata['unanswered']; $csv .= K_TAB . $usrtestdata['undisplayed']; $csv .= K_TAB . $usrtestdata['unrated']; if ($mr['testuser_status'] == 4) { $csv .= K_TAB . $l['w_locked']; } else { $csv .= K_TAB . $l['w_unlocked']; } $csv .= K_TAB . F_compact_string(htmlspecialchars($usrtestdata['comment'], ENT_NOQUOTES, $l['a_meta_charset'])); // collects data for descriptive statistics $statsdata['score'][] = $mr['total_score'] / $usrtestdata['max_score']; $statsdata['right'][] = $usrtestdata['right'] / $usrtestdata['all']; $statsdata['wrong'][] = $usrtestdata['wrong'] / $usrtestdata['all']; $statsdata['unanswered'][] = $usrtestdata['unanswered'] / $usrtestdata['all']; $statsdata['undisplayed'][] = $usrtestdata['undisplayed'] / $usrtestdata['all']; $statsdata['unrated'][] = $usrtestdata['unrated'] / $usrtestdata['all']; } } else { F_display_db_error(); } $csv .= K_NEWLINE; // separator // calculate statistics $stats = F_getArrayStatistics($statsdata); $excludestat = array('sum', 'variance'); $calcpercent = array('mean', 'median', 'mode', 'minimum', 'maximum', 'range', 'standard_deviation'); $csv .= K_TAB . K_TAB . K_TAB . K_TAB . 'passed_total' . K_TAB . $passed . K_NEWLINE; $csv .= K_TAB . K_TAB . K_TAB . K_TAB . 'passed_percent [%]' . K_TAB . round(100 * ($passed / $itemcount)) . K_NEWLINE; $csv .= K_NEWLINE; // separator $csv .= $l['w_statistics'] . K_NEWLINE; // separator // headers $csv .= K_TAB . K_TAB . K_TAB . K_TAB . K_TAB . K_TAB; $csv .= $l['w_score'] . K_TAB; $csv .= $l['w_answers_right_th'] . K_TAB; $csv .= $l['w_answers_wrong_th'] . K_TAB; $csv .= $l['w_questions_unanswered_th'] . K_TAB; $csv .= $l['w_questions_undisplayed_th'] . K_TAB; $csv .= $l['w_questions_unrated'] . K_NEWLINE; foreach ($stats as $row => $columns) { if (!in_array($row, $excludestat)) { $csv .= K_TAB . K_TAB . K_TAB . K_TAB . K_TAB . $l['w_' . $row] . K_TAB; $csv .= round($columns['score'], 3) . K_TAB; $csv .= round($columns['right'], 3) . K_TAB; $csv .= round($columns['wrong'], 3) . K_TAB; $csv .= round($columns['unanswered'], 3) . K_TAB; $csv .= round($columns['undisplayed'], 3) . K_TAB; $csv .= round($columns['unrated'], 3) . K_NEWLINE; if (in_array($row, $calcpercent)) { $csv .= K_TAB . K_TAB . K_TAB . K_TAB . K_TAB . $row . ' [%]' . K_TAB; $csv .= round(100 * ($columns['score'] / $usrtestdata['max_score'])) . K_TAB; $csv .= round(100 * ($columns['right'] / $usrtestdata['all'])) . K_TAB; $csv .= round(100 * ($columns['wrong'] / $usrtestdata['all'])) . K_TAB; $csv .= round(100 * ($columns['unanswered'] / $usrtestdata['all'])) . K_TAB; $csv .= round(100 * ($columns['undisplayed'] / $usrtestdata['all'])) . K_TAB; $csv .= round(100 * ($columns['unrated'] / $usrtestdata['all'])) . K_NEWLINE; } } } return $csv; }
/** * Returns a regular expression to match authorised directories. * @return a regular expression to match authorised directories. */ function F_getAuthorizedDirs() { require_once '../config/tce_config.php'; require_once '../../shared/code/tce_functions_authorization.php'; if ($_SESSION['session_user_level'] >= K_AUTH_ADMINISTRATOR) { return '[^/]*'; } $reg = F_getAuthorizedUsers($_SESSION['session_user_id']); return str_replace(',', '|', $reg); }
/** * Display user selection XHTML table (popup mode). * @author Nicola Asuni * @since 2012-04-14 * @param $order_field (string) Order by column name. * @param $orderdir (int) Order direction. * @param $firstrow (int) Number of first row to display. * @param $rowsperpage (int) Number of rows per page. * @param $andwhere (string) Additional SQL WHERE query conditions. * @param $searchterms (string) Search terms. * @param string $cid ID of the calling form field. * @return false in case of empty database, true otherwise */ function F_show_select_test_popup($order_field, $orderdir, $firstrow, $rowsperpage, $andwhere = '', $searchterms = '', $cid = 0) { global $l, $db; require_once '../config/tce_config.php'; require_once '../../shared/code/tce_functions_page.php'; require_once '../../shared/code/tce_functions_form.php'; $filter = 'cid=' . $cid; if ($l['a_meta_dir'] == 'rtl') { $txtalign = 'right'; $numalign = 'left'; } else { $txtalign = 'left'; $numalign = 'right'; } $order_field = F_escape_sql($db, $order_field); $orderdir = intval($orderdir); $firstrow = intval($firstrow); $rowsperpage = intval($rowsperpage); if (empty($order_field) or !in_array($order_field, array('test_name', 'test_description', 'test_begin_time', 'test_end_time', 'test_duration_time', 'test_ip_range', 'test_results_to_users', 'test_report_to_users', 'test_score_right', 'test_score_wrong', 'test_score_unanswered', 'test_max_score', 'test_user_id', 'test_score_threshold', 'test_random_questions_select', 'test_random_questions_order', 'test_questions_order_mode', 'test_random_answers_select', 'test_random_answers_order', 'test_answers_order_mode', 'test_comment_enabled', 'test_menu_enabled', 'test_noanswer_enabled', 'test_mcma_radio', 'test_repeatable', 'test_mcma_partial_score', 'test_logout_on_timeout'))) { $order_field = 'test_begin_time DESC,test_name'; } if ($orderdir == 0) { $nextorderdir = 1; $full_order_field = $order_field; } else { $nextorderdir = 0; $full_order_field = $order_field . ' DESC'; } if (!F_count_rows(K_TABLE_TESTS)) { // if the table is void (no items) display message F_print_error('MESSAGE', $l['m_databasempty']); return FALSE; } $wherequery = ''; if (empty($wherequery)) { $wherequery = ' WHERE'; } else { $wherequery .= ' AND'; } $wherequery .= ' (test_id>0)'; if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) { $wherequery .= ' AND test_user_id IN (' . F_getAuthorizedUsers($_SESSION['session_user_id']) . ')'; } if (!empty($andwhere)) { $wherequery .= ' AND (' . $andwhere . ')'; } $sql = 'SELECT * FROM ' . K_TABLE_TESTS . $wherequery . ' ORDER BY ' . $full_order_field; if (K_DATABASE_TYPE == 'ORACLE') { $sql = 'SELECT * FROM (' . $sql . ') WHERE rownum BETWEEN ' . $firstrow . ' AND ' . ($firstrow + $rowsperpage) . ''; } else { $sql .= ' LIMIT ' . $rowsperpage . ' OFFSET ' . $firstrow . ''; } if ($r = F_db_query($sql, $db)) { if ($m = F_db_fetch_array($r)) { // -- Table structure with links: echo '<div class="container">'; echo '<table class="userselect" style="font-size:80%;">' . K_NEWLINE; // table header echo '<tr>' . K_NEWLINE; if (strlen($searchterms) > 0) { $filter .= '&searchterms=' . urlencode($searchterms); } echo F_select_table_header_element('test_begin_time', $nextorderdir, $l['w_time_begin'] . ' ' . $l['w_datetime_format'], $l['w_time_begin'], $order_field, $filter); echo F_select_table_header_element('test_end_time', $nextorderdir, $l['w_time_end'] . ' ' . $l['w_datetime_format'], $l['w_time_end'], $order_field, $filter); echo F_select_table_header_element('test_name', $nextorderdir, $l['h_test_name'], $l['w_name'], $order_field, $filter); echo F_select_table_header_element('test_description', $nextorderdir, $l['h_test_description'], $l['w_description'], $order_field, $filter); echo '</tr>' . K_NEWLINE; $itemcount = 0; do { $itemcount++; // on click the user ID will be returned on the calling form field $jsaction = 'javascript:window.opener.document.getElementById(\'' . $cid . '\').value=' . $m['test_id'] . ';'; $jsaction .= 'window.opener.document.getElementById(\'' . $cid . '\').onchange();'; $jsaction .= 'window.close();'; echo '<tr>' . K_NEWLINE; echo '<td style="text-align:' . $txtalign . ';"> ' . htmlspecialchars($m['test_begin_time'], ENT_NOQUOTES, $l['a_meta_charset']) . '</td>' . K_NEWLINE; echo '<td style="text-align:' . $txtalign . ';"> ' . htmlspecialchars($m['test_end_time'], ENT_NOQUOTES, $l['a_meta_charset']) . '</td>' . K_NEWLINE; echo '<td style="text-align:' . $txtalign . ';"> <a href="#" onclick="' . $jsaction . '" title="[' . $l['w_select'] . ']">' . htmlspecialchars($m['test_name'], ENT_NOQUOTES, $l['a_meta_charset']) . '</a></td>' . K_NEWLINE; echo '<td style="text-align:' . $txtalign . ';"> ' . htmlspecialchars($m['test_description'], ENT_NOQUOTES, $l['a_meta_charset']) . '</td>' . K_NEWLINE; echo '</tr>' . K_NEWLINE; } while ($m = F_db_fetch_array($r)); echo '</table>' . K_NEWLINE; echo '<input type="hidden" name="order_field" id="order_field" value="' . $order_field . '" />' . K_NEWLINE; echo '<input type="hidden" name="orderdir" id="orderdir" value="' . $orderdir . '" />' . K_NEWLINE; echo '<input type="hidden" name="firstrow" id="firstrow" value="' . $firstrow . '" />' . K_NEWLINE; echo '<input type="hidden" name="rowsperpage" id="rowsperpage" value="' . $rowsperpage . '" />' . K_NEWLINE; echo '<div class="row"><hr /></div>' . K_NEWLINE; // --------------------------------------------------------------- // -- page jumper (menu for successive pages) if ($rowsperpage > 0) { $sql = 'SELECT count(*) AS total FROM ' . K_TABLE_TESTS . '' . $wherequery . ''; if (!empty($order_field)) { $param_array = '&order_field=' . urlencode($order_field) . ''; } if (!empty($orderdir)) { $param_array .= '&orderdir=' . $orderdir . ''; } if (!empty($searchterms)) { $param_array .= '&searchterms=' . urlencode($searchterms) . ''; } $param_array .= '&submitted=1'; F_show_page_navigator($_SERVER['SCRIPT_NAME'], $sql, $firstrow, $rowsperpage, $param_array); } echo '</div>' . K_NEWLINE; } else { F_print_error('MESSAGE', $l['m_search_void']); } } else { F_display_db_error(); } return TRUE; }