tagging as ATutor 1.5.4-release
[atutor.git] / tools / tests / results.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton        */
6 /* Adaptive Technology Resource Centre / University of Toronto                          */
7 /* http://atutor.ca                                                                                                                     */
8 /*                                                                                                                                                      */
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 /****************************************************************************/
13 // $Id$
14 define('AT_INCLUDE_PATH', '../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_TESTS);
17
18 $tid = intval($_REQUEST['tid']);
19
20
21 if (isset($_GET['delete'], $_GET['id'])) {
22         header('Location:delete_result.php?tid='.$tid.SEP.'rid='.$_GET['id']);
23         exit;
24 } else if (isset($_GET['edit'], $_GET['id'])) {
25         header('Location:view_results.php?tid='.$tid.SEP.'rid='.$_GET['id']);
26         exit;
27 } else if (isset($_GET['edit']) && !$_GET['id'] && !$_GET['asc'] && !$_GET['desc'] && !$_GET['filter'] && !$_GET['reset_filter']) {
28         $msg->addError('NO_ITEM_SELECTED');
29 }
30
31 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
32
33 if ($_GET['reset_filter']) {
34         unset($_GET);
35 }
36
37 $orders = array('asc' => 'desc', 'desc' => 'asc');
38 $cols   = array('login' => 1, 'full_name' => 1, 'date_taken' => 1, 'fs' => 1);
39
40 if (isset($_GET['asc'])) {
41         $order = 'asc';
42         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'login';
43 } else if (isset($_GET['desc'])) {
44         $order = 'desc';
45         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'login';
46 } else {
47         // no order set
48         $order = 'asc';
49         $col   = 'login';
50 }
51
52 require(AT_INCLUDE_PATH.'header.inc.php');
53
54 if (isset($_GET['status']) && ($_GET['status'] != '') && ($_GET['status'] != 2)) {
55         if ($_GET['status'] == 0) {
56                 $status = " AND R.final_score=''";
57         } else {
58                 $status = " AND R.final_score<>''";
59         }
60         $page_string .= SEP.'status='.$_GET['status'];
61 } else {
62         $status = '';
63 }
64
65 //get test info
66 $sql    = "SELECT out_of, anonymous, random, title FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
67 $result = mysql_query($sql, $db);
68 if (!($row = mysql_fetch_array($result))){
69         $msg->printErrors('ITEM_NOT_FOUND');
70         require (AT_INCLUDE_PATH.'footer.inc.php');
71         exit;
72 }
73 $out_of = $row['out_of'];
74 $anonymous = $row['anonymous'];
75 $random = $row['random'];
76
77 //count total
78 $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";
79 $result = mysql_query($sql, $db);
80 $row    = mysql_fetch_array($result);
81 $num_sub = $row['cnt'];
82
83 //get results based on filtre and sorting
84 if ($anonymous == 1) {
85         $sql    = "SELECT R.*, '<em>"._AT('anonymous')."</em>' AS login FROM ".TABLE_PREFIX."tests_results R WHERE R.test_id=$tid $status ORDER BY $col $order";
86 } else {        
87         $sql    = "SELECT R.*, login, CONCAT(first_name, ' ', second_name, ' ', 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 $status ORDER BY $col $order, R.final_score $order";
88 }
89
90 $result = mysql_query($sql, $db);
91 if ($anonymous == 1) {
92         $guest_text = '<em>'._AT('anonymous').'</em>';
93 } else {
94         $guest_text = '- '._AT('guest').' -';
95 }
96 while ($row = mysql_fetch_assoc($result)) {
97         $row['full_name'] = $row['full_name'] ? $row['full_name'] : $guest_text;
98         $row['login']     = $row['login']     ? $row['login']     : $guest_text;
99         $rows[$row['result_id']] = $row;
100 }
101
102 $num_results = mysql_num_rows($result);
103
104 //count unmarked: no need to do this query if filtre is already getting unmarked
105 if (isset($_GET['status']) && ($_GET['status'] != '') && ($_GET['status'] == 0)) {
106         $num_unmarked = $num_results;
107 } else {
108         $sql            = "SELECT count(*) as cnt FROM ".TABLE_PREFIX."tests_results R, ".TABLE_PREFIX."members M WHERE R.test_id=$tid AND R.member_id=M.member_id AND R.final_score=''";
109         $result = mysql_query($sql, $db);
110         $row = mysql_fetch_array($result);
111         $num_unmarked = $row['cnt'];
112 }
113
114 ?>
115 <h3><?php echo AT_print($row['title'], 'tests.title'); ?></h3><br />
116
117 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
118         <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
119
120         <div class="input-form">
121                 <div class="row">
122                         <h3><?php echo _AT('results_found', $num_results); ?></h3>
123                 </div>
124
125                 <div class="row">
126                         <?php echo _AT('status'); ?><br />
127                         <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> 
128
129                         <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> 
130
131                         <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> 
132
133                 </div>
134
135                 <div class="row buttons">
136                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
137                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
138                 </div>
139         </div>
140 </form>
141
142 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
143 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
144
145 <table class="data" summary="" rules="cols">
146 <colgroup>
147         <?php if ($col == 'login'): ?>
148                 <col />
149                 <col class="sort" />
150                 <col span="3" />
151         <?php elseif ($col == 'full_name'): ?>
152                 <col span="2" />
153                 <col class="sort" />
154                 <col span="2" />
155         <?php elseif($col == 'date_taken'): ?>
156                 <col span="3" />
157                 <col class="sort" />
158                 <col span="1" />
159         <?php elseif($col == 'fs'): ?>
160                 <col span="4" />
161                 <col class="sort" />
162         <?php endif; ?>
163 </colgroup>
164 <thead>
165 <tr>
166         <th scope="col" width="1%">&nbsp;</th>
167         <th scope="col"><a href="tools/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=login"><?php echo _AT('login_name'); ?></a></th>
168         <th scope="col"><a href="tools/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=full_name"><?php echo _AT('full_name'); ?></a></th>
169         <th scope="col"><a href="tools/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=date_taken"><?php echo _AT('date_taken'); ?></a></th>
170         <th scope="col"><a href="tools/tests/results.php?tid=<?php echo $tid.$page_string.SEP.$orders[$order]; ?>=fs"><?php echo _AT('mark'); ?></a></th>
171 </tr>
172 </thead>
173 <tfoot>
174 <tr>
175         <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>
176 </tr>
177 </tfoot>
178 <tbody>
179 <?php if ($rows): ?>
180         <?php foreach ($rows as $row): ?>
181                 <tr onmousedown="document.form['r<?php echo $row['result_id']; ?>'].checked = true;rowselect(this);" id="r_<?php echo $row['result_id']; ?>">
182                         <td><input type="radio" name="id" value="<?php echo $row['result_id']; ?>" id="r<?php echo $row['result_id']; ?>" /></td>
183                         <td><label for="r<?php echo $row['result_id']; ?>"><?php echo $row['login']; ?></label></td>
184                         <td><?php echo $row['full_name']; ?></td>
185                         <td><?php echo AT_date('%j/%n/%y %G:%i', $row['date_taken'], AT_DATE_MYSQL_DATETIME); ?></td>
186                         <td align="center">
187                                 <?php if ($out_of) {
188                                         if ($random) {
189                                                 $out_of = get_random_outof($tid, $row['result_id']);
190                                         }
191
192                                         if ($row['final_score'] != '') { 
193                                                 echo $row['final_score'].'/'.$out_of;
194                                         } else {
195                                                 echo _AT('unmarked');
196                                         }
197                                 } else {
198                                         echo _AT('na');
199                                 }
200                                 ?>
201                         </td>
202                 </tr>
203         <?php endforeach; ?>
204 <?php else: ?>
205         <tr>
206                 <td colspan="4"><?php echo _AT('none_found'); ?></td>
207         </tr>
208 <?php endif; ?>
209 </tbody>
210 </table>
211 </form>
212 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>