2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]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(
20 define('SVN', '$Id$');
22 $focus['search
'] = 'focus
';
24 require_once('./global.php
');
26 if (!can_perform('cansearch
'))
28 $message->error_permission();
31 define('MODE
', intval($bugsys->in['mode
']));
32 define('MODE_ANY
', ((MODE == 1) ? 1 : 0));
33 define('MODE_ALL
', ((MODE == 2) ? 1 : 0));
34 define('MODE_RAW
', ((MODE == 3) ? 1 : 0));
36 define('SEARCH_WORD_MIN
', 3);
38 $show['search
'] = true;
40 // ###################################################################
42 if (empty($_REQUEST['do']))
44 $_REQUEST['do'] = 'search
';
47 // ###################################################################
49 if ($_REQUEST['do'] == 'process
')
51 // -------------------------------------------------------------------
52 // parse out our product/component/version
53 $pcv = parse_pcv_select($bugsys->in['pcv_select
']);
55 // -------------------------------------------------------------------
57 if ($bugsys->in['summary
'])
59 $keywords = preg_split('#\s+#', $bugsys->in['summary']);
61 // #*# need to have some str to bool conversions
63 foreach ($keywords AS $word)
65 if (strlen($word) < SEARCH_WORD_MIN
)
72 $querybuild['text'] .= " +$word";
76 $querybuild['text'] .= " $word";
79 if (!preg_match('#-(.+?)#', trim($word)))
85 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
86 $hilight = trim($hilight);
87 $hilight = preg_replace('#\s#', '+', $hilight);
89 $temp = trim($querybuild['text']);
91 if (MODE_ALL OR MODE_RAW)
93 $bool_flag = ' IN BOOLEAN MODE';
96 $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)";
99 // -------------------------------------------------------------------
101 if ($bugsys->in['reporter'])
103 // force email or name?? make a distinction?
104 // more elegant way to do this? probably
105 $user = $db->query_first("SELECT
* FROM user WHERE email LIKE
'%" . str_replace('%
', '\%
', $bugsys->in['reporter
']) . "' OR displayname LIKE
'%" . str_replace('%
', '\%
', $bugsys->in['reporter
']) . "%'");
108 $querybuild['reporter'] = "AND bug
.userid
= $user[userid
] OR comment
.userid
= $user[userid
]";
112 // -------------------------------------------------------------------
113 // product/component/version stuff
114 if (is_array($bugsys->in['pcv']))
116 $querybuild['pcv'] = "AND bug
.productid
= $pcv[product
] AND bug
.componentid
= $pcv[component
] AND bug
.versionid
= $pcv[version
]";
119 // -------------------------------------------------------------------
120 // severity, priority, status, resolution, assignedto
123 if ($bugsys->in['severity'])
125 $querybuild['severity'] = "AND bug
.severity
= " . intval($bugsys->in['severity']);
129 if ($bugsys->in['priority'])
131 $querybuild['priority'] = "AND bug
.priority
= " . intval($bugsys->in['priority']);
135 if ($bugsys->in['status'])
137 $querybuild['status'] = "AND bug
.status
= " . intval($bugsys->in['status']);
141 if ($bugsys->in['resolution'])
143 $querybuild['resolution'] = "AND bug
.resolution
= " . intval($bugsys->in['resolution']);
147 if ($bugsys->in['assignedto'])
149 $querybuild['assignedto'] = "AND bug
.assignedto
= " . intval($bugsys->in['assignedto']);
152 // -------------------------------------------------------------------
154 if ($bugsys->in['date'])
156 // now - (seconds/day * number of days)
157 $dateline = time() - (intval($bugsys->in['date']) * 3600);
158 $querybuild['date'] = "AND bug
.dateline
>= $dateline";
161 // -------------------------------------------------------------------
163 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
165 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
166 while ($favourite = $db->fetch_array($favourites))
168 $ids[] = $favourite['bugid'];
170 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
173 // -------------------------------------------------------------------
175 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
176 $orderby = array('ASC', 'DESC');
177 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
178 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
180 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
182 else if ($bugsys->in
['sortby'] == 'relevance')
191 // -------------------------------------------------------------------
193 $fields_fetch = $bugsys->db
->query("
195 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
196 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
197 ON (bugfield.fieldid = permission.fieldid)
198 WHERE permission.mask <> 0
199 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
200 AND bugfield.cansearch = 1"
202 while ($field = $bugsys->db
->fetch_array($fields_fetch))
204 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
['custom']["$field[fieldid]"])))
206 if ($field['type'] == 'input_checkbox')
208 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ? 0 : 1);
210 else if ($field['type'] == 'input_text')
212 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
214 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
216 $temp = unserialize($field['selects']);
217 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
222 // -------------------------------------------------------------------
223 // have to search something
224 if (count($querybuild) < 1)
226 $message->error($lang->string('You have to enter some criteria to search for'));
229 // -------------------------------------------------------------------
232 SELECT bug.*, comment.commentid,
233 user1.displayname AS firstreport,
234 user2.displayname AS lastpost
235 FROM " . TABLE_PREFIX
. "bug AS bug
236 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
237 ON (bug.bugid = comment.bugid)
238 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
239 ON (bug.userid = user1.userid)
240 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
241 ON (bug.lastpostby = user2.userid)
242 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
243 ON (bug.bugid = bugfieldvalue.bugid)
245 " . implode("\n\t\t", $querybuild) . ((!can_perform('canviewhidden')) ? "
247 AND !comment.hidden" : "") . "
251 $search = $db->query($query);
253 $numrows = $db->num_rows($search);
257 $message->error($lang->string('No search results were returned that matched your criteria.'));
260 while ($result = $db->fetch_array($search))
262 $ids[] = $result['bugid'];
263 $results[] = $result;
266 if ($bugsys->userinfo['userid'])
269 REPLACE INTO
" . TABLE_PREFIX . "search
270 (userid
, dateline
, query
, ids
, orderby
, hilight
)
272 (" . $bugsys->userinfo['userid'] . ",
273 " . TIMENOW . ", '" . $bugsys->escape($query) . "',
274 '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
275 '" . $bugsys->escape($hilight) . "'
282 $_REQUEST['do'] = 'results';
285 // ###################################################################
287 if ($_REQUEST['do'] == 'search')
289 if ($bugsys->userinfo['userid'] AND !$bugsys->in['new'])
291 if ($cachedsearch = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "search WHERE userid
= " . $bugsys->userinfo['userid']))
293 $_REQUEST['do'] = 'results';
307 $pcv_select = construct_pcv_select('radio', '--');
309 // -------------------------------------------------------------------
311 $fields = construct_custom_fields($bug);
312 $show['customfields'] = ($fields ? true : false);
314 $bugsys->debug('fields modulo: ' . count($fields) % 2);
316 foreach ($fields AS $field)
318 $bugsys->debug("i
= $i");
321 $customfields['right'] .= $field;
325 $customfields['left'] .= $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($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 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
393 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
394 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
395 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
396 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
397 $bug['lastposttime'] = (($bug['hiddendisplay']) ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
398 $bug['lastpost'] = (($bug['hiddendisplay']) ? $bug['hiddenlastpost'] : $bug['lastpost']);
399 $bug['lastposttime'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']);
400 $bug['urladd'] = "&hilight=$hilight";
401 eval('$bugs .= "' . $template->fetch('trackerhome_bits
') . '";');
404 eval('$template->flush("' . $template->fetch('search_results
') . '");');
407 /*=====================================================================*\
408 || ###################################################################
411 || ###################################################################
412 \*=====================================================================*/