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(
18 define('SVN', '$Id$');
20 require_once('./global.php');
22 if (!can_perform('cansearch'))
24 $message->error_permission();
27 define('MODE', intval($bugsys->in
['mode']));
28 define('MODE_ANY', ((MODE
== 1) ?
1 : 0));
29 define('MODE_ALL', ((MODE
== 2) ?
1 : 0));
30 define('MODE_RAW', ((MODE
== 3) ?
1 : 0));
32 define('SEARCH_WORD_MIN', 3);
34 $show['search'] = true
;
36 // ###################################################################
38 if (empty($_REQUEST['do']))
40 $_REQUEST['do'] = 'search';
43 // ###################################################################
45 if ($_REQUEST['do'] == 'results')
47 // -------------------------------------------------------------------
48 // parse out our product/component/version
49 $pcv = parse_pcv_select($bugsys->in
['pcv_select']);
51 // -------------------------------------------------------------------
53 if ($bugsys->in
['summary'])
55 $keywords = preg_split('#\s+#', $bugsys->in
['summary']);
57 // #*# need to have some str to bool conversions
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\tMATCH (bug.summary) AGAINST ('$temp'$bool_flag)\n\t\t\t\tOR 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 user WHERE email = '" . $bugsys->in
['reporter'] . "' OR MATCH (displayname) AGAINST ('" . $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']))
112 $querybuild['pcv'] = "AND bug.productid = $pcv[product] AND bug.componentid = $pcv[component] AND bug.versionid = $pcv[version]";
115 // -------------------------------------------------------------------
116 // severity, priority, status, resolution, assignedto
119 if ($bugsys->in
['severity'])
121 $querybuild['severity'] = "AND bug.severity = " . intval($bugsys->in
['severity']);
125 if ($bugsys->in
['priority'])
127 $querybuild['priority'] = "AND bug.priority = " . intval($bugsys->in
['priority']);
131 if ($bugsys->in
['status'])
133 $querybuild['status'] = "AND bug.status = " . intval($bugsys->in
['status']);
137 if ($bugsys->in
['resolution'])
139 $querybuild['resolution'] = "AND bug.resolution = " . intval($bugsys->in
['resolution']);
143 if ($bugsys->in
['assignedto'])
145 $querybuild['assignedto'] = "AND bug.assignedto = " . intval($bugsys->in
['assignedto']);
148 // -------------------------------------------------------------------
150 if ($bugsys->in
['date'])
152 // now - (seconds/day * number of days)
153 $dateline = time() - (intval($bugsys->in
['date']) * 3600);
154 $querybuild['date'] = "AND bug.dateline >= $dateline";
157 // -------------------------------------------------------------------
159 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
161 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
162 while ($favourite = $db->fetch_array($favourites))
164 $ids[] = $favourite['bugid'];
166 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
169 // -------------------------------------------------------------------
171 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
172 $orderby = array('ASC', 'DESC');
173 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
174 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
176 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
178 else if ($bugsys->in
['sortby'] == 'relevance')
187 // -------------------------------------------------------------------
189 $fields_fetch = $bugsys->db
->query("
191 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
192 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
193 ON (bugfield.fieldid = permission.fieldid)
194 WHERE permission.mask <> 0
195 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
196 AND bugfield.cansearch = 1"
198 while ($field = $bugsys->db
->fetch_array($fields_fetch))
200 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
['custom']["$field[fieldid]"])))
202 if ($field['type'] == 'input_checkbox')
204 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ?
0 : 1);
206 else if ($field['type'] == 'input_text')
208 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
210 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
212 $temp = unserialize($field['selects']);
213 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
218 // -------------------------------------------------------------------
219 // have to search something
220 if (count($querybuild) < 1)
222 $message->error('you need to search for something!');
225 // -------------------------------------------------------------------
227 $search = $db->query("
228 SELECT bug.*, comment.commentid,
229 user1.displayname AS firstreport,
230 user2.displayname AS lastpost
231 FROM " . TABLE_PREFIX
. "bug AS bug
232 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
233 ON (bug.bugid = comment.bugid)
234 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
235 ON (bug.userid = user1.userid)
236 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
237 ON (bug.lastpostby = user2.userid)
238 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
239 ON (bug.bugid = bugfieldvalue.bugid)
241 " . implode("\n\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
243 AND !comment.hidden" : "") . "
248 $numrows = $db->num_rows($search);
252 $message->error('no results found');
255 while ($bug = $db->fetch_array($search))
257 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
258 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
259 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
260 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
261 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
262 $bug['lastpostinfo'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']) . ' by ' . $bug['lastpost'];
263 $bug['urladd'] = "&hilight=$hilight";
264 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
267 eval('$template->flush("' . $template->fetch('search_results') . '");');
270 // ###################################################################
272 if ($_REQUEST['do'] == 'search')
274 $pcv_select = construct_pcv_select('radio', '--');
276 // -------------------------------------------------------------------
278 $fields_fetch = $bugsys->db
->query("
280 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
281 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
282 ON (bugfield.fieldid = permission.fieldid)
283 WHERE permission.mask <> 0
284 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
285 AND bugfield.cansearch = 1"
287 while ($field = $bugsys->db
->fetch_array($fields_fetch))
289 switch ($field['type'])
292 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
295 case 'input_checkbox':
296 $selected = (($value) ?
' checked="checked"' : '');
302 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
308 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
312 $label = 'Un-Checked';
314 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
316 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
319 case 'select_single':
320 $selectopts = unserialize($field['selects']);
321 $value = trim($value);
326 $selected = ' selected="selected"';
327 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
330 foreach ($selectopts AS $id => $select)
332 $select = trim($select);
333 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
335 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
338 $fieldbits .= $tempfield;
342 // -------------------------------------------------------------------
344 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, true
);
345 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, true
);
346 $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, true
);
347 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, true
);
349 $select['dev'] = '<option value="0" selected="selected"></option>';
350 foreach ($bugsys->datastore
['assignto'] AS $dev)
352 $value = $dev['userid'];
353 $label = construct_user_display($dev, false
);
354 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
357 eval('$template->flush("' . $template->fetch('search') . '");');
360 /*=====================================================================*\
361 || ###################################################################
364 || ###################################################################
365 \*=====================================================================*/