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