]>
src.bluestatic.org Git - bugdar.git/blob - search.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 $fetchtemplates = array (
19 define ( 'SVN' , ' $Id $' );
21 $focus [' search
'] = ' focus
';
23 require_once(' ./ global . php
');
24 require_once(' ./ includes
/ functions_product
. php
');
26 if (!can_perform(' cansearch
'))
28 $message- >error_permission();
31 define(' MODE_ANY
', ( $bugsys- >in[' mode
'] == 1));
32 define(' MODE_ALL
', ( $bugsys- >in[' mode
'] == 2));
33 define(' MODE_RAW
', ( $bugsys- >in[' mode
'] == 3));
35 define(' SEARCH_WORD_MIN
', 3);
37 $show [' search
'] = true;
39 // ###################################################################
41 if (empty( $_REQUEST [' do ']))
43 $_REQUEST [' do '] = ' search
';
46 // ###################################################################
48 if ( $_REQUEST [' do '] == ' process
')
50 // -------------------------------------------------------------------
52 if ( $bugsys- >in[' summary
'])
54 $keywords = preg_split(' #\s+#', $bugsys->in['summary']);
56 // #*# need to have some str to bool conversions
57 // #*# need to make sure the word isn't on MySQL's bad side (less than 3 chars. and not a common word)
59 foreach ( $keywords AS $word )
61 if ( strlen ( $word ) < SEARCH_WORD_MIN
)
68 $querybuild [ 'text' ] .= " + $word" ;
72 $querybuild ['text'] .= " $word" ;
75 if (! preg_match ( '#-(.+?)#' , trim ( $word )))
81 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight );
82 $hilight = trim( $hilight );
83 $hilight = preg_replace('#\s#', '+', $hilight );
85 $temp = trim( $querybuild ['text']);
87 if (MODE_ALL OR MODE_RAW)
89 $bool_flag = ' IN BOOLEAN MODE';
92 $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) ";
95 // -------------------------------------------------------------------
97 if ( $bugsys- >in['reporter'])
99 // force email or name?? make a distinction?
100 // more elegant way to do this? probably
101 $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
']) . "%' ");
104 $querybuild ['reporter'] = " AND bug
. userid
= $user [ userid
] OR comment
. userid
= $user [ userid
] ";
108 // -------------------------------------------------------------------
109 // product/component/version stuff
110 if (is_array( $bugsys- >in['pcv_select']))
112 foreach ( $bugsys- >in['pcv_select'] AS $pcv )
114 $pcv = parse_pcv_select( $pcv , true);
115 $products [] = $pcv ['product'];
116 $components [] = $pcv ['component'];
117 $versions [] = $pcv ['version'];
119 $querybuild ['pcv'] = " AND bug
. productid
IN ( " . implode(',', $products ) . " ) AND bug
. componentid
IN ( " . implode(',', $components ) . " ) AND bug
. versionid
IN ( " . implode(',', $versions ) . " ) ";
122 // -------------------------------------------------------------------
123 // severity, priority, status, resolution, assignedto
126 if ( $bugsys- >in['severity'])
128 $querybuild ['severity'] = " AND bug
. severity
= " . intval( $bugsys- >in['severity']);
132 if ( $bugsys- >in['priority'])
134 $querybuild ['priority'] = " AND bug
. priority
= " . intval( $bugsys- >in['priority']);
138 if ( $bugsys- >in['status'])
140 $querybuild ['status'] = " AND bug
. status
= " . intval( $bugsys- >in['status']);
144 if ( $bugsys- >in['resolution'])
146 $querybuild ['resolution'] = " AND bug
. resolution
= " . intval( $bugsys- >in['resolution']);
150 if ( $bugsys- >in['assignedto'])
152 $querybuild ['assignedto'] = " AND bug
. assignedto
= " . intval( $bugsys- >in['assignedto']);
155 // -------------------------------------------------------------------
157 if ( $bugsys- >in['date'])
159 // now - (seconds/day * number of days)
160 $dateline = time() - (intval( $bugsys- >in['date']) * 3600);
161 $querybuild ['date'] = " AND bug
. dateline
>= $dateline" ;
164 // -------------------------------------------------------------------
166 if ( $bugsys- > in
[ 'favourite' ] AND $bugsys- > userinfo
[ 'userid' ])
168 $favourites = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
169 while ( $favourite = $db- > fetch_array ( $favourites ))
171 $ids [] = $favourite [ 'bugid' ];
173 $querybuild [ 'favourites' ] = "AND bug.bugid IN (" . implode ( ', ' , $ids ) . ")" ;
176 // -------------------------------------------------------------------
178 $sortby = array ( 'bugid' , 'severity' , 'priority' , 'status' , 'resolution' , 'dateline' );
179 $orderby = array ( 'ASC' , 'DESC' );
180 $bugsys- > in
[ 'orderby' ] = strtoupper ( $bugsys- > in
[ 'orderby' ]);
181 if ( in_array ( $bugsys- > in
[ 'sortby' ], $sortby ) AND in_array ( $bugsys- > in
[ 'orderby' ], $orderby ))
183 $sortclause = "ORDER BY " . $bugsys- > in
[ 'sortby' ] . ' ' . $bugsys- > in
[ 'orderby' ];
185 else if ( $bugsys- > in
[ 'sortby' ] == 'relevance' )
194 // -------------------------------------------------------------------
196 $fields_fetch = $bugsys- > db
-> query ( "
198 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
199 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
200 ON (bugfield.fieldid = permission.fieldid)
201 WHERE permission.mask <> 0
202 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
203 AND bugfield.cansearch = 1"
205 while ( $field = $bugsys- > db
-> fetch_array ( $fields_fetch ))
207 if (! empty ( $bugsys- > in
[ "field $field [fieldid]" ]) OR ( $field [ 'type' ] == 'select_single' AND isset ( $bugsys- > in
[ "field $field [fieldid]" ])))
209 if ( $field [ 'type' ] == 'input_checkbox' )
211 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = " . (( $bugsys- > in
[ "field $field [fieldid]" ] == 1 ) ? 0 : 1 );
213 else if ( $field [ 'type' ] == 'input_text' )
215 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] LIKE '%" . $bugsys- > in
[ "field $field [fieldid]" ] . "%'" ;
217 else if ( $field [ 'type' ] == 'select_single' AND $bugsys- > in
[ "field $field [fieldid]" ] != - 1 )
219 $temp = unserialize ( $field [ 'selects' ]);
220 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = '" . trim ( $temp [ intval ( $bugsys- > in
[ "field $field [fieldid]" ]) ]) . "'" ;
225 // -------------------------------------------------------------------
226 // have to search something
227 if ( count ( $querybuild ) < 1 )
229 $message- > error ( $lang- > string ( 'You have to enter some criteria to search for' ));
232 // -------------------------------------------------------------------
235 SELECT bug.*, comment.commentid,
236 user1.displayname AS firstreport,
237 user2.displayname AS lastpost
238 FROM " . TABLE_PREFIX
. "bug AS bug
239 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
240 ON (bug.bugid = comment.bugid)
241 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
242 ON (bug.userid = user1.userid)
243 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
244 ON (bug.lastpostby = user2.userid)
245 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
246 ON (bug.bugid = bugfieldvalue.bugid)
248 AND bug.productid IN (#<'ONBITS:VIEW'>#)
249 AND (!bug.hidden OR (bug.hidden AND bug.productid IN (#<'ONBITS:HIDDEN'>#)))
250 " . implode ( " \n\t\t " , $querybuild ) . "
254 $runquery = str_replace(array(" #<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden')), $query);
256 $search = $db- > query ( $runquery );
258 $numrows = $db- > num_rows ( $search );
262 $message- > error ( $lang- > string ( 'No search results were returned that matched your criteria.' ));
265 while ( $result = $db- > fetch_array ( $search ))
267 $ids [] = $result [ 'bugid' ];
268 $results [] = $result ;
271 if ( $bugsys- > userinfo
[ 'userid' ])
274 REPLACE INTO " . TABLE_PREFIX
. "search
275 (userid, dateline, query, ids, orderby, hilight)
277 (" . $bugsys- > userinfo
[ 'userid' ] . ",
278 " . TIMENOW
. ", '" . $bugsys- > escape ( $query ) . "',
279 '" . implode ( ',' , $ids ) . "', '" . $bugsys- > escape ( $sortclause ) . "',
280 '" . $bugsys- > escape ( $hilight ) . "'
287 $_REQUEST [ 'do' ] = 'results' ;
290 // ###################################################################
292 if ( $_REQUEST [ 'do' ] == 'search' )
294 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $bugsys- > in
[ 'new' ])
296 if ( $cachedsearch = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]))
298 $_REQUEST [ 'do' ] = 'results' ;
312 $pcv_select = construct_pcv_select ();
314 // -------------------------------------------------------------------
316 $fields = construct_custom_fields ( $bug , true );
318 foreach ( $fields AS $field )
322 $customfields [ 'left' ] .= $field ;
326 $customfields [ 'right' ] .= $field ;
331 // -------------------------------------------------------------------
333 $select [ 'severity' ] = construct_datastore_select ( 'severity' , 'severity' , 'severityid' , 0 , true );
334 $select [ 'priority' ] = construct_datastore_select ( 'priority' , 'priority' , 'priorityid' , 0 , true );
335 $select [ 'status' ] = construct_datastore_select ( 'status' , 'status' , 'statusid' , 0 , true );
336 $select [ 'resolution' ] = construct_datastore_select ( 'resolution' , 'resolution' , 'resolutionid' , 0 , true );
338 $select [ 'dev' ] = '<option value="0" selected="selected"></option>' ;
339 foreach ( $bugsys- > datastore
[ 'assignto' ] AS $dev )
341 $value = $dev [ 'userid' ];
342 $label = construct_user_display ( $dev , false );
343 eval ( ' $select [dev] .= "' . $template- > fetch ( 'selectoption' ) . '";' );
346 eval ( ' $template- >flush("' . $template- > fetch ( 'search' ) . '");' );
350 // ###################################################################
352 if ( $_REQUEST [ 'do' ] == 'results' )
354 $show [ 'cached' ] = false ;
355 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $justprocess )
357 $search = $cachedsearch ;
358 if ( $search [ 'dateline' ] < TIMENOW
- 900 OR $bugsys- > in
[ 'rerun' ])
360 $search = $db- > query ( str_replace ( array ( "#<'ONBITS:VIEW'>#" , "#<'ONBITS:HIDDEN'>#" ), array ( fetch_on_bits ( 'canviewbugs' ), fetch_on_bits ( 'canviewhidden' )), $search [ 'query' ]));
361 while ( $bug = $db- > fetch_array ( $search ))
363 $ids [] = $bug [ 'bugid' ];
366 $db- > query ( "UPDATE " . TABLE_PREFIX
. "search SET ids = '" . implode ( ',' , $ids ) . "', dateline = " . TIMENOW
. " WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
370 $search = $db- > query ( "
371 SELECT bug.*, user1.displayname AS firstreport,
372 user2.displayname AS lastpost
373 FROM " . TABLE_PREFIX
. "bug AS bug
374 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
375 ON (bug.userid = user1.userid)
376 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
377 ON (bug.lastpostby = user2.userid)
378 WHERE bug.bugid IN ( $search [ids])
381 while ( $bug = $db- > fetch_array ( $search ))
386 $show [ 'cached' ] = true ;
387 $hilight = $search [ 'hilight' ];
390 foreach ( $results AS $bug )
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 [productid]" ][ 'title' ];
395 $bug [ 'version' ] = $bugsys- > datastore
[ 'version' ][ " $bug [versionid]" ][ '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 [ 'hiddenlastpost' ] : $bug [ 'lastpost' ]);
402 $bug [ 'lastposttime' ] = $datef- > format ( $bugsys- > options
[ 'dateformat' ], $bug [ 'lastposttime' ]);
403 $bug [ 'urladd' ] = "&hilight= $hilight" ;
404 eval(' $bugs .= " ' . $template- >fetch(' trackerhome_bits
') . ' ";');
407 eval(' $template- >flush(" ' . $template- >fetch(' search_results
') . ' ");');
410 /*=====================================================================*\
411 || ###################################################################
414 || ###################################################################
415 \*=====================================================================*/