moved code up one level to eliminate the docs subdirectory
[acontent.git] / home / editor / editor_tabs / tests.inc.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14 global $_course_id, $_content_id;
15
16 include_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
17 include_once(TR_INCLUDE_PATH.'classes/DAO/TestsDAO.class.php');
18 /* Get the list of associated tests with this content on page load */
19 $cid = $_REQUEST['cid'] = $_content_id; //uses request 'cause after 'saved', the cid will become $_GET.
20
21 $testsDAO = new TestsDAO();
22
23 $num_tests = 0;
24 $all_tests = $testsDAO->getByCourseID($_course_id);
25 /* get a list of all the tests we have, and links to create, edit, delete, preview */
26 //$sql  = "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue 
27 //             FROM ".TABLE_PREFIX."tests 
28 //            WHERE course_id=$_SESSION[course_id] 
29 //            ORDER BY start_date DESC";
30 //$result       = mysql_query($sql, $db);
31 if (is_array($all_tests)) $num_tests = count($all_tests);
32
33 //If there are no tests, don't display anything except a message
34 if ($num_tests == 0){
35         $msg->addInfo(array('NO_TESTS', TR_BASE_HREF.'tests/create_test.php?_course_id='.$_course_id));
36         $msg->printInfos();
37         return;
38 }
39 else {
40         $i = 0;
41         foreach ($all_tests as $row) {
42                 $results[$i]['test_id'] = $row['test_id'];
43                 $results[$i]['title'] = $row['title'];
44                         
45                 $i++;
46         }
47 }
48 ?>
49 <div class="row">
50         <span style="font-weight:bold"><?php echo _AT('about_content_tests', TR_BASE_HREF.'tests/create_test.php?_course_id='.$_course_id); ?></span>
51 </div>
52
53 <div class="row">
54         <p><?php echo _AT('custom_test_message'); ?></p>
55         <textarea name="test_message"><?php echo $_POST['test_message']; ?></textarea>
56 </div>
57
58 <?php 
59 if (is_array($results)) print_test_table($results, $_POST['tid']);
60
61 function print_test_table($results, $post_tids, $id_prefix='') {?>
62         <div>
63         <input type="hidden" name="visited_tests" value="1" />
64         <table class="data" summary="" style="width: 90%" rules="cols">
65         <thead>
66         <tr>
67                 <th scope="col">&nbsp;</th>
68                 <th scope="col"><?php echo _AT('title');          ?></th>
69         </tr>
70         </thead>
71         <tbody>
72         <?php if (is_array($results)) { ?>
73         <?php foreach ($results as $row) { ?>
74         <?php
75                 $checkMe = '';
76                 if (is_array($post_tids) && in_array($row['test_id'], $post_tids)){
77                         $checkMe = ' checked="checked"';
78                 } 
79         ?>
80         <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']; ?>">
81                 <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>
82                 <td><?php echo $row['title']; ?></td>
83         </tr>
84         <?php } ?>
85         <?php } ?>
86         </tbody>
87         </table>
88         </div>
89         <br />
90 <?php }?>
91
92 <script language="javascript" type="text/javascript">
93         function toggleTestSelect(r_id){
94                 var row = document.getElementById(r_id);
95                 var checkBox = row.cells[0].firstChild;
96
97                 if (checkBox.checked == true){
98                         checkBox.checked = false;
99                 } else {
100                         checkBox.checked = true;
101                 }
102         }
103 </script>