r1395: - Searching of custom fields now works, but we break all saved searches
[bugdar.git] / search.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright 2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'search',
24 'search_results',
25 'search_update',
26 'search_save',
27 'trackerhome_bits',
28 'list_head',
29 'pagenav_bit',
30 'pagenav'
31 );
32
33 define('SVN', '$Id$');
34
35 $focus['search'] = 'focus';
36
37 require_once('./global.php');
38 require_once('./includes/functions_product.php');
39 require_once('./includes/class_sort.php');
40 require_once('./includes/api_bug.php');
41 require_once('./includes/class_api_error.php');
42
43 APIError(array($message, 'error'));
44
45 if (!can_perform('cansearch'))
46 {
47 $message->error_permission();
48 }
49
50 define('MODE_ANY', ($bugsys->in['mode'] == 1));
51 define('MODE_ALL', ($bugsys->in['mode'] == 2));
52 define('MODE_RAW', ($bugsys->in['mode'] == 3));
53
54 $var = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'");
55 define('SEARCH_WORD_MIN', $var['Value']);
56
57 $db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = 0 AND dateline < " . (TIMENOW - 3600));
58
59 $show['search'] = true;
60
61 // ###################################################################
62
63 if (empty($_REQUEST['do']))
64 {
65 $_REQUEST['do'] = 'search';
66 }
67
68 // ###################################################################
69
70 if ($_REQUEST['do'] == 'process')
71 {
72 // -------------------------------------------------------------------
73 // handle keywords
74 if ($bugsys->in['summary'])
75 {
76 $keywords = preg_split('#\s+#', $bugsys->in['summary']);
77
78 // TODO - need to have some str to bool conversions
79
80 foreach ($keywords AS $word)
81 {
82 if (strlen($word) < SEARCH_WORD_MIN)
83 {
84 continue;
85 }
86
87 if (MODE_ALL)
88 {
89 $querybuild['text'] .= " +$word";
90 }
91 else
92 {
93 $querybuild['text'] .= " $word";
94 }
95
96 if (!preg_match('#-(.+?)#', trim($word)))
97 {
98 $hilight .= " $word";
99 }
100 }
101
102 $hilight = preg_replace('#[^0-9a-zA-Z_ ]#', '', $hilight);
103 $hilight = trim($hilight);
104 $hilight = preg_replace('#\s#', '+', $hilight);
105
106 $temp = trim($querybuild['text']);
107
108 if (MODE_ALL OR MODE_RAW)
109 {
110 $bool_flag = ' IN BOOLEAN MODE';
111 }
112
113 $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)";
114 }
115
116 // -------------------------------------------------------------------
117 // reporter
118 if ($bugsys->in['reporter'])
119 {
120 // force email or name?? make a distinction?
121 // more elegant way to do this? probably
122 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email LIKE '%" . str_replace('%', '\%', $bugsys->input_escape('reporter')) . "' OR displayname LIKE '%" . str_replace('%', '\%', $bugsys->input_escape('reporter')) . "%'");
123 if ($user['userid'])
124 {
125 $querybuild['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]";
126 }
127 }
128
129 // -------------------------------------------------------------------
130 // product/component/version stuff
131 if (is_array($bugsys->in['product']))
132 {
133 foreach ($bugsys->in['product'] AS $prod)
134 {
135 $product = explode(',', $prod);
136 $product = $bugsys->clean($product, TYPE_UINT);
137 $products[] = $product[0];
138 $components[] = $product[1];
139 $versions[] = $product[2];
140 }
141 $querybuild['pcv'] = "AND bug.product IN (" . implode(',', $products) . ") AND bug.component IN (" . implode(',', $components) . ") AND bug.version IN (" . implode(',', $versions) . ")";
142 }
143
144 // -------------------------------------------------------------------
145 // severity, priority, status, resolution, assignedto
146
147 // severity
148 if ($bugsys->in['severity'])
149 {
150 $bugsys->input_clean('severity', TYPE_UINT);
151 $querybuild['severity'] = "AND bug.severity IN (" . implode(',', $bugsys->in['severity']) . ")";
152 }
153
154 // priority
155 if ($bugsys->in['priority'])
156 {
157 $bugsys->input_clean('priority', TYPE_UINT);
158 $querybuild['priority'] = "AND bug.priority IN (" . implode(',', $bugsys->in['priority']) . ")";
159 }
160
161 // status
162 if ($bugsys->in['status'])
163 {
164 $bugsys->input_clean('status', TYPE_UINT);
165 $querybuild['status'] = "AND bug.status IN (" . implode(',', $bugsys->in['status']) . ")";
166 }
167
168 // resolution
169 if ($bugsys->in['resolution'])
170 {
171 $bugsys->input_clean('resolution', TYPE_UINT);
172 $querybuild['resolution'] = "AND bug.resolution IN (" . implode(',', $bugsys->in['resolution']) . ")";
173 }
174
175 // assignment
176 if ($bugsys->in['assignedto'])
177 {
178 $bugsys->input_clean('assignedto', TYPE_UINT);
179 $querybuild['assignedto'] = "AND bug.assignedto IN (" . implode(',', $bugsys->in['assignedto']) . ")";
180 }
181
182 // -------------------------------------------------------------------
183 // date
184 if ($bugsys->in['date'])
185 {
186 // now - (seconds/day * number of days)
187 $dateline = time() - ($bugsys->input_clean('date', TYPE_INT) * 3600);
188 $querybuild['date'] = "AND bug.dateline >= $dateline";
189 }
190
191 // -------------------------------------------------------------------
192 // favorites
193 $bugsys->input_clean('favorite', TYPE_INT);
194 if ($bugsys->in['favorite'] != 0 AND $bugsys->userinfo['userid'])
195 {
196 $favorites = $db->query("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE userid = " . $bugsys->userinfo['userid']);
197 while ($favorite = $db->fetch_array($favorites))
198 {
199 $ids[] = $favorite['bugid'];
200 }
201 $querybuild['favorites'] = "AND bug.bugid " . ($bugsys->in['favorite'] > 0 ? "IN" : "NOT IN") . " (" . implode(', ', $ids) . ")";
202 }
203
204 // -------------------------------------------------------------------
205 // sort by
206 $sortby = array('bugid', 'severity', 'priority', 'status', 'resolution', 'dateline');
207 $orderby = array('ASC', 'DESC');
208 $bugsys->in['orderby'] = strtoupper($bugsys->in['orderby']);
209 if (in_array($bugsys->in['sortby'], $sortby) AND in_array($bugsys->in['orderby'], $orderby))
210 {
211 $sortclause = "ORDER BY " . $bugsys->in['sortby'] . ' ' . $bugsys->in['orderby'];
212 }
213 else if ($bugsys->in['sortby'] == 'relevance')
214 {
215 $sortclause = '';
216 }
217 else
218 {
219 $sortclause = '';
220 }
221
222 // -------------------------------------------------------------------
223 // custom fields
224 $fields_fetch = $bugsys->db->query("
225 SELECT bugfield.*
226 FROM " . TABLE_PREFIX . "bugfield AS bugfield
227 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
228 ON (bugfield.fieldid = permission.fieldid)
229 WHERE permission.mask <> 0
230 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
231 AND bugfield.cansearch = 1"
232 );
233 while ($field = $bugsys->db->fetch_array($fields_fetch))
234 {
235 if (!empty($bugsys->in["custom$field[fieldid]"]) OR ($field['type'] == 'select_single' AND isset($bugsys->in["custom$field[fieldid]"])))
236 {
237 if ($field['type'] == 'input_checkbox' AND $bugsys->input_clean("custom$field[fieldid]", TYPE_INT) != 0)
238 {
239 $querybuild[] = "AND bug.custom$field[fieldid] = " . ($bugsys->in["custom$field[fieldid]"] > 0 ? 1 : 0);
240 }
241 else if ($field['type'] == 'input_text')
242 {
243 $querybuild[] = "AND bug.custom$field[fieldid] LIKE '%" . $bugsys->in["custom$field[fieldid]"] . "%'";
244 }
245 else if ($field['type'] == 'select_single' AND $bugsys->in["custom$field[fieldid]"] != -1)
246 {
247 $temp = unserialize($field['selects']);
248 $querybuild[] = "AND bug.custom$field[fieldid] = '" . trim($temp[ intval($bugsys->in["custom$field[fieldid]"]) ]) . "'";
249 }
250 }
251 }
252
253 // -------------------------------------------------------------------
254 // have to search something
255 if (sizeof($querybuild) < 1)
256 {
257 $message->error(sprintf(_('You have to enter some criteria to search for. Note that words less than %1$d characters are ignored by the search engine (and some other very common words, too).'), SEARCH_WORD_MIN));
258 }
259
260 // -------------------------------------------------------------------
261 // do the search
262 $query = "
263 SELECT bug.*, comment.commentid
264 FROM " . TABLE_PREFIX . "bug AS bug
265 LEFT JOIN " . TABLE_PREFIX . "comment AS comment
266 ON (bug.bugid = comment.bugid)
267 WHERE bug.bugid <> 0
268 AND bug.product IN (#<'ONBITS:VIEW'>#)
269 AND (!bug.hidden OR (bug.hidden AND bug.product IN (#<'ONBITS:HIDDEN'>#))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (#<'ONBITS:OWNHIDDEN'>#))" : "") . ")
270 " . implode("\n\t\t", $querybuild) . "
271 GROUP BY bug.bugid
272 $sortclause";
273
274 $runquery = str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewonhidden')), $query);
275
276 $search = $db->query($runquery);
277
278 $numrows = $db->num_rows($search);
279
280 if ($numrows < 1)
281 {
282 $message->error(_('No search results were returned that matched your criteria.'));
283 }
284
285 while ($result = $db->fetch_array($search))
286 {
287 $ids[] = $result['bugid'];
288 $results[] = $result;
289 }
290
291 if ($bugsys->userinfo['userid'])
292 {
293 $db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid'] . " AND name IS NULL");
294 }
295
296 $db->query("
297 INSERT INTO " . TABLE_PREFIX . "search
298 (userid, dateline, query, ids, orderby, hilight, resultcount)
299 VALUES
300 (" . $bugsys->userinfo['userid'] . ",
301 " . TIMENOW . ", '" . $bugsys->escape($query) . "',
302 '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
303 '" . $bugsys->escape($hilight) . "',
304 " . sizeof($results) . "
305 )"
306 );
307
308 $searchid = $db->insert_id();
309
310 $justprocess = true;
311 $search = array('ids' => implode(',', $ids), 'orderby' => $sortclause);
312
313 $_POST['do'] = 'results';
314 }
315
316 // ###################################################################
317
318 if ($_REQUEST['do'] == 'search')
319 {
320 if ($bugsys->in['searchid'] AND !$bugsys->in['new'])
321 {
322 if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']))
323 {
324 $_POST['do'] = 'results';
325 $searchid = $cachedsearch['searchid'];
326 }
327 else
328 {
329 $newsearch = true;
330 }
331 }
332 else if ($bugsys->userinfo['userid'] AND !$bugsys->in['new'])
333 {
334 if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']))
335 {
336 $_POST['do'] = 'results';
337 $searchid = $cachedsearch['searchid'];
338 }
339 else
340 {
341 $newsearch = true;
342 }
343 }
344 else
345 {
346 $newsearch = true;
347 }
348
349 if ($newsearch)
350 {
351 if (!is_array($bugsys->datastore['product']))
352 {
353 $message->error(_('No products are setup, therefore there can be no bugs and thus search cannot function.'));
354 }
355
356 if (!is_array($bugsys->datastore['version']))
357 {
358 $message->error(_('No versions have been added underneath your product(s), there can be no bugs and thus search cannot function.'));
359 }
360
361 $productSelect = ConstructProductSelect();
362
363 // -------------------------------------------------------------------
364 // custom fields
365 $fields = construct_custom_fields(null, true, false, true);
366 $i = 0;
367 foreach ($fields AS $field)
368 {
369 if ($i % 2 == 0)
370 {
371 $customfields['left'] .= $field;
372 }
373 else
374 {
375 $customfields['right'] .= $field;
376 }
377 $i++;
378 }
379
380 // -------------------------------------------------------------------
381 // built-in fields
382 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
383 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
384 $select['status'] = construct_datastore_select('status', 'status', 'statusid');
385 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
386
387 $searches = '';
388 if ($bugsys->userinfo['userid'])
389 {
390 $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . $bugsys->userinfo['userid']);
391 while ($search = $db->fetch_array($searchesFetch))
392 {
393 $value = $search['searchid'];
394 $label = $search['name'];
395 eval('$searches .= "' . $template->fetch('selectoption') . '";');
396 }
397 }
398
399 $select['dev'] = '';
400 foreach ($bugsys->datastore['assignto'] AS $dev)
401 {
402 $value = $dev['userid'];
403 $label = construct_user_display($dev, false);
404 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
405 }
406
407 eval('$template->flush("' . $template->fetch('search') . '");');
408 }
409 }
410
411 // ###################################################################
412
413 if ($_REQUEST['do'] == 'update')
414 {
415 $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
416 if (!$search)
417 {
418 $message->error_permission();
419 }
420
421 $productSelect = ConstructProductSelect();
422
423 $show['update'] = true;
424
425 // -------------------------------------------------------------------
426 // custom fields
427 $fields = construct_custom_fields(null, true, false, true);
428 $i = 0;
429 foreach ($fields AS $field)
430 {
431 if ($i % 2 == 0)
432 {
433 $customfields['left'] .= $field;
434 }
435 else
436 {
437 $customfields['right'] .= $field;
438 }
439 $i++;
440 }
441
442 // -------------------------------------------------------------------
443 // built-in fields
444 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, 0);
445 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, 0);
446 $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, 0);
447 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, 0);
448
449 $select['dev'] = '';
450 $value = '0';
451 $label = '';
452 $selected = true;
453 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
454 $selected = false;
455 foreach ($bugsys->datastore['assignto'] AS $dev)
456 {
457 $value = $dev['userid'];
458 $label = construct_user_display($dev, false);
459 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
460 }
461
462 eval('$template->flush("' . $template->fetch('search_update') . '");');
463 }
464
465 // ###################################################################
466
467 if ($_POST['do'] == 'doupdate')
468 {
469 $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
470 if (!$search)
471 {
472 $message->error_permission();
473 }
474
475 // find all the bugs that we can edit
476 $bugs = $db->query("
477 SELECT * FROM " . TABLE_PREFIX . "bug
478 WHERE bugid IN ($search[ids])
479 AND product IN (" . fetch_on_bits('canviewbugs') . ")
480 AND
481 (
482 product IN (" . fetch_on_bits('caneditother') . ")
483 OR
484 (userid = " . $bugsys->userinfo['userid'] . " AND product IN (" . fetch_on_bits('caneditown') . "))
485 )
486 ");
487 while ($bug = $db->fetch_array($bugs))
488 {
489 if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['product']))
490 {
491 continue;
492 }
493
494 $api = new BugApi($bugsys);
495 $log = new Logging();
496 $log->set_bugid($bug['bugid']);
497 $log->add_data(true, $bug, $log->getCommonFields());
498
499 if ($bugsys->in['status'] AND can_perform('canchangestatus', $bug['product']))
500 {
501 $api->set('status', $bugsys->in['status']);
502 }
503 if ($bugsys->in['priority'] AND can_perform('canchangestatus', $bug['product']))
504 {
505 $api->set('priority', $bugsys->in['priority']);
506 }
507 if ($bugsys->in['severity'])
508 {
509 $api->set('severity', $bugsys->in['severity']);
510 }
511 if ($bugsys->in['resolution'] AND can_perform('canchangestatus', $bug['product']))
512 {
513 $api->set('resolution', $bugsys->in['resolution']);
514 }
515 if ($bugsys->in['assignedto'] AND can_perform('canassign', $bug['product']))
516 {
517 $api->set('severity', $bugsys->in['severity']);
518 }
519 if ($bugsys->in['product'])
520 {
521 $product = explode(',', $bugsys->in['product']);
522 $api->set('product', $product[0]);
523 $api->set('component', $product[1]);
524 $api->set('version', $product[2]);
525 }
526
527 $log->add_data(false, $api->values, $log->getCommonFields());
528
529 process_custom_fields($api, $message);
530
531 $api->update();
532 $log->update_history();
533 }
534
535 $message->redirect(_('The specified bugs have been updated and you will now return to your search results.'), 'search.php?do=results&searchid=' . $bugsys->in['searchid']);
536 }
537
538 // ###################################################################
539
540 if ($_REQUEST['do'] == 'export')
541 {
542 if (!$bugsys->in['searchid'] AND $bugsys->userinfo['userid'])
543 {
544 $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']);
545 }
546 else if ($bugsys->in['searchid'])
547 {
548 $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
549 }
550 else
551 {
552 $message->error(_('The search results are trying to export are invalid. Please start over <a href="search.php?new=1">here</a> and try again.'));
553 }
554
555 if (!$search)
556 {
557 $message->error(_('Your search has expired because it is older than one hour. Please start over <a href="search.php?new=1">here</a>.'));
558 }
559
560 $bugs = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby]");
561
562 $xml = '<?xml version="1.0" encoding="' . $language['charset'] . '"?>
563
564 <bugdarExport user="' . $bugsys->unsanitize(construct_user_display($bugsys->userinfo, false)) . '" date="' . $datef->format('r', TIMENOW) . '" searchid="' . $search['searchid'] . '">';
565
566 while ($bug = $db->fetch_array($bugs))
567 {
568 $xml .= "\n\t<bug>";
569
570 ProcessBugDataForDisplay(&$bug);
571
572 $xml .= "\n\t\t<id>" . $bug['bugid'] . "</id>";
573 $xml .= "\n\t\t<dateReported>" . $datef->format('r', $bug['dateline']) . "</dateReported>";
574 if ($bug['userid'])
575 {
576 $xml .= "\n\t\t<reporter>" . construct_user_display($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $bug[userid]"), false) . "</reporter>";
577 }
578 $xml .= "\n\t\t<summary>" . $bug['summary'] . "</summary>";
579 $xml .= "\n\t\t<product>" . $bug['product'] . "</product>";
580 if ($bug['component'])
581 {
582 $xml .= "\n\t\t<component>" . $bug['component'] . "</component>";
583 }
584 $xml .= "\n\t\t<version>" . $bug['version'] . "</version>";
585 $xml .= "\n\t\t<status>" . $bug['status'] . "</status>";
586 if ($bug['assignedto'])
587 {
588 $xml .= "\n\t\t<assignedTo>" . construct_user_display($bugsys->datastore['assignto']["$bug[assignedto]"], false) . "</assignedTo>";
589 }
590 $xml .= "\n\t\t<resolution>" . $bug['resolution'] . "</resolution>";
591 $xml .= "\n\t\t<severity>" . $bug['severity'] . "</severity>";
592 $xml .= "\n\t\t<priority>" . $bug['priority'] . "</priority>";
593
594 $xml .= "\n\t</bug>";
595 }
596
597 $xml .= "\n</bugdarExport>";
598
599 $funct->download_file($xml, _('bugdar-search-' . $search['searchid'] . '.xml'), true);
600 }
601
602 // ###################################################################
603
604 if ($_POST['do'] == 'dosave')
605 {
606 $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
607 if (!$search)
608 {
609 $message->add_error(_('The search does not exist.'));
610 }
611 if ($search['name'])
612 {
613 $message->add_error(sprintf(_('This search has already been named "%1$s".'), $search['name']));
614 }
615 if (empty($bugsys->in['name']))
616 {
617 $message->add_error(_('The name cannot be empty.'));
618 }
619
620 if (!$message->items)
621 {
622 $db->query("UPDATE " . TABLE_PREFIX . "search SET name = '" . $bugsys->input_escape('name') . "' WHERE searchid = " . $bugsys->in['searchid']);
623 $message->redirect(_('Your search has been saved.'), 'search.php?searchid=' . $search['searchid']);
624 }
625 else
626 {
627 $message->error_list_process();
628 $_REQUEST['do'] = 'save';
629 $show['errors'] = true;
630 }
631 }
632
633 // ###################################################################
634
635 if ($_REQUEST['do'] == 'save')
636 {
637 if (!$bugsys->userinfo['userid'])
638 {
639 $message->error_permission();
640 }
641
642 eval('$template->flush("' . $template->fetch('search_save') . '");');
643 }
644
645 // ###################################################################
646
647 if ($_POST['do'] == 'results')
648 {
649 $show['cached'] = false;
650 if ($searchid AND !$justprocess)
651 {
652 $search = $cachedsearch;
653 if ($search['dateline'] < TIMENOW - 900 OR $bugsys->in['rerun'])
654 {
655 $research = $db->query(str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewownhidden')), $search['query']));
656 while ($bug = $db->fetch_array($research))
657 {
658 $ids[] = $bug['bugid'];
659 $results[] = $bug;
660 }
661 $search['ids'] = implode(',', $ids);
662 $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW . ", resultcount = " . sizeof($results) . " WHERE searchid = " . $search['searchid']);
663 }
664 $show['cached'] = true;
665 $hilight = $search['hilight'];
666 }
667
668 if (!$search['ids'])
669 {
670 $message->error(_('No bugs matched your search criteria. Please <a href="search.php?new=1">try again</a> with different search requirements.'));
671 }
672
673 LoadPaginationFramework();
674 $pagination->setTotal($search['resultcount']);
675 $pagination->splitPages();
676
677 $sort = new ListSorter('search');
678
679 $show['save'] = ($bugsys->userinfo['userid'] AND !$search['name']);
680 $show['update'] = can_perform('caneditother');
681
682 $bugs = '';
683 $search = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby] LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage());
684 while ($bug = $db->fetch_array($search))
685 {
686 $funct->exec_swap_bg($stylevar['alt_color'], '');
687 ProcessBugDataForDisplay(&$bug, $funct->bgcolour);
688 $bugs .= $sort->constructRow($bug, "&amp;hilight=$hilight");
689 }
690
691 $columnHeads = $sort->constructColumnHeaders(false);
692 $show['pagenav'] = ($pagination->getPageCount() > 1);
693 $pagenav = $pagination->constructPageNav('search.php?searchid=' . $searchid);
694
695 eval('$template->flush("' . $template->fetch('search_results') . '");');
696 }
697
698 /*=====================================================================*\
699 || ###################################################################
700 || # $HeadURL$
701 || # $Id$
702 || ###################################################################
703 \*=====================================================================*/
704 ?>