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\tMATCH (bug.summary) AGAINST ('$temp'$bool_flag)\n\t\t\t\tOR 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 $bugsys->input_clean('severity', TYPE_UINT
);
138 $querybuild['severity'] = "AND bug.severity IN (" . implode(',', $bugsys->in
['severity']) . ")";
142 if ($bugsys->in
['priority'])
144 $bugsys->input_clean('priority', TYPE_UINT
);
145 $querybuild['priority'] = "AND bug.priority IN (" . implode(',', $bugsys->in
['priority']) . ")";
149 if ($bugsys->in
['status'])
151 $bugsys->input_clean('status', TYPE_UINT
);
152 $querybuild['status'] = "AND bug.status IN (" . implode(',', $bugsys->in
['status']) . ")";
156 if ($bugsys->in
['resolution'])
158 $bugsys->input_clean('resolution', TYPE_UINT
);
159 $querybuild['resolution'] = "AND bug.resolution IN (" . implode(',', $bugsys->in
['resolution']) . ")";
163 if ($bugsys->in
['assignedto'])
165 $bugsys->input_clean('assignedto', TYPE_UINT
);
166 $querybuild['assignedto'] = "AND bug.assignedto IN (" . implode(',', $bugsys->in
['assignedto']) . ")";
169 // -------------------------------------------------------------------
171 if ($bugsys->in
['date'])
173 // now - (seconds/day * number of days)
174 $dateline = time() - ($bugsys->input_clean('date', TYPE_INT
)) * 3600);
175 $querybuild['date'] = "AND bug.dateline >= $dateline";
178 // -------------------------------------------------------------------
180 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
182 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
183 while ($favourite = $db->fetch_array($favourites))
185 $ids[] = $favourite['bugid'];
187 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
190 // -------------------------------------------------------------------
192 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
193 $orderby = array('ASC', 'DESC');
194 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
195 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
197 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
199 else if ($bugsys->in
['sortby'] == 'relevance')
208 // -------------------------------------------------------------------
210 $fields_fetch = $bugsys->db
->query("
212 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
213 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
214 ON (bugfield.fieldid = permission.fieldid)
215 WHERE permission.mask <> 0
216 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
217 AND bugfield.cansearch = 1"
219 while ($field = $bugsys->db
->fetch_array($fields_fetch))
221 if (!empty($bugsys->in
["field$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
["field$field[fieldid]"])))
223 if ($field['type'] == 'input_checkbox')
225 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
["field$field[fieldid]"] == 1) ?
0 : 1);
227 else if ($field['type'] == 'input_text')
229 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
["field$field[fieldid]"] . "%'";
231 else if ($field['type'] == 'select_single' AND $bugsys->in
["field$field[fieldid]"] != -1)
233 $temp = unserialize($field['selects']);
234 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
["field$field[fieldid]"]) ]) . "'";
239 // -------------------------------------------------------------------
240 // have to search something
241 if (sizeof($querybuild) < 1)
243 $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
));
246 // -------------------------------------------------------------------
249 SELECT bug.*, comment.commentid,
250 user1.displayname AS firstreport,
251 user2.displayname AS lastpost
252 FROM " . TABLE_PREFIX
. "bug AS bug
253 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
254 ON (bug.bugid = comment.bugid)
255 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
256 ON (bug.userid = user1.userid)
257 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
258 ON (bug.lastpostby = user2.userid)
259 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
260 ON (bug.bugid = bugfieldvalue.bugid)
262 AND bug.productid IN (#<'ONBITS:VIEW'>#)
263 AND (!bug.hidden OR (bug.hidden AND bug.productid IN (#<'ONBITS:HIDDEN'>#)))
264 " . implode("\n\t\t", $querybuild) . "
268 $runquery = str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden')), $query);
270 $search = $db->query($runquery);
272 $numrows = $db->num_rows($search);
276 $message->error($lang->string('No search results were returned that matched your criteria.'));
279 while ($result = $db->fetch_array($search))
281 $ids[] = $result['bugid'];
282 $results[] = $result;
285 if ($bugsys->userinfo
['userid'])
288 REPLACE INTO " . TABLE_PREFIX
. "search
289 (userid, dateline, query, ids, orderby, hilight)
291 (" . $bugsys->userinfo
['userid'] . ",
292 " . TIMENOW
. ", '" . $bugsys->escape($query) . "',
293 '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
294 '" . $bugsys->escape($hilight) . "'
301 $_REQUEST['do'] = 'results';
304 // ###################################################################
306 if ($_REQUEST['do'] == 'search')
308 if ($bugsys->userinfo
['userid'] AND !$bugsys->in
['new'])
310 if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "search WHERE userid = " . $bugsys->userinfo
['userid']))
312 $_REQUEST['do'] = 'results';
326 $pcv_select = construct_pcv_select();
328 // -------------------------------------------------------------------
330 $fields = construct_custom_fields(null
, true
);
332 foreach ($fields AS $field)
336 $customfields['left'] .= $field;
340 $customfields['right'] .= $field;
345 // -------------------------------------------------------------------
347 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
348 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
349 $select['status'] = construct_datastore_select('status', 'status', 'statusid');
350 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
353 foreach ($bugsys->datastore
['assignto'] AS $dev)
355 $value = $dev['userid'];
356 $label = construct_user_display($dev, false
);
357 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
360 eval('$template->flush("' . $template->fetch('search') . '");');
364 // ###################################################################
366 if ($_REQUEST['do'] == 'results')
368 $show['cached'] = false
;
369 if ($bugsys->userinfo
['userid'] AND !$justprocess)
371 $search = $cachedsearch;
372 if ($search['dateline'] < TIMENOW
- 900 OR $bugsys->in
['rerun'])
374 $search = $db->query(str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden')), $search['query']));
375 while ($bug = $db->fetch_array($search))
377 $ids[] = $bug['bugid'];
380 $db->query("UPDATE " . TABLE_PREFIX
. "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW
. " WHERE userid = " . $bugsys->userinfo
['userid']);
384 $search = $db->query("
385 SELECT bug.*, user1.displayname AS firstreport,
386 user2.displayname AS lastpost
387 FROM " . TABLE_PREFIX
. "bug AS bug
388 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
389 ON (bug.userid = user1.userid)
390 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
391 ON (bug.lastpostby = user2.userid)
392 WHERE bug.bugid IN ($search[ids])
395 while ($bug = $db->fetch_array($search))
400 $show['cached'] = true
;
401 $hilight = $search['hilight'];
404 foreach ($results AS $bug)
406 $funct->exec_swap_bg($stylevar['alt_colour'], '');
407 $bug['bgcolour'] = ($bugsys->userinfo
['showcolours'] ?
$bugsys->datastore
['status']["$bug[status]"]['color'] : $funct->bgcolour
);
408 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
409 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
410 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
411 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
412 $bug['priority'] = $bugsys->datastore
['priority']["$bug[priority]"]['priority'];
413 $bug['severity'] = $bugsys->datastore
['severity']["$bug[severity]"]['severity'];
414 $bug['lastposttime'] = (($bug['hiddendisplay']) ?
$bug['hiddenlastposttime'] : $bug['lastposttime']);
415 $bug['lastpost'] = (($bug['hiddendisplay']) ?
$bug['hiddenlastpost'] : $bug['lastpost']);
416 $bug['lastposttime'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']);
417 $bug['urladd'] = "&hilight=$hilight";
418 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
421 eval('$template->flush("' . $template->fetch('search_results') . '");');
424 /*=====================================================================*\
425 || ###################################################################
428 || ###################################################################
429 \*=====================================================================*/