Store highlighting rules differently to make them more reliable
authorkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 29 Oct 2002 22:15:21 +0000 (22:15 +0000)
committerkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 29 Oct 2002 22:15:21 +0000 (22:15 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4075 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
functions/db_prefs.php
functions/file_prefs.php
include/load_prefs.php
src/options_highlight.php
src/options_order.php

index 8e3280d16784bb5bf91b8245caf177432dfca4f3..4abfcd9fe27f6db0376f61950b39c3c5a00f6de7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,13 @@
 *************************************
-*** Squirrelmail Devel Series 1.3 ***
+*** SquirrelMail Devel Series 1.3 ***
 *************************************
 
-       
-Version 1.3.2 -- cvs
+Version 1.3.3 -- cvs
+-------------
+  - Change the way highlighting rules are stored to make them more reliable and
+    easier to manage.
+
+Version 1.3.2
 -------------
   - Rewrite of message delivery related functions.
   - Userinterface modifications.
index 1e4a2a727c90d7253bb5c5186193f613282732eb..3708441dac832583a3940c7b3b4e595e663ece04 100644 (file)
@@ -165,10 +165,6 @@ class dbPrefs {
 
         unset($prefs_cache[$key]);
 
-        if(substr($key, 0, 9) == 'highlight') {
-            $this->renumberHighlightList($user);
-        }
-
         return true;
     }
 
@@ -271,65 +267,6 @@ class dbPrefs {
         }
     }
 
-    /*
-     * When a highlight option is deleted the preferences module
-     * must renumber the list.  This should be done somewhere else,
-     * but it is not, so....
-     */
-    function renumberHighlightList($user) {
-        if (!$this->open()) {
-            return;
-        }
-        $query = sprintf("SELECT %s, %s as prefkey, %s as prefval FROM %s WHERE %s='%s' ".
-                         "AND %s LIKE 'highlight%%' ORDER BY %s",
-                         $this->user_field,
-                         $this->key_field,
-                         $this->val_field,
-                         $this->table,
-                         $this->user_field,
-                         $this->dbh->quoteString($user),
-                         $this->key_field,
-                         $this->key_field);
-
-        $res = $this->dbh->query($query);
-        if(DB::isError($res)) {
-            $this->failQuery($res);
-        }
-
-        /* Store old data in array */
-        $rows = Array();
-        while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
-            $rows[] = $row;
-        }
-
-        /* Renumber keys of old data */
-        $hilinum = 0;
-        for($i = 0; $i < count($rows) ; $i++) {
-            $oldkey = $rows[$i]['prefkey'];
-            $newkey = substr($oldkey, 0, 9) . $hilinum;
-            $hilinum++;
-
-            if($oldkey != $newkey) {
-                $query = sprintf("UPDATE %s SET %s='%s' ".
-                                 "WHERE %s ='%s' AND %s='%s'",
-                                 $this->table,
-                                 $this->key_field,
-                                 $this->dbh->quoteString($newkey),
-                                 $this->user_field,
-                                 $this->dbh->quoteString($user),
-                                 $this->key_field,
-                                 $this->dbh->quoteString($oldkey));
-
-                $res = $this->dbh->simpleQuery($query);
-                if(DB::isError($res)) {
-                    $this->failQuery($res);
-                }
-            }
-        }
-
-        return;
-    }
-
 } /* end class dbPrefs */
 
 
index 8a4287eb0a1aa23a7513b212d726e09a97cd103a..c707d52f143988e8a269620aa772ddcebf4d509d 100644 (file)
@@ -54,6 +54,7 @@ function cachePrefValues($data_dir, $username) {
         if ($equalsAt > 0) {
             $key = substr($pref, 0, $equalsAt);
             $value = substr($pref, $equalsAt + 1);
+            /* this is to 'rescue' old-style highlighting rules. */
             if (substr($key, 0, 9) == 'highlight') {
                 $key = 'highlight' . $highlight_num;
                 $highlight_num ++;
index 35064bfa87d848bd45c3664f93271dc8b9d84f39..b1a8439fa7aaa008354d6a730316e2343fe5340b 100644 (file)
@@ -158,15 +158,23 @@ $left_refresh = strtolower($left_refresh);
 $sort = getPref($data_dir, $username, 'sort', 6 );
 
 /** Load up the Signature file **/
-$signature_abs = $signature = getSig($data_dir, $username, "g");
-
-/* Highlight comes in with the form: name, color, header, value. */
-for ($i = 0; $hlt = getPref($data_dir, $username, "highlight$i"); ++$i) {
-    $highlight_array = explode(',', $hlt);
-    $message_highlight_list[$i]['name'] = $highlight_array[0];
-    $message_highlight_list[$i]['color'] = $highlight_array[1];
-    $message_highlight_list[$i]['value'] = $highlight_array[2];
-    $message_highlight_list[$i]['match_type'] = $highlight_array[3];
+$signature_abs = $signature = getSig($data_dir, $username, 'g');
+
+/* use new way of storing highlighting rules */
+if( $ser = getPref($data_dir, $username, 'hililist') ) {
+    $message_highlight_list = unserialize($ser);
+} else {
+    /* use old way */
+    for ($i = 0; $hlt = getPref($data_dir, $username, "highlight$i"); ++$i) {
+        $highlight_array = explode(',', $hlt);
+        $message_highlight_list[$i]['name'] = $highlight_array[0];
+        $message_highlight_list[$i]['color'] = $highlight_array[1];
+        $message_highlight_list[$i]['value'] = $highlight_array[2];
+        $message_highlight_list[$i]['match_type'] = $highlight_array[3];
+        removePref($data_dir, $user_name, "highlight$i");
+    }
+    /* store in new format for the next time */
+    setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
 }
 
 /* Index order lets you change the order of the message index */
index bfb43caed35dbf945a70c2e8225333a2ad7178a7..7b2ff63504348dc7f74ef1fd3995dbc31d6424c6 100644 (file)
@@ -48,7 +48,6 @@ if (isset($_GET['value'])) {
     $value = $_GET['value'];
 }
 
-$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
 /* end of get globals */
  
 function oh_opt( $val, $sel, $tit ) {
@@ -66,27 +65,41 @@ if (! isset($message_highlight_list)) {
 }
 
 if ($action == 'delete' && isset($theid)) {
-    removePref($data_dir, $username, "highlight$theid");
-    header( "Location: $SCRIPT_NAME" );
+
+    $new_rules = array();
+    foreach($message_highlight_list as $rid => $rule) {
+         if($rid != $theid) {
+             $new_rules[] = $rule;
+         }
+    }
+    $message_highlight_list = $new_rules;    
+
+    setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
+
+    header( 'Location: options_highlight.php' );
     exit;
 } else if ($action == 'save') {
-    if (!$theid) $theid = 0;
-    $identname = str_replace(',', ' ', $identname);
+
     if ($color_type == 1) $newcolor = $newcolor_choose;
     elseif ($color_type == 2) $newcolor = $newcolor_input;
     else $newcolor = $color_type;
 
-    $newcolor = str_replace(',', '', $newcolor);
     $newcolor = str_replace('#', '', $newcolor);
     $newcolor = str_replace('"', '', $newcolor);
     $newcolor = str_replace('\'', '', $newcolor);
     $value = str_replace(',', ' ', $value);
 
-    setPref($data_dir, $username, "highlight$theid", $identname.','.$newcolor.','.$value.','.$match_type);
-    $message_highlight_list[$theid]['name'] = $identname;
-    $message_highlight_list[$theid]['color'] = $newcolor;
-    $message_highlight_list[$theid]['value'] = $value;
-    $message_highlight_list[$theid]['match_type'] = $match_type;
+    if(isset($theid)) {
+        $message_highlight_list[$theid] = 
+            array( 'name' => $identname, 'color' => $newcolor,
+                   'value' => $value, 'match_type' => $match_type );
+    } else {
+        $message_highlight_list[] = 
+            array( 'name' => $identname, 'color' => $newcolor,
+                   'value' => $value, 'match_type' => $match_type );
+    }
+
+    setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
 }
 displayPageHeader($color, 'None');
 
@@ -147,11 +160,6 @@ if (count($message_highlight_list) >= 1) {
         "<br>\n";
 }
 if ($action == 'edit' || $action == 'add') {
-    if (!isset($theid))
-    {
-        $theid = count($message_highlight_list);
-        $message_highlight_list[$theid] = array();
-    }
 
     $color_list[0] = '4444aa';
     $color_list[1] = '44aa44';
@@ -295,7 +303,7 @@ if ($action == 'edit' || $action == 'add') {
     for ($i=0; $i < 14; $i++) {
         ${"selected".$i} = '';
     }
-    if (isset($message_highlight_list[$theid]['color'])) {
+    if ($action == 'edit' && isset($message_highlight_list[$theid]['color'])) {
         for ($i=0; $i < 14; $i++) {
             if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
             $selected_choose = ' checked';
@@ -305,7 +313,7 @@ if ($action == 'edit' || $action == 'add') {
     }
     }
 
-    if (isset($message_highlight_list[$theid]['color'])) {
+    if ($action == 'edit' && isset($message_highlight_list[$theid]['color'])) {
         $current_color = $message_highlight_list[$theid]['color'];
     }
     else {
@@ -332,14 +340,15 @@ if ($action == 'edit' || $action == 'add') {
 
     echo '<form name="f" action="options_highlight.php">' . "\n";
     echo '<input type="hidden" value="save" name="action">' . "\n";
-    echo '<input type="hidden" value="'.$theid.'" name="theid">' . "\n";
+    if($action == 'edit')
+        echo '<input type="hidden" value="'.$theid.'" name="theid">' . "\n";
     echo html_tag( 'table', '', 'center', '', 'width="80%" cellpadding="3" cellspacing="0" border="0"' ) . "\n";
     echo html_tag( 'tr', '', '', $color[0] ) . "\n";
     echo html_tag( 'td', '', 'right', '', 'nowrap' ) . "<b>\n";
     echo _("Identifying name") . ":";
     echo '      </b></td>' . "\n";
     echo html_tag( 'td', '', 'left' ) . "\n";
-    if (isset($message_highlight_list[$theid]['name']))
+    if ($action == 'edit' && isset($message_highlight_list[$theid]['name']))
         $disp = $message_highlight_list[$theid]['name'];
     else
         $disp = '';
@@ -412,7 +421,7 @@ if ($action == 'edit' || $action == 'add') {
             _("Subject") );
     echo "         </select>\n";
     echo '<b>' . _("Matches") . ':</b> ';
-    if (isset($message_highlight_list[$theid]['value']))
+    if ($action == 'edit' && isset($message_highlight_list[$theid]['value']))
         $disp = $message_highlight_list[$theid]['value'];
     else
         $disp = '';
index 14a366cae5c9b0d04a84e60db1b44f1b9658dd89..7424259d95e240da2001d6a6d82c50a1a9ff8140 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 1999-2002 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- * Displays message highlighting options
+ * Displays messagelist column order options
  *
  * $Id$
  */
@@ -22,9 +22,6 @@ require_once(SM_PATH . 'functions/plugin.php');
 require_once(SM_PATH . 'functions/html.php');
 
 /* get globals */
-if (isset($_GET['action'])) {
-    $action = $_GET['action'];
-}
 if (isset($_GET['num'])) {
     $num = $_GET['num'];
 }
@@ -45,11 +42,6 @@ elseif (isset($_POST['submit'])) {
 }
 /* end of get globals */
 
-if (! isset($action)) { $action = ''; }
-if ($action == 'delete' && isset($theid)) {
-    removePref($data_dir, $username, "highlight$theid");
-} elseif ($action == 'save') {
-} 
 displayPageHeader($color, 'None');
 
    echo