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 $focus['search'] = 'focus';
22 require_once('./global.php');
24 if (!can_perform('cansearch'))
26 $message->error_permission();
29 define('MODE', intval($bugsys->in
['mode']));
30 define('MODE_ANY', ((MODE
== 1) ?
1 : 0));
31 define('MODE_ALL', ((MODE
== 2) ?
1 : 0));
32 define('MODE_RAW', ((MODE
== 3) ?
1 : 0));
34 define('SEARCH_WORD_MIN', 3);
36 $show['search'] = true
;
38 // ###################################################################
40 if (empty($_REQUEST['do']))
42 $_REQUEST['do'] = 'search';
45 // ###################################################################
47 if ($_REQUEST['do'] == 'results')
49 // -------------------------------------------------------------------
50 // parse out our product/component/version
51 $pcv = parse_pcv_select($bugsys->in
['pcv_select']);
53 // -------------------------------------------------------------------
55 if ($bugsys->in
['summary'])
57 $keywords = preg_split('#\s+#', $bugsys->in
['summary']);
59 // #*# need to have some str to bool conversions
61 foreach ($keywords AS $word)
63 if (strlen($word) < SEARCH_WORD_MIN
)
70 $querybuild['text'] .= " +$word";
74 $querybuild['text'] .= " $word";
77 if (!preg_match('#-(.+?)#', trim($word)))
83 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
84 $hilight = trim($hilight);
85 $hilight = preg_replace('#\s#', '+', $hilight);
87 $temp = trim($querybuild['text']);
89 if (MODE_ALL
OR MODE_RAW
)
91 $bool_flag = ' IN BOOLEAN MODE';
94 $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)";
97 // -------------------------------------------------------------------
99 if ($bugsys->in
['reporter'])
101 // force email or name?? make a distinction?
102 // more elegant way to do this? probably
103 $user = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in
['reporter'] . "' OR MATCH (displayname) AGAINST ('" . $bugsys->in
['reporter'] . "')");
106 $querybuild['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]";
110 // -------------------------------------------------------------------
111 // product/component/version stuff
112 if (is_array($bugsys->in
['pcv']))
114 $querybuild['pcv'] = "AND bug.productid = $pcv[product] AND bug.componentid = $pcv[component] AND bug.versionid = $pcv[version]";
117 // -------------------------------------------------------------------
118 // severity, priority, status, resolution, assignedto
121 if ($bugsys->in
['severity'])
123 $querybuild['severity'] = "AND bug.severity = " . intval($bugsys->in
['severity']);
127 if ($bugsys->in
['priority'])
129 $querybuild['priority'] = "AND bug.priority = " . intval($bugsys->in
['priority']);
133 if ($bugsys->in
['status'])
135 $querybuild['status'] = "AND bug.status = " . intval($bugsys->in
['status']);
139 if ($bugsys->in
['resolution'])
141 $querybuild['resolution'] = "AND bug.resolution = " . intval($bugsys->in
['resolution']);
145 if ($bugsys->in
['assignedto'])
147 $querybuild['assignedto'] = "AND bug.assignedto = " . intval($bugsys->in
['assignedto']);
150 // -------------------------------------------------------------------
152 if ($bugsys->in
['date'])
154 // now - (seconds/day * number of days)
155 $dateline = time() - (intval($bugsys->in
['date']) * 3600);
156 $querybuild['date'] = "AND bug.dateline >= $dateline";
159 // -------------------------------------------------------------------
161 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
163 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
164 while ($favourite = $db->fetch_array($favourites))
166 $ids[] = $favourite['bugid'];
168 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
171 // -------------------------------------------------------------------
173 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
174 $orderby = array('ASC', 'DESC');
175 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
176 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
178 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
180 else if ($bugsys->in
['sortby'] == 'relevance')
189 // -------------------------------------------------------------------
191 $fields_fetch = $bugsys->db
->query("
193 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
194 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
195 ON (bugfield.fieldid = permission.fieldid)
196 WHERE permission.mask <> 0
197 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
198 AND bugfield.cansearch = 1"
200 while ($field = $bugsys->db
->fetch_array($fields_fetch))
202 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
['custom']["$field[fieldid]"])))
204 if ($field['type'] == 'input_checkbox')
206 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ?
0 : 1);
208 else if ($field['type'] == 'input_text')
210 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
212 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
214 $temp = unserialize($field['selects']);
215 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
220 // -------------------------------------------------------------------
221 // have to search something
222 if (count($querybuild) < 1)
224 $message->error('you need to search for something!');
227 // -------------------------------------------------------------------
229 $search = $db->query("
230 SELECT bug.*, comment.commentid,
231 user1.displayname AS firstreport,
232 user2.displayname AS lastpost
233 FROM " . TABLE_PREFIX
. "bug AS bug
234 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
235 ON (bug.bugid = comment.bugid)
236 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
237 ON (bug.userid = user1.userid)
238 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
239 ON (bug.lastpostby = user2.userid)
240 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
241 ON (bug.bugid = bugfieldvalue.bugid)
243 " . implode("\n\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
245 AND !comment.hidden" : "") . "
250 $numrows = $db->num_rows($search);
254 $message->error('no results found');
257 while ($bug = $db->fetch_array($search))
259 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
260 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
261 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
262 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
263 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
264 $bug['lastpostinfo'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']) . ' by ' . $bug['lastpost'];
265 $bug['urladd'] = "&hilight=$hilight";
266 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
269 eval('$template->flush("' . $template->fetch('search_results') . '");');
272 // ###################################################################
274 if ($_REQUEST['do'] == 'search')
276 $pcv_select = construct_pcv_select('radio', '--');
278 // -------------------------------------------------------------------
280 $fields_fetch = $bugsys->db
->query("
282 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
283 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
284 ON (bugfield.fieldid = permission.fieldid)
285 WHERE permission.mask <> 0
286 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
287 AND bugfield.cansearch = 1"
289 while ($field = $bugsys->db
->fetch_array($fields_fetch))
291 switch ($field['type'])
294 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
297 case 'input_checkbox':
298 $selected = (($value) ?
' checked="checked"' : '');
304 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
310 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
314 $label = 'Un-Checked';
316 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
318 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
321 case 'select_single':
322 $selectopts = unserialize($field['selects']);
323 $value = trim($value);
328 $selected = ' selected="selected"';
329 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
332 foreach ($selectopts AS $id => $select)
334 $select = trim($select);
335 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
337 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
340 $fieldbits .= $tempfield;
344 // -------------------------------------------------------------------
346 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, true
);
347 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, true
);
348 $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, true
);
349 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, true
);
351 $select['dev'] = '<option value="0" selected="selected"></option>';
352 foreach ($bugsys->datastore
['assignto'] AS $dev)
354 $value = $dev['userid'];
355 $label = construct_user_display($dev, false
);
356 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
359 eval('$template->flush("' . $template->fetch('search') . '");');
362 /*=====================================================================*\
363 || ###################################################################
366 || ###################################################################
367 \*=====================================================================*/