C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\webboard\search.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/* $Id: search.php,v 1.1.1.1 2002/10/28 19:13:47 pbaecher Exp $ */
/*
          ThWboard - PHP/MySQL Bulletin Board System
        ==============================================
            (c) 2000, 2001 by
               Paul Baecher         <paul@thewall.de>
               Felix Gonschorek   <funner@thewall.de>

          download the latest version:
            http://www.thwboard.de

          This  program is  free  software;  you can
          redistribute it and/or modify it under the
          terms of the GNU General Public License as
          published by the Free Software Foundation;
          either  version 2 of  the License,  or (at
          your option) any later version.

        ==============================================

*/

include "./inc/header.inc.php";

$config['hitsperpage'] = 20;

$P = new Permission($g_user['groupids']);

if( 
$startsearch )
{

    
$a_board = array();
    
$r_board thwb_query("SELECT boardid FROM $pref"."board WHERE boarddisabled='0'");
    while( 
$board mysql_fetch_array($r_board) )
    {
        
$a_board[] = $board['boardid'];
    }
    
    
$a_boardlist = array();
    if( 
$selectedboards[0] == )
    {
        
// search all available boards, id = 0 - all boards
        
$selectedboards $a_board;
    }

    while( list(, 
$boardid) = each($selectedboards) )
    {
        
$P->set_boardid($boardid);
        if( 
$boardid != -&& $P->has_permissionP_VIEW ) )
        {
            if (
in_array($boardid,$a_board))
            {
                
$a_boardlist[] = $boardid;
            }
        }
    }
    
    
$boards implode(','$a_boardlist);
    if( !
$boards )
    {
        
message('Fehler''Sie k&#xF6;nnen keine Boards/Kategorien durchsuchen.');
    }
    
    if( !
$page )
    {
        
$page 0;
    }

    
$where[] = "(post.threadid=thread.threadid)";
    
$where[] = "(thread.boardid IN (".addslashes($boards)."))";

    if( 
$repliesonly == "yes" )
    {
        
$where[] = "(thread.threadreplies>0)";
    }

    if( 
$period == "yes" )
    {
        
$searchstart mktime(000$startmonth1$startyear);
        
$searchend mktime(000$endmonth 10$endyear);

        
$where[] = "(thread.threadtime>$searchstart AND thread.threadtime<$searchend)";
    }

    if( 
$searchfor == "post" )
    {
        
$a_words explode(" "$words);
        
$sqlwords = array();
        while( list(
$key$val) = each($a_words) )
        {
            if( 
strlen($val) < )
            {
                
message("Fehler""Sie können nicht nach Wörtern mit weniger als 3 Zeichen suchen.");
            }
            if( 
$key )
            {
                
message("Fehler""Sie können maximal nach 6 Wörtern suchen.");
            }
            if( 
$config['slow_search'] )
                
$sqlwords[] = "INSTR(LOWER(post.posttext),LOWER('" addslashes($val) . "'))>0";
            else
                
$sqlwords[] = "INSTR(post.posttext,'" addslashes($val) . "')>0";
        }

        
$where[] = '(' implode(' ' . ($searchmethod == 'OR' 'OR' 'AND') . ' '$sqlwords) . ')';
    }
    elseif( 
$searchfor == "author" )
    {
        
$r_user thwb_query("SELECT userid FROM ".$pref."user WHERE LOWER(username)=LOWER('" addslashes($words) . "')");
        
$user mysql_fetch_array($r_user);

        if( !
$user[userid] )
        {
            
message("Fehler""Der Autor nach dem Sie suchen wollen existiert nicht!");
        }

        
$where[] = "(post.userid='$user[userid]')";
    }
    elseif( 
$searchfor == "today" )
    {
        
$where[] = "(thread.threadtime)>" . (time() - (60 60 24));
    }
    elseif( 
$searchfor == "lastthreads" )
    {
        
$where[] = "(thread.threadtime)>" . (time() - (60 60 24 intval($days)));
    }
    else
    {
        
$a_words explode(" "$words);
        
$sqlwords = array();
        while( list(
$key$val) = each($a_words) )
        {
            if( 
strlen($val) < )
            {
                
message("Fehler""Sie können nicht nach Wörtern mit weniger als 3 Zeichen suchen.");
            }
            if( 
$key )
            {
                
message("Fehler""Sie können maximal nach 6 Wörtern suchen.");
            }
            if( 
$config['slow_search'] )
                
$sqlwords[] = "INSTR(LOWER(thread.threadtopic),LOWER('" addslashes($val) . "'))>0";
            else
                
$sqlwords[] = "INSTR(thread.threadtopic,'" addslashes($val) . "')>0";
        }

        
$where[] = '(' implode(' ' . ($searchmethod == 'OR' 'OR' 'AND') . ' '$sqlwords) . ')';
    }

    
// ergebnisanzahl selecten -> seiten
    /* echo */ 
$query "
            SELECT DISTINCT
                thread.threadid AS hits
            FROM
                "
.$pref."thread AS thread,
                "
.$pref."post AS post
            WHERE
                " 
implode(" AND "$where) . "
            LIMIT 100"
;
    
$r_presearch thwb_query($query);
    
$resultcount mysql_num_rows($r_presearch);

    
/*echo*/ $query "
                SELECT DISTINCT
                thread.threadid,
                thread.threadtopic,
                thread.boardid,
                thread.threadtime,
                thread.threadlastreplyby,
                thread.threadauthor,
                thread.threadreplies
            FROM
                "
.$pref."thread AS thread,
                "
.$pref."post AS post
            WHERE
                " 
implode(" AND "$where) . "
            ORDER BY
                thread.threadtime DESC LIMIT " 
$page $config['hitsperpage'] . ", " $config['hitsperpage'];

    
$r_search thwb_query($query);

    if( 
$error mysql_error() )
    {
        
message("Fehler""Fehler");
    }

    if( 
mysql_num_rows($r_search) == )
    {
        
message("Keine Themen gefunden""Es wurden keine Themen gefunden die Ihren Suchkriterien entsprechen!<br><a href=\"search.php\">Neue Suche</a>");
    }

    
$r_board thwb_query("
        SELECT
            board.boardid, board.boardname, category.categoryname
        FROM
            "
.$pref."board AS board,
            "
.$pref."category AS category
        WHERE
            board.categoryid=category.categoryid"
);
    while( 
$board mysql_fetch_array($r_board) )
    {
        
$boardpath[$board['boardid']] = $board['categoryname'] . ' / ' $board['boardname'];
    }

    
$frame = new Template("templates/" $style['styletemplate'] . "/frame.html");
    
$searchresult = new Template("templates/" $style['styletemplate'] . "/searchresult.html");
    
$searchresultrow = new Template("templates/" $style['styletemplate'] . "/searchresultrow.html");

    
$pages ceil($resultcount $config['hitsperpage']);
    
$pagesstring "";

    for( 
$i 0$i $pages$i++ )
    {
        if( 
$i == $page )
        {
            
$pagesstring .= "&gt;" . ($i 1)  . "&lt; ";
        }
        else
        { 
            
$pagesstring .= '[<a href="search.php?page='.$i.
                
'&searchfor='.$searchfor.
                
'&words='.$words.
                
'&searchmethod='.$searchmethod.
                
'&repliesonly='.$repliesonly.
                
'&period='.$period.
                
'&startmonth='.$startmonth.
                
'&startyear='.$startyear.
                
'&endmonth='.$endmonth.
                
'&endyear='.$endyear.
                
'&days='.$days;

            
reset($selectedboards);
            while( list(, 
$selectedboard) = each($selectedboards) )
            {
                
$pagesstring .= '&selectedboards[]='.$selectedboard;
            }
    
            
$pagesstring .= '&startsearch=1">'.($i 1).'</a>] ';
        }
    }

    while( 
$search mysql_fetch_array($r_search))
    {
        
$i++;
        if( 
$i )
        {
            
$rowbgcolor $style[CellB];
        }
        else
        {
            
$rowbgcolor $style[CellA];
        }
        
$search['threadtopic'] = parse_code($search['threadtopic']);
        
$search['threadauthor'] = parse_code($search['threadauthor']);
        
$search['threadlastreplyby'] = parse_code($search['threadlastreplyby']);
        
$search['threadtime'] = form_date($search['threadtime']);
        
$search['threadpath'] = $boardpath[$search[boardid]];
        
$highlight = @implode(' '$a_words);
        eval(
$searchresultrow->GetTemplate("RESULT_ROWS"));
    }

    
$navpath .= 'Suchergebnisse';

    eval(
$searchresult->GetTemplate("CONTENT"));
    eval(
$frame->GetTemplate());
}
else
{
    
// select boards
    
$a_board = array();
    
$r_board thwb_query("SELECT boardname, boardid, categoryid FROM $pref"."board WHERE boarddisabled='0' ORDER BY boardorder ASC");
    while( 
$board mysql_fetch_array($r_board) )
    {
        
$P->set_boardid($board['boardid']);
        if( 
$P->has_permissionP_VIEW) )
        {
            
$a_board[$board['categoryid']][] = $board;
        }
    }
    
    
$boards '';
    
$r_category thwb_query("SELECT categoryname, categoryid FROM ".$pref."category ORDER BY categoryorder ASC");
    while( 
$category mysql_fetch_array($r_category) )
    {
        if( 
$a_board[$category['categoryid']] )
        {
            
$boards .= '<option value="-1">' $category['categoryname'] . '</option>';
            while( list(, 
$board) = @each($a_board[$category['categoryid']]) )
            {
                
$boards .= '<option value="' $board['boardid'] . '">- ' $board['boardname'] . '</option>';
            }
        }
    }


    
$getdate getdate(time());

    
$Tframe = new Template("templates/".$style['styletemplate']."/frame.html");
    
$Tsearchform = new Template("templates/".$style['styletemplate']."/searchform.html");

    
$navpath .= 'Sucheinstellungen';

    eval(
$Tsearchform->GetTemplate("CONTENT"));
    eval(
$Tframe->GetTemplate());
}


?>