made a copy
[atutor.git] / tools / tests / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 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
15 $page = 'tests';
16 define('AT_INCLUDE_PATH', '../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_TESTS);
19
20 if (isset($_GET['edit'], $_GET['id'])) {
21         header('Location: edit_test.php?tid='.$_GET['id']);
22         exit;
23 } else if (isset($_GET['preview'], $_GET['id'])) {
24         header('Location: preview.php?tid='.$_GET['id']);
25         exit;
26 } else if (isset($_GET['questions'], $_GET['id'])) {
27         header('Location: questions.php?tid='.$_GET['id']);
28         exit;
29 } else if (isset($_GET['submissions'], $_GET['id'])) {
30         header('Location: results.php?tid='.$_GET['id']);
31         exit;
32 } else if (isset($_GET['statistics'], $_GET['id'])) {
33         header('Location: results_all_quest.php?tid='.$_GET['id']);
34         exit;
35 } else if (isset($_GET['delete'], $_GET['id'])) {
36         header('Location: delete_test.php?tid='.$_GET['id']);
37         exit;
38 } else if (isset($_GET['export'], $_GET['id'])){
39         header('Location: export_test.php?tid='.$_GET['id']);
40 } else if (isset($_GET['edit']) 
41                 || isset($_GET['preview']) 
42                 || isset($_GET['questions']) 
43                 || isset($_GET['submissions']) 
44                 || isset($_GET['statistics']) 
45                 || isset($_GET['delete'])
46                 || isset($_GET['export'])) {
47
48         $msg->addError('NO_ITEM_SELECTED');
49 }
50
51 require(AT_INCLUDE_PATH.'header.inc.php');
52
53
54 /* get a list of all the tests we have, and links to create, edit, delete, preview */
55
56 $sql    = "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue FROM ".TABLE_PREFIX."tests WHERE course_id=$_SESSION[course_id] ORDER BY start_date DESC";
57 $result = mysql_query($sql, $db);
58 $num_tests = mysql_num_rows($result);
59
60 $cols=6;
61 ?>
62 <form method="post" action="<?php echo 'tools/tests/import_test.php'; ?>" enctype="multipart/form-data" >
63 <div class="input-form" style="width: 40%">
64         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('import_test'); ?></legend>
65         <div class="row">
66                 <label for="to_file"><?php echo _AT('upload_test'); ?></label><br />
67                 <input type="file" name="file" id="to_file" />
68         </div>
69
70         <div class="row buttons">
71                 <input type="submit" name="submit_import" value="<?php echo _AT('import'); ?>" />
72         </div>
73         </fieldset>
74 </div>
75 </form>
76
77 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
78 <table class="data" summary="" style="width: 90%" rules="cols">
79 <thead>
80 <tr>
81         <th scope="col">&nbsp;</th>
82         <th scope="col"><?php echo _AT('title');          ?></th>
83         <th scope="col"><?php echo _AT('status');         ?></th>
84         <th scope="col"><?php echo _AT('availability');   ?></th>
85         <th scope="col"><?php echo _AT('result_release'); ?></th>
86         <th scope="col"><?php echo _AT('submissions');    ?></th>
87         <th scope="col"><?php echo _AT('assigned_to');    ?></th>
88 </tr>
89 </thead>
90
91 <?php if ($num_tests): ?>
92         <tfoot>
93         <tr>
94                 <td colspan="7">
95                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" />
96                         <input type="submit" name="preview" value="<?php echo _AT('preview'); ?>" />
97                         <input type="submit" name="questions" value="<?php echo _AT('questions'); ?>" />
98                 </td>
99         </tr>
100         <tr>    
101                 <td colspan="7" style="padding-left:38px;">
102                         <input type="submit" name="submissions" value="<?php echo _AT('submissions'); ?>" />
103                         <input type="submit" name="statistics" value="<?php echo _AT('statistics'); ?>" />
104                         <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
105                         <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />
106                 </td>
107         </tr>
108         </tfoot>
109         <tbody>
110
111         <?php while ($row = mysql_fetch_assoc($result)) : ?>
112                 <tr onmousedown="document.form['t<?php echo $row['test_id']; ?>'].checked = true;rowselect(this);" id="r_<?php echo $row['test_id']; ?>">
113                         <td><input type="radio" name="id" value="<?php echo $row['test_id']; ?>" id="t<?php echo $row['test_id']; ?>" /></td>
114                         <td><label for="t<?php echo $row['test_id']; ?>"><?php echo $row['title']; ?></label></td>
115                         <td><?php
116                                 if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
117                                         echo '<em>'._AT('ongoing').'</em>';
118                                 } else if ($row['ue'] < time() ) {
119                                         echo '<em>'._AT('expired').'</em>';
120                                 } else if ($row['us'] > time() ) {
121                                         echo '<em>'._AT('pending').'</em>';
122                                 } ?></td>
123                         <td><?php $startend_date_format=_AT('startend_date_format'); 
124
125                                 echo AT_date($startend_date_format, $row['start_date'], AT_DATE_MYSQL_DATETIME). ' ' ._AT('to_2').' ';
126                                 echo AT_date($startend_date_format, $row['end_date'], AT_DATE_MYSQL_DATETIME); ?></td>
127
128                         <td><?php 
129                                 if ($row['result_release'] == AT_RELEASE_IMMEDIATE) {
130                                         echo _AT('release_immediate');
131                                 } else if ($row['result_release'] == AT_RELEASE_MARKED) {
132                                         echo _AT('release_marked');
133                                 } else if ($row['result_release'] == AT_RELEASE_NEVER) {
134                                         echo _AT('release_never');
135                                 }
136                         ?></td>
137                         <td><?php
138                                 //get # marked submissions
139                                 $sql_sub = "SELECT COUNT(*) AS sub_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id'];
140                                 $result_sub     = mysql_query($sql_sub, $db);
141                                 $row_sub = mysql_fetch_assoc($result_sub);
142                                 echo $row_sub['sub_cnt'].' '._AT('submissions').', ';
143
144                                 //get # submissions
145                                 $sql_sub = "SELECT COUNT(*) AS marked_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id']." AND final_score=''";
146                                 $result_sub     = mysql_query($sql_sub, $db);
147                                 $row_sub = mysql_fetch_assoc($result_sub);
148                                 echo $row_sub['marked_cnt'].' '._AT('unmarked');
149                                 ?>
150                         </td>
151                         <td><?php
152                                 //get assigned groups
153                                 $sql_sub = "SELECT G.title FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."tests_groups T USING (group_id) WHERE T.test_id=".$row['test_id'];
154                                 $result_sub     = mysql_query($sql_sub, $db);
155                                 if (mysql_num_rows($result_sub) == 0) {
156                                         echo _AT('everyone');
157                                 } else {
158                                         $assigned_groups = '';
159                                         while ($row_sub = mysql_fetch_assoc($result_sub)) {
160                                                 $assigned_groups .= $row_sub['title'].', ';
161                                         }
162                                         echo substr($assigned_groups, 0, -2);
163                                 }                               
164                                 ?>
165                         </td>
166                 </tr>
167         <?php endwhile; ?>
168 <?php else: ?>
169         <tbody>
170         <tr>
171                 <td colspan="7"><?php echo _AT('none_found'); ?></td>
172         </tr>
173 <?php endif; ?>
174 </tbody>
175 </table>
176 </form>
177
178 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>