switched doctype to standard compliance mode
[squirrelmail.git] / src / options_order.php
index f253b456b4a6b9453e796d7a8c609e25cc6bfef8..5e1c36f2adbf08e86aa9270f731febbfa47308e5 100644 (file)
 <?php
-   /**
-    **  options_highlight.php
-    **
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  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($page_header_php))
-      include("../functions/page_header.php");
-   if (!isset($display_messages_php))
-      include("../functions/display_messages.php");
-   if (!isset($imap_php))
-      include("../functions/imap.php");
-   if (!isset($array_php))
-      include("../functions/array.php");
-   if (!isset($i18n_php))
-      include("../functions/i18n.php");
-   if (!isset($plugin_php))
-      include("../functions/plugin.php");
-
-
-   if ($action == "delete" && isset($theid)) {
-      removePref($data_dir, $username, "highlight$theid");
-   } else if ($action == "save") {
-   } 
-   include("../src/load_prefs.php");
-   displayPageHeader($color, "None");
-?>
-   <br>
-   <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<?php echo $color[0] ?>">
-      <center><b><?php echo _("Options") . " - " . _("Index Order"); ?></b></center>
-   </td></tr></table>
 
-   <table width=95% align=center border=0><tr><td>
-<?php
+/**
+ * options_order.php
+ *
+ * Displays messagelist column order options
+ *
+ * @copyright &copy; 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package squirrelmail
+ * @subpackage prefs
+ */
 
-   $available[1] = _("Checkbox");
-   $available[2] = _("From");
-   $available[3] = _("Date");
-   $available[4] = _("Subject");
-   $available[5] = _("Flags");
-   $available[6] = _("Size");
-   
-   if ($method == "up" && $num > 1) {
-      $prev = $num-1;
-      $tmp = $index_order[$prev];
-      $index_order[$prev] = $index_order[$num];
-      $index_order[$num] = $tmp;
-   } else if ($method == "down" && $num < count($index_order)) {
-      $next = $num++;
-      $tmp = $index_order[$next];
-      $index_order[$next] = $index_order[$num];
-      $index_order[$num] = $tmp;
-   } else if ($method == "remove" && $num) {
-      for ($i=1; $i < 8; $i++) {
-         removePref($data_dir, $username, "order$i"); 
-      }
-      for ($j=1,$i=1; $i <= count($index_order); $i++) {
-         if ($i != $num) {
-            $new_ary[$j] = $index_order[$i];
-            $j++;
-         }
-      }
-      $index_order = array();
-      $index_order = $new_ary;
-      if (count($index_order) < 1) {
-         include "../src/load_prefs.php";
-      }
-   } else if ($method == "add" && $add) {
-      $index_order[count($index_order)+1] = $add;
-   }
+/**
+ * Path for SquirrelMail required files.
+ * @ignore
+ */
+define('SM_PATH','../');
 
-   if ($method) {
-      for ($i=1; $i <= count($index_order); $i++) {
-         setPref($data_dir, $username, "order$i", $index_order[$i]);
-      }
-   }
-   echo "<center>";
-   echo "<table cellspacing=0 cellpadding=0 border=0 width=65%><tr><td>\n";
-   echo _("The index order is the order that the columns are arranged in the message index.  You can add, remove, and move columns around to customize them to fit your needs.");
-   echo "</td></tr></table></center><br>";
-
-   if (count($index_order))
-   {
-      echo "<center>";
-      echo "<table cellspacing=0 cellpadding=0 border=0>\n";
-      for ($i=1; $i <= count($index_order); $i++) {
-         $tmp = $index_order[$i];
-         echo "<tr>";
-         echo "<td><small><a href=\"options_order.php?method=up&num=$i\">". _("up") ."</a></small></td>\n";
-         echo "<td><small>&nbsp;|&nbsp;</small></td>\n";
-         echo "<td><small><a href=\"options_order.php?method=down&num=$i\">". _("down") . "</a></small></td>\n";
-         echo "<td><small>&nbsp;|&nbsp;</small></td>\n";
-         echo "<td>";
-         // Always show the subject
-         if ($tmp != 4)
-            echo "<small><a href=\"options_order.php?method=remove&num=$i\">" . _("remove") . "</a></small>";
-         echo "</td>\n";
-         echo "<td><small>&nbsp;-&nbsp;</small></td>\n";
-         echo "<td>" . $available[$tmp] . "</td>\n";
-         echo "</tr>\n";
-      }
-      echo "</table>\n";
-      echo "</center>";
+/* SquirrelMail required files. */
+include_once(SM_PATH . 'include/validate.php');
+include_once(SM_PATH . 'functions/global.php');
+include_once(SM_PATH . 'functions/display_messages.php');
+include_once(SM_PATH . 'functions/imap.php');
+include_once(SM_PATH . 'functions/plugin.php');
+include_once(SM_PATH . 'functions/html.php');
+include_once(SM_PATH . 'functions/forms.php');
+include_once(SM_PATH . 'functions/arrays.php');
+//require_once(SM_PATH . 'functions/options.php');
+
+/* get globals */
+if (sqgetGlobalVar('num',       $num,       SQ_GET)) {
+   $num = (int) $num;
+} else {
+   $num = false;
+}
+if (!sqgetGlobalVar('method', $method)) {
+    $method = '';
+} else {
+    $method = htmlspecialchars($method);
+}
+if (!sqgetGlobalVar('positions', $pos, SQ_GET)) {
+    $pos = 0;
+} else {
+    $pos = (int) $pos;
+}
+
+if (!sqgetGlobalVar('account', $account, SQ_GET)) {
+    $iAccount = 0;
+} else {
+    $iAccount = (int) $account;
+}
+
+if (sqgetGlobalVar('mailbox', $mailbox, SQ_GET)) {
+   $aMailboxPrefs = unserialize(getPref($data_dir, $username, "pref_".$iAccount.'_'.urldecode($mailbox)));
+   if (isset($aMailboxPrefs[MBX_PREF_COLUMNS])) {
+       $index_order = $aMailboxPrefs[MBX_PREF_COLUMNS];
    }
-   
-   if (count($index_order) != count($available)) {
-   echo "<center><form name=f method=post action=options_order.php>";
-   echo "<select name=add>";
-   for ($i=1; $i <= count($available); $i++) {
-      $found = false;
-      for ($j=1; $j <= count($index_order); $j++) {
-         if ($index_order[$j] == $i) {
-            $found = true;
+} else {
+    $index_order_ser = getPref($data_dir, $username, 'index_order');
+    if ($index_order_ser) {
+        $index_order=unserialize($index_order_ser);
+    }
+}
+if (!isset($index_order)) {
+    if (isset($internal_date_sort) && $internal_date_sort == false) {
+        $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
+    } else {
+        $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_INT_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
+    }
+}
+
+if (!sqgetGlobalVar('account', $account,  SQ_GET)) {
+   $account = 0; // future work, multiple imap accounts
+} else {
+   $account = (int) $account;
+}
+
+/* end of get globals */
+
+/***************************************************************/
+/* Finally, display whatever page we are supposed to show now. */
+/***************************************************************/
+
+displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
+
+
+/**
+ * Change the column order of a mailbox
+ *
+ * @param array  $index_order (reference) contains an ordered list with columns
+ * @param string $method action to take, move, add and remove are supported
+ * @param int    $num target column
+ * @param int    $pos positions to move a column in the index_order array
+ * @return bool  $r A change in the ordered list took place.
+ */
+function change_columns_list(&$index_order,$method,$num,$pos=0) {
+    $r = false;
+    switch ($method) {
+      case 'move': $r = sqm_array_move_value($index_order,$num,$pos); break;
+      case 'add':
+          $index_order[] = (int) $num;
+          $r = true;
+          /**
+           * flush the cache in order to retrieve the new columns
+           */
+          sqsession_unregister('mailbox_cache');
+          break;
+      case 'remove':
+        if(in_array($num, $index_order)) {
+            unset($index_order[array_search($num, $index_order)]);
+            $index_order = array_values($index_order);
+            $r = true;
+        }
+        break;
+      default: break;
+    }
+    return $r;
+}
+
+/**
+ * Column to string translation array
+ */
+$available[SQM_COL_CHECK]      = _("Checkbox");
+$available[SQM_COL_FROM]       = _("From");
+$available[SQM_COL_DATE]       = _("Date");
+$available[SQM_COL_SUBJ]       = _("Subject");
+$available[SQM_COL_FLAGS]      = _("Flags");
+$available[SQM_COL_SIZE]       = _("Size");
+$available[SQM_COL_PRIO]       = _("Priority");
+$available[SQM_COL_ATTACHMENT] = _("Attachments");
+$available[SQM_COL_INT_DATE]   = _("Received");
+$available[SQM_COL_TO]         = _("To");
+$available[SQM_COL_CC]         = _("Cc");
+$available[SQM_COL_BCC]        = _("Bcc");
+
+if (change_columns_list($index_order,$method,$num,$pos)) {
+    if ($method) {
+        // TODO, bound index_order to mailbox and make a difference between the global index_order and mailbox bounded index_order
+        setPref($data_dir, $username, 'index_order', serialize($index_order));
+    }
+}
+
+
+$opts = array();
+if (count($index_order) != count($available)) {
+    for ($i=0; $i < count($available); $i++) {
+        if (!in_array($i,$index_order)) {
+             $opts[$i] = $available[$i];
          }
-      }
-      if (!$found) {
-         echo "<option value=$i>$available[$i]</option>";
-      }
-   }
-   echo "</select>";
-   echo "<input type=hidden value=add name=method>";
-   echo "<input type=submit value=\""._("Add")."\" name=submit>";
-   echo "</form></center>";
-   }
+    }
+}
+
+
+
+viewOrderForm($available, $index_order,$opts,urldecode($mailbox));
+
+
+// FOOD for html designers
+function viewOrderForm($aColumns, $aOrder, $aOpts, $mailbox) {
+   global $color;
+?>
+
+  <table align="center" width="95%" border="0" cellpadding="1" cellspacing="0">
+    <tr>
+      <td align="center" bgcolor="<?php echo $color[0];?>">
+        <b> <?php echo _("Options");?> - <?php echo _("Index Order");?> </b>
+        <table width="100%" border="0" cellpadding="8" cellspacing="0">
+          <tr>
+            <td align="center" bgcolor="<?php echo $color[4];?>">
+              <table width="65%" border="0" cellpadding="0" cellspacing="0">
+                <tr>
+                  <td>
+                    <?php echo _("The index order is the order that the columns are arranged in the message index. You can add, remove, and move columns around to customize them to fit your needs.");?>
+                  </td>
+                </tr>
+              </table>
+              <br>
 
-   echo "<br><center><a href=\"../src/options.php\">" . _("Return to options page") . "</a></center>";
+<?php if (count($aOrder)) { ?>
+              <table cellspacing="0" cellpadding="0" border="0">
+<?php     foreach($aOrder as $i => $iCol) {
+             $sQuery = "&amp;num=$iCol";
+             if (isset($mailbox) && $mailbox) {
+                 $sQuery .= '&amp;mailbox='.urlencode($mailbox);
+             }
 
 ?>
-   </td></tr></table>
-</body></html>
+                <tr>
+<?php         if ($i) { ?>
+                  <td><small><a href="options_order.php?method=move&amp;positions=-1&amp;num=<?php echo $sQuery; ?>"> <?php echo _("up");?> </a></small></td>
+<?php         } else { ?>
+                  <td>&nbsp;</td>
+<?php         } // else ?>
+                  <td><small>&nbsp;|&nbsp;</small></td>
+<?php         if ($i < count($aOrder) -1) { ?>
+                  <td><small><a href="options_order.php?method=move&amp;positions=1&amp;num=<?php echo $sQuery; ?>"> <?php echo _("down");?> </a></small></td>
+<?php         } else { ?>
+                  <td>&nbsp;</td>
+<?php         } // else ?>
+                  <td><small>&nbsp;|&nbsp;</small></td>
+<?php
+              /* Always show the subject */
+              if ($iCol !== SQM_COL_SUBJ && $iCol !== SQM_COL_FLAGS) {
+?>
+                  <td><small><a href="options_order.php?method=remove&amp;num=<?php echo $sQuery; ?>"> <?php echo _("remove");?> </a></small></td>
+<?php         } else { ?>
+                  <td>&nbsp;</td>
+<?php         } // else ?>
+                  <td><small>&nbsp;|&nbsp;</small></td>
+                  <td><?php echo $aColumns[$iCol]; ?></td>
+                </tr>
+<?php
+          } // foreach
+      } // if
+?>
+              </table>
+
+<?php
+    if (count($aOpts)) {
+        echo addForm('options_order.php', 'get', 'f');
+        echo addSelect('num', $aOpts, '', TRUE);
+        echo addHidden('method', 'add');
+        if (isset($mailbox) && $mailbox) {
+            echo addHidden('mailbox', urlencode($mailbox));
+        }
+        echo addSubmit(_("Add"), 'submit');
+        echo '</form>';
+    }
+?>
+          <p><a href="../src/options.php"><?php echo _("Return to options page");?></a></p><br>
+        </td></tr>
+      </table>
+    </td></tr>
+  </table>
+
+<?php
+}
+$oTemplate->display('footer.tpl');
+?>
\ No newline at end of file