* speed improvemnts in sorting
[squirrelmail.git] / src / options_highlight.php
index 491dbe992ef3132fc066881f83c6c50208c3fdc1..44335ba9493560d81939f630dc878b3e3a732a78 100644 (file)
@@ -7,14 +7,15 @@
     **
     **  Displays message highlighting options
     **
+    **  $Id$
     **/
 
    session_start();
 
-   if (!isset($config_php))
-      include("../config/config.php");
    if (!isset($strings_php))
       include("../functions/strings.php");
+   if (!isset($config_php))
+      include("../config/config.php");
    if (!isset($page_header_php))
       include("../functions/page_header.php");
    if (!isset($display_messages_php))
       include("../functions/array.php");
    if (!isset($i18n_php))
       include("../functions/i18n.php");
+   if (!isset($plugin_php))
+      include("../functions/plugin.php");
 
+   if (! isset($action))
+       $action = '';
+   if (! isset($message_highlight_list))
+       $message_highlight_list = array();
 
-   if ($action == "delete" && isset($id)) {
-      removePref($data_dir, $username, "highlight$id");
+   if ($action == "delete" && isset($theid)) {
+      removePref($data_dir, $username, "highlight$theid");
    } else if ($action == "save") {
-      if (!$id) $id = 0;
-      $name = ereg_replace(",", " ", $name);
+      if (!$theid) $theid = 0;
+      $identname = ereg_replace(",", " ", $identname);
+      $identname = str_replace("\\\\", "\\", $identname);
+      $identname = str_replace("\\\"", "\"", $identname);
+      $identname = str_replace("\"", """, $identname);
       if ($color_type == 1) $newcolor = $newcolor_choose;
       else $newcolor = $newcolor_input;
  
       $newcolor = ereg_replace("#", "", $newcolor);
       $newcolor = "$newcolor";
       $value = ereg_replace(",", " ", $value);
-      setPref($data_dir, $username, "highlight$id", $name.",".$newcolor.",".$value.",".$match_type);
-      $message_highlight_list[$id]["name"] = $name;
-      $message_highlight_list[$id]["color"] = $newcolor;
-      $message_highlight_list[$id]["value"] = $value;
-      $message_highlight_list[$id]["match_type"] = $match_type;
+      $value = str_replace("\\\\", "\\", $value);
+      $value = str_replace("\\\"", "\"", $value);
+      $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;
    } 
    include("../src/load_prefs.php");
    displayPageHeader($color, "None");
 ?>
    <br>
-   <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<? echo $color[0] ?>">
-      <center><b><? echo _("Options") . " - " . _("Message Highlighting"); ?></b></center>
+   <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<?php echo $color[0] ?>">
+      <center><b><?php echo _("Options") . " - " . _("Message Highlighting"); ?></b></center>
    </td></tr></table>
 
-<?
+<?php
    echo "<br><center>[<a href=\"options_highlight.php?action=add\">" . _("New") . "</a>]";
    echo " - [<a href=\"options.php\">"._("Done")."</a>]</center><br>\n";
    if (count($message_highlight_list) >= 1) {
@@ -61,7 +75,7 @@
       for ($i=0; $i < count($message_highlight_list); $i++) {
          echo "<tr>\n";
          echo "   <td width=1% bgcolor=" . $color[4] . ">\n";
-         echo "<nobr><small>[<a href=\"options_highlight.php?action=edit&id=$i\">" . _("Edit") . "</a>]&nbsp;[<a href=\"options_highlight.php?action=delete&id=$i\">"._("Delete")."</a>]</small></nobr>\n";
+         echo "<nobr><small>[<a href=\"options_highlight.php?action=edit&theid=$i\">" . _("Edit") . "</a>]&nbsp;[<a href=\"options_highlight.php?action=delete&theid=$i\">"._("Delete")."</a>]</small></nobr>\n";
          echo "   </td>";
          echo "   <td bgcolor=" . $message_highlight_list[$i]["color"] . ">\n";
          echo "      " . $message_highlight_list[$i]["name"];
@@ -78,7 +92,8 @@
       echo "<br>\n";
    }
    if ($action == "edit" || $action == "add") {
-      if (!isset($id)) $id = count($message_highlight_list);
+      if (!isset($theid)) $theid = count($message_highlight_list);
+          $message_highlight_list[$theid] = array();
  
       $color_list[0] = "4444aa";
       $color_list[1] = "44aa44";
       $color_list[11] = "bfbfbf";
       $color_list[12] = "dfdfdf";
       $color_list[13] = "ffffff";               
+      
+      $selected_input = "";
+      
       for ($i=0; $i < 14; $i++) {
-         if ($color_list[$i] == $message_highlight_list[$id]["color"]) {
-            $selected_choose = " checked";
-            ${"selected".$i} = " selected";
-            continue;
-         }
+         ${"selected".$i} = "";
+      }
+      if (isset($message_highlight_list[$theid]["color"])) {
+         for ($i=0; $i < 14; $i++) {
+            if ($color_list[$i] == $message_highlight_list[$theid]["color"]) {
+               $selected_choose = " checked";
+               ${"selected".$i} = " selected";
+               continue;
+            }
+            }
       }
-      if (!$message_highlight_list[$id]["color"])
+      if (!isset($message_highlight_list[$theid]["color"]))
          $selected_choose = " checked";
-      else if (!$selected_choose)
+      else if (!isset($selected_choose))
          $selected_input = " checked";
  
-      echo "<form action=\"options_highlight.php\">\n";
+      echo "<form name=f action=\"options_highlight.php\">\n";
       echo "<input type=\"hidden\" value=\"save\" name=\"action\">\n";
-      echo "<input type=\"hidden\" value=\"$id\" name=\"id\">\n";
+      echo "<input type=\"hidden\" value=\"$theid\" name=\"theid\">\n";
       echo "<table width=80% align=center cellpadding=3 cellspacing=0 border=0>\n";
       echo "   <tr bgcolor=\"$color[0]\">\n";
       echo "      <td align=right width=25%><b>\n";
       echo _("Identifying name") . ":";
       echo "      </b></td>\n";
       echo "      <td width=75%>\n";
-      echo "         <input type=\"text\" value=\"".$message_highlight_list[$id]["name"]."\" name=\"name\">";
+      if (isset($message_highlight_list[$theid]["name"]))
+          $disp = $message_highlight_list[$theid]["name"];
+      else
+          $disp = "";
+      $disp = str_replace("\\\\", "\\", $disp);
+      $disp = str_replace("\\\"", "\"", $disp);
+      $disp = str_replace("\"", "&quot;", $disp);
+      echo "         <input type=\"text\" value=\"".$disp."\" name=\"identname\">";
       echo "      </td>\n";
       echo "   </tr>\n";
       echo "   <tr><td><small><small>&nbsp;</small></small></td></tr>\n";
       echo "            <option value=\"$color_list[12]\"$selected12>" . _("Light Gray") . "\n";
       echo "            <option value=\"$color_list[13]\"$selected13>" . _("White") . "\n";
       echo "         </select><br>\n";
-      echo "         <input type=\"radio\" name=color_type value=2$selected_input> &nbsp;". _("Other:") ."<input type=\"text\" value=\"";                                 
-      if ($selected_input) echo $message_highlight_list[$id]["color"];
+      echo "         <input type=\"radio\" name=color_type value=2$selected_input> &nbsp;". _("Other:") ."<input type=\"text\" value=\"";
+      if ($selected_input) echo $message_highlight_list[$theid]["color"];
       echo "\" name=\"newcolor_input\" size=7> "._("Ex: 63aa7f")."<br>\n";
       echo "      </td>\n";
       echo "   </tr>\n";
       echo "      </b></td>\n";
       echo "      <td width=75%>\n";
       echo "         <select name=match_type>\n";
-      if ($message_highlight_list[$id]["match_type"] == "from")    echo "            <option value=\"from\" selected>From\n";
+      if (isset($message_highlight_list[$theid]["match_type"]) && $message_highlight_list[$theid]["match_type"] == "from")    echo "            <option value=\"from\" selected>From\n";
       else                                                         echo "            <option value=\"from\">From\n";
-      if ($message_highlight_list[$id]["match_type"] == "to")      echo "            <option value=\"to\" selected>To\n";
+      if (isset($message_highlight_list[$theid]["match_type"]) && $message_highlight_list[$theid]["match_type"] == "to")      echo "            <option value=\"to\" selected>To\n";
       else                                                         echo "            <option value=\"to\">To\n";
-      if ($message_highlight_list[$id]["match_type"] == "cc")      echo "            <option value=\"cc\" selected>Cc\n";
+      if (isset($message_highlight_list[$theid]["match_type"]) && $message_highlight_list[$theid]["match_type"] == "cc")      echo "            <option value=\"cc\" selected>Cc\n";
       else                                                         echo "            <option value=\"cc\">Cc\n";
-      if ($message_highlight_list[$id]["match_type"] == "to_cc")   echo "            <option value=\"to_cc\" selected>To or Cc\n";
+      if (isset($message_highlight_list[$theid]["match_type"]) && $message_highlight_list[$theid]["match_type"] == "to_cc")   echo "            <option value=\"to_cc\" selected>To or Cc\n";
       else                                                         echo "            <option value=\"to_cc\">To or Cc\n";
-      if ($message_highlight_list[$id]["match_type"] == "subject") echo "            <option value=\"subject\" selected>Subject\n";
+      if (isset($message_highlight_list[$theid]["match_type"]) && $message_highlight_list[$theid]["match_type"] == "subject") echo "            <option value=\"subject\" selected>Subject\n";
       else                                                         echo "            <option value=\"subject\">Subject\n";
       echo "         </select>\n";
-      echo "         <nobr><input type=\"text\" value=\"".$message_highlight_list[$id]["value"]."\" name=\"value\"> &nbsp;(";
-      echo _("Regular Expression");
-      echo ")\n      <nobr></td>\n";
+      if (isset($message_highlight_list[$theid]["value"]))
+          $disp = $message_highlight_list[$theid]["value"];
+      else
+          $disp = '';
+      $disp = str_replace("\\\\", "\\", $disp);
+      $disp = str_replace("\\\"", "\"", $disp);
+      $disp = str_replace("\"", "&quot;", $disp);
+      echo "         <nobr><input type=\"text\" value=\"".$disp."\" name=\"value\">";
+      echo "        <nobr></td>\n";
       echo "   </tr>\n";
       echo "</table>\n";
       echo "<center><input type=\"submit\" value=\"" . _("Submit") . "\"></center>\n";
       echo "</form>\n";
+      do_hook("options_highlight_bottom");
    } 
 ?>
 </body></html>