- 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><br>';
-
- if (count($index_order))
- {
- 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> | </small></td>' . "\n";
- echo "<td><small><a href=\"options_order.php?method=down&num=$i\">". _("down") . "</a></small></td>\n";
- echo '<td><small> | </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> - </small></td>' . "\n";
- echo '<td>' . $available[$tmp] . "</td>\n";
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
-
- if (count($index_order) != count($available)) {
- echo '<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;
- }
- }
- if (!$found) {
- echo "<option value=\"$i\">$available[$i]</option>";
+} 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];