(no commit message)
[atutor.git] / 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 <div class="row">
111         <?php
112         //Need radio button 'cause one checkbox makes the states indeterministic
113         //@harris
114         $test_export_y_checked = '';
115         $test_export_n_checked = '';
116         if ($_POST['allow_test_export'] == 1){
117                 $test_export_y_checked = ' checked="checked"';
118         } else {
119                 $test_export_n_checked = ' checked="checked"';
120         }
121         
122         echo _AT('allow_test_export');
123 ?>
124
125         <input type="radio" name="allow_test_export" id="allow_test_export" value="1" <?php echo $test_export_y_checked; ?>/>
126         <label for="allow_test_export"><?php echo _AT('yes'); ?></label>
127         <input type="radio" name="allow_test_export" id="disallow_test_export" value="0" <?php echo $test_export_n_checked; ?>/>
128         <label for="disallow_test_export"><?php echo _AT('no'); ?></label>
129 </div>
130
131
132 <div class="row">
133         <p><?php echo _AT('custom_test_message'); ?></p>
134         <textarea name="test_message"><?php echo $_POST['test_message']; ?></textarea>
135 </div>
136
137 <?php print_test_table($results, $_POST['tid']);?>
138
139 <?php 
140 // display pre-tests
141 $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$_REQUEST[cid] AND type='".CONTENT_PRE_TEST."'";
142 $result = mysql_query($sql, $db);
143 while ($row = mysql_fetch_assoc($result)) {
144         $_POST['pre_tid'][] = $row['item_id'];
145 }
146
147 ?>
148 <div class="row">
149         <span style="font-weight:bold"><?php echo _AT('define_pretest'); ?></span><br />
150         <small>&middot; <?php echo _AT('about_pretest'); ?></small><br />
151         <?php echo _AT('applies_to_all_sub_pages');?>
152 </div>
153
154 <?php print_test_table($results, $_POST['pre_tid'], 'pre_');?>
155
156 <?php function print_test_table($results, $post_tids, $id_prefix='') {?>
157         <div>
158         <table class="data" summary="" style="width: 90%" rules="cols">
159         <thead>
160         <tr>
161                 <th scope="col">&nbsp;</th>
162                 <th scope="col"><?php echo _AT('title');          ?></th>
163                 <th scope="col"><?php echo _AT('status');         ?></th>
164                 <th scope="col"><?php echo _AT('availability');   ?></th>
165                 <th scope="col"><?php echo _AT('result_release'); ?></th>
166                 <th scope="col"><?php echo _AT('submissions');    ?></th>
167                 <th scope="col"><?php echo _AT('pass_score');     ?></th>
168                 <th scope="col"><?php echo _AT('assigned_to');    ?></th>
169         </tr>
170         </thead>
171         <tbody>
172         <?php foreach ($results as $row) { ?>
173         <?php
174                 $checkMe = '';
175                 if (is_array($post_tids) && in_array($row['test_id'], $post_tids)){
176                         $checkMe = ' checked="checked"';
177                 } 
178         ?>
179         <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']; ?>">
180                 <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>
181                 <td><?php echo $row['title']; ?></td>
182                 <td><?php echo $row['status']; ?></td>
183                 <td><?php echo $row['availability']; ?></td>
184                 <td><?php echo $row['result_release']; ?></td>
185                 <td><?php echo $row['submissions']; ?></td>
186                 <td><?php echo $row['pass_score']; ?></td>
187                 <td><?php echo $row['assign_to']; ?></td>
188         </tr>
189         <?php } ?>
190         </tbody>
191         </table>
192         </div>
193         <br />
194 <?php }?>
195
196 <script language="javascript" type="text/javascript">
197         function toggleTestSelect(r_id){
198                 var row = document.getElementById(r_id);
199                 var checkBox = row.cells[0].firstChild;
200
201                 if (checkBox.checked == true){
202                         checkBox.checked = false;
203                 } else {
204                         checkBox.checked = true;
205                 }
206         }
207 </script>