Codechange: Klassen im Tabellenkopf eingefügt und via CSS dazugehörige Breitenangaben...
[wmmkf.git] / search.php
blob546f6d3cc8acc77d6550c2654c5dc326909950cd
1 <?php
2 ###############################################################################
3 # my little forum #
4 # Copyright (C) 2005 Alex #
5 # http://www.mylittlehomepage.net/ #
6 # #
7 # This program is free software; you can redistribute it and/or #
8 # modify it under the terms of the GNU General Public License #
9 # as published by the Free Software Foundation; either version 2 #
10 # of the License, or (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program; if not, write to the Free Software #
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
20 ###############################################################################
22 include("inc.php");
23 include_once("functions/include.prepare.php");
26 // Seiten-Navigation für suche.php
27 function snav($page, $suchergebnisse, $count, $search, $ao, $category) {
28 global $lang;
30 $output = '';
31 if ($count > $suchergebnisse)
33 $new_index_before = $page - 1;
34 $new_index_after = $page + 1;
35 $site_count = ceil($count / $suchergebnisse);
36 if ($new_index_before >= 0)
38 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?search='.$search;
39 $output .= '&amp;category='.$category.'&amp;ao='.$ao.'&amp;page='.$new_index_before;
40 $output .= '" title="'.outputLangDebugInAttributes($lang['previous_page_linktitle']).'"><b>&laquo;</b></a>&nbsp;';
43 if ($page == 3)
45 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?search='.$search;
46 $output .= '&amp;category='.$category.'&amp;ao='.$ao.'&amp;page=0"><b>1</b></a>&nbsp;';
48 else if ($page > 3)
50 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?search='.$search;
51 $output .= '&amp;category='.$category.'&amp;ao='.$ao.'&amp;page=0">';
52 $output .= '<b>1</b></a>&nbsp;<b>...</b>&nbsp;';
55 for ($i = 0; $i < $site_count; $i++)
57 $pagen_nr = $i;
58 if ($page == $pagen_nr or $page == $pagen_nr-1 or $page == $pagen_nr+1 or $page == $pagen_nr-2 or $page == $pagen_nr+2)
60 if ($page != $pagen_nr)
62 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?search='.$search;
63 $output .= '&amp;category='.$category.'&amp;ao='.$ao.'&amp;page=';
64 $output .= $pagen_nr.'"><b>'.($pagen_nr+1).'</b></a>&nbsp;';
66 else
68 $output .= '<span style="color: red; font-weight: bold;"><b>'.($pagen_nr+1).'</b></span>&nbsp;';
73 if ($new_index_after < $site_count)
75 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?search='.$search;
76 $output .= '&amp;category='.$category.'&amp;ao='.$ao.'&amp;page='.$new_index_after;
77 $output .= '" title="'.outputLangDebugInAttributes($lang['next_page_linktitle']).'"><b>&raquo;</b></a>';
80 return $output;
81 } # End: snav
85 function pnav($page, $how_many_per_page, $count, $show_postings) {
86 global $lang;
88 $output = '';
89 if ($count > $how_many_per_page)
91 if (($page-1) >= 0)
93 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?show_postings='.$show_postings;
94 $output .= '&amp;page='.($page-1).'" title="'.outputLangDebugInAttributes($lang['previous_page_linktitle']);
95 $output .= '"><b>&laquo;</b></a>&nbsp;';
97 $page_count = ceil($count/$how_many_per_page);
99 if (($page+1) == 1)
101 $output .= '<span style="color: red; font-weight: bold;">1</span>&nbsp;';
103 else
105 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?show_postings=';
106 $output .= $show_postings.'&amp;page=0"><b>1</b></a>&nbsp;';
109 for ($x=$page; $x<$page+4; $x++)
111 if ($x > 1 && $x <= $page_count)
113 if ($x == $page+1)
115 $output .= '<span style="color: red; font-weight: bold;">'.$x.'</span>&nbsp;';
117 else
119 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?show_postings=';
120 $output .= $show_postings.'&amp;page='.($x-1).'"><b>'.$x.'</b></a>&nbsp;';
124 if (($page+1) < $page_count)
126 $output .= '<a href="'.$_SERVER["SCRIPT_NAME"].'?show_postings=';
127 $output .= $show_postings.'&amp;page='.($page+1).'" title="';
128 $output .= outputLangDebugInAttributes($lang['next_page_linktitle']).'"><b>&raquo;</b></a>';
131 return $output;
132 } # End: pnav
134 if ($settings['access_for_users_only'] == 1 && !isset($_SESSION[$settings['session_prefix'].'user_id']))
136 header("location: ".$settings['forum_address']."login.php?msg=noaccess");
137 die("<a href=\"login.php?msg=noaccess\">further...</a>");
140 $page = !empty($_GET['page']) ? intval($_GET['page']) : 0;
141 $search = !empty($_GET['search']) ? $_GET['search'] : '';
142 $ao = !empty($_GET['ao']) ? $_GET['ao'] : 'and';
143 $show_postings = (!empty($_GET['show_postings'])) ? intval($_GET['show_postings']) : '';
145 $ul = $page * $settings['search_results_per_page'];
147 unset($entrydata);
149 if (substr($search, 1, 1) == "\"") $ao="phrase";
151 $search = str_replace("\"", "", $search);
152 #$search = stripslashes($search);
153 $search = trim($search);
154 $search = mysql_real_escape_string($search);
155 $search_array = explode(" ", $search);
156 $search_anz = str_replace(" ", ", ", $search);
158 $search_category = (isset($category) and $category != 0) ? " AND category='".mysql_real_escape_string($category)."'" : "";
160 if ($ao == "or")
162 $search_string = "concat(subject, name, place, text, email, hp) LIKE '%".implode("%' OR concat(subject, name, place, text, email, hp) LIKE '%",$search_array)."%'".$search_category;
164 else if ($ao == "phrase")
166 $search_string = "concat(subject, name, place, text, email, hp) LIKE '%".$search."%'".$search_category;
168 else
170 $search_string = "concat(subject, name, place, text, email, hp) LIKE '%".implode("%' AND concat(subject, name, place, text, email, hp) LIKE '%",$search_array)."%'".$search_category;
173 if (empty($search) && isset($show_postings)) $search_string = "user_id = '".$show_postings."'";
175 $searchQuery = "SELECT
177 pid,
178 tid,
179 UNIX_TIMESTAMP(time + INTERVAL ".$time_difference." HOUR) AS Uhrzeit,
180 subject,
181 name,
182 category
183 FROM ".$db_settings['forum_table']."
184 WHERE ".$search_string;
186 $countQuery = "SELECT
187 COUNT(*)
188 FROM ".$db_settings['forum_table']."
189 WHERE ".$search_string;
191 if (is_array($categories))
193 $searchQuery .= "
194 AND category IN (".$category_ids_query.")";
195 $countQuery .= "
196 AND category IN (".$category_ids_query.")";
198 $searchQuery .= "
199 ORDER BY tid DESC,
200 time ASC
201 LIMIT ".$ul.", ".$settings['search_results_per_page'];
203 $result = mysql_query($searchQuery, $connid);
204 if(!$result) die($lang['db_error']);
206 $count_result = mysql_query($countQuery, $connid);
207 list($count) = mysql_fetch_row($count_result);
210 // HTML:
211 $wo = strip_tags($lang['search_title']);
212 $subnav_1 = "";
213 if (isset($search) && empty($show_postings))
215 if ($search != "" && $ao=="phrase")
217 $subnav_1 .= $lang['phrase']." <b>".htmlspecialchars($search)."</b>";
219 else if ($search != "" && count($search_array) == 1)
221 $subnav_1 .= $lang['search_term']." <b>".htmlspecialchars($search_anz)."</b>";
223 else if ($search != "" && count($search_array) > 1)
225 $subnav_1 .= $lang['search_term']." <b>".htmlspecialchars($search_anz)."</b>";
227 else
229 $subnav_1 .= "&nbsp;";
230 $topnav = '<img src="img/where.png" alt="" width="11" height="8" /><b>'.$lang['search_title'].'</b>';
233 if ($count > 0 && $search != "")
235 $subnav_1 .= " - ".$lang['search_result']." ";
237 if ($count > 0 && $search != "" && $count > $settings['search_results_per_page'])
239 $lang['search_result_range'] = str_replace("[from]", ($page*$settings['search_results_per_page'])+1, $lang['search_result_range']);
240 $lang['search_result_range'] = str_replace("[to]", ((1+$page)*$settings['search_results_per_page']), $lang['search_result_range']);
241 $lang['search_result_range'] = str_replace("[total]", $count, $lang['search_result_range']);
242 $subnav_1 .= $lang['search_result_range'];
244 else if ($count > 0 && $search != "" && $count <= $settings['search_results_per_page'])
246 $subnav_1 .= $count;
248 else
250 $subnav_1 .= "&nbsp;";
251 #$topnav = '<img src="img/where.png" alt="" width="11" height="8" /><b>'.$lang['search_title'].'</b>';
254 else if (isset($show_postings) && empty($search))
256 $user_name_result = mysql_query("SELECT user_name FROM ".$db_settings['userdata_table']." WHERE user_id = '".$show_postings."' LIMIT 1", $connid);
257 if (!$user_name_result) die($lang['db_error']);
258 $field = mysql_fetch_assoc($user_name_result);
259 mysql_free_result($user_name_result);
260 $lang['show_userdata_linktitle'] = str_replace("[name]", htmlspecialchars($field["user_name"]), $lang['show_userdata_linktitle']);
261 $lang['postings_by_user'] = str_replace('[name]', '<a href="user.php?id='.$show_postings.'" title="'.outputLangDebugInAttributes($lang['show_userdata_linktitle']).'">'.htmlspecialchars($field["user_name"]).'</a>', $lang['postings_by_user']);
262 $subnav_1 .= '<img src="img/where.png" alt="" width="11" height="8" border="0"><b>'.$lang['postings_by_user'].'</b>';
265 if (isset($search) && $search != "")
267 $subnav_2 = snav($page, $settings['search_results_per_page'], $count, $search, $ao, $category);
269 else if (isset($show_postings) && $show_postings !="")
271 $subnav_2 = pnav($page, $settings['search_results_per_page'], $count, $show_postings);
273 parse_template();
274 echo $header;
276 if (isset($search))
278 $search_match = htmlspecialchars($search);
280 else
282 $search_match = "";
285 if (isset($search) && empty($show_postings))
287 echo '<form action="search.php" method="get" title="';
288 echo outputLangDebugInAttributes($lang['search_formtitle']).'"><div class="search">'."\n";
289 echo '<input type="text" name="search" value="'.htmlspecialchars($search_match).'" size="30" />'."\n";
290 if ($categories!=false)
292 echo '<select size="1" name="category">'."\n";
293 echo '<option value="0"';
294 echo (isset($category) && $category==0) ? ' selected="selected"' : '';
295 echo '>'.$lang['show_all_categories'].'</option>'."\n";
296 while (list($key, $val) = each($categories))
298 if ($key!=0)
300 echo '<option value="'.$key.'"';
301 echo ($key==$category) ? ' selected="selected"' : '';
302 echo '>'.$val.'</option>'."\n";
305 echo '</select>'."\n";
307 echo '<input type="submit" name="" value="'.outputLangDebugInAttributes($lang['search_submit']).'" /><br />'."\n";
308 echo '<input type="radio" name="ao" value="and"';
309 echo ($ao == "and") ? ' checked="checked"' : '';
310 echo ' />'.$lang['search_and'].'&nbsp;<input type="radio" class="search-radio"';
311 echo ' name="ao" value="or"';
312 echo ($ao == "or") ? ' checked="checked"' : '';
313 echo ' />'.$lang['search_or'].'&nbsp;<input type="radio" class="search-radio"';
314 echo ' name="ao" value="phrase"';
315 echo ($ao == "phrase") ? ' checked="checked"' : '';
316 echo ' />'.$lang['search_phrase'].'</div></form>'."\n";
319 if ($count == 0 && $search != "")
321 echo '<p class="caution">';
322 if (count($search_array) > 1 && $ao == "and")
324 echo $lang['no_match_and'];
326 else if (count($search_array) > 1 && $ao == "or")
328 echo $lang['no_match_or'];
330 else if (count($search_array) > 1 && $ao == "phrase")
332 echo $lang['no_match_phrase'];
334 else
336 echo $lang['search_no_match'];
338 echo '</p>'."\n";
341 if (!empty($search) || !empty($show_postings))
343 echo '<ul id="searchresults">'."\n";
344 $i=0;
345 while ($entrydata = mysql_fetch_assoc($result))
347 $search_author_info_x = str_replace("[name]", htmlspecialchars($entrydata["name"]), $lang['search_author_info']);
348 $search_author_info_x = str_replace("[time]", strftime($lang['time_format'],$entrydata["Uhrzeit"]), $search_author_info_x);
349 echo '<li><a class="';
350 echo ($entrydata['pid'] == 0) ? 'thread' : 'reply-search';
351 echo '" href="';
352 if (isset($_SESSION[$settings['session_prefix'].'user_view'])
353 && $_SESSION[$settings['session_prefix'].'user_view']=='board')
355 echo 'board_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
357 else if (isset($_SESSION[$settings['session_prefix'].'user_view'])
358 && $_SESSION[$settings['session_prefix'].'user_view']=='thread')
360 echo 'forum_entry.php?id='.$entrydata['id'];
362 else if (isset($_SESSION[$settings['session_prefix'].'user_view'])
363 && $_SESSION[$settings['session_prefix'].'user_view']=='mix')
365 echo 'mix_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
367 else if (isset($_COOKIE['user_view'])
368 && $_COOKIE['user_view']=='board')
370 echo 'board_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
372 else if (isset($_COOKIE['user_view']) && $_COOKIE['user_view']=='thread')
374 echo 'forum_entry.php?id='.$entrydata['id'];
376 else if (isset($_COOKIE['user_view']) && $_COOKIE['user_view']=='mix')
378 echo 'mix_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
380 else if (isset($standard) && $standard=='board')
382 echo 'board_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
384 else if (isset($standard) && $standard=='mix')
386 echo 'mix_entry.php?id='.$entrydata['tid'].'#p'.$entrydata['id'];
388 else
390 echo 'forum_entry.php?id='.$entrydata['id'];
392 echo '">'.htmlspecialchars($entrydata['subject']).'</a> ';
393 echo $search_author_info_x;
394 if (isset($categories[$entrydata["category"]]) && $categories[$entrydata["category"]]!='')
396 echo ' <span class="category">('.$categories[$entrydata["category"]].')</span>';
398 echo '</li>'."\n";
400 echo "</ul>\n";
402 echo $footer;