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(
19 define('SVN', '$Id$');
21 $focus['search'] = 'focus';
23 require_once('./global.php');
25 if (!can_perform('cansearch'))
27 $message->error_permission();
30 define('MODE', intval($bugsys->in
['mode']));
31 define('MODE_ANY', ((MODE
== 1) ?
1 : 0));
32 define('MODE_ALL', ((MODE
== 2) ?
1 : 0));
33 define('MODE_RAW', ((MODE
== 3) ?
1 : 0));
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'] == 'results')
50 // -------------------------------------------------------------------
51 // parse out our product/component/version
52 $pcv = parse_pcv_select($bugsys->in
['pcv_select']);
54 // -------------------------------------------------------------------
56 if ($bugsys->in
['summary'])
58 $keywords = preg_split('#\s+#', $bugsys->in
['summary']);
60 // #*# need to have some str to bool conversions
62 foreach ($keywords AS $word)
64 if (strlen($word) < SEARCH_WORD_MIN
)
71 $querybuild['text'] .= " +$word";
75 $querybuild['text'] .= " $word";
78 if (!preg_match('#-(.+?)#', trim($word)))
84 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
85 $hilight = trim($hilight);
86 $hilight = preg_replace('#\s#', '+', $hilight);
88 $temp = trim($querybuild['text']);
90 if (MODE_ALL
OR MODE_RAW
)
92 $bool_flag = ' IN BOOLEAN MODE';
95 $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)";
98 // -------------------------------------------------------------------
100 if ($bugsys->in
['reporter'])
102 // force email or name?? make a distinction?
103 // more elegant way to do this? probably
104 $user = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in
['reporter'] . "' OR MATCH (displayname) AGAINST ('" . $bugsys->in
['reporter'] . "')");
107 $querybuild['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]";
111 // -------------------------------------------------------------------
112 // product/component/version stuff
113 if (is_array($bugsys->in
['pcv']))
115 $querybuild['pcv'] = "AND bug.productid = $pcv[product] AND bug.componentid = $pcv[component] AND bug.versionid = $pcv[version]";
118 // -------------------------------------------------------------------
119 // severity, priority, status, resolution, assignedto
122 if ($bugsys->in
['severity'])
124 $querybuild['severity'] = "AND bug.severity = " . intval($bugsys->in
['severity']);
128 if ($bugsys->in
['priority'])
130 $querybuild['priority'] = "AND bug.priority = " . intval($bugsys->in
['priority']);
134 if ($bugsys->in
['status'])
136 $querybuild['status'] = "AND bug.status = " . intval($bugsys->in
['status']);
140 if ($bugsys->in
['resolution'])
142 $querybuild['resolution'] = "AND bug.resolution = " . intval($bugsys->in
['resolution']);
146 if ($bugsys->in
['assignedto'])
148 $querybuild['assignedto'] = "AND bug.assignedto = " . intval($bugsys->in
['assignedto']);
151 // -------------------------------------------------------------------
153 if ($bugsys->in
['date'])
155 // now - (seconds/day * number of days)
156 $dateline = time() - (intval($bugsys->in
['date']) * 3600);
157 $querybuild['date'] = "AND bug.dateline >= $dateline";
160 // -------------------------------------------------------------------
162 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
164 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
165 while ($favourite = $db->fetch_array($favourites))
167 $ids[] = $favourite['bugid'];
169 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
172 // -------------------------------------------------------------------
174 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
175 $orderby = array('ASC', 'DESC');
176 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
177 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
179 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
181 else if ($bugsys->in
['sortby'] == 'relevance')
190 // -------------------------------------------------------------------
192 $fields_fetch = $bugsys->db
->query("
194 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
195 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
196 ON (bugfield.fieldid = permission.fieldid)
197 WHERE permission.mask <> 0
198 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
199 AND bugfield.cansearch = 1"
201 while ($field = $bugsys->db
->fetch_array($fields_fetch))
203 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
['custom']["$field[fieldid]"])))
205 if ($field['type'] == 'input_checkbox')
207 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ?
0 : 1);
209 else if ($field['type'] == 'input_text')
211 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
213 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
215 $temp = unserialize($field['selects']);
216 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
221 // -------------------------------------------------------------------
222 // have to search something
223 if (count($querybuild) < 1)
225 $message->error('you need to search for something!');
228 // -------------------------------------------------------------------
230 $search = $db->query("
231 SELECT bug.*, comment.commentid,
232 user1.displayname AS firstreport,
233 user2.displayname AS lastpost
234 FROM " . TABLE_PREFIX
. "bug AS bug
235 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
236 ON (bug.bugid = comment.bugid)
237 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
238 ON (bug.userid = user1.userid)
239 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
240 ON (bug.lastpostby = user2.userid)
241 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
242 ON (bug.bugid = bugfieldvalue.bugid)
244 " . implode("\n\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
246 AND !comment.hidden" : "") . "
251 $numrows = $db->num_rows($search);
255 $message->error('no results found');
258 while ($bug = $db->fetch_array($search))
260 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
261 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
262 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
263 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
264 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
265 $bug['lastpostinfo'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']) . ' by ' . $bug['lastpost'];
266 $bug['urladd'] = "&hilight=$hilight";
267 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
270 eval('$template->flush("' . $template->fetch('search_results') . '");');
273 // ###################################################################
275 if ($_REQUEST['do'] == 'search')
277 $pcv_select = construct_pcv_select('radio', '--');
279 // -------------------------------------------------------------------
281 $fields_fetch = $bugsys->db
->query("
283 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
284 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
285 ON (bugfield.fieldid = permission.fieldid)
286 WHERE permission.mask <> 0
287 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
288 AND bugfield.cansearch = 1"
290 while ($field = $bugsys->db
->fetch_array($fields_fetch))
292 switch ($field['type'])
295 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
298 case 'input_checkbox':
299 $selected = (($value) ?
' checked="checked"' : '');
305 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
311 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
315 $label = 'Un-Checked';
317 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
319 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
322 case 'select_single':
323 $selectopts = unserialize($field['selects']);
324 $value = trim($value);
329 $selected = ' selected="selected"';
330 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
333 foreach ($selectopts AS $id => $select)
335 $select = trim($select);
336 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
338 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
341 $fieldbits .= $tempfield;
345 // -------------------------------------------------------------------
347 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, true
);
348 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, true
);
349 $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, true
);
350 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, true
);
352 $select['dev'] = '<option value="0" selected="selected"></option>';
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') . '");');
363 /*=====================================================================*\
364 || ###################################################################
367 || ###################################################################
368 \*=====================================================================*/