From 6e1989af8b10812eab0867a49450345b29c616f8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 10 Dec 2006 23:22:22 +0000 Subject: [PATCH] r1351: - Column options are now stored right for the admin setting - Added a searchid system to allow multiple guest searches and to setup the framework for saved searches --- admin/setting.php | 9 +++- docs/schema_changes.sql | 8 +++- includes/init.php | 1 + search.php | 85 ++++++++++++++++++++++++++---------- templates/search_results.tpl | 11 ++--- 5 files changed, 81 insertions(+), 33 deletions(-) diff --git a/admin/setting.php b/admin/setting.php index 7c1d158..c32b4da 100755 --- a/admin/setting.php +++ b/admin/setting.php @@ -47,7 +47,14 @@ if ($_POST['do'] == 'update') { if (is_array($value)) { - $value = implode(',', $value); + if ($varname == 'columnoptions') + { + $value = serialize($value); + } + else + { + $value = implode(',', $value); + } } $db->query("REPLACE INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('" . $bugsys->escape($varname) . "', '" . $bugsys->escape($value) . "')"); diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index dd01cf1..50e7dce 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -4,4 +4,10 @@ ALTER TABLE `comment` ADD parselinks BOOL NULL; ALTER TABLE user ADD columnoptions TEXT NULL; -ALTER TABLE product CHANGE componentmother parentid int(10) UNSIGNED NULL; +ALTER TABLE product CHANGE componentmother parentid INT UNSIGNED NULL; + +ALTER TABLE search DROP PRIMARY KEY; + +ALTER TABLE search ADD searchid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY; + +ALTER TABLE search ADD name VARCHAR(250) NULL; diff --git a/includes/init.php b/includes/init.php index 783f9b8..45418b8 100755 --- a/includes/init.php +++ b/includes/init.php @@ -94,6 +94,7 @@ while ($store = $db->fetch_array($datastoretemp)) $bugsys->datastore["$store[title]"] = unserialize($store['data']); } $bugsys->options = $bugsys->datastore['setting']; +$bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']); unset($bugsys->datastore['setting']); $bugsys->setAppVersion($bugsys->options['trackerversion']); diff --git a/search.php b/search.php index bb72ac0..0db9207 100644 --- a/search.php +++ b/search.php @@ -33,6 +33,7 @@ $focus['search'] = 'focus'; require_once('./global.php'); require_once('./includes/functions_product.php'); +require_once('./includes/class_sort.php'); if (!can_perform('cansearch')) { @@ -46,6 +47,8 @@ define('MODE_RAW', ($bugsys->in['mode'] == 3)); $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; // ################################################################### @@ -278,26 +281,30 @@ if ($_REQUEST['do'] == 'process') $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'; } // ################################################################### @@ -306,9 +313,22 @@ if ($_REQUEST['do'] == 'search') { 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 { @@ -374,8 +394,24 @@ if ($_REQUEST['do'] == 'search') 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 here and try again.')); + } + + if (!$search) + { + $message->error(_('Your search has expired because it is older than one hour. Please start over here.')); + } + $bugs = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($search[ids]) $search[orderby]"); $xml = ' @@ -420,10 +456,10 @@ if ($_REQUEST['do'] == 'export') // ################################################################### -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']) @@ -435,7 +471,7 @@ if ($_REQUEST['do'] == 'results') $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']; @@ -445,17 +481,20 @@ if ($_REQUEST['do'] == 'results') $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') . '");'); } diff --git a/templates/search_results.tpl b/templates/search_results.tpl index e632f3b..7b11a82 100644 --- a/templates/search_results.tpl +++ b/templates/search_results.tpl @@ -11,23 +11,18 @@ $header
{@"This search has been cached for your convenience. You can perform a new search by clicking here."}
-
{@"Alternatively, you can re-run this search by clicking here."}
+
{@"Alternatively, you can re-run this search by clicking here."}

- - - - - - +$columnHeads $bugs
{@"ID"}{@"Summary/Reporter"}{@"Product/Version"}{@"Status/Resolution"}{@"Priority/Severity"}{@"Last Post"}
-
{@"Export results as XML"}
+
{@"Export results as XML"}
-- 2.43.5