made a copy
[atutor.git] / include / html / editor_tabs / tests.inc.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Harris Wong                    */
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: tests.inc.php 7208 2008-01-09 16:07:24Z harris $
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15 ?>
16
17 <?php
18 /* Get the list of associated tests with this content on page load */
19
20 $_REQUEST['cid'] = intval($_REQUEST['cid']);    //uses request 'cause after 'saved', the cid will become $_GET.
21 $sql = 'SELECT * FROM '.TABLE_PREFIX."content_tests_assoc WHERE content_id=$_REQUEST[cid]";
22 $result = mysql_query($sql, $db);
23 while ($row = mysql_fetch_assoc($result)) {
24         $_POST['tid'][] = $row['test_id'];
25 }
26
27 /* get a list of all the tests we have, and links to create, edit, delete, preview */
28
29 $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";
30 $result = mysql_query($sql, $db);
31 $num_tests = mysql_num_rows($result);
32
33 //If there are no tests, don't display anything except a message
34 if ($num_tests == 0){
35         $msg->addInfo('NO_TESTS');
36         $msg->printInfos();
37         return;
38 }
39 ?>
40
41
42 <div class="row">
43         <p><?php echo _AT('about_content_tests'); ?></p>
44 </div>
45
46
47 <div class="row">
48         <?php
49         //Need radio button 'cause one checkbox makes the states indeterministic
50         //@harris
51         $test_export_y_checked = '';
52         $test_export_n_checked = '';
53         if ($_POST['allow_test_export'] == 1){
54                 $test_export_y_checked = ' checked="checked"';
55         } else {
56                 $test_export_n_checked = ' checked="checked"';
57         }
58         
59         echo _AT('allow_test_export');
60 ?>
61
62         <input type="radio" name="allow_test_export" id="allow_test_export" value="1" <?php echo $test_export_y_checked; ?>/>
63         <label for="allow_test_export"><?php echo _AT('yes'); ?></label>
64         <input type="radio" name="allow_test_export" id="disallow_test_export" value="0" <?php echo $test_export_n_checked; ?>/>
65         <label for="disallow_test_export"><?php echo _AT('no'); ?></label>
66 </div>
67
68
69 <div class="row">
70         <p><?php echo _AT('custom_test_message'); ?></p>
71         <textarea name="test_message"><?php echo $_POST['test_message']; ?></textarea>
72 </div>
73
74 <table class="data" summary="" style="width: 90%" rules="cols">
75 <thead>
76 <tr>
77         <th scope="col">&nbsp;</th>
78         <th scope="col"><?php echo _AT('title');          ?></th>
79         <th scope="col"><?php echo _AT('status');         ?></th>
80         <th scope="col"><?php echo _AT('availability');   ?></th>
81         <th scope="col"><?php echo _AT('result_release'); ?></th>
82         <th scope="col"><?php echo _AT('submissions');    ?></th>
83         <th scope="col"><?php echo _AT('assigned_to');    ?></th>
84 </tr>
85 </thead>
86 <tbody>
87 <?php while ($row = mysql_fetch_assoc($result)) : ?>
88 <?php
89         $checkMe = '';
90         if (is_array($_POST['tid']) && in_array($row['test_id'], $_POST['tid'])){
91                 $checkMe = ' checked="checked"';
92         } 
93 ?>
94 <script language="javascript" type="text/javascript">
95         function toggleTestSelect(r_id){
96                 var row = document.getElementById(r_id);
97                 var checkBox = row.cells[0].firstChild;
98
99                 if (checkBox.checked == true){
100                         checkBox.checked = false;
101                 } else {
102                         checkBox.checked = true;
103                 }
104         }
105 </script>
106 <tr onmousedown="toggleTestSelect('r_<?php echo $row['test_id']; ?>');rowselect(this);" id="r_<?php echo $row['test_id']; ?>">
107         <td><input type="checkbox" name="tid[]" value="<?php echo $row['test_id']; ?>" id="t<?php echo $row['test_id']; ?>" <?php echo $checkMe; ?>/></td>
108         <td><?php echo $row['title']; ?></td>
109         <td><?php
110                 if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
111                         echo '<em>'._AT('ongoing').'</em>';
112                 } else if ($row['ue'] < time() ) {
113                         echo '<em>'._AT('expired').'</em>';
114                 } else if ($row['us'] > time() ) {
115                         echo '<em>'._AT('pending').'</em>';
116                 } ?></td>
117         <td><?php $startend_date_format=_AT('startend_date_format'); 
118
119                 echo AT_date($startend_date_format, $row['start_date'], AT_DATE_MYSQL_DATETIME). ' ' ._AT('to_2').' ';
120                 echo AT_date($startend_date_format, $row['end_date'], AT_DATE_MYSQL_DATETIME); ?></td>
121
122         <td><?php 
123                 if ($row['result_release'] == AT_RELEASE_IMMEDIATE) {
124                         echo _AT('release_immediate');
125                 } else if ($row['result_release'] == AT_RELEASE_MARKED) {
126                         echo _AT('release_marked');
127                 } else if ($row['result_release'] == AT_RELEASE_NEVER) {
128                         echo _AT('release_never');
129                 }
130         ?></td>
131         <td><?php
132                 //get # marked submissions
133                 $sql_sub = "SELECT COUNT(*) AS sub_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id'];
134                 $result_sub     = mysql_query($sql_sub, $db);
135                 $row_sub = mysql_fetch_assoc($result_sub);
136                 echo $row_sub['sub_cnt'].' '._AT('submissions').', ';
137
138                 //get # submissions
139                 $sql_sub = "SELECT COUNT(*) AS marked_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id']." AND final_score=''";
140                 $result_sub     = mysql_query($sql_sub, $db);
141                 $row_sub = mysql_fetch_assoc($result_sub);
142                 echo $row_sub['marked_cnt'].' '._AT('unmarked');
143                 ?>
144         </td>
145         <td><?php
146                 //get assigned groups
147                 $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'];
148                 $result_sub     = mysql_query($sql_sub, $db);
149                 if (mysql_num_rows($result_sub) == 0) {
150                         echo _AT('everyone');
151                 } else {
152                         $row_sub = mysql_fetch_assoc($result_sub);
153                         echo $row_sub['title'];
154                         do {
155                                 echo ', '.$row_sub['title'];
156                         } while ($row_sub = mysql_fetch_assoc($result_sub));
157                 }                               
158                 ?>
159         </td>
160 </tr>
161 <?php endwhile; ?>
162 </tbody>
163 </table>