From: kink Date: Tue, 29 Oct 2002 22:15:21 +0000 (+0000) Subject: Store highlighting rules differently to make them more reliable X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=1c159927990ad2cfc7b44abb7102437383263e74 Store highlighting rules differently to make them more reliable git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4075 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/ChangeLog b/ChangeLog index 8e3280d1..4abfcd9f 100644 --- 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. diff --git a/functions/db_prefs.php b/functions/db_prefs.php index 1e4a2a72..3708441d 100644 --- a/functions/db_prefs.php +++ b/functions/db_prefs.php @@ -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 */ diff --git a/functions/file_prefs.php b/functions/file_prefs.php index 8a4287eb..c707d52f 100644 --- a/functions/file_prefs.php +++ b/functions/file_prefs.php @@ -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 ++; diff --git a/include/load_prefs.php b/include/load_prefs.php index 35064bfa..b1a8439f 100644 --- a/include/load_prefs.php +++ b/include/load_prefs.php @@ -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 */ diff --git a/src/options_highlight.php b/src/options_highlight.php index bfb43cae..7b2ff635 100644 --- a/src/options_highlight.php +++ b/src/options_highlight.php @@ -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) { "
\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 '
' . "\n"; echo '' . "\n"; - echo '' . "\n"; + if($action == 'edit') + echo '' . "\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' ) . "\n"; echo _("Identifying name") . ":"; echo ' ' . "\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 " \n"; echo '' . _("Matches") . ': '; - if (isset($message_highlight_list[$theid]['value'])) + if ($action == 'edit' && isset($message_highlight_list[$theid]['value'])) $disp = $message_highlight_list[$theid]['value']; else $disp = ''; diff --git a/src/options_order.php b/src/options_order.php index 14a366ca..7424259d 100644 --- a/src/options_order.php +++ b/src/options_order.php @@ -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