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 require_once('./global.php');
20 if (!can_perform('cansearch'))
22 $message->error_permission();
25 define('MODE', intval($bugsys->in
['mode']));
26 define('MODE_ANY', ((MODE
== 1) ?
1 : 0));
27 define('MODE_ALL', ((MODE
== 2) ?
1 : 0));
28 define('MODE_RAW', ((MODE
== 3) ?
1 : 0));
30 define('SEARCH_WORD_MIN', 3);
32 $show['search'] = true
;
34 // ###################################################################
36 if (empty($_REQUEST['do']))
38 $_REQUEST['do'] = 'search';
41 // ###################################################################
43 if ($_REQUEST['do'] == 'results')
45 // -------------------------------------------------------------------
46 // parse out our product/component/version
47 $pcv = parse_pcv_select($bugsys->in
['pcv_select']);
49 // -------------------------------------------------------------------
51 if ($bugsys->in
['summary'])
53 $keywords = preg_split('#\s+#', $bugsys->in
['summary']);
55 // #*# need to have some str to bool conversions
57 foreach ($keywords AS $word)
59 if (strlen($word) < SEARCH_WORD_MIN
)
66 $querybuild['text'] .= " +$word";
70 $querybuild['text'] .= " $word";
73 if (!preg_match('#-(.+?)#', trim($word)))
79 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
80 $hilight = trim($hilight);
81 $hilight = preg_replace('#\s#', '+', $hilight);
83 $temp = trim($querybuild['text']);
85 if (MODE_ALL
OR MODE_RAW
)
87 $bool_flag = ' IN BOOLEAN MODE';
90 $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)";
93 // -------------------------------------------------------------------
95 if ($bugsys->in
['reporter'])
97 // force email or name?? make a distinction?
98 // more elegant way to do this? probably
99 $user = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in
['reporter'] . "' OR MATCH (displayname) AGAINST ('" . $bugsys->in
['reporter'] . "')");
102 $querybuild['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]";
106 // -------------------------------------------------------------------
107 // product/component/version stuff
108 if (is_array($bugsys->in
['pcv']))
110 $querybuild['pcv'] = "AND bug.productid = $pcv[product] AND bug.componentid = $pcv[component] AND bug.versionid = $pcv[version]";
113 // -------------------------------------------------------------------
114 // severity, priority, status, resolution, assignedto
117 if ($bugsys->in
['severity'])
119 $querybuild['severity'] = "AND bug.severity = " . intval($bugsys->in
['severity']);
123 if ($bugsys->in
['priority'])
125 $querybuild['priority'] = "AND bug.priority = " . intval($bugsys->in
['priority']);
129 if ($bugsys->in
['status'])
131 $querybuild['status'] = "AND bug.status = " . intval($bugsys->in
['status']);
135 if ($bugsys->in
['resolution'])
137 $querybuild['resolution'] = "AND bug.resolution = " . intval($bugsys->in
['resolution']);
141 if ($bugsys->in
['assignedto'])
143 $querybuild['assignedto'] = "AND bug.assignedto = " . intval($bugsys->in
['assignedto']);
146 // -------------------------------------------------------------------
148 if ($bugsys->in
['date'])
150 // now - (seconds/day * number of days)
151 $dateline = time() - (intval($bugsys->in
['date']) * 3600);
152 $querybuild['date'] = "AND bug.dateline >= $dateline";
155 // -------------------------------------------------------------------
157 if ($bugsys->in
['favourite'] AND $bugsys->userinfo
['userid'])
159 $favourites = $db->query("SELECT * FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $bugsys->userinfo
['userid']);
160 while ($favourite = $db->fetch_array($favourites))
162 $ids[] = $favourite['bugid'];
164 $querybuild['favourites'] = "AND bug.bugid IN (" . implode(', ', $ids) . ")";
167 // -------------------------------------------------------------------
169 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
170 $orderby = array('ASC', 'DESC');
171 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
172 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
174 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
176 else if ($bugsys->in
['sortby'] == 'relevance')
185 // -------------------------------------------------------------------
187 $fields_fetch = $bugsys->db
->query("
189 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
190 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
191 ON (bugfield.fieldid = permission.fieldid)
192 WHERE permission.mask <> 0
193 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
194 AND bugfield.cansearch = 1"
196 while ($field = $bugsys->db
->fetch_array($fields_fetch))
198 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in
['custom']["$field[fieldid]"])))
200 if ($field['type'] == 'input_checkbox')
202 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ?
0 : 1);
204 else if ($field['type'] == 'input_text')
206 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
208 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
210 $temp = unserialize($field['selects']);
211 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
216 // -------------------------------------------------------------------
217 // have to search something
218 if (count($querybuild) < 1)
220 $message->error('you need to search for something!');
223 // -------------------------------------------------------------------
225 $search = $db->query("
226 SELECT bug.*, comment.commentid,
227 user1.displayname AS firstreport,
228 user2.displayname AS lastpost
229 FROM " . TABLE_PREFIX
. "bug AS bug
230 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
231 ON (bug.bugid = comment.bugid)
232 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
233 ON (bug.userid = user1.userid)
234 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
235 ON (bug.lastpostby = user2.userid)
236 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
237 ON (bug.bugid = bugfieldvalue.bugid)
239 " . implode("\n\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
241 AND !comment.hidden" : "") . "
246 $numrows = $db->num_rows($search);
250 $message->error('no results found');
253 while ($bug = $db->fetch_array($search))
255 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
256 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
257 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
258 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
259 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
260 $bug['lastpostinfo'] = $datef->format($bugsys->options
['dateformat'], $bug['lastposttime']) . ' by ' . $bug['lastpost'];
261 $bug['urladd'] = "&hilight=$hilight";
262 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
265 eval('$template->flush("' . $template->fetch('search_results') . '");');
268 // ###################################################################
270 if ($_REQUEST['do'] == 'search')
272 $pcv_select = construct_pcv_select('radio', '--');
274 // -------------------------------------------------------------------
276 $fields_fetch = $bugsys->db
->query("
278 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
279 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
280 ON (bugfield.fieldid = permission.fieldid)
281 WHERE permission.mask <> 0
282 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
283 AND bugfield.cansearch = 1"
285 while ($field = $bugsys->db
->fetch_array($fields_fetch))
287 switch ($field['type'])
290 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
293 case 'input_checkbox':
294 $selected = (($value) ?
' checked="checked"' : '');
300 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
306 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
310 $label = 'Un-Checked';
312 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
314 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
317 case 'select_single':
318 $selectopts = unserialize($field['selects']);
319 $value = trim($value);
324 $selected = ' selected="selected"';
325 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
328 foreach ($selectopts AS $id => $select)
330 $select = trim($select);
331 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
333 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
336 $fieldbits .= $tempfield;
340 // -------------------------------------------------------------------
342 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, true
);
343 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, true
);
344 $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, true
);
345 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, true
);
347 $select['dev'] = '<option value="0" selected="selected"></option>';
348 foreach ($bugsys->datastore
['assignto'] AS $dev)
350 $value = $dev['userid'];
351 $label = construct_user_display($dev, false
);
352 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
355 eval('$template->flush("' . $template->fetch('search') . '");');
358 /*=====================================================================*\
359 || ###################################################################
362 || ###################################################################
363 \*=====================================================================*/