2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\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
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
\r
16 require(AT_INCLUDE_PATH.'../mods/_core/cats_categories/lib/admin_categories.inc.php');
\r
18 if ($_POST['reset_filter']) { unset($_POST); }
\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
26 $sql_access = '<>-1';
\r
27 $_POST['access'] = '';
\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
35 $sql_category = '<>-1';
\r
36 $_POST['category'] = -1; // all (because 0 = uncategorized)
\r
39 if (isset($_POST['include']) && $_POST['include'] == 'one') {
\r
40 $checked_include_one = ' checked="checked"';
\r
41 $page_string .= SEP.'include=one';
\r
43 $_POST['include'] = 'all';
\r
44 $checked_include_all = ' checked="checked"';
\r
45 $page_string .= SEP.'include=all';
\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
53 if ($_POST['include'] == 'all') {
\r
54 $predicate = 'AND ';
\r
60 foreach ($search as $term) {
\r
61 $term = trim($term);
\r
62 $term = str_replace(array('%','_'), array('\%', '\_'), $term);
\r
64 $term = '%'.$term.'%';
\r
65 $sql_search .= "((title LIKE '$term') OR (description LIKE '$term')) $predicate";
\r
68 $sql_search = '('.substr($sql_search, 0, -strlen($predicate)).')';
\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
76 // calculate number of results found
\r
77 $num_results = mysql_num_rows($courses_result);
\r
79 while ($row = mysql_fetch_assoc($courses_result))
\r
80 if (in_array($row['course_id'], $existing_courses)) $num_results--;
\r
82 if ($num_results > 0) mysql_data_seek($courses_result, 0);
\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
88 select_categories(get_categories(), 0, $_POST['category'], false);
\r
89 $categories_select = ob_get_contents();
\r
92 $has_categories = false;
\r
93 if ($categories_select != '<option value="0"></option>') {
\r
94 $has_categories = true;
\r
98 <div class="input-form" style="width:95%;">
\r
100 <h4><?php echo _AT('results_found', $num_results); ?></h4>
\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
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
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
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
114 <?php if ($has_categories): ?>
\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
126 <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('title').', '._AT('description'); ?>)</label><br />
\r
128 <input type="text" name="search" id="search" size="40" value="<?php echo htmlspecialchars($_POST['search']); ?>" />
\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
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
141 <table summary="" class="data" rules="cols" style="width: 95%; margin:auto;">
\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
154 <div class="buttons" style="float:left">
\r
155 <input type="submit" name="add" value="<?php echo _AT('add'); ?>" />
\r
163 if ($num_results == 0)
\r
167 <td colspan="3"><?php echo _AT('none_found'); ?></td>
\r
171 else if ($row = mysql_fetch_assoc($courses_result))
\r
173 if (!in_array($row['course_id'], $existing_courses))
\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
183 } while ($row = mysql_fetch_assoc($courses_result));
\r
192 <br style="clear:both;" />
\r
195 <script language="JavaScript" type="text/javascript">
\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
208 function togglerowhighlight(obj, boxid) {
\r
209 if (document.getElementById(boxid).checked) {
\r
210 obj.className = 'selected';
\r
212 obj.className = '';
\r