require_once('./global.php');
require_once('./includes/functions_product.php');
+require_once('./includes/class_sort.php');
if (!can_perform('cansearch'))
{
$var = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'");
define('SEARCH_WORD_MIN', $var['Value']);
+$db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = 0 AND dateline < " . (TIMENOW - 3600));
+
$show['search'] = true;
// ###################################################################
$ids[] = $result['bugid'];
$results[] = $result;
}
-
+
if ($bugsys->userinfo['userid'])
{
- $db->query("
- REPLACE INTO " . TABLE_PREFIX . "search
- (userid, dateline, query, ids, orderby, hilight, resultcount)
- VALUES
- (" . $bugsys->userinfo['userid'] . ",
- " . TIMENOW . ", '" . $bugsys->escape($query) . "',
- '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
- '" . $bugsys->escape($hilight) . "',
- " . sizeof($results) . "
- )"
- );
+ $db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid'] . " AND name IS NULL");
}
+ $db->query("
+ INSERT INTO " . TABLE_PREFIX . "search
+ (userid, dateline, query, ids, orderby, hilight, resultcount)
+ VALUES
+ (" . $bugsys->userinfo['userid'] . ",
+ " . TIMENOW . ", '" . $bugsys->escape($query) . "',
+ '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
+ '" . $bugsys->escape($hilight) . "',
+ " . sizeof($results) . "
+ )"
+ );
+
+ $searchid = $db->insert_id();
+
$justprocess = true;
$search = array('ids' => implode(',', $ids), 'orderby' => $sortclause);
- $_REQUEST['do'] = 'results';
+ $_POST['do'] = 'results';
}
// ###################################################################
{
if ($bugsys->userinfo['userid'] AND !$bugsys->in['new'])
{
- if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid']))
+ if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']))
+ {
+ $_POST['do'] = 'results';
+ $searchid = $cachedsearch['searchid'];
+ }
+ else
+ {
+ $newsearch = true;
+ }
+ }
+ else if ($bugsys->in['searchid'] AND !$bugsys->in['new'])
+ {
+ if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']))
{
- $_REQUEST['do'] = 'results';
+ $_POST['do'] = 'results';
+ $searchid = $cachedsearch['searchid'];
}
else
{
if ($_REQUEST['do'] == 'export')
{
- // TODO - allow guests to use the export function too
- $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid']);
+ if (!$bugsys->in['searchid'] AND $bugsys->userinfo['userid'])
+ {
+ $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']);
+ }
+ else if ($bugsys->in['searchid'])
+ {
+ $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
+ }
+ else
+ {
+ $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.'));
+ }
+
+ if (!$search)
+ {
+ $message->error(_('Your search has expired because it is older than one hour. Please start over <a href="search.php?new=1">here</a>.'));
+ }
+
$bugs = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby]");
$xml = '<?xml version="1.0" encoding="' . $language['charset'] . '"?>
// ###################################################################
-if ($_REQUEST['do'] == 'results')
+if ($_POST['do'] == 'results')
{
$show['cached'] = false;
- if ($bugsys->userinfo['userid'] AND !$justprocess)
+ if ($searchid AND !$justprocess)
{
$search = $cachedsearch;
if ($search['dateline'] < TIMENOW - 900 OR $bugsys->in['rerun'])
$results[] = $bug;
}
$search['ids'] = implode(',', $ids);
- $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW . ", resultcount = " . sizeof($results) . " WHERE userid = " . $bugsys->userinfo['userid']);
+ $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW . ", resultcount = " . sizeof($results) . " WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT));
}
$show['cached'] = true;
$hilight = $search['hilight'];
$pagination->setTotal($search['resultcount']);
$pagination->splitPages();
+ $sort = new ListSorter('search');
+
+ $bugs = '';
$search = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby] LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage());
while ($bug = $db->fetch_array($search))
{
$funct->exec_swap_bg($stylevar['alt_color'], '');
ProcessBugDataForDisplay(&$bug, $funct->bgcolour);
- $bug['urladd'] = "&hilight=$hilight";
- eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
+ $bugs .= $sort->constructRow($bug, "&hilight=$hilight");
}
+ $columnHeads = $sort->constructColumnHeaders(false);
$show['pagenav'] = ($pagination->getPageCount() > 1);
- $pagenav = $pagination->constructPageNav('search.php');
+ $pagenav = $pagination->constructPageNav('search.php?searchid=' . $searchid);
eval('$template->flush("' . $template->fetch('search_results') . '");');
}