X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Foptions_order.php;h=3775b6e0956947ee483d9f6f16c26f1123c8a5b7;hb=49ec41bc19432f2e2a22abff92494209809aa18e;hp=d08454c6d876075f8753f2777d64696bf3ca47ff;hpb=6bc68ee5725b293258475b15f6bcfac5a3dc068d;p=squirrelmail.git
diff --git a/src/options_order.php b/src/options_order.php
index d08454c6..3775b6e0 100644
--- a/src/options_order.php
+++ b/src/options_order.php
@@ -1,158 +1,166 @@
' . _("Options") . ' - ' . _("Index Order") . '' .
- html_tag( 'table', '', '', '', 'width="100%" border="0" cellpadding="8" cellspacing="0"' ) .
- html_tag( 'tr' ) .
- html_tag( 'td', '', 'center', $color[4] );
-
- $available[1] = _("Checkbox");
- $available[2] = _("From");
- $available[3] = _("Date");
- $available[4] = _("Subject");
- $available[5] = _("Flags");
- $available[6] = _("Size");
-
- if (! isset($method)) { $method = ''; }
-
- 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_once(SM_PATH . 'include/load_prefs.php');
+/***************************************************************/
+/* Finally, display whatever page we are supposed to show now. */
+/***************************************************************/
+
+displayPageHeader($color, null, (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;
}
- } else if ($method == 'add' && $add) {
- /* User should not be able to insert PHP-code here */
- $add = str_replace ('', '..', $add);
- $add = ereg_replace ('<.*script.*language.*php.*>', '..', $add);
- $add = str_replace ('<%', '..', $add);
- $index_order[count($index_order)+1] = $add;
+ 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) {
- for ($i=1; $i <= count($index_order); $i++) {
- setPref($data_dir, $username, "order$i", $index_order[$i]);
- }
+ // 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));
}
- echo html_tag( 'table',
- html_tag( 'tr',
- html_tag( 'td',
- _("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.")
- )
- ) ,
- '', '', '', 'width="65%" border="0" cellpadding="0" cellspacing="0"' ) . "
\n";
-
- if (count($index_order))
- {
- echo html_tag( 'table', '', '', '', ' cellspacing="0" cellpadding="0" border="0"' ) . "\n";
- for ($i=1; $i <= count($index_order); $i++) {
- $tmp = $index_order[$i];
- echo html_tag( 'tr' );
- echo html_tag( 'td', ''. _("up") .'' );
- echo html_tag( 'td', ' | ' );
- echo html_tag( 'td', ''. _("down") .'' );
- echo html_tag( 'td', ' | ' );
- echo html_tag( 'td' );
- /* Always show the subject */
- if ($tmp != 4)
- echo '' . _("remove") . '';
- else
- echo ' ';
- echo '';
- echo html_tag( 'td', ' - ' );
- echo html_tag( 'td', $available[$tmp] );
- echo '' . "\n";
- }
- echo '' . "\n";
- }
-
- if (count($index_order) != count($available)) {
-
- $opts = array();
- 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) {
- $opts[$i] = $available[$i];
- }
- }
+}
+
- echo addForm('options_order.php', 'post', 'f');
- echo addSelect('add', $opts, '', TRUE);
- echo addHidden('method', 'add');
- echo addSubmit(_("Add"), 'submit');
- echo '';
+$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];
+ }
}
-
- echo html_tag( 'p', '' . _("Return to options page") . '