remove old readme
[atutor.git] / docs / mods / _core / editor / editor_tabs / tests.inc.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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 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 $sql    = "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue 
29              FROM ".TABLE_PREFIX."tests 
30             WHERE course_id=$_SESSION[course_id] 
31             ORDER BY start_date DESC";
32 $result = mysql_query($sql, $db);
33 $num_tests = mysql_num_rows($result);
34
35 //If there are no tests, don't display anything except a message
36 if ($num_tests == 0){
37         $msg->addInfo('NO_TESTS');
38         $msg->printInfos();
39         return;
40 }
41
42 $i = 0;
43 while($row = mysql_fetch_assoc($result))
44 {
45         $results[$i]['test_id'] = $row['test_id'];
46         $results[$i]['title'] = $row['title'];
47         
48         if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
49                 $results[$i]['status'] = '<strong>'._AT('ongoing').'</strong>';
50         } else if ($row['ue'] < time() ) {
51                 $results[$i]['status'] = '<strong>'._AT('expired').'</strong>';
52         } else if ($row['us'] > time() ) {
53                 $results[$i]['status'] = '<strong>'._AT('pending').'</strong>';
54         } 
55
56         $startend_date_format=_AT('startend_date_format'); 
57
58         $results[$i]['availability'] = AT_date($startend_date_format, $row['start_date'], AT_DATE_MYSQL_DATETIME). ' ' ._AT('to_2').' ';
59         $results[$i]['availability'] .= AT_date($startend_date_format, $row['end_date'], AT_DATE_MYSQL_DATETIME);
60         
61         // get result release
62         if ($row['result_release'] == AT_RELEASE_IMMEDIATE)
63                 $results[$i]['result_release'] = _AT('release_immediate');
64         else if ($row['result_release'] == AT_RELEASE_MARKED)
65                 $results[$i]['result_release'] = _AT('release_marked');
66         else if ($row['result_release'] == AT_RELEASE_NEVER)
67                 $results[$i]['result_release'] = _AT('release_never');
68                 
69         //get # marked submissions
70         $sql_sub = "SELECT COUNT(*) AS sub_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id'];
71         $result_sub     = mysql_query($sql_sub, $db);
72         $row_sub = mysql_fetch_assoc($result_sub);
73         $results[$i]['submissions'] = $row_sub['sub_cnt'].' '._AT('submissions').', ';
74
75         //get # submissions
76         $sql_sub = "SELECT COUNT(*) AS marked_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id']." AND final_score=''";
77         $result_sub     = mysql_query($sql_sub, $db);
78         $row_sub = mysql_fetch_assoc($result_sub);
79         $results[$i]['submissions'] .= $row_sub['marked_cnt'].' '._AT('unmarked');
80
81         //get assigned groups
82         $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'];
83         $result_sub     = mysql_query($sql_sub, $db);
84         if (mysql_num_rows($result_sub) == 0) {
85                 $results[$i]['assign_to'] = _AT('everyone');
86         } else {
87                 $row_sub = mysql_fetch_assoc($result_sub);
88                 $results[$i]['assign_to'] = $row_sub['title'];
89                 do {
90                         $results[$i]['assign_to'] .= ', '.$row_sub['title'];
91                 } while ($row_sub = mysql_fetch_assoc($result_sub));
92         }
93         
94         if ($row['passscore'] == 0 && $row['passpercent'] == 0)
95                 $results[$i]['pass_score'] = _AT('no_pass_score');
96         else if ($row['passscore'] <> 0)
97                 $results[$i]['pass_score'] = $row['passscore'];
98         else if ($row['passpercent'] <> 0)
99                 $results[$i]['pass_score'] = $row['passpercent'].'%';
100                 
101         $i++;
102 }
103 ?>
104
105
106 <div class="row">
107         <span style="font-weight:bold"><?php echo _AT('about_content_tests'); ?></span>
108 </div>
109
110 <input type="hidden" name="allow_test_export" id="disallow_test_export" value="0"/>
111
112 <!-- <div class="row">
113 This option has been commented out for the timebeing until the ability to export and view 
114 tests a part of a CP or CP is actually possible
115
116         <?php
117         //Need radio button 'cause one checkbox makes the states indeterministic
118         //@harris
119 /*
120         $test_export_y_checked = '';
121         $test_export_n_checked = '';
122         if ($_POST['allow_test_export'] == 1){
123                 $test_export_y_checked = ' checked="checked"';
124         } else {
125                 $test_export_n_checked = ' checked="checked"';
126         }
127         
128         echo _AT('allow_test_export');
129 */
130 ?>
131
132         <input type="radio" name="allow_test_export" id="allow_test_export" value="1" <?php //echo $test_export_y_checked; ?>/>
133         <label for="allow_test_export"><?php //echo _AT('yes'); ?></label>
134         <input type="radio" name="allow_test_export" id="disallow_test_export" value="0" <?php //echo $test_export_n_checked; ?>/>
135         <label for="disallow_test_export"><?php //echo _AT('no'); ?></label>
136 </div>
137 -->
138
139 <div class="row">
140         <p><?php echo _AT('custom_test_message'); ?></p>
141         <textarea name="test_message"><?php echo $_POST['test_message']; ?></textarea>
142 </div>
143
144 <?php print_test_table($results, $_POST['tid']);?>
145
146 <?php 
147 // display pre-tests
148 $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$_REQUEST[cid] AND type='".CONTENT_PRE_TEST."'";
149 $result = mysql_query($sql, $db);
150 while ($row = mysql_fetch_assoc($result)) {
151         $_POST['pre_tid'][] = $row['item_id'];
152 }
153
154 ?>
155 <div class="row">
156         <span style="font-weight:bold"><?php echo _AT('define_pretest'); ?></span><br />
157         <small>&middot; <?php echo _AT('about_pretest'); ?></small><br />
158         <?php echo _AT('applies_to_all_sub_pages');?>
159 </div>
160
161 <?php print_test_table($results, $_POST['pre_tid'], 'pre_');?>
162
163 <?php function print_test_table($results, $post_tids, $id_prefix='') {?>
164         <div>
165         <table class="data" summary="" style="width: 90%" rules="cols">
166         <thead>
167         <tr>
168                 <th scope="col">&nbsp;</th>
169                 <th scope="col"><?php echo _AT('title');          ?></th>
170                 <th scope="col"><?php echo _AT('status');         ?></th>
171                 <th scope="col"><?php echo _AT('availability');   ?></th>
172                 <th scope="col"><?php echo _AT('result_release'); ?></th>
173                 <th scope="col"><?php echo _AT('submissions');    ?></th>
174                 <th scope="col"><?php echo _AT('pass_score');     ?></th>
175                 <th scope="col"><?php echo _AT('assigned_to');    ?></th>
176         </tr>
177         </thead>
178         <tbody>
179         <?php foreach ($results as $row) { ?>
180         <?php
181                 $checkMe = '';
182                 if (is_array($post_tids) && in_array($row['test_id'], $post_tids)){
183                         $checkMe = ' checked="checked"';
184                 } 
185         ?>
186         <tr onmousedown="toggleTestSelect('<?php echo $id_prefix; ?>r_<?php echo $row['test_id']; ?>');rowselect(this);" id="<?php echo $id_prefix; ?>r_<?php echo $row['test_id']; ?>">
187                 <td><input type="checkbox" name="<?php echo $id_prefix; ?>tid[]" value="<?php echo $row['test_id']; ?>" id="<?php echo $id_prefix; ?>t<?php echo $row['test_id']; ?>" <?php echo $checkMe; ?> onmouseup="this.checked=!this.checked" /></td>
188                 <td><?php echo $row['title']; ?></td>
189                 <td><?php echo $row['status']; ?></td>
190                 <td><?php echo $row['availability']; ?></td>
191                 <td><?php echo $row['result_release']; ?></td>
192                 <td><?php echo $row['submissions']; ?></td>
193                 <td><?php echo $row['pass_score']; ?></td>
194                 <td><?php echo $row['assign_to']; ?></td>
195         </tr>
196         <?php } ?>
197         </tbody>
198         </table>
199         </div>
200         <br />
201 <?php }?>
202
203 <script language="javascript" type="text/javascript">
204         function toggleTestSelect(r_id){
205                 var row = document.getElementById(r_id);
206                 var checkBox = row.cells[0].firstChild;
207
208                 if (checkBox.checked == true){
209                         checkBox.checked = false;
210                 } else {
211                         checkBox.checked = true;
212                 }
213         }
214 </script>