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
15 // NOTE! please see include/lib/search.inc.php NOTE!
\r
17 //initialize variables
\r
18 $checked_include_one = '';
\r
19 $checked_include_all = '';
\r
20 $checked_find_in_course = '';
\r
21 $checked_find_in_my_courses = '';
\r
22 $checked_find_in_all_courses = '';
\r
23 $checked_sw_all = '';
\r
24 $checked_sw_content = '';
\r
25 $checked_sw_forums = '';
\r
26 $checked_display_as_courses = '';
\r
27 $checked_display_as_pages = '';
\r
28 $checked_display_as_summaries = '';
\r
30 /* some error checking can go here: */
\r
31 if (isset($_GET['search'])) {
\r
32 $_GET['words'] = stripslashes($addslashes($_GET['words']));
\r
33 $_GET['words'] = str_replace(array('"', '\''), '', $_GET['words']);
\r
34 if ($_GET['include'] == 'all') {
\r
35 $checked_include_all = ' checked="checked"';
\r
37 $_GET['include'] = 'one';
\r
39 $checked_include_one = ' checked="checked"';
\r
42 if ($_GET['find_in'] == 'this') {
\r
43 $checked_find_in_course = ' checked="checked"';
\r
44 } else if ($_GET['find_in'] == 'my') {
\r
45 $checked_find_in_my_courses = ' checked="checked"';
\r
47 $_GET['find_in'] = 'all';
\r
49 $checked_find_in_all_courses = ' checked="checked"';
\r
52 if ($_GET['display_as'] == 'pages') {
\r
53 $checked_display_as_pages = ' checked="checked"';
\r
54 } else if ($_GET['display_as'] == 'courses') {
\r
55 $checked_display_as_courses = ' checked="checked"';
\r
57 $_GET['display_as'] = 'summaries';
\r
59 $checked_display_as_summaries = ' checked="checked"';
\r
62 // search within options
\r
63 if ($_GET['search_within']=='content'){
\r
64 $checked_sw_content = ' checked="checked"';
\r
65 } elseif ($_GET['search_within']=='forums') {
\r
66 $checked_sw_forums = ' checked="checked"';
\r
68 $checked_sw_all = ' checked="checked"';
\r
73 $checked_include_all = ' checked="checked"';
\r
74 $checked_sw_all = ' checked="checked"';
\r
76 if ($_SESSION['course_id'] > 0) {
\r
77 $checked_find_in_course = ' checked="checked"';
\r
78 $checked_display_as_pages = ' checked="checked"';
\r
79 } else if ($_SESSION['valid_user']) {
\r
80 $checked_find_in_my_courses = ' checked="checked"';
\r
81 $checked_display_as_courses = ' checked="checked"';
\r
83 $checked_find_in_all_courses = ' checked="checked"';
\r
84 $checked_display_as_summaries = ' checked="checked"';
\r
87 if (isset($_GET['search']) && !$_GET['words']) {
\r
88 $msg->printErrors('SEARCH_TERM_REQUIRED');
\r
94 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>#search_results" name="form">
\r
95 <input type="hidden" name="search" value="1" />
\r
96 <div class="input-form">
\r
98 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="keywords"><?php echo _AT('search_words'); ?></label><br />
\r
99 <input type="text" name="words" size="30" id="keywords" value="<?php echo $_GET['words']; ?>" />
\r
103 <?php echo _AT('search_match'); ?><br />
\r
104 <input type="radio" name="include" value="all" id="all" <?php echo $checked_include_all; ?> /><label for="all"><?php echo _AT('search_all_words'); ?></label><br />
\r
105 <input type="radio" name="include" value="one" id="one" <?php echo $checked_include_one; ?> /><label for="one"><?php echo _AT('search_any_word'); ?></label>
\r
109 <?php echo _AT('find_results_in'); ?><br />
\r
110 <?php if ($_SESSION['course_id'] > 0) : ?>
\r
111 <input type="radio" name="find_in" value="this" id="f1" <?php echo $checked_find_in_course; ?> /><label for="f1"><?php echo _AT('this_course_only'); ?></label><br />
\r
114 <?php if ($_SESSION['valid_user'] && ($_SESSION['course_id'] > -1)) : ?>
\r
115 <input type="radio" name="find_in" value="my" id="f2" <?php echo $checked_find_in_my_courses; ?> /><label for="f2"><?php echo _AT('my_enrolled_courses'); ?></label><br />
\r
118 <input type="radio" name="find_in" value="all" id="f3" <?php echo $checked_find_in_all_courses; ?> /><label for="f3"><?php echo _AT('all_available_courses'); ?></label>
\r
122 <?php echo _AT('search_in'); ?><br />
\r
123 <input type="radio" name="search_within" value="all" id="sw_all" <?php echo $checked_sw_all; ?> /><label for="sw_all"><?php echo _AT('all'); ?></label>
\r
124 <input type="radio" name="search_within" value="content" id="sw_content" <?php echo $checked_sw_content; ?> /><label for="sw_content"><?php echo _AT('content'); ?></label>
\r
125 <input type="radio" name="search_within" value="forums" id="sw_forums" <?php echo $checked_sw_forums; ?> /><label for="sw_forums"><?php echo _AT('forums'); ?></label>
\r
129 <?php echo _AT('display'); ?><br />
\r
130 <input type="radio" name="display_as" value="pages" id="d1" <?php echo $checked_display_as_pages; ?> /><label for="d1"><?php echo _AT('as_individual_content'); ?></label><br />
\r
132 <input type="radio" name="display_as" value="courses" id="d2" <?php echo $checked_display_as_courses; ?> /><label for="d2"><?php echo _AT('grouped_by_course'); ?></label><br />
\r
134 <input type="radio" name="display_as" value="summaries" id="d3" <?php echo $checked_display_as_summaries; ?> /><label for="d3"><?php echo _AT('course_summaries'); ?></label><br /><br />
\r
137 <div class="row buttons">
\r
138 <input type="submit" name="search" value="<?php echo _AT('search'); ?>" />
\r
145 /* search results go down here: */
\r
146 if (isset($_GET['search']) && isset($_GET['words'])) {
\r
147 $search_results = array(); // the content search results
\r
148 $search_totals = array(); // total score per course
\r
149 $num_found = 0; // total results found
\r
150 $total_score = 0; // total score (temporary per course)
\r
151 $results_per_page = 10; // number of results per page
\r
152 $highlight_system_courses = $system_courses;
\r
154 if ($_GET['include'] == 'all') {
\r
155 $predicate = 'AND';
\r
160 if (($_GET['find_in'] == 'this') && ($_SESSION['course_id'] > 0)) {
\r
161 if ($_GET['display_as'] == 'pages') {
\r
162 $search_results = get_search_result($_GET['words'], $predicate, $_SESSION['course_id'], $num_found, $total_score);
\r
163 } else { // 'courses' or 'summaries' :
\r
164 $search_results[$_SESSION['course_id']] = get_search_result($_GET['words'], $predicate, $_SESSION['course_id'], $num_found, $total_score);
\r
165 $search_totals[$_SESSION['course_id']] = $total_score;
\r
168 if ($_GET['find_in'] == 'my') {
\r
169 $my_courses = get_my_courses($_SESSION['member_id']);
\r
170 } else { // $_GET['find_in'] == 'all' (or other). always safe to perform.
\r
171 $my_courses = get_all_courses($_SESSION['member_id']);
\r
174 foreach ($my_courses as $tmp_course_id) {
\r
175 if ($_GET['display_as'] == 'pages') {
\r
176 // merge all the content results together
\r
177 $search_results = array_merge($search_results, get_search_result($_GET['words'], $predicate, $tmp_course_id, $num_found, $total_score));
\r
181 $search_results[$tmp_course_id] = get_search_result($_GET['words'], $predicate, $tmp_course_id, $num_found, $total_score);
\r
182 if ($total_score) {
\r
183 $search_totals[$tmp_course_id] = $total_score;
\r
184 } // else: no content found in this course.
\r
189 if ($_GET['display_as'] == 'summaries') {
\r
190 $num_found = count($search_totals);
\r
193 echo '<a name="search_results"></a><h3>'.$num_found.' '._AT('search_results').'</h3>';
\r
196 $msg->printInfos('NO_SEARCH_RESULTS');
\r
197 require(AT_INCLUDE_PATH.'footer.inc.php');
\r
199 } else if (!$num_found && count($search_totals)) {
\r
200 // meaning: no pages were found, just courses:
\r
201 $num_found = count($search_totals);
\r
204 $num_pages = ceil($num_found / $results_per_page);
\r
206 $page = isset($_GET['p']) ? intval($_GET['p']) : 0;
\r
211 $count = (($page-1) * $results_per_page) + 1;
\r
213 $pages_text = '<div class="paging">';
\r
214 $pages_text .= '<ul>';
\r
215 for ($i=1; $i<=$num_pages; $i++) {
\r
216 $pages_text .= '<li>';
\r
218 $pages_text .= '<a class="current" href="'.$_SERVER['PHP_SELF'].'?search=1'.SEP.'words='.urlencode($_GET['words']).SEP.'include='.$_GET['include'].SEP.'find_in='.$_GET['find_in'].SEP.'search_within='.$_GET['search_within'].SEP.'display_as='.$_GET['display_as'].SEP.'p='.$i.'#search_results"><strong>'.$i.'</strong></a>';
\r
220 $pages_text .= '<a href="'.$_SERVER['PHP_SELF'].'?search=1'.SEP.'words='.urlencode($_GET['words']).SEP.'include='.$_GET['include'].SEP.'find_in='.$_GET['find_in'].SEP.'search_within='.$_GET['search_within'].SEP.'display_as='.$_GET['display_as'].SEP.'p='.$i.'#search_results">'.$i.'</a>';
\r
222 $pages_text .= '</li>';
\r
224 $pages_text .= '</ul>';
\r
225 $pages_text .= '</div>';
\r
229 if ($_GET['display_as'] == 'pages') {
\r
230 uasort($search_results, 'score_cmp');
\r
232 $search_results = array_slice($search_results, ($page-1)*$results_per_page, $results_per_page);
\r
234 echo '<div class="results">';
\r
235 print_search_pages($search_results);
\r
236 echo '</div>'."\n";
\r
238 arsort($search_totals);
\r
239 reset($search_totals);
\r
241 $skipped = 0; // number that have been skipped
\r
242 $printed_so_far = 0; // number printed on this page
\r
244 foreach ($search_totals as $tmp_course_id => $score) {
\r
246 if ($printed_so_far == $results_per_page) {
\r
250 $increment_count = false;
\r
251 if (count($search_results[$tmp_course_id]) && ($_GET['display_as'] == 'courses')) {
\r
252 uasort($search_results[$tmp_course_id], 'score_cmp');
\r
253 reset($search_results[$tmp_course_id]);
\r
255 $num_available = count($search_results[$tmp_course_id]); // total number available for this course
\r
257 if ($printed_so_far == $results_per_page) {
\r
261 if ($skipped < $count) {
\r
262 // this course is being truncated
\r
263 // implies that it's at the start of the page
\r
264 $start = ($page -1) * $results_per_page - $skipped;
\r
266 $total_here = count($search_results[$tmp_course_id]);
\r
268 $search_results[$tmp_course_id] = array_slice($search_results[$tmp_course_id], $start, $results_per_page - $printed_so_far);
\r
270 $num_printing = count($search_results[$tmp_course_id]);
\r
272 $printed_so_far += $num_printing;
\r
273 $skipped += ($num_available - $num_printing);
\r
275 if ($num_printing == 0) {
\r
278 $increment_count = true;
\r
281 if ($printed_so_far == $results_per_page) {
\r
285 $total_here = count($search_results[$tmp_course_id]);
\r
286 if (($total_here == 0) || ($_GET['display_as'] == 'summaries')) {
\r
287 if ($skipped < ($page-1) * $results_per_page) {
\r
291 $printed_so_far ++;
\r
292 $increment_count = true;
\r
294 $printed_so_far += $total_here;
\r
297 echo '<h5 class="search-results"> '._AT('results_from', '<a href="bounce.php?course='.$tmp_course_id.'">'.$highlight_system_courses[$tmp_course_id]['title'] .'</a>').' - '._AT('pages_found', $total_here) . '</h5>';
\r
300 echo '<p class="search-description">';
\r
301 if ($highlight_system_courses[$tmp_course_id]['description']) {
\r
302 echo $highlight_system_courses[$tmp_course_id]['description'];
\r
304 echo '<strong>'._AT('no_description').'</strong>';
\r
307 echo '<br /><small class="search-info">[<strong>'._AT('Access').':</strong> ';
\r
309 switch ($highlight_system_courses[$tmp_course_id]['access']){
\r
311 echo _AT('public');
\r
314 echo _AT('protected');
\r
317 echo _AT('private');
\r
320 $language =& $languageManager->getLanguage($highlight_system_courses[$tmp_course_id]['primary_language']);
\r
322 echo '. <strong>'._AT('primary_language').':</strong> ' . $language->getTranslatedName();
\r
328 if ($_GET['display_as'] != 'summaries') {
\r
329 echo '<div class="results">';
\r
330 print_search_pages($search_results[$tmp_course_id]);
\r