made a copy
[atutor.git] / include / html / tests_questions.inc.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                       */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg & Boon-Hau Teh */\r
6 /* Adaptive Technology Resource Centre / University of Toronto          */\r
7 /* http://atutor.ca                                                                                                     */\r
8 /*                                                                      */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                                        */\r
12 /************************************************************************/\r
13 // $Id$\r
14 \r
15 if (!defined('AT_INCLUDE_PATH')) { exit; }\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(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');\r
25 ?>\r
26 \r
27         <div class="input-form" style="width:42em;">\r
28         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('category'); ?></legend>\r
29         <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
30                 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />\r
31                 <div class="row">\r
32                         <label for="cats"><?php echo _AT('category'); ?></label><br />\r
33                         <select name="category_id" id="cats">\r
34                                 <option value="-1"><?php echo _AT('cats_all'); ?></option>\r
35                                 <?php print_question_cats($_GET['category_id']); ?>\r
36                         </select>\r
37                 </div>\r
38                 <div class="row buttons">\r
39                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />\r
40                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />\r
41                 </div>\r
42                 </form>\r
43 \r
44                 </fieldset>\r
45         </div>\r
46 \r
47 <?php\r
48 \r
49 $cats = array();\r
50 if ($_GET['category_id'] >= 0) {\r
51         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions_categories WHERE course_id=$_SESSION[course_id] AND category_id=$_GET[category_id] ORDER BY title";\r
52 } else {\r
53         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions_categories WHERE course_id=$_SESSION[course_id] ORDER BY title";\r
54 }\r
55 \r
56 $result = mysql_query($sql, $db);\r
57 if ($_GET['category_id'] <= 0) {\r
58         $cats[] = array('title' => _AT('cats_uncategorized'), 'category_id' => 0);\r
59 }\r
60 \r
61 while ($row = mysql_fetch_assoc($result)) {\r
62         $cats[] = $row;\r
63 }\r
64 \r
65         $cols = 3;\r
66 ?>\r
67 <?php if ($tid): ?>\r
68         <form method="post" action="tools/tests/add_test_questions_confirm.php" name="form">\r
69 <?php else: ?>\r
70         <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">\r
71 <?php endif; ?>\r
72 <table class="data" summary="" rules="cols">\r
73 <thead>\r
74 <tr>\r
75         <th scope="col">&nbsp;</th>\r
76         <th scope="col"><?php echo _AT('question'); ?></th>\r
77         <th scope="col"><?php echo _AT('type'); ?></th>\r
78 </tr>\r
79 </thead>\r
80 <tfoot>\r
81 <?php if ($tid): ?>\r
82         <tr>\r
83                 <td colspan="3">\r
84                         <input type="hidden" name="tid" value="<?php echo $tid; ?>" />\r
85                         <input type="submit" name="submit" value="<?php echo _AT('add_to_test_survey'); ?>" accesskey="s" />\r
86                         <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />\r
87                 </td>\r
88         </tr>\r
89 <?php else: ?>\r
90         <tr>\r
91                 <td colspan="3">\r
92                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> \r
93                         <input type="submit" name="preview" value="<?php echo _AT('preview'); ?>" />\r
94                         <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />\r
95                         <select name='qti_export_version' >\r
96                                 <option selected='selected' value='1.2.1'>QTI 1.2.1</option>\r
97                                 <option value='2.1'>QTI 2.1</option>\r
98                         </select>\r
99                         <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />\r
100                 </td>\r
101         </tr>\r
102 <?php endif; ?>\r
103 </tfoot>\r
104 <tbody>\r
105 <?php\r
106 \r
107 $question_flag = FALSE;\r
108 \r
109 //output categories\r
110 foreach ($cats as $cat) {\r
111         //ouput questions\r
112         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND category_id=".$cat['category_id']." ORDER BY question";\r
113         $result = mysql_query($sql, $db);\r
114         if ($row = mysql_fetch_assoc($result)) {\r
115                 $question_flag = TRUE;\r
116                 echo '<tr>';\r
117                 echo '<th colspan="'.$cols.'">';\r
118 \r
119                 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
120                 echo '</th>';\r
121                 echo '</tr>';\r
122 \r
123                 do {\r
124                         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
125                         echo '<td>';\r
126                         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
127                         echo '<td>';\r
128                         echo '<a title="'.htmlentities($row[question], ENT_QUOTES, 'UTF-8').'">';\r
129                         echo AT_PRINT(htmlentities(validate_length($row['question'], 100, VALIDATE_LENGTH_FOR_DISPLAY), ENT_QUOTES, 'UTF-8'), 'tests_questions.question');\r
130                         echo '</a>';\r
131                         echo '</td>';\r
132                         echo '<td>';\r
133                         $o = TestQuestions::getQuestion($row['type']);\r
134                         $o->printName();\r
135                                         \r
136                         echo '</td>';\r
137                         \r
138                         echo '</tr>';\r
139 \r
140                 } while ($row = mysql_fetch_assoc($result));\r
141         } \r
142 }  \r
143 if (!$question_flag) {\r
144         echo '<tr><td colspan="'.$cols.'">'._AT('none_found').'</td></tr>';\r
145 }\r
146 ?>\r
147 </tbody>\r
148 </table>\r
149 </form>\r
150 \r
151 <script language="javascript" type="text/javascript">\r
152 // <!--\r
153         function selectCat(catID, cat) {\r
154                 for (var i=0;i<document.form.elements.length;i++) {\r
155                         var e = document.form.elements[i];\r
156                         if ((e.name == 'questions[' + catID + '][]') && (e.type=='checkbox')) {\r
157                                 e.checked = cat.checked;\r
158                                 togglerowhighlight(document.getElementById("r" + e.id), e.id);\r
159                         }\r
160                 }\r
161         }\r
162         \r
163 function togglerowhighlight(obj, boxid) {\r
164         if (document.getElementById(boxid).checked) {\r
165                 obj.className = 'selected';\r
166         } else {\r
167                 obj.className = '';\r
168         }\r
169 }\r
170 // -->\r
171 </script>\r