d94eb73c4976f97b5fa24f65b8e0a80f7f34e7b1
[atutor.git] / docs / mods / _core / courses / admin / auto_enroll_filter_courses.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\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 \r
14 if (!defined('AT_INCLUDE_PATH')) { exit; }\r
15 \r
16 require(AT_INCLUDE_PATH.'../mods/_core/cats_categories/lib/admin_categories.inc.php');\r
17 \r
18 if ($_POST['reset_filter']) { unset($_POST); }\r
19 \r
20 $page_string = '';\r
21 \r
22 if (isset($_POST['access']) && in_array($_POST['access'], array('public','private','protected'))) {\r
23         $page_string .= SEP.'access='.$_POST['access'];\r
24         $sql_access = "='{$_POST['access']}'";\r
25 } else {\r
26         $sql_access     = '<>-1';\r
27         $_POST['access'] = '';\r
28 }\r
29 \r
30 if (isset($_POST['category']) && ($_POST['category'] > -1)) {\r
31         $_POST['category'] = intval($_POST['category']);\r
32         $page_string .= SEP.'category='.$_POST['category'];\r
33         $sql_category = '='.$_POST['category'];\r
34 } else {\r
35         $sql_category     = '<>-1';\r
36         $_POST['category'] = -1; // all (because 0 = uncategorized)\r
37 }\r
38 \r
39 if (isset($_POST['include']) && $_POST['include'] == 'one') {\r
40         $checked_include_one = ' checked="checked"';\r
41         $page_string .= SEP.'include=one';\r
42 } else {\r
43         $_POST['include'] = 'all';\r
44         $checked_include_all = ' checked="checked"';\r
45         $page_string .= SEP.'include=all';\r
46 }\r
47 \r
48 if (!empty($_POST['search'])) {\r
49         $page_string .= SEP.'search='.urlencode($stripslashes($_POST['search']));\r
50         $search = $addslashes($_POST['search']);\r
51         $search = explode(' ', $search);\r
52 \r
53         if ($_POST['include'] == 'all') {\r
54                 $predicate = 'AND ';\r
55         } else {\r
56                 $predicate = 'OR ';\r
57         }\r
58 \r
59         $sql_search = '';\r
60         foreach ($search as $term) {\r
61                 $term = trim($term);\r
62                 $term = str_replace(array('%','_'), array('\%', '\_'), $term);\r
63                 if ($term) {\r
64                         $term = '%'.$term.'%';\r
65                         $sql_search .= "((title LIKE '$term') OR (description LIKE '$term')) $predicate";\r
66                 }\r
67         }\r
68         $sql_search = '('.substr($sql_search, 0, -strlen($predicate)).')';\r
69 } else {\r
70         $sql_search = '1';\r
71 }\r
72 \r
73 $sql    = "SELECT * FROM ".TABLE_PREFIX."courses WHERE access $sql_access AND cat_id $sql_category AND $sql_search AND hide=0 ORDER BY title";\r
74 $courses_result = mysql_query($sql, $db);\r
75 \r
76 // calculate number of results found\r
77 $num_results = mysql_num_rows($courses_result);\r
78 \r
79 while ($row = mysql_fetch_assoc($courses_result)) \r
80         if (in_array($row['course_id'], $existing_courses)) $num_results--;\r
81 \r
82 if ($num_results > 0) mysql_data_seek($courses_result, 0);\r
83 \r
84 // get the categories <select>, if there are any.\r
85 // we need ob_start/ob_clean, because select_categories() outputs directly.\r
86 // we do this so that if there are no categories, then the option doesn't appear.\r
87 ob_start();\r
88 select_categories(get_categories(), 0, $_POST['category'], false);\r
89 $categories_select = ob_get_contents();\r
90 ob_clean();\r
91 \r
92 $has_categories = false;\r
93 if ($categories_select != '<option value="0"></option>') {\r
94         $has_categories = true;\r
95 }\r
96 \r
97 ?>\r
98         <div class="input-form" style="width:95%;">\r
99                 <div class="row">\r
100                         <h4><?php echo _AT('results_found', $num_results); ?></h4>\r
101                 </div>\r
102 \r
103                 <div class="row">\r
104                         <?php echo _AT('access'); ?><br />\r
105                         <input type="radio" name="access" value="private" id="s1" <?php if ($_POST['access'] == 'private') { echo 'checked="checked"'; } ?> /><label for="s1"><?php echo _AT('private'); ?></label> \r
106 \r
107                         <input type="radio" name="access" value="protected" id="s2" <?php if ($_POST['access'] == 'protected') { echo 'checked="checked"'; } ?> /><label for="s2"><?php echo _AT('protected'); ?></label>\r
108 \r
109                         <input type="radio" name="access" value="public" id="s3" <?php if ($_POST['access'] == 'public') { echo 'checked="checked"'; } ?> /><label for="s3"><?php echo _AT('public'); ?></label>\r
110 \r
111                         <input type="radio" name="access" value="" id="s" <?php if ($_POST['access'] == '') { echo 'checked="checked"'; } ?> /><label for="s"><?php echo _AT('all'); ?></label>\r
112                 </div>\r
113 \r
114                 <?php if ($has_categories): ?>\r
115                 <div class="row">\r
116                         <label for="category"><?php echo _AT('category'); ?></label><br/>\r
117                         <select name="category" id="category">\r
118                                 <option value="-1">- - - <?php echo _AT('cats_all'); ?> - - -</option>\r
119                                 <option value="0" <?php if ($_POST['category'] == 0) { echo 'selected="selected"'; } ?>>- - - <?php echo _AT('cats_uncategorized'); ?> - - -</option>\r
120                                 <?php echo $categories_select; ?>\r
121                         </select>\r
122                 </div>\r
123                 <?php endif; ?>\r
124 \r
125                 <div class="row">\r
126                         <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('title').', '._AT('description'); ?>)</label><br />\r
127 \r
128                         <input type="text" name="search" id="search" size="40" value="<?php echo htmlspecialchars($_POST['search']); ?>" />\r
129                         <br/>\r
130                         <?php echo _AT('search_match'); ?>:\r
131                         <input type="radio" name="include" value="all" id="match_all" <?php echo $checked_include_all; ?> /><label for="match_all"><?php echo _AT('search_all_words'); ?></label> \r
132                         <input type="radio" name="include" value="one" id="match_one" <?php echo $checked_include_one; ?> /><label for="match_one"><?php echo _AT('search_any_word'); ?></label>\r
133                 </div>\r
134 \r
135                 <div class="row buttons">\r
136                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>"/>\r
137                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>"/>\r
138                 </div>\r
139 \r
140                 <div class="row">\r
141                 <table summary="" class="data" rules="cols" style="width: 95%; margin:auto;">\r
142                 \r
143                 <thead>\r
144                 <tr>\r
145                         <th scope="col"><input type="checkbox" value="<?php echo _AT('select_all'); ?>" id="all_add" title="<?php echo _AT('select_all'); ?>" name="selectall_add" onclick="CheckAll('add_ids[]', 'selectall_add');" /></th>\r
146                         <th scope="col"><?php echo _AT('title'); ?></th>\r
147                         <th scope="col"><?php echo _AT('category'); ?></th>\r
148                 </tr>\r
149                 </thead>\r
150 \r
151                 <tfoot>\r
152                 <tr>\r
153                         <td colspan="4">\r
154                                 <div class="buttons" style="float:left">\r
155                                 <input type="submit" name="add" value="<?php echo _AT('add'); ?>" /> \r
156                                 </div>\r
157                         </td>\r
158                 </tr>\r
159                 </tfoot>\r
160 \r
161                 <tbody>\r
162 <?php\r
163 if ($num_results == 0)\r
164 {\r
165 ?>\r
166                 <tr>\r
167                         <td colspan="3"><?php echo _AT('none_found'); ?></td>\r
168                 </tr>\r
169 <?php \r
170 }\r
171 else if ($row = mysql_fetch_assoc($courses_result)) \r
172         do {\r
173                 if (!in_array($row['course_id'], $existing_courses))\r
174                 {\r
175         ?>\r
176                 <tr onmousedown="document.form['a<?php echo $row['course_id']; ?>'].checked = !document.form['a<?php echo $row['course_id']; ?>'].checked; togglerowhighlight(this, 'a<?php echo $row['course_id']; ?>');" id="ra<?php echo $row['course_id']; ?>">\r
177                         <td width="10"><label for="ta<?php echo $row['course_id']; ?>"><input type="checkbox" name="add_ids[]" value="<?php echo $row['course_id']; ?>" id="a<?php echo $row['course_id']; ?>" onmouseup="this.checked=!this.checked" /></label></td>\r
178                         <td id="ta<?php echo $row['course_id']; ?>"><?php echo $row['title']; ?></td>\r
179                         <td><?php echo $cats[$row['cat_id']]; ?></td>\r
180                 </tr>\r
181         <?php \r
182                 }\r
183         } while ($row = mysql_fetch_assoc($courses_result)); \r
184 ?>\r
185                 </tbody>\r
186         </table>\r
187         </div>\r
188         \r
189         <div class="row">\r
190                 &nbsp;\r
191         </div>\r
192 <br style="clear:both;" />\r
193 </div>\r
194 \r
195 <script language="JavaScript" type="text/javascript">\r
196 //<!--\r
197 function CheckAll(element_name, selectall_name) {\r
198 //      alert(document.form.elements.length);\r
199         for (var i=0;i<document.form.elements.length;i++)       {\r
200                 var e = document.form.elements[i];\r
201                 if ((e.name == element_name) && (e.type=='checkbox')) {\r
202                         e.checked = eval("document.form." + selectall_name + ".checked");\r
203                         togglerowhighlight(document.getElementById("r" + e.id), e.id);\r
204                 }\r
205         }\r
206 }\r
207 \r
208 function togglerowhighlight(obj, boxid) {\r
209         if (document.getElementById(boxid).checked) {\r
210                 obj.className = 'selected';\r
211         } else {\r
212                 obj.className = '';\r
213         }\r
214 }\r
215 //-->\r
216 </script>\r