2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
12 if (!defined('AT_INCLUDE_PATH')) { exit; }
13 require(AT_INCLUDE_PATH.'../mods/_core/cats_categories/lib/admin_categories.inc.php');
16 $cats[0] = _AT('cats_uncategorized');
18 $sql = "SELECT cat_id, cat_name FROM ".TABLE_PREFIX."course_cats";
19 $result = mysql_query($sql,$db);
20 while($row = mysql_fetch_array($result)) {
21 $cats[$row['cat_id']] = $row['cat_name'];
24 if ($_GET['reset_filter']) { unset($_GET); }
28 if (isset($_GET['access']) && in_array($_GET['access'], array('public','private','protected'))) {
29 $page_string .= SEP.'access='.$_GET['access'];
30 $sql_access = "='{$_GET['access']}'";
36 if (isset($_GET['category']) && ($_GET['category'] > -1)) {
37 $_GET['category'] = intval($_GET['category']);
38 $page_string .= SEP.'category='.$_GET['category'];
39 $sql_category = '='.$_GET['category'];
41 $sql_category = '<>-1';
42 $_GET['category'] = -1; // all (because 0 = uncategorized)
45 if (isset($_GET['include']) && $_GET['include'] == 'one') {
46 $checked_include_one = ' checked="checked"';
47 $page_string .= SEP.'include=one';
49 $_GET['include'] = 'all';
50 $checked_include_all = ' checked="checked"';
51 $page_string .= SEP.'include=all';
54 if (!empty($_GET['search'])) {
55 $page_string .= SEP.'search='.urlencode($stripslashes($_GET['search']));
56 $search = $addslashes($_GET['search']);
57 $search = explode(' ', $search);
59 if ($_GET['include'] == 'all') {
66 foreach ($search as $term) {
68 $term = str_replace(array('%','_'), array('\%', '\_'), $term);
70 $term = '%'.$term.'%';
71 $sql_search .= "((title LIKE '$term') OR (description LIKE '$term')) $predicate";
74 $sql_search = '('.substr($sql_search, 0, -strlen($predicate)).')';
79 $sql = "SELECT COUNT(course_id) AS cnt FROM ".TABLE_PREFIX."courses WHERE access $sql_access AND cat_id $sql_category AND $sql_search AND hide=0";
80 $result = mysql_query($sql, $db);
81 $row = mysql_fetch_assoc($result);
82 $num_results = $row['cnt'];
84 $sql = "SELECT * FROM ".TABLE_PREFIX."courses WHERE access $sql_access AND cat_id $sql_category AND $sql_search AND hide=0 ORDER BY title";
85 $courses_result = mysql_query($sql, $db);
87 // add "enroll me" link if the user is not the course owner and is not enrolled
88 while ($row = mysql_fetch_assoc($courses_result)) {
89 if ($_SESSION['member_id'] > 0) {
90 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=".$row['course_id'];
91 $result = mysql_query($sql, $db);
93 if ($row['access'] == 'private') {
94 $enroll_link = '<a href="'.$_base_path.'users/private_enroll.php?course='.$row['course_id'].'">'. _AT('enroll_me').'</a>';
96 $enroll_link = '<a href="'.$_base_path.'enroll.php?course='.$row['course_id'].'">'. _AT('enroll_me').'</a>';
99 if (mysql_num_rows($result) == 0 && $_SESSION['member_id'] <> $row['member_id']) {
100 $row['enroll_link'] = $enroll_link;
101 } else if ($row['access'] == 'private') {
102 $enrollment_row = mysql_fetch_assoc($result);
103 if ($enrollment_row['approved'] == 'n') $row['enroll_link'] = $enroll_link;
106 $courses_rows[] = $row;
109 // get the categories <select>, if there are any.
110 // we need ob_start/ob_clean, because select_categories() outputs directly.
111 // we do this so that if there are no categories, then the option doesn't appear.
113 select_categories(get_categories(), 0, $_GET['category'], false);
114 $categories_select = ob_get_contents();
117 $has_categories = false;
118 if ($categories_select != '<option value="0"></option>') {
119 $has_categories = true;
122 if ($_SESSION['first_login']) {
123 $msg->addInfo(array('FIRST_PREFS', $_base_path.'users/pref_wizard/index.php'));
126 $savant->assign('cats', $cats);
127 $savant->assign('num_results', $num_results);
128 $savant->assign('has_categories', $has_categories);
129 $savant->assign('categories_select', $categories_select);
130 $savant->assign('checked_include_all', $checked_include_all);
131 $savant->assign('checked_include_one', $checked_include_one);
132 $savant->assign('courses_rows', $courses_rows);
134 $savant->display('users/browse.tmpl.php');