moved code up one level to eliminate the docs subdirectory
[acontent.git] / tests / html / tests_questions.inc.php
1 <?php\r
2 /************************************************************************/\r
3 /* AContent                                                             */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2010                                                   */\r
6 /* Inclusive Design Institute                                           */\r
7 /*                                                                      */\r
8 /* This program is free software. You can redistribute it and/or        */\r
9 /* modify it under the terms of the GNU General Public License          */\r
10 /* as published by the Free Software Foundation.                        */\r
11 /************************************************************************/\r
12 \r
13 if (!defined('TR_INCLUDE_PATH')) { exit; }\r
14 \r
15 global $_course_id;\r
16 \r
17 if (isset($_GET['reset_filter'])) {\r
18         unset($_GET['category_id']);\r
19 }\r
20 if (!isset($_GET['category_id'])) {\r
21         // Suppress warnings\r
22         $_GET['category_id'] = -1;\r
23 }\r
24 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');\r
25 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsCategoriesDAO.class.php');\r
26 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');\r
27 //require_once(TR_INCLUDE_PATH.'../tests/classes/TestsUtility.class.php');\r
28 \r
29 $testsQuestionsDAO = new TestsQuestionsDAO();\r
30 $testsQuestionsCategoriesDAO = new TestsQuestionsCategoriesDAO();\r
31 \r
32 $cats = array();\r
33 if ($_GET['category_id'] >= 0) {\r
34         $category_row = $testsQuestionsCategoriesDAO->get($_GET[category_id]);\r
35 } else {\r
36         $category_rows = $testsQuestionsCategoriesDAO->getByCourseID($_course_id);\r
37 }\r
38 \r
39 //$result       = mysql_query($sql, $db);\r
40 if ($_GET['category_id'] <= 0) {\r
41         $cats[] = array('title' => _AT('cats_uncategorized'), 'category_id' => 0);\r
42 }\r
43 \r
44 if (is_array($category_rows)) {\r
45         foreach ($category_rows as $row) $cats[] = $row;\r
46 }\r
47 else if (isset($category_row) && $category_row <> '') {\r
48         $cats[] = $category_row;\r
49 }\r
50 \r
51 $cols = 3;\r
52 ?>\r
53 \r
54 <?php if ($tid): ?>\r
55         <form method="post" action="tests/add_test_questions_confirm.php?_course_id=<?php echo $_course_id; ?>" name="form">\r
56 <?php else: ?>\r
57         <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">\r
58 <?php endif; ?>\r
59 <input type="hidden" name="_course_id" value="<?php echo $_course_id; ?>" />\r
60 <table class="data" summary="" rules="cols">\r
61 <thead>\r
62 <tr>\r
63         <th scope="col">&nbsp;</th>\r
64         <th scope="col"><?php echo _AT('question'); ?></th>\r
65         <th scope="col"><?php echo _AT('type'); ?></th>\r
66 </tr>\r
67 </thead>\r
68 <tfoot>\r
69 <?php if ($tid): ?>\r
70         <tr>\r
71                 <td colspan="3">\r
72                         <input type="hidden" name="tid" value="<?php echo $tid; ?>" />\r
73                         <input type="submit" name="submit" value="<?php echo _AT('add_to_test_survey'); ?>" accesskey="s" />\r
74                         <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />\r
75                 </td>\r
76         </tr>\r
77 <?php else: ?>\r
78         <tr>\r
79                 <td colspan="3">\r
80                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> \r
81                         <input type="submit" name="preview" value="<?php echo _AT('preview'); ?>" />\r
82                         <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />\r
83                         <select name='qti_export_version' >\r
84                                 <option selected='selected' value='1.2.1'>QTI 1.2.1</option>\r
85                                 <option value='2.1'>QTI 2.1</option>\r
86                         </select>\r
87                         <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />\r
88                 </td>\r
89         </tr>\r
90 <?php endif; ?>\r
91 </tfoot>\r
92 <tbody>\r
93 <?php\r
94 \r
95 $question_flag = FALSE;\r
96 \r
97 //output categories\r
98 foreach ($cats as $cat) {\r
99         //ouput questions\r
100         $rows = $testsQuestionsDAO->getByCourseIDAndCategoryID($_course_id, $cat['category_id']);\r
101         if (is_array($rows)) {\r
102                 $question_flag = TRUE;\r
103                 echo '<tr>';\r
104                 echo '<th colspan="'.$cols.'">';\r
105 \r
106                 echo '<input type="checkbox" name="cat'.$cat['category_id'].'" id="cat'.$cat['category_id'].'" onclick="javascript:selectCat('.$cat['category_id'].', this);" /><label for="cat'.$cat['category_id'].'">'.$cat['title'].'</label>';\r
107                 echo '</th>';\r
108                 echo '</tr>';\r
109 \r
110                 foreach ($rows as $row) {\r
111                         echo '<tr onmousedown="document.form[\'q' . $row['question_id'] . '\'].checked = !document.form[\'q' . $row['question_id'] . '\'].checked; togglerowhighlight(this, \'q'.$row['question_id'].'\');" id="rq'.$row['question_id'].'">';\r
112                         echo '<td>';\r
113                         echo '<input type="checkbox" value="'.$row['question_id'].'|'.$row['type'].'" name="questions['.$cat['category_id'].'][]" id="q'.$row['question_id'].'" onmouseup="this.checked=!this.checked" /></td>';\r
114                         echo '<td>';\r
115                         echo '<a title="'.htmlentities_utf8($row[question], ENT_QUOTES, 'UTF-8').'">';\r
116                         echo AT_print(htmlentities_utf8(Utility::validateLength($row['question'], 100, 1), ENT_QUOTES, 'UTF-8'), 'tests_questions.question');\r
117                         echo '</a>';\r
118                         echo '</td>';\r
119                         echo '<td>';\r
120                         $o = TestQuestions::getQuestion($row['type']);\r
121                         $o->printName();\r
122                                         \r
123                         echo '</td>';\r
124                         \r
125                         echo '</tr>';\r
126                 }\r
127         } \r
128 }  \r
129 if (!$question_flag) {\r
130         echo '<tr><td colspan="'.$cols.'">'._AT('none_found').'</td></tr>';\r
131 }\r
132 ?>\r
133 </tbody>\r
134 </table>\r
135 </form>\r
136 \r
137 <script language="javascript" type="text/javascript">\r
138 // <!--\r
139         function selectCat(catID, cat) {\r
140                 for (var i=0;i<document.form.elements.length;i++) {\r
141                         var e = document.form.elements[i];\r
142                         if ((e.name == 'questions[' + catID + '][]') && (e.type=='checkbox')) {\r
143                                 e.checked = cat.checked;\r
144                                 togglerowhighlight(document.getElementById("r" + e.id), e.id);\r
145                         }\r
146                 }\r
147         }\r
148         \r
149 function togglerowhighlight(obj, boxid) {\r
150         if (document.getElementById(boxid).checked) {\r
151                 obj.className = 'selected';\r
152         } else {\r
153                 obj.className = '';\r
154         }\r
155 }\r
156 // -->\r
157 </script>\r