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 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
158 $orderby = array('ASC', 'DESC');
159 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
160 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
162 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
164 else if ($bugsys->in
['sortby'] == 'relevance')
170 $message->error('bad sort');
173 // -------------------------------------------------------------------
175 $fields_fetch = $bugsys->db
->query("
177 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
178 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
179 ON (bugfield.fieldid = permission.fieldid)
180 WHERE permission.mask <> 0
181 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
182 AND bugfield.cansearch = 1"
184 while ($field = $bugsys->db
->fetch_array($fields_fetch))
186 if (!empty($bugsys->in
['custom']["$field[fieldid]"]) OR $field['type'] == 'select_single')
188 if ($field['type'] == 'input_checkbox')
190 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = " . (($bugsys->in
['custom']["$field[fieldid]"] == 1) ?
0 : 1);
192 else if ($field['type'] == 'input_text')
194 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] LIKE '%" . $bugsys->in
['custom']["$field[fieldid]"] . "%'";
196 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[fieldid]"] != -1)
198 $temp = unserialize($field['selects']);
199 $querybuild[] = "AND bugfieldvalue.field$field[fieldid] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[fieldid]"]) ]) . "'";
204 // -------------------------------------------------------------------
205 // have to search something
206 if (count($querybuild) < 1)
208 $message->error('you need to search for something!');
211 // -------------------------------------------------------------------
213 $search = $db->query("
214 SELECT bug.*, comment.commentid,
215 user1.displayname AS firstreport,
216 user2.displayname AS lastpost
217 FROM " . TABLE_PREFIX
. "bug AS bug
218 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
219 ON (bug.bugid = comment.bugid)
220 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
221 ON (bug.userid = user1.userid)
222 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
223 ON (bug.lastpostby = user2.userid)
224 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
225 ON (bug.bugid = bugfieldvalue.bugid)
227 " . implode("\n\t\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
229 AND !comment.hidden" : "") . "
234 $numrows = $db->num_rows($search);
238 $message->error('no results found');
241 while ($bug = $db->fetch_array($search))
243 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
244 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
245 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
246 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
247 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
248 $bug['lastpostinfo'] = datelike('standard', $bug['lastposttime']) . ' by ' . $bug['lastpost'];
249 $bug['urladd'] = "&hilight=$hilight";
250 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
253 eval('$template->flush("' . $template->fetch('search_results') . '");');
256 // ###################################################################
258 if ($_REQUEST['do'] == 'search')
260 $pcv_select = construct_pcv_select('radio', '--');
262 // -------------------------------------------------------------------
264 $fields_fetch = $bugsys->db
->query("
266 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
267 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
268 ON (bugfield.fieldid = permission.fieldid)
269 WHERE permission.mask <> 0
270 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
271 AND bugfield.cansearch = 1"
273 while ($field = $bugsys->db
->fetch_array($fields_fetch))
275 switch ($field['type'])
278 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
281 case 'input_checkbox':
282 $selected = (($value) ?
' checked="checked"' : '');
288 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
294 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
298 $label = 'Un-Checked';
300 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
302 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
305 case 'select_single':
306 $selectopts = unserialize($field['selects']);
307 $value = trim($value);
312 $selected = ' selected="selected"';
313 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
316 foreach ($selectopts AS $id => $select)
318 $select = trim($select);
319 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
321 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
324 $fieldbits .= $tempfield;
328 // -------------------------------------------------------------------
330 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $selectedvalue = 0, $includeblank = true
);
331 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $selectedvalue = 0, $includeblank = true
);
332 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $selectedvalue = 0, $includeblank = true
);
333 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $selectedvalue = 0, $includeblank = true
);
335 $select['dev'] = '<option value="0" selected="selected"></option>';
336 foreach ($bugsys->datastore
['assignto'] AS $dev)
338 $value = $dev['userid'];
339 $label = construct_user_display($dev, false
);
340 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
343 eval('$template->flush("' . $template->fetch('search') . '");');
346 /*=====================================================================*\
347 || ###################################################################
350 || ###################################################################
351 \*=====================================================================*/