Simple POP3 Fetch Mail -> POP3 Fetch Mail
[squirrelmail.git] / src / options_highlight.php
index 7b2ff63504348dc7f74ef1fd3995dbc31d6424c6..1c2da7c3cb29c6c503d84b702b49faa8ef205571 100644 (file)
@@ -3,15 +3,16 @@
 /**
  * options_highlight.php
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * Displays message highlighting options
  *
  * $Id$
+ * @package squirrelmail
  */
 
-/* Path for SquirrelMail required files. */
+/** Path for SquirrelMail required files. */
 define('SM_PATH','../');
 
 /* SquirrelMail required files. */
@@ -64,19 +65,40 @@ if (! isset($message_highlight_list)) {
     $message_highlight_list = array();
 }
 
-if ($action == 'delete' && isset($theid)) {
-
+if (isset($theid) && ($action == 'delete') ||
+                     ($action == 'up')     ||
+                     ($action == 'down')) {
     $new_rules = array();
-    foreach($message_highlight_list as $rid => $rule) {
-         if($rid != $theid) {
-             $new_rules[] = $rule;
-         }
+    switch($action) {
+        case('delete'):
+            foreach($message_highlight_list as $rid => $rule) {
+                 if($rid != $theid) {
+                     $new_rules[] = $rule;
+                 }
+            }
+            break;
+        case('down'):
+            $theid++;
+        case('up'):
+            foreach($message_highlight_list as $rid => $rule) {
+                if($rid == $theid) {
+                    $temp_rule         = $new_rules[$rid-1];
+                    $new_rules[$rid-1] = $rule;
+                    $new_rules[$rid]   = $temp_rule;
+                } else {
+                    $new_rules[$rid]   = $rule;
+                }
+            }
+            break;
+        default:
+            $new_rules = $message_highlight_list;
+            break;
     }
     $message_highlight_list = $new_rules;    
 
     setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
 
-    header( 'Location: options_highlight.php' );
+    header( 'Location: ' .get_location(). '/options_highlight.php' );
     exit;
 } else if ($action == 'save') {
 
@@ -108,16 +130,17 @@ html_tag( 'table', "\n" .
     html_tag( 'tr', "\n" .
         html_tag( 'td', '<center><b>' . _("Options") . ' - ' . _("Message Highlighting") . '</b></center>', 'left')
     ),
-    'center', $color[9], 'width="95% border="0" cellpadding="1" cellspacing="0"' ) . "<br>\n" .
-html_tag( 'table', '', '', '', 'width="100% border="0" cellpadding="1" cellspacing="0"' ) . 
+    'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"' ) . "<br>\n" .
+html_tag( 'table', '', '', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) . 
      html_tag( 'tr' ) . "\n" .
          html_tag( 'td', '', 'left' );
 
 echo '<center>[<a href="options_highlight.php?action=add">' . _("New") . '</a>]'.
         ' - [<a href="options.php">'._("Done").'</a>]</center><br>'."\n";
-if (count($message_highlight_list) >= 1) {
-    echo html_tag( 'table', '', 'center', '', 'width="80% border="0" cellpadding="3" cellspacing="0"' ) . "\n";
-    for ($i=0; $i < count($message_highlight_list); $i++) {
+$mhl_count = count($message_highlight_list);
+if ($mhl_count > 0) {
+    echo html_tag( 'table', '', 'center', '', 'width="80%" border="0" cellpadding="3" cellspacing="0"' ) . "\n";
+    for ($i=0; $i < $mhl_count; $i++) {
         $match_type = '';
         switch ($message_highlight_list[$i]['match_type'] ) {
             case 'from' :
@@ -137,12 +160,21 @@ if (count($message_highlight_list) >= 1) {
             break;
         }
 
+        $links = '<small>[<a href="options_highlight.php?action=edit&amp;theid=' . $i . '">' .
+                 _("Edit") .
+                 '</a>]&nbsp;[<a href="options_highlight.php?action=delete&amp;theid='.  $i . '">' .
+                 _("Delete");
+        if($i > 0) {
+            $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=up&amp;theid='.  $i . '">' .  _("Up");
+        }
+        if($i+1 < $mhl_count) {
+            $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=down&amp;theid='.  $i . '">' .  _("Down");
+        }
+        $links .= '</a>]</small>';
+
         echo html_tag( 'tr',
                     html_tag( 'td',
-                        '<small>[<a href="options_highlight.php?action=edit&amp;theid=' . $i . '">' .
-                        _("Edit") .
-                        '</a>]&nbsp;[<a href="options_highlight.php?action=delete&amp;theid='.
-                        $i . '">' . _("Delete") . '</a>]</small>' ,
+                        $links,
                     'left', $color[4], 'width="20%" nowrap' ) .
                     html_tag( 'td',
                         htmlspecialchars($message_highlight_list[$i]['name']) ,
@@ -303,23 +335,24 @@ if ($action == 'edit' || $action == 'add') {
     for ($i=0; $i < 14; $i++) {
         ${"selected".$i} = '';
     }
-    if ($action == 'edit' && isset($message_highlight_list[$theid]['color'])) {
+    if ($action == 'edit' && isset($theid) && 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;
+                $selected_choose = ' checked';
+                ${"selected".$i} = ' selected';
+                continue;
             }
-    }
+        }
     }
 
-    if ($action == 'edit' && isset($message_highlight_list[$theid]['color'])) {
+    if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
         $current_color = $message_highlight_list[$theid]['color'];
     }
     else {
         $current_color = '63aa7f';
     }
 
+    $pre_defined_color = 0;
     for($x = 0; $x < 5; $x++) {
         for($y = 0; $y < 19; $y++) {
             $gridindex = "$y,$x";
@@ -341,14 +374,14 @@ if ($action == 'edit' || $action == 'add') {
     echo '<form name="f" action="options_highlight.php">' . "\n";
     echo '<input type="hidden" value="save" name="action">' . "\n";
     if($action == 'edit')
-        echo '<input type="hidden" value="'.$theid.'" name="theid">' . "\n";
+        echo '<input type="hidden" value="'.(isset($theid)?$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 ($action == 'edit' && isset($message_highlight_list[$theid]['name']))
+    if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['name']))
         $disp = $message_highlight_list[$theid]['name'];
     else
         $disp = '';
@@ -377,7 +410,7 @@ if ($action == 'edit' || $action == 'add') {
     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[$theid]["color"];
+    if ($selected_input && isset($theid)) echo $message_highlight_list[$theid]["color"];
     echo '" name="newcolor_input" size="7"> '._("Ex: 63aa7f")."<br>\n";
     echo "      </td>\n";
     echo "   </tr>\n";
@@ -405,23 +438,23 @@ if ($action == 'edit' || $action == 'add') {
     echo html_tag( 'td', '', 'center', '', 'colspan="2"' ) . "\n";
     echo "         <select name=match_type>\n";
     oh_opt( 'from',
-            ($message_highlight_list[$theid]['match_type'] == 'from'),
+            (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'from':1),
             _("From") );
     oh_opt( 'to',
-            ($message_highlight_list[$theid]['match_type'] == 'to'),
+            (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to':0),
             _("To") );
     oh_opt( 'cc',
-            ($message_highlight_list[$theid]['match_type'] == 'cc'),
+            (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'cc':0),
             _("Cc") );
     oh_opt( 'to_cc',
-            ($message_highlight_list[$theid]['match_type'] == 'to_cc'),
+            (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to_cc':0),
             _("To or Cc") );
     oh_opt( 'subject',
-            ($message_highlight_list[$theid]['match_type'] == 'subject'),
+            (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'subject':0),
             _("Subject") );
     echo "         </select>\n";
     echo '<b>' . _("Matches") . ':</b> ';
-    if ($action == 'edit' && isset($message_highlight_list[$theid]['value']))
+    if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['value']))
         $disp = $message_highlight_list[$theid]['value'];
     else
         $disp = '';
@@ -436,4 +469,4 @@ if ($action == 'edit' || $action == 'add') {
 }
 do_hook('options_highlight_bottom');
 ?>
-</body></html>
+</table></body></html>