]>
src.bluestatic.org Git - bugdar.git/blob - search.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $fetchtemplates = array (
30 define ( 'SVN' , ' $Id $' );
32 $focus [' search
'] = ' focus
';
34 require_once(' ./ global . php
');
35 require_once(' ./ includes
/ functions_product
. php
');
36 require_once(' ./ includes
/ class_pagination
. php
');
38 if (!can_perform(' cansearch
'))
40 $message- >error_permission();
43 define(' MODE_ANY
', ( $bugsys- >in[' mode
'] == 1));
44 define(' MODE_ALL
', ( $bugsys- >in[' mode
'] == 2));
45 define(' MODE_RAW
', ( $bugsys- >in[' mode
'] == 3));
47 $var = $db- >query_first("SHOW VARIABLES LIKE ' ft_min_word_len
'");
48 define(' SEARCH_WORD_MIN
', $var [' Value
']);
50 $show [' search
'] = true;
52 // ###################################################################
54 if (empty( $_REQUEST [' do ']))
56 $_REQUEST [' do '] = ' search
';
59 // ###################################################################
61 if ( $_REQUEST [' do '] == ' process
')
63 // -------------------------------------------------------------------
65 if ( $bugsys- >in[' summary
'])
67 $keywords = preg_split(' #\s+#', $bugsys->in['summary']);
69 // #*# need to have some str to bool conversions
71 foreach ( $keywords AS $word )
73 if ( strlen ( $word ) < SEARCH_WORD_MIN
)
80 $querybuild [ 'text' ] .= " + $word" ;
84 $querybuild ['text'] .= " $word" ;
87 if (! preg_match ( '#-(.+?)#' , trim ( $word )))
93 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight );
94 $hilight = trim( $hilight );
95 $hilight = preg_replace('#\s#', '+', $hilight );
97 $temp = trim( $querybuild ['text']);
99 if (MODE_ALL OR MODE_RAW)
101 $bool_flag = ' IN BOOLEAN MODE';
104 $querybuild ['text'] = " AND\n\t\t\t (\n\t\t\t\t MATCH
( bug
. summary
) AGAINST ( ' $temp' $bool_flag ) \n\t\t\t\t OR MATCH (comment.comment) AGAINST (' $temp'$bool_flag )\n\t\t\t) ";
107 // -------------------------------------------------------------------
109 if ( $bugsys- >in['reporter'])
111 // force email or name?? make a distinction?
112 // more elegant way to do this? probably
113 $user = $db- >query_first(" SELECT
* FROM
" . TABLE_PREFIX . " user WHERE email LIKE
'%" . str_replace(' %
', ' \%
', $bugsys- >in[' reporter
']) . "' OR displayname LIKE
'%" . str_replace(' %
', ' \%
', $bugsys- >in[' reporter
']) . "%' ");
116 $querybuild ['reporter'] = " AND bug
. userid
= $user [ userid
] OR comment
. userid
= $user [ userid
] ";
120 // -------------------------------------------------------------------
121 // product/component/version stuff
122 if (is_array( $bugsys- >in['pcv_select']))
124 foreach ( $bugsys- >in['pcv_select'] AS $pcv )
126 $pcv = parse_pcv_select( $pcv , true);
127 $products [] = $pcv ['product'];
128 $components [] = $pcv ['component'];
129 $versions [] = $pcv ['version'];
131 $querybuild ['pcv'] = " AND bug
. product
IN ( " . implode(',', $products ) . " ) AND bug
. component
IN ( " . implode(',', $components ) . " ) AND bug
. version
IN ( " . implode(',', $versions ) . " ) ";
134 // -------------------------------------------------------------------
135 // severity, priority, status, resolution, assignedto
138 if ( $bugsys- >in['severity'])
140 $bugsys- >input_clean('severity', TYPE_UINT);
141 $querybuild ['severity'] = " AND bug
. severity
IN ( " . implode(',', $bugsys- >in['severity']) . " ) ";
145 if ( $bugsys- >in['priority'])
147 $bugsys- >input_clean('priority', TYPE_UINT);
148 $querybuild ['priority'] = " AND bug
. priority
IN ( " . implode(',', $bugsys- >in['priority']) . " ) ";
152 if ( $bugsys- >in['status'])
154 $bugsys- >input_clean('status', TYPE_UINT);
155 $querybuild ['status'] = " AND bug
. status
IN ( " . implode(',', $bugsys- >in['status']) . " ) ";
159 if ( $bugsys- >in['resolution'])
161 $bugsys- >input_clean('resolution', TYPE_UINT);
162 $querybuild ['resolution'] = " AND bug
. resolution
IN ( " . implode(',', $bugsys- >in['resolution']) . " ) ";
166 if ( $bugsys- >in['assignedto'])
168 $bugsys- >input_clean('assignedto', TYPE_UINT);
169 $querybuild ['assignedto'] = " AND bug
. assignedto
IN ( " . implode(',', $bugsys- >in['assignedto']) . " ) ";
172 // -------------------------------------------------------------------
174 if ( $bugsys- >in['date'])
176 // now - (seconds/day * number of days)
177 $dateline = time() - ( $bugsys- >input_clean('date', TYPE_INT) * 3600);
178 $querybuild ['date'] = " AND bug
. dateline
>= $dateline" ;
181 // -------------------------------------------------------------------
183 if (( $bugsys- > in
[ 'favourite' ] == 1 OR $bugsys- > in
[ 'favourite' ] == 0 ) AND $bugsys- > userinfo
[ 'userid' ])
185 $favourites = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
186 while ( $favourite = $db- > fetch_array ( $favourites ))
188 $ids [] = $favourite [ 'bugid' ];
190 $querybuild [ 'favourites' ] = "AND bug.bugid " . ( $bugsys- > in
[ 'favourite' ] == 0 ? "NOT IN" : "IN" ) . " (" . implode ( ', ' , $ids ) . ")" ;
193 // -------------------------------------------------------------------
195 $sortby = array ( 'bugid' , 'severity' , 'priority' , 'status' , 'resolution' , 'dateline' );
196 $orderby = array ( 'ASC' , 'DESC' );
197 $bugsys- > in
[ 'orderby' ] = strtoupper ( $bugsys- > in
[ 'orderby' ]);
198 if ( in_array ( $bugsys- > in
[ 'sortby' ], $sortby ) AND in_array ( $bugsys- > in
[ 'orderby' ], $orderby ))
200 $sortclause = "ORDER BY " . $bugsys- > in
[ 'sortby' ] . ' ' . $bugsys- > in
[ 'orderby' ];
202 else if ( $bugsys- > in
[ 'sortby' ] == 'relevance' )
211 // -------------------------------------------------------------------
213 $fields_fetch = $bugsys- > db
-> query ( "
215 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
216 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
217 ON (bugfield.fieldid = permission.fieldid)
218 WHERE permission.mask <> 0
219 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
220 AND bugfield.cansearch = 1"
222 while ( $field = $bugsys- > db
-> fetch_array ( $fields_fetch ))
224 if (! empty ( $bugsys- > in
[ "field $field [fieldid]" ]) OR ( $field [ 'type' ] == 'select_single' AND isset ( $bugsys- > in
[ "field $field [fieldid]" ])))
226 if ( $field [ 'type' ] == 'input_checkbox' )
228 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = " . (( $bugsys- > in
[ "field $field [fieldid]" ] == 1 ) ? 0 : 1 );
230 else if ( $field [ 'type' ] == 'input_text' )
232 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] LIKE '%" . $bugsys- > in
[ "field $field [fieldid]" ] . "%'" ;
234 else if ( $field [ 'type' ] == 'select_single' AND $bugsys- > in
[ "field $field [fieldid]" ] != - 1 )
236 $temp = unserialize ( $field [ 'selects' ]);
237 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = '" . trim ( $temp [ intval ( $bugsys- > in
[ "field $field [fieldid]" ]) ]) . "'" ;
242 // -------------------------------------------------------------------
243 // have to search something
244 if ( sizeof ( $querybuild ) < 1 )
246 $message- > error ( sprintf ( $lang- > string ( 'You have to enter some criteria to search for. Node that words less than %1 $d characters are ignored by the search engine (and some other very common words, too).' ), SEARCH_WORD_MIN
));
249 // -------------------------------------------------------------------
252 SELECT bug.*, comment.commentid
253 FROM " . TABLE_PREFIX
. "bug AS bug
254 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
255 ON (bug.bugid = comment.bugid)
256 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
257 ON (bug.bugid = bugfieldvalue.bugid)
259 AND bug.product IN (#<'ONBITS:VIEW'>#)
260 AND (!bug.hidden OR (bug.hidden AND bug.product IN (#<'ONBITS:HIDDEN'>#)))
261 " . implode ( " \n\t\t " , $querybuild ) . "
265 $runquery = str_replace(array(" #<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden')), $query);
267 $search = $db- > query ( $runquery );
269 $numrows = $db- > num_rows ( $search );
273 $message- > error ( $lang- > string ( 'No search results were returned that matched your criteria.' ));
276 while ( $result = $db- > fetch_array ( $search ))
278 $ids [] = $result [ 'bugid' ];
279 $results [] = $result ;
282 if ( $bugsys- > userinfo
[ 'userid' ])
285 REPLACE INTO " . TABLE_PREFIX
. "search
286 (userid, dateline, query, ids, orderby, hilight, resultcount)
288 (" . $bugsys- > userinfo
[ 'userid' ] . ",
289 " . TIMENOW
. ", '" . $bugsys- > escape ( $query ) . "',
290 '" . implode ( ',' , $ids ) . "', '" . $bugsys- > escape ( $sortclause ) . "',
291 '" . $bugsys- > escape ( $hilight ) . "',
292 " . sizeof ( $results ) . "
299 $_REQUEST [ 'do' ] = 'results' ;
302 // ###################################################################
304 if ( $_REQUEST [ 'do' ] == 'search' )
306 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $bugsys- > in
[ 'new' ])
308 if ( $cachedsearch = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]))
310 $_REQUEST [ 'do' ] = 'results' ;
324 $pcv_select = construct_pcv_select ();
326 // -------------------------------------------------------------------
328 $fields = construct_custom_fields ( null , true );
330 foreach ( $fields AS $field )
334 $customfields [ 'left' ] .= $field ;
338 $customfields [ 'right' ] .= $field ;
343 // -------------------------------------------------------------------
345 $select [ 'severity' ] = construct_datastore_select ( 'severity' , 'severity' , 'severityid' );
346 $select [ 'priority' ] = construct_datastore_select ( 'priority' , 'priority' , 'priorityid' );
347 $select [ 'status' ] = construct_datastore_select ( 'status' , 'status' , 'statusid' );
348 $select [ 'resolution' ] = construct_datastore_select ( 'resolution' , 'resolution' , 'resolutionid' );
351 foreach ( $bugsys- > datastore
[ 'assignto' ] AS $dev )
353 $value = $dev [ 'userid' ];
354 $label = construct_user_display ( $dev , false );
355 eval ( ' $select [dev] .= "' . $template- > fetch ( 'selectoption' ) . '";' );
358 eval ( ' $template- >flush("' . $template- > fetch ( 'search' ) . '");' );
362 // ###################################################################
364 if ( $_REQUEST [ 'do' ] == 'results' )
366 $show [ 'cached' ] = false ;
367 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $justprocess )
369 $search = $cachedsearch ;
370 if ( $search [ 'dateline' ] < TIMENOW
- 900 OR $bugsys- > in
[ 'rerun' ])
372 $research = $db- > query ( str_replace ( array ( "#<'ONBITS:VIEW'>#" , "#<'ONBITS:HIDDEN'>#" ), array ( fetch_on_bits ( 'canviewbugs' ), fetch_on_bits ( 'canviewhidden' )), $search [ 'query' ]));
373 while ( $bug = $db- > fetch_array ( $research ))
375 $ids [] = $bug [ 'bugid' ];
378 $search [ 'ids' ] = implode ( ',' , $ids );
379 $db- > query ( "UPDATE " . TABLE_PREFIX
. "search SET ids = '" . implode ( ',' , $ids ) . "', dateline = " . TIMENOW
. ", resultcount = " . sizeof ( $results ) . " WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
381 $show [ 'cached' ] = true ;
382 $hilight = $search [ 'hilight' ];
385 $pagination = new Pagination ( 'p' , 'pp' );
386 $pagination- > total
= $search [ 'resultcount' ];
387 $pagination- > split_pages ();
389 $search = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid IN ( $search [ids]) $search [orderby] LIMIT " . $pagination- > fetch_limit ( $pagination- > page
- 1 ) . ", " . $pagination- > perpage
);
390 while ( $bug = $db- > fetch_array ( $search ))
392 $funct- > exec_swap_bg ( $stylevar [ 'alt_colour' ], '' );
393 $bug [ 'bgcolour' ] = ( $bugsys- > userinfo
[ 'showcolours' ] ? $bugsys- > datastore
[ 'status' ][ " $bug [status]" ][ 'color' ] : $funct- > bgcolour
);
394 $bug [ 'product' ] = $bugsys- > datastore
[ 'product' ][ " $bug [product]" ][ 'title' ];
395 $bug [ 'version' ] = $bugsys- > datastore
[ 'version' ][ " $bug [version]" ][ 'version' ];
396 $bug [ 'status' ] = $bugsys- > datastore
[ 'status' ][ " $bug [status]" ][ 'status' ];
397 $bug [ 'resolution' ] = $bugsys- > datastore
[ 'resolution' ][ " $bug [resolution]" ][ 'resolution' ];
398 $bug [ 'priority' ] = $bugsys- > datastore
[ 'priority' ][ " $bug [priority]" ][ 'priority' ];
399 $bug [ 'severity' ] = $bugsys- > datastore
[ 'severity' ][ " $bug [severity]" ][ 'severity' ];
400 $bug [ 'lastposttime' ] = ( $bug [ 'hiddendisplay' ] ? $bug [ 'hiddenlastposttime' ] : $bug [ 'lastposttime' ]);
401 $bug [ 'lastpost' ] = ( $bug [ 'hiddendisplay' ] ? $bug [ 'hiddenlastpostbyname' ] : $bug [ 'lastpostbyname' ]);
402 $bug [ 'lastposttime' ] = $datef- > format ( $bugsys- > options
[ 'dateformat' ], $bug [ 'lastposttime' ]);
403 $bug [ 'urladd' ] = "&hilight= $hilight" ;
404 eval(' $bugs .= " ' . $template- >fetch(' trackerhome_bits
') . ' ";');
407 $show ['pagenav'] = ( $pagination- >pagecount > 1 ? true : false);
408 $pagenav = $pagination- >construct_page_nav('search.php');
410 eval(' $template- >flush(" ' . $template- >fetch(' search_results
') . ' ");');
413 /*=====================================================================*\
414 || ###################################################################
417 || ###################################################################
418 \*=====================================================================*/