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