2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_TESTS);
18 function sortByFullName($cell1, $cell2)
22 if ($order == 'asc') return (strcmp($cell1['full_name'], $cell2['full_name']) > 0) ? 1 : -1;
23 else return (strcmp($cell1['full_name'], $cell2['full_name']) < 0) ? 1 : -1;
26 $tid = intval($_REQUEST['tid']);
28 if (isset($_GET['delete'], $_GET['id'])) {
29 $ids = implode(',', $_GET['id']);
30 header('Location:delete_result.php?tid='.$tid.SEP.'rid='.$ids);
32 } else if (isset($_GET['edit'], $_GET['id'])) {
33 if (count($_GET['id']) > 1) {
34 $msg->addError('SELECT_ONE_ITEM');
36 header('Location:view_results_manage.php?tid='.$tid.SEP.'rid='.$_GET['id'][0]);
39 } else if ((isset($_GET['edit']) || isset($_GET['delete'])) && !$_GET['id'] && !$_GET['asc'] && !$_GET['desc'] && !$_GET['filter'] && !$_GET['reset_filter']) {
40 $msg->addError('NO_ITEM_SELECTED');
43 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
45 if ($_GET['reset_filter']) {
49 $orders = array('asc' => 'desc', 'desc' => 'asc');
50 $cols = array('login' => 1, 'full_name' => 1, 'date_taken' => 1, 'fs' => 1, 'time_spent' => 1);
52 if (isset($_GET['asc'])) {
54 $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'login';
55 } else if (isset($_GET['desc'])) {
57 $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'login';
64 require(AT_INCLUDE_PATH.'header.inc.php');
66 if (isset($_GET['status']) && ($_GET['status'] != '') && ($_GET['status'] != 2)) {
67 if ($_GET['status'] == 0) {
68 $status = " AND R.final_score=''";
70 $status = " AND R.final_score<>''";
72 $page_string .= SEP.'status='.$_GET['status'];
77 if ($_GET['user_type'] == 1 || $_GET['user_type'] == 2) {
78 if ($_GET['user_type'] == 1) {
79 $status = " AND R.member_id not like 'G_%' AND R.member_id > 0 ";
81 $status = " AND (R.member_id like 'G_%' OR R.member_id = 0) ";
83 $page_string .= SEP.'user_type='.$_GET['user_type'];
87 $sql = "SELECT out_of, anonymous, random, title FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
88 $result = mysql_query($sql, $db);
89 if (!($row = mysql_fetch_array($result))){
90 $msg->printErrors('ITEM_NOT_FOUND');
91 require (AT_INCLUDE_PATH.'footer.inc.php');
94 $out_of = $row['out_of'];
95 $anonymous = $row['anonymous'];
96 $random = $row['random'];
97 $title = $row['title'];
100 $sql = "SELECT count(*) as cnt FROM ".TABLE_PREFIX."tests_results R LEFT JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE R.test_id=$tid AND R.status=1";
101 $result = mysql_query($sql, $db);
102 $row = mysql_fetch_array($result);
103 $num_sub = $row['cnt'];
105 //get results based on filtre and sorting
106 if ($anonymous == 1) {
107 // Keep login, full_name and fs fields even if not used: ORDER BY relies upon them
108 $sql = "SELECT R.*, (UNIX_TIMESTAMP(R.end_time) - UNIX_TIMESTAMP(R.date_taken)) AS time_spent, '' AS login, '' AS full_name, R.final_score+0.0 AS fs FROM ".TABLE_PREFIX."tests_results R WHERE R.test_id=$tid AND R.status=1 $status ";
110 // $sql = "SELECT R.*, M.login, (UNIX_TIMESTAMP(R.end_time) - UNIX_TIMESTAMP(R.date_taken)) AS time_spent, CONCAT(M.first_name, ' ', M.second_name, ' ', M.last_name) AS full_name, R.final_score+0.0 AS fs FROM ".TABLE_PREFIX."tests_results R LEFT JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE R.test_id=$tid AND R.status=1 $status ORDER BY $col $order, R.final_score $order";
112 $sql = "SELECT R.*, login, (UNIX_TIMESTAMP(R.end_time) - UNIX_TIMESTAMP(R.date_taken)) AS time_spent, R.final_score+0.0 AS fs FROM ".TABLE_PREFIX."tests_results R LEFT JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE R.test_id=$tid AND R.status=1 $status ";
115 // handle order by full_name separately
116 if ($col <> 'full_name') $sql .= " ORDER BY $col $order";
120 if ($col <> 'full_name')
121 $sql .= ", R.final_score $order";
123 $sql .= " ORDER BY R.final_score $order";
126 $result = mysql_query($sql, $db);
128 if ($anonymous == 1) {
129 $guest_text = '<strong>'._AT('anonymous').'</strong>';
131 $guest_text = '- '._AT('guest').' -';
133 while ($row = mysql_fetch_assoc($result)) {
134 $full_name = AT_print(get_display_name($row['member_id']), 'members.full_name');
135 $row['full_name'] = $full_name ? $full_name : $guest_text;
136 $row['login'] = $row['login'] ? $row['login'] : $guest_text;
137 $rows[$row['result_id']] = $row;
140 if ($col == "full_name") usort($rows, "sortByFullName");
142 $num_results = mysql_num_rows($result);
144 //count unmarked: no need to do this query if filtre is already getting unmarked
145 if (isset($_GET['status']) && ($_GET['status'] != '') && ($_GET['status'] == 0)) {
146 $num_unmarked = $num_results;
148 $sql = "SELECT count(*) as cnt FROM ".TABLE_PREFIX."tests_results R, ".TABLE_PREFIX."members M WHERE R.test_id=$tid AND R.status=1 AND R.member_id=M.member_id AND R.final_score=''";
149 $result = mysql_query($sql, $db);
150 $row = mysql_fetch_array($result);
151 $num_unmarked = $row['cnt'];
155 <!--h3><?php //echo AT_print($row['title'], 'tests.title'); ?></h3><br / -->
157 <h3><?php echo AT_print($title, 'tests.title'); ?></h3><br />
158 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
159 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
161 <div class="input-form">
162 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('filter'); ?></legend>
164 <h3><?php echo _AT('results_found', $num_results); ?></h3>
168 <?php echo _AT('status'); ?><br />
169 <input type="radio" name="status" value="1" id="s0" <?php if ($_GET['status'] == 1) { echo 'checked="checked"'; } ?> /><label for="s0"><?php echo _AT('marked_label', $num_sub - $num_unmarked); ?></label>
170 <input type="radio" name="status" value="0" id="s1" <?php if ($_GET['status'] == 0) { echo 'checked="checked"'; } ?> /><label for="s1"><?php echo _AT('unmarked_label', $num_unmarked); ?></label>
171 <input type="radio" name="status" value="2" id="s2" <?php if (!isset($_GET['status']) || ($_GET['status'] != 0 && $_GET['status'] != 1)) { echo 'checked="checked"'; } ?> /><label for="s2"><?php echo _AT('all_label', $num_sub); ?></label>
176 <?php echo _AT('user_type'); ?><br />
177 <input type="radio" name="user_type" value="1" id="u0" <?php if ($_GET['user_type'] == 1) { echo 'checked="checked"'; } ?> /><label for="u0"><?php echo _AT('registered_members'); ?></label>
178 <input type="radio" name="user_type" value="2" id="u1" <?php if ($_GET['user_type'] == 2) { echo 'checked="checked"'; } ?> /><label for="u1"><?php echo _AT('guests'); ?></label>
179 <input type="radio" name="user_type" value="0" id="u2" <?php if (!isset($_GET['user_type']) || ($_GET['user_type'] != 1 && $_GET['user_type'] != 2)) { echo 'checked="checked"'; } ?> /><label for="u2"><?php echo _AT('all'); ?></label>
182 <div class="row buttons">
183 <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
184 <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
190 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
191 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
193 <table class="data" summary="" rules="cols">
195 <?php if ($col == 'login'): ?>
199 <?php elseif ($col == 'full_name'): ?>
203 <?php elseif($col == 'date_taken'): ?>
207 <?php elseif($col == 'time_spent'): ?>
211 <?php elseif($col == 'fs'): ?>
218 <th scope="col" align="left"><input type="checkbox" value="<?php echo _AT('select_all'); ?>" id="all" title="<?php echo _AT('select_all'); ?>" name="selectall" onclick="CheckAll();" /></th>
219 <th scope="col"><a href="mods/_standard/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=login"><?php echo _AT('login_name'); ?></a></th>
220 <th scope="col"><a href="mods/_standard/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=full_name"><?php echo _AT('full_name'); ?></a></th>
221 <th scope="col"><a href="mods/_standard/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=date_taken"><?php echo _AT('date_taken'); ?></a></th>
222 <th scope="col"><a href="mods/_standard/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=time_spent"><?php echo _AT('time_spent'); ?></a></th>
223 <th scope="col"><a href="mods/_standard/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=fs"><?php echo _AT('mark'); ?></a></th>
228 <td colspan="6"><input type="submit" name="edit" value="<?php echo _AT('view_mark_test'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>
233 <?php foreach ($rows as $row): ?>
234 <tr onmousedown="document.form['r<?php echo $row['result_id']; ?>'].checked = !document.form['r<?php echo $row['result_id']; ?>'].checked; togglerowhighlight(this, 'r<?php echo $row['result_id']; ?>');" id="rr<?php echo $row['result_id']; ?>">
235 <td><input type="checkbox" name="id[]" value="<?php echo $row['result_id']; ?>" id="r<?php echo $row['result_id']; ?>" onmouseup="this.checked=!this.checked" /></td>
236 <td><?php echo $row['login']; ?></td>
238 if ($anonymous == 0 && $row['member_id']){
239 echo $row['full_name'];
241 echo $guest_text; // no need in AT_print(): $guest_text is a trusted _AT() output
244 <td><?php $startend_date_format=_AT('startend_date_format'); echo AT_date( $startend_date_format, $row['date_taken'], AT_DATE_MYSQL_DATETIME); ?></td>
245 <td><?php echo get_human_time($row['time_spent']); ?></td>
250 $out_of = get_random_outof($tid, $row['result_id']);
253 if ($row['final_score'] != '') {
254 echo $row['final_score'].'/'.$out_of;
256 echo _AT('unmarked');
267 <td colspan="6"><?php echo _AT('none_found'); ?></td>
274 <script language="JavaScript" type="text/javascript">
276 function CheckAll() {
277 for (var i=0;i<document.form.elements.length;i++) {
278 var e = document.form.elements[i];
279 if ((e.name == 'id[]') && (e.type=='checkbox')) {
280 e.checked = document.form.selectall.checked;
281 togglerowhighlight(document.getElementById("r" + e.id), e.id);
286 function togglerowhighlight(obj, boxid) {
287 if (document.getElementById(boxid).checked) {
288 obj.className = 'selected';
295 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>