$orderdir = 1; $nextorderdir = 0; $full_order_field = $order_field . ' DESC'; } $filter .= '&orderdir=' . $orderdir . ''; echo '<div class="container">' . K_NEWLINE; echo '<div class="tceformbox">' . K_NEWLINE; echo '<form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post" enctype="multipart/form-data" id="form_resultallusers">' . K_NEWLINE; echo '<div class="row">' . K_NEWLINE; echo '<span class="label">' . K_NEWLINE; echo '<label for="test_id">' . $l['w_test'] . '</label>' . K_NEWLINE; echo '</span>' . K_NEWLINE; echo '<span class="formw">' . K_NEWLINE; echo '<input type="hidden" name="changecategory" id="changecategory" value="" />' . K_NEWLINE; echo '<select name="test_id" id="test_id" size="0" onchange="document.getElementById(\'form_resultallusers\').changecategory.value=1; document.getElementById(\'form_resultallusers\').submit()" title="' . $l['h_test'] . '">' . K_NEWLINE; $sql = 'SELECT * FROM ' . K_TABLE_TESTS . ' WHERE test_id IN (' . F_getTestIDResults($test_id, $user_id) . ') ORDER BY test_begin_time DESC, test_name'; if ($r = F_db_query($sql, $db)) { echo '<option value="0"'; if ($test_id == 0) { echo ' selected="selected"'; } echo '> - </option>' . K_NEWLINE; while ($m = F_db_fetch_array($r)) { echo '<option value="' . $m['test_id'] . '"'; if ($m['test_id'] == $test_id) { echo ' selected="selected"'; } echo '>' . substr($m['test_begin_time'], 0, 10) . ' ' . htmlspecialchars($m['test_name'], ENT_NOQUOTES, $l['a_meta_charset']) . '</option>' . K_NEWLINE; } } else { F_display_db_error();
/** * Returns users statistic array for the selected test. * @param $test_id (int) test ID. * @param $group_id (int) group ID - if greater than zero, filter stats for the specified user group. * @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 $full_order_field (string) Ordering fields for SQL query. * @param $pubmode (boolean) If true filter the results for the public interface. * @param $stats (int) 2 = full stats; 1 = user stats; 0 = disabled stats; * return $data array containing test statistics. */ function F_getAllUsersTestStat($test_id, $group_id = 0, $user_id = 0, $startdate = 0, $enddate = 0, $full_order_field = 'total_score', $pubmode = false, $stats = 2) { require_once '../config/tce_config.php'; require_once '../../shared/code/tce_functions_test.php'; require_once '../../shared/code/tce_functions_statistics.php'; global $db, $l; $test_id = intval($test_id); $group_id = intval($group_id); $user_id = intval($user_id); $data = array(); $data['svgpoints'] = ''; $data['testuser'] = array(); $sqlr = 'SELECT testuser_id, testuser_test_id, testuser_creation_time, testuser_status, user_id, user_lastname, user_firstname, user_name, user_email, 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_USERS . ''; if ($group_id > 0) { $sqlr .= ',' . K_TABLE_USERGROUP . ''; } $sqlr .= ' WHERE testlog_testuser_id=testuser_id AND testuser_user_id=user_id'; if ($test_id > 0) { $sqlr .= ' AND testuser_test_id=' . $test_id . ''; } elseif ($pubmode) { $sqlr .= ' AND testuser_test_id IN (' . F_getTestIDResults($test_id, $user_id) . ')'; } if ($group_id > 0) { $sqlr .= ' AND usrgrp_user_id=user_id AND usrgrp_group_id=' . $group_id . ''; } if ($user_id > 0) { $sqlr .= ' AND user_id=' . $user_id . ''; } if (!empty($startdate)) { $startdate_time = strtotime($startdate); $startdate = date(K_TIMESTAMP_FORMAT, $startdate_time); $sqlr .= ' AND testuser_creation_time>=\'' . $startdate . '\''; } if (!empty($enddate)) { $enddate_time = strtotime($enddate); $enddate = date(K_TIMESTAMP_FORMAT, $enddate_time); $sqlr .= ' AND testuser_creation_time<=\'' . $enddate . '\''; } if ($stats > 1) { // get stats $data += F_getTestStat($test_id, $group_id, $user_id, $startdate, $enddate); } $sqlr .= ' GROUP BY testuser_id, testuser_test_id, testuser_creation_time, user_id, user_lastname, user_firstname, user_name, user_email, 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['testuser_test_id'], $mr['user_id'], $mr['testuser_id']); if ($stats > 0) { $teststat = F_getTestStat($mr['testuser_test_id'], $group_id, $mr['user_id'], $startdate, $enddate, $mr['testuser_id']); } $data['testuser']['\'' . $mr['testuser_id'] . '\''] = array(); $data['testuser']['\'' . $mr['testuser_id'] . '\'']['test'] = $usrtestdata; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['num'] = $itemcount; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['id'] = $mr['testuser_id']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_id'] = $mr['user_id']; $halfscore = $usrtestdata['test_max_score'] / 2; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['testuser_creation_time'] = $mr['testuser_creation_time']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['testuser_end_time'] = $mr['testuser_end_time']; if ($mr['testuser_end_time'] <= 0 or strtotime($mr['testuser_end_time']) < strtotime($mr['testuser_creation_time'])) { $time_diff = $usrtestdata['test_duration_time'] * K_SECONDS_IN_MINUTE; } else { $time_diff = strtotime($mr['testuser_end_time']) - strtotime($mr['testuser_creation_time']); //sec } $data['testuser']['\'' . $mr['testuser_id'] . '\'']['time_diff'] = gmdate('H:i:s', $time_diff); $passmsg = false; if ($usrtestdata['test_score_threshold'] > 0) { if ($usrtestdata['user_score'] >= $usrtestdata['test_score_threshold']) { $passmsg = true; $passed++; } } elseif ($usrtestdata['user_score'] > $halfscore) { $passmsg = true; $passed++; } if ($usrtestdata['test_max_score'] > 0) { $total_score_perc = round(100 * $mr['total_score'] / $usrtestdata['test_max_score']); } else { $total_score_perc = 0; } $data['testuser']['\'' . $mr['testuser_id'] . '\'']['passmsg'] = $passmsg; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_name'] = $mr['user_name']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_email'] = $mr['user_email']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_lastname'] = $mr['user_lastname']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_firstname'] = $mr['user_firstname']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['total_score'] = $mr['total_score']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['total_score_perc'] = $total_score_perc; if ($stats > 0) { $data['testuser']['\'' . $mr['testuser_id'] . '\'']['right'] = $teststat['qstats']['right']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['right_perc'] = $teststat['qstats']['right_perc']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['wrong'] = $teststat['qstats']['wrong']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['wrong_perc'] = $teststat['qstats']['wrong_perc']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unanswered'] = $teststat['qstats']['unanswered']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unanswered_perc'] = $teststat['qstats']['unanswered_perc']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['undisplayed'] = $teststat['qstats']['undisplayed']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['undisplayed_perc'] = $teststat['qstats']['undisplayed_perc']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unrated'] = $teststat['qstats']['unrated']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unrated_perc'] = $teststat['qstats']['unrated_perc']; } else { $data['testuser']['\'' . $mr['testuser_id'] . '\'']['right'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['right_perc'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['wrong'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['wrong_perc'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unanswered'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unanswered_perc'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['undisplayed'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['undisplayed_perc'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unrated'] = ''; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['unrated_perc'] = ''; } if ($mr['testuser_status'] > 3) { $data['testuser']['\'' . $mr['testuser_id'] . '\'']['locked'] = true; } else { $data['testuser']['\'' . $mr['testuser_id'] . '\'']['locked'] = false; } // remaining user time in minutes $data['testuser']['\'' . $mr['testuser_id'] . '\'']['remaining_time'] = round((time() - strtotime($usrtestdata['user_test_start_time'])) / K_SECONDS_IN_MINUTE) - $usrtestdata['test_duration_time']; $data['testuser']['\'' . $mr['testuser_id'] . '\'']['user_comment'] = $usrtestdata['user_comment']; // SVG points $data['svgpoints'] .= 'x' . $data['testuser']['\'' . $mr['testuser_id'] . '\'']['total_score_perc'] . 'v' . $data['testuser']['\'' . $mr['testuser_id'] . '\'']['right_perc']; // collects data for descriptive statistics $statsdata['score'][] = $mr['total_score']; $statsdata['score_perc'][] = $total_score_perc; if ($stats > 0) { $statsdata['right'][] = $teststat['qstats']['right']; $statsdata['right_perc'][] = $teststat['qstats']['right_perc']; $statsdata['wrong'][] = $teststat['qstats']['wrong']; $statsdata['wrong_perc'][] = $teststat['qstats']['wrong_perc']; $statsdata['unanswered'][] = $teststat['qstats']['unanswered']; $statsdata['unanswered_perc'][] = $teststat['qstats']['unanswered_perc']; $statsdata['undisplayed'][] = $teststat['qstats']['undisplayed']; $statsdata['undisplayed_perc'][] = $teststat['qstats']['undisplayed_perc']; $statsdata['unrated'][] = $teststat['qstats']['unrated']; $statsdata['unrated_perc'][] = $teststat['qstats']['unrated_perc']; } else { $statsdata['right'][] = ''; $statsdata['right_perc'][] = ''; $statsdata['wrong'][] = ''; $statsdata['wrong_perc'][] = ''; $statsdata['unanswered'][] = ''; $statsdata['unanswered_perc'][] = ''; $statsdata['undisplayed'][] = ''; $statsdata['undisplayed_perc'][] = ''; $statsdata['unrated'][] = ''; $statsdata['unrated_perc'][] = ''; } } } else { F_display_db_error(); } $data['passed'] = $passed; $passed_perc = 0; if ($itemcount > 0) { $passed_perc = round(100 * $passed / $itemcount); } $data['passed_perc'] = $passed_perc; $data['num_records'] = $itemcount; if ($itemcount > 0) { // calculate statistics $data['statistics'] = F_getArrayStatistics($statsdata); } return $data; }