]>
src.bluestatic.org Git - bugdar.git/blob - search.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 (
28 define ( 'SVN' , ' $Id $' );
30 $focus [' search
'] = ' focus
';
32 require_once(' ./ global . php
');
33 require_once(' ./ includes
/ functions_product
. php
');
35 if (!can_perform(' cansearch
'))
37 $message- >error_permission();
40 define(' MODE_ANY
', ( $bugsys- >in[' mode
'] == 1));
41 define(' MODE_ALL
', ( $bugsys- >in[' mode
'] == 2));
42 define(' MODE_RAW
', ( $bugsys- >in[' mode
'] == 3));
44 $var = $db- >query_first("SHOW VARIABLES LIKE ' ft_min_word_len
'");
45 define(' SEARCH_WORD_MIN
', $var [' Value
']);
47 $show [' search
'] = true;
49 // ###################################################################
51 if (empty( $_REQUEST [' do ']))
53 $_REQUEST [' do '] = ' search
';
56 // ###################################################################
58 if ( $_REQUEST [' do '] == ' process
')
60 // -------------------------------------------------------------------
62 if ( $bugsys- >in[' summary
'])
64 $keywords = preg_split(' #\s+#', $bugsys->in['summary']);
66 // #*# need to have some str to bool conversions
68 foreach ( $keywords AS $word )
70 if ( strlen ( $word ) < SEARCH_WORD_MIN
)
77 $querybuild [ 'text' ] .= " + $word" ;
81 $querybuild ['text'] .= " $word" ;
84 if (! preg_match ( '#-(.+?)#' , trim ( $word )))
90 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight );
91 $hilight = trim( $hilight );
92 $hilight = preg_replace('#\s#', '+', $hilight );
94 $temp = trim( $querybuild ['text']);
96 if (MODE_ALL OR MODE_RAW)
98 $bool_flag = ' IN BOOLEAN MODE';
101 $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) ";
104 // -------------------------------------------------------------------
106 if ( $bugsys- >in['reporter'])
108 // force email or name?? make a distinction?
109 // more elegant way to do this? probably
110 $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
']) . "%' ");
113 $querybuild ['reporter'] = " AND bug
. userid
= $user [ userid
] OR comment
. userid
= $user [ userid
] ";
117 // -------------------------------------------------------------------
118 // product/component/version stuff
119 if (is_array( $bugsys- >in['pcv_select']))
121 foreach ( $bugsys- >in['pcv_select'] AS $pcv )
123 $pcv = parse_pcv_select( $pcv , true);
124 $products [] = $pcv ['product'];
125 $components [] = $pcv ['component'];
126 $versions [] = $pcv ['version'];
128 $querybuild ['pcv'] = " AND bug
. productid
IN ( " . implode(',', $products ) . " ) AND bug
. componentid
IN ( " . implode(',', $components ) . " ) AND bug
. versionid
IN ( " . implode(',', $versions ) . " ) ";
131 // -------------------------------------------------------------------
132 // severity, priority, status, resolution, assignedto
135 if ( $bugsys- >in['severity'])
137 $querybuild ['severity'] = " AND bug
. severity
= " . intval( $bugsys- >in['severity']);
141 if ( $bugsys- >in['priority'])
143 $querybuild ['priority'] = " AND bug
. priority
= " . intval( $bugsys- >in['priority']);
147 if ( $bugsys- >in['status'])
149 $querybuild ['status'] = " AND bug
. status
= " . intval( $bugsys- >in['status']);
153 if ( $bugsys- >in['resolution'])
155 $querybuild ['resolution'] = " AND bug
. resolution
= " . intval( $bugsys- >in['resolution']);
159 if ( $bugsys- >in['assignedto'])
161 $querybuild ['assignedto'] = " AND bug
. assignedto
= " . intval( $bugsys- >in['assignedto']);
164 // -------------------------------------------------------------------
166 if ( $bugsys- >in['date'])
168 // now - (seconds/day * number of days)
169 $dateline = time() - (intval( $bugsys- >in['date']) * 3600);
170 $querybuild ['date'] = " AND bug
. dateline
>= $dateline" ;
173 // -------------------------------------------------------------------
175 if ( $bugsys- > in
[ 'favourite' ] AND $bugsys- > userinfo
[ 'userid' ])
177 $favourites = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
178 while ( $favourite = $db- > fetch_array ( $favourites ))
180 $ids [] = $favourite [ 'bugid' ];
182 $querybuild [ 'favourites' ] = "AND bug.bugid IN (" . implode ( ', ' , $ids ) . ")" ;
185 // -------------------------------------------------------------------
187 $sortby = array ( 'bugid' , 'severity' , 'priority' , 'status' , 'resolution' , 'dateline' );
188 $orderby = array ( 'ASC' , 'DESC' );
189 $bugsys- > in
[ 'orderby' ] = strtoupper ( $bugsys- > in
[ 'orderby' ]);
190 if ( in_array ( $bugsys- > in
[ 'sortby' ], $sortby ) AND in_array ( $bugsys- > in
[ 'orderby' ], $orderby ))
192 $sortclause = "ORDER BY " . $bugsys- > in
[ 'sortby' ] . ' ' . $bugsys- > in
[ 'orderby' ];
194 else if ( $bugsys- > in
[ 'sortby' ] == 'relevance' )
203 // -------------------------------------------------------------------
205 $fields_fetch = $bugsys- > db
-> query ( "
207 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
208 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
209 ON (bugfield.fieldid = permission.fieldid)
210 WHERE permission.mask <> 0
211 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
212 AND bugfield.cansearch = 1"
214 while ( $field = $bugsys- > db
-> fetch_array ( $fields_fetch ))
216 if (! empty ( $bugsys- > in
[ "field $field [fieldid]" ]) OR ( $field [ 'type' ] == 'select_single' AND isset ( $bugsys- > in
[ "field $field [fieldid]" ])))
218 if ( $field [ 'type' ] == 'input_checkbox' )
220 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = " . (( $bugsys- > in
[ "field $field [fieldid]" ] == 1 ) ? 0 : 1 );
222 else if ( $field [ 'type' ] == 'input_text' )
224 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] LIKE '%" . $bugsys- > in
[ "field $field [fieldid]" ] . "%'" ;
226 else if ( $field [ 'type' ] == 'select_single' AND $bugsys- > in
[ "field $field [fieldid]" ] != - 1 )
228 $temp = unserialize ( $field [ 'selects' ]);
229 $querybuild [] = "AND bugfieldvalue.field $field [fieldid] = '" . trim ( $temp [ intval ( $bugsys- > in
[ "field $field [fieldid]" ]) ]) . "'" ;
234 // -------------------------------------------------------------------
235 // have to search something
236 if ( count ( $querybuild ) < 1 )
238 $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
));
241 // -------------------------------------------------------------------
244 SELECT bug.*, comment.commentid,
245 user1.displayname AS firstreport,
246 user2.displayname AS lastpost
247 FROM " . TABLE_PREFIX
. "bug AS bug
248 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
249 ON (bug.bugid = comment.bugid)
250 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
251 ON (bug.userid = user1.userid)
252 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
253 ON (bug.lastpostby = user2.userid)
254 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
255 ON (bug.bugid = bugfieldvalue.bugid)
257 AND bug.productid IN (#<'ONBITS:VIEW'>#)
258 AND (!bug.hidden OR (bug.hidden AND bug.productid IN (#<'ONBITS:HIDDEN'>#)))
259 " . implode ( " \n\t\t " , $querybuild ) . "
263 $runquery = str_replace(array(" #<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden')), $query);
265 $search = $db- > query ( $runquery );
267 $numrows = $db- > num_rows ( $search );
271 $message- > error ( $lang- > string ( 'No search results were returned that matched your criteria.' ));
274 while ( $result = $db- > fetch_array ( $search ))
276 $ids [] = $result [ 'bugid' ];
277 $results [] = $result ;
280 if ( $bugsys- > userinfo
[ 'userid' ])
283 REPLACE INTO " . TABLE_PREFIX
. "search
284 (userid, dateline, query, ids, orderby, hilight)
286 (" . $bugsys- > userinfo
[ 'userid' ] . ",
287 " . TIMENOW
. ", '" . $bugsys- > escape ( $query ) . "',
288 '" . implode ( ',' , $ids ) . "', '" . $bugsys- > escape ( $sortclause ) . "',
289 '" . $bugsys- > escape ( $hilight ) . "'
296 $_REQUEST [ 'do' ] = 'results' ;
299 // ###################################################################
301 if ( $_REQUEST [ 'do' ] == 'search' )
303 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $bugsys- > in
[ 'new' ])
305 if ( $cachedsearch = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]))
307 $_REQUEST [ 'do' ] = 'results' ;
321 $pcv_select = construct_pcv_select ();
323 // -------------------------------------------------------------------
325 $fields = construct_custom_fields ( null , true );
327 foreach ( $fields AS $field )
331 $customfields [ 'left' ] .= $field ;
335 $customfields [ 'right' ] .= $field ;
340 // -------------------------------------------------------------------
342 $select [ 'severity' ] = construct_datastore_select ( 'severity' , 'severity' , 'severityid' , 0 , true );
343 $select [ 'priority' ] = construct_datastore_select ( 'priority' , 'priority' , 'priorityid' , 0 , true );
344 $select [ 'status' ] = construct_datastore_select ( 'status' , 'status' , 'statusid' , 0 , true );
345 $select [ 'resolution' ] = construct_datastore_select ( 'resolution' , 'resolution' , 'resolutionid' , 0 , true );
347 $select [ 'dev' ] = '<option value="0" selected="selected"></option>' ;
348 foreach ( $bugsys- > datastore
[ 'assignto' ] AS $dev )
350 $value = $dev [ 'userid' ];
351 $label = construct_user_display ( $dev , false );
352 eval ( ' $select [dev] .= "' . $template- > fetch ( 'selectoption' ) . '";' );
355 eval ( ' $template- >flush("' . $template- > fetch ( 'search' ) . '");' );
359 // ###################################################################
361 if ( $_REQUEST [ 'do' ] == 'results' )
363 $show [ 'cached' ] = false ;
364 if ( $bugsys- > userinfo
[ 'userid' ] AND ! $justprocess )
366 $search = $cachedsearch ;
367 if ( $search [ 'dateline' ] < TIMENOW
- 900 OR $bugsys- > in
[ 'rerun' ])
369 $search = $db- > query ( str_replace ( array ( "#<'ONBITS:VIEW'>#" , "#<'ONBITS:HIDDEN'>#" ), array ( fetch_on_bits ( 'canviewbugs' ), fetch_on_bits ( 'canviewhidden' )), $search [ 'query' ]));
370 while ( $bug = $db- > fetch_array ( $search ))
372 $ids [] = $bug [ 'bugid' ];
375 $db- > query ( "UPDATE " . TABLE_PREFIX
. "search SET ids = '" . implode ( ',' , $ids ) . "', dateline = " . TIMENOW
. " WHERE userid = " . $bugsys- > userinfo
[ 'userid' ]);
379 $search = $db- > query ( "
380 SELECT bug.*, user1.displayname AS firstreport,
381 user2.displayname AS lastpost
382 FROM " . TABLE_PREFIX
. "bug AS bug
383 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
384 ON (bug.userid = user1.userid)
385 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
386 ON (bug.lastpostby = user2.userid)
387 WHERE bug.bugid IN ( $search [ids])
390 while ( $bug = $db- > fetch_array ( $search ))
395 $show [ 'cached' ] = true ;
396 $hilight = $search [ 'hilight' ];
399 foreach ( $results AS $bug )
401 $funct- > exec_swap_bg ( $stylevar [ 'alt_colour' ], '' );
402 $bug [ 'bgcolour' ] = ( $bugsys- > userinfo
[ 'showcolours' ] ? $bugsys- > datastore
[ 'status' ][ " $bug [status]" ][ 'color' ] : $funct- > bgcolour
);
403 $bug [ 'product' ] = $bugsys- > datastore
[ 'product' ][ " $bug [productid]" ][ 'title' ];
404 $bug [ 'version' ] = $bugsys- > datastore
[ 'version' ][ " $bug [versionid]" ][ 'version' ];
405 $bug [ 'status' ] = $bugsys- > datastore
[ 'status' ][ " $bug [status]" ][ 'status' ];
406 $bug [ 'resolution' ] = $bugsys- > datastore
[ 'resolution' ][ " $bug [resolution]" ][ 'resolution' ];
407 $bug [ 'priority' ] = $bugsys- > datastore
[ 'priority' ][ " $bug [priority]" ][ 'priority' ];
408 $bug [ 'severity' ] = $bugsys- > datastore
[ 'severity' ][ " $bug [severity]" ][ 'severity' ];
409 $bug [ 'lastposttime' ] = (( $bug [ 'hiddendisplay' ]) ? $bug [ 'hiddenlastposttime' ] : $bug [ 'lastposttime' ]);
410 $bug [ 'lastpost' ] = (( $bug [ 'hiddendisplay' ]) ? $bug [ 'hiddenlastpost' ] : $bug [ 'lastpost' ]);
411 $bug [ 'lastposttime' ] = $datef- > format ( $bugsys- > options
[ 'dateformat' ], $bug [ 'lastposttime' ]);
412 $bug [ 'urladd' ] = "&hilight= $hilight" ;
413 eval(' $bugs .= " ' . $template- >fetch(' trackerhome_bits
') . ' ";');
416 eval(' $template- >flush(" ' . $template- >fetch(' search_results
') . ' ");');
419 /*=====================================================================*\
420 || ###################################################################
423 || ###################################################################
424 \*=====================================================================*/