PageRenderTime 28ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_core/courses/admin/auto_enroll_filter_courses.php

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