r1351: - Column options are now stored right for the admin setting
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 10 Dec 2006 23:22:22 +0000 (23:22 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 10 Dec 2006 23:22:22 +0000 (23:22 +0000)
- Added a searchid system to allow multiple guest searches and to setup the framework for saved searches

admin/setting.php
docs/schema_changes.sql
includes/init.php
search.php
templates/search_results.tpl

index 7c1d1587473ae9c259a7a117809de147f72cee00..c32b4da0a37a61db98e9aa648735b92625a2f862 100755 (executable)
@@ -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) . "')");
index dd01cf18e6ee394e11f1e05e0e4b07aaa50b9b3c..50e7dce6faeb74c6094aa6a179d4a2eaf43d588f 100644 (file)
@@ -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;
index 783f9b864a282bc4515a31e25f1c27824e24bbba..45418b82df038e7891b2d84d4ebd40547cb63c32 100755 (executable)
@@ -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']);
index bb72ac036e04e0e4068ead102159e030b1f11b17..0db9207674b38316c5789533c116f2bb63c73daf 100644 (file)
@@ -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 <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'] . '"?>
@@ -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'] = "&amp;hilight=$hilight";
-               eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";');
+               $bugs .= $sort->constructRow($bug, "&amp;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') . '");');
 }
index e632f3bc813bc170a2d11ba301ae8844a811b587..7b11a820abc3e9a0b61a2a4f6a6ce44024c76061 100644 (file)
@@ -11,23 +11,18 @@ $header
 
 <if condition="$show['cached']">
 <div style="font-weight: bold"><a href="search.php?new=1">{@"This search has been cached for your convenience. You can perform a new search by clicking here."}</a></div>
-<div><a href="search.php?rerun=1">{@"Alternatively, you can re-run this search by clicking here."}</a></div>
+<div><a href="search.php?rerun=1&amp;searchid=$searchid">{@"Alternatively, you can re-run this search by clicking here."}</a></div>
 <br />
 </if>
 
 <table border="$stylevar[border]" cellspacing="$stylevar[spacing]" cellpadding="$stylevar[padding]px" width="$stylevar[normal_width]">
 <tr class="listinghead">
-       <td>{@"ID"}</td>
-       <td>{@"Summary/Reporter"}</td>
-       <td>{@"Product/Version"}</td>
-       <td>{@"Status/Resolution"}</td>
-       <td>{@"Priority/Severity"}</td>
-       <td>{@"Last Post"}</td>
+$columnHeads
 </tr>
 $bugs
 </table>
 
-<div><a href="search.php?do=export">{@"Export results as XML"}</a></div>
+<div><a href="search.php?do=export&amp;searchid=$searchid">{@"Export results as XML"}</a></div>
 
 <if condition="$show['pagenav']">
 <!-- pagenav -->