Re: clear saved searches

Bo Daley <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <[email protected]>
> > this patch adds a link allowing people to clear their list of saved
> > searches. those search lists seem to have a habit of getting long very
> > quickly.
>
> It'd be nice to be able to clear individual searches instead of losing the
> whole lot of them. Also, this seems to reference a file (clearsearch.php)
> that doesn't exist. And why does the action show up on screens that the
> search list isn't displayed on?

ooops -- hopefully I've included all the files this time (must've been getting
dangerously close to the end of the week when I posted that one) plus I've
cleaned up the action a bit so it won't display unless there are saved
searches. Also it now supports clearing individual searches as well as clearing
them all in one go.

this uses the 'delete.gif' icon which isn't in Whups yet - so if this looks ok
feel free to copy it over.

bo.


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
clearsearch.php (application/x-httpd-php, 975 B)
<?php
/**
 * $Horde$
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 */

@define('WHUPS_BASE', dirname(__FILE__));
require_once WHUPS_BASE . '/lib/base.php';

$vars = &Horde_Form::getDefaultVars();
$clear = $vars->getVar('clear');
$search_name = $vars->getVar('search_name');

if (!empty($clear) && $clear) {
    // clear searches for current user
    if (!empty($search_name)) {
        $whups->clearUserSearches(Auth::getAuth(), $search_name);
        $msg = _("Search cleared.");
    } else {
        $whups->clearUserSearches(Auth::getAuth());
        $msg = _("Searches cleared.");
    }
    $notification->push($msg, 'horde.success'); 
} else {
    $notification->push(_("No searches cleared."), 'horde.warning');
}

/* Return to the previous page. */
$referer = basename($_SERVER['HTTP_REFERER']);
header('Location: ' . Horde::applicationUrl($referer, true));
exit;
sql.php.diff (text/diff, 897 B)
Index: sql.php
===================================================================
RCS file: /repository/whups/lib/Driver/sql.php,v
retrieving revision 1.106
diff -u -r1.106 sql.php
--- sql.php	20 Jun 2003 20:13:42 -0000	1.106
+++ sql.php	23 Jun 2003 02:43:48 -0000
@@ -1350,6 +1350,16 @@
         return $searches;
     }
 
+    function clearUserSearches($user, $search_name=null)
+    {
+        $query = 'DELETE FROM whups_users_searches WHERE user_uid = ' . $this->_db->quote($user);
+        if (!empty($search_name)) {
+            $query .= ' AND search_name = ' . $this->_db->quote($search_name);
+        }
+        Horde::logMessage('SQL Query by Whups_Driver_sql::getUserSearches(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        return $this->_query($query);
+    }
+
     function saveSearch($name, $getvars)
     {
         $userid  = $this->_db->quote(Auth::getAuth());
useractions.inc.diff (text/diff, 1.5 KB)
Index: useractions.inc
===================================================================
RCS file: /repository/whups/templates/useractions.inc,v
retrieving revision 1.8
diff -u -r1.8 useractions.inc
--- useractions.inc	27 Apr 2003 00:28:21 -0000	1.8
+++ useractions.inc	23 Jun 2003 02:47:10 -0000
@@ -16,13 +16,26 @@
             return;
         }
 
+        $clearurl = Horde::addParameter('clearsearch.php', 'clear', 1);
+
         $renderer->beginActive($title);
+        
+        if (count($results)) {
+            echo "<tr class=\"item\"><td colspan=\"2\" align=\"right\">" . Horde::widget($clearurl, _("Clear All Searches"), 'widget', '', '', _("Clear All Searches")) . "</td></tr>\n";
+        }
 
         $z = 0;
         foreach ($results as $name => $search_getvars) {
             $z++;
             $item = "item" . ($z % 2);
-            echo "<tr class=\"$item\"><td colspan=\"2\">" . Horde::link(Horde::applicationUrl("search.php?$search_getvars"), $name) . $name . "</a></td></tr>\n";
+            echo "<tr class=\"$item\">\n"; ?>
+            <td nowrap="nowrap">
+            <?php echo Horde::link(Horde::applicationUrl(Horde::addParameter($clearurl, 'search_name', $name)), _("Delete Search"), 'widget'); ?>
+            <?php echo Horde::img('delete.gif', _("Delete Search")); ?>
+            </a></td>
+            <?php
+            echo "<td>" . Horde::link(Horde::applicationUrl("search.php?$search_getvars"), $name) . $name . "</a></td>\n";
+            echo "</tr>\n";
         }
 
         $renderer->end();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.