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(
16 //'search_results_bit'
19 require_once('./global.php');
21 if (!can_perform('cansearch'))
23 $message->error_permission();
26 define('MODE', intval($bugsys->in
['mode']));
27 define('MODE_ANY', ((MODE
== 1) ?
1 : 0));
28 define('MODE_ALL', ((MODE
== 2) ?
1 : 0));
29 define('MODE_RAW', ((MODE
== 3) ?
1 : 0));
31 define('SEARCH_WORD_MIN', 3);
33 $show['search'] = true
;
35 // ###################################################################
37 if (empty($_REQUEST['do']))
39 $_REQUEST['do'] = 'search';
42 // ###################################################################
44 if ($_REQUEST['do'] == 'results')
46 // -------------------------------------------------------------------
47 // parse out our product/component/version
48 $pcv = parse_pcv_select($bugsys->in
['pcv_select']);
50 // -------------------------------------------------------------------
52 if ($bugsys->in
['summary'])
54 $keywords = preg_split('#\s+#', $bugsys->in
['summary']);
56 // #*# need to have some str to bool conversions
58 foreach ($keywords AS $word)
60 if (strlen($word) < SEARCH_WORD_MIN
)
67 $querybuild['text'] .= " +$word";
71 $querybuild['text'] .= " $word";
74 if (!preg_match('#-(.+?)#', trim($word)))
80 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
81 $hilight = trim($hilight);
82 $hilight = preg_replace('#\s#', '+', $hilight);
84 $temp = trim($querybuild['text']);
86 if (MODE_ALL
OR MODE_RAW
)
88 $bool_flag = ' IN BOOLEAN MODE';
91 $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)";
94 // -------------------------------------------------------------------
96 if ($bugsys->in
['reporter'])
98 // force email or name?? make a distinction?
99 // more elegant way to do this? probably
100 $user = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in
['reporter'] . "' OR MATCH (displayname) AGAINST ('" . $bugsys->in
['reporter'] . "')");
103 $querybuild['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]";
107 // -------------------------------------------------------------------
108 // product/component/version stuff
109 if (is_array($bugsys->in
['pcv']))
111 $querybuild['pcv'] = "AND bug.productid = $pcv[product] AND bug.componentid = $pcv[component] AND bug.versionid = $pcv[version]";
114 // -------------------------------------------------------------------
115 // severity, priority, status, resolution, assignedto
118 if ($bugsys->in
['severity'])
120 $querybuild['severity'] = "AND bug.severity = " . intval($bugsys->in
['severity']);
124 if ($bugsys->in
['priority'])
126 $querybuild['priority'] = "AND bug.priority = " . intval($bugsys->in
['priority']);
130 if ($bugsys->in
['status'])
132 $querybuild['status'] = "AND bug.status = " . intval($bugsys->in
['status']);
136 if ($bugsys->in
['resolution'])
138 $querybuild['resolution'] = "AND bug.resolution = " . intval($bugsys->in
['resolution']);
142 if ($bugsys->in
['assignedto'])
144 $querybuild['assignedto'] = "AND bug.assignedto = " . intval($bugsys->in
['assignedto']);
147 // -------------------------------------------------------------------
149 if ($bugsys->in
['date'])
151 // now - (seconds/day * number of days)
152 $dateline = time() - (intval($bugsys->in
['date']) * 3600);
153 $querybuild['date'] = "AND bug.dateline >= $dateline";
156 // -------------------------------------------------------------------
158 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
159 $orderby = array('ASC', 'DESC');
160 $bugsys->in
['orderby'] = strtoupper($bugsys->in
['orderby']);
161 if (in_array($bugsys->in
['sortby'], $sortby) AND in_array($bugsys->in
['orderby'], $orderby))
163 $sortclause = "ORDER BY " . $bugsys->in
['sortby'] . ' ' . $bugsys->in
['orderby'];
165 else if ($bugsys->in
['sortby'] == 'relevance')
171 $message->error('bad sort');
174 // -------------------------------------------------------------------
176 $fields_fetch = $bugsys->db
->query("
178 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
179 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
180 ON (bugfield.fieldid = permission.fieldid)
181 WHERE permission.mask <> 0
182 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
183 AND bugfield.cansearch = 1"
185 while ($field = $bugsys->db
->fetch_array($fields_fetch))
187 if (!empty($bugsys->in
['custom']["$field[shortname]"]) OR $field['type'] == 'select_single')
189 if ($field['type'] == 'input_checkbox')
191 $querybuild[] = "AND bugfieldvalue.$field[shortname] = " . (($bugsys->in
['custom']["$field[shortname]"] == 1) ?
0 : 1);
193 else if ($field['type'] == 'input_text')
195 $querybuild[] = "AND bugfieldvalue.$field[shortname] LIKE '%" . $bugsys->in
['custom']["$field[shortname]"] . "%'";
197 else if ($field['type'] == 'select_single' AND $bugsys->in
['custom']["$field[shortname]"] != -1)
199 $temp = unserialize($field['selects']);
200 $querybuild[] = "AND bugfieldvalue.$field[shortname] = '" . trim($temp[ intval($bugsys->in
['custom']["$field[shortname]"]) ]) . "'";
205 // -------------------------------------------------------------------
206 // have to search something
207 if (count($querybuild) < 1)
209 $message->error('you need to search for something!');
212 // -------------------------------------------------------------------
214 $search = $db->query("
215 SELECT bug.*, comment.commentid,
216 user1.displayname AS firstreport,
217 user2.displayname AS lastpost
218 FROM " . TABLE_PREFIX
. "bug AS bug
219 LEFT JOIN " . TABLE_PREFIX
. "comment AS comment
220 ON (bug.bugid = comment.bugid)
221 LEFT JOIN " . TABLE_PREFIX
. "user AS user1
222 ON (bug.userid = user1.userid)
223 LEFT JOIN " . TABLE_PREFIX
. "user AS user2
224 ON (bug.lastpostby = user2.userid)
225 LEFT JOIN " . TABLE_PREFIX
. "bugvaluefill AS bugfieldvalue
226 ON (bug.bugid = bugfieldvalue.bugid)
228 " . implode("\n\t\t\t", $querybuild) . ((!can_perform('canviewhidden')) ?
"
230 AND !comment.hidden" : "") . "
235 $numrows = $db->num_rows($search);
237 print_r($querybuild);
241 $message->error('no results found');
244 while ($bug = $db->fetch_array($search))
246 $bug['bgcolour'] = $bugsys->datastore
['status']["$bug[status]"]['color'];
247 $bug['product'] = $bugsys->datastore
['product']["$bug[productid]"]['title'];
248 $bug['version'] = $bugsys->datastore
['version']["$bug[versionid]"]['version'];
249 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
250 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
251 $bug['lastpostinfo'] = datelike('standard', $bug['lastposttime']) . ' by ' . $bug['lastpost'];
252 $bug['urladd'] = "&hilight=$hilight";
253 eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
256 eval('$template->flush("' . $template->fetch('search_results') . '");');
259 // ###################################################################
261 if ($_REQUEST['do'] == 'search')
263 $pcv_select = construct_pcv_select('radio', '--');
265 // -------------------------------------------------------------------
267 $fields_fetch = $bugsys->db
->query("
269 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
270 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
271 ON (bugfield.fieldid = permission.fieldid)
272 WHERE permission.mask <> 0
273 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
274 AND bugfield.cansearch = 1"
276 while ($field = $bugsys->db
->fetch_array($fields_fetch))
278 switch ($field['type'])
281 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
284 case 'input_checkbox':
285 $selected = (($value) ?
' checked="checked"' : '');
291 eval('$options = "' . $bugsys->template
->fetch('selectoption') . '";');
297 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
301 $label = 'Un-Checked';
303 eval('$options .= "' . $bugsys->template
->fetch('selectoption') . '";');
305 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
308 case 'select_single':
309 $selectopts = unserialize($field['selects']);
310 $value = trim($value);
315 $selected = ' selected="selected"';
316 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
319 foreach ($selectopts AS $id => $select)
321 $select = trim($select);
322 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
324 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
327 $fieldbits .= $tempfield;
331 // -------------------------------------------------------------------
333 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $selectedvalue = 0, $includeblank = true
);
334 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $selectedvalue = 0, $includeblank = true
);
335 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $selectedvalue = 0, $includeblank = true
);
336 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $selectedvalue = 0, $includeblank = true
);
338 $select['dev'] = '<option value="0" selected="selected"></option>';
339 foreach ($bugsys->datastore
['assignto'] AS $dev)
341 $value = $dev['userid'];
342 $label = construct_user_display($dev, false
);
343 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
346 eval('$template->flush("' . $template->fetch('search') . '");');
349 /*=====================================================================*\
350 || ###################################################################
353 || ###################################################################
354 \*=====================================================================*/