Add comments reminding someone to make a fix here
[squirrelmail.git] / src / options_order.php
CommitLineData
221ca7bf 1<?php
35586184 2/**
3 * options_order.php
4 *
1c159927 5 * Displays messagelist column order options
35586184 6 *
4b5049de 7 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 9 * @version $Id$
8f6f9ba5 10 * @package squirrelmail
ca479ad1 11 * @subpackage prefs
35586184 12 */
13
30967a1e 14/**
202bcbcc 15 * Include the SquirrelMail initialization file.
30967a1e 16 */
202bcbcc 17require('../include/init.php');
86725763 18
19/* SquirrelMail required files. */
202bcbcc 20require_once(SM_PATH . 'functions/forms.php');
221ca7bf 21
fe369c70 22/* get globals */
91c27aee 23if (sqgetGlobalVar('num', $num, SQ_GET)) {
24 $num = (int) $num;
25} else {
26 $num = false;
27}
28if (!sqgetGlobalVar('method', $method)) {
29 $method = '';
30} else {
31 $method = htmlspecialchars($method);
32}
33if (!sqgetGlobalVar('positions', $pos, SQ_GET)) {
34 $pos = 0;
35} else {
36 $pos = (int) $pos;
37}
38
39if (!sqgetGlobalVar('account', $account, SQ_GET)) {
40 $iAccount = 0;
41} else {
42 $iAccount = (int) $account;
43}
44
45if (sqgetGlobalVar('mailbox', $mailbox, SQ_GET)) {
46 $aMailboxPrefs = unserialize(getPref($data_dir, $username, "pref_".$iAccount.'_'.urldecode($mailbox)));
47 if (isset($aMailboxPrefs[MBX_PREF_COLUMNS])) {
48 $index_order = $aMailboxPrefs[MBX_PREF_COLUMNS];
49 }
50} else {
51 $index_order_ser = getPref($data_dir, $username, 'index_order');
52 if ($index_order_ser) {
53 $index_order=unserialize($index_order_ser);
54 }
55}
56if (!isset($index_order)) {
57 if (isset($internal_date_sort) && $internal_date_sort == false) {
58 $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
59 } else {
60 $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);
1043bfcb 61 }
91c27aee 62}
63
64if (!sqgetGlobalVar('account', $account, SQ_GET)) {
65 $account = 0; // future work, multiple imap accounts
66} else {
67 $account = (int) $account;
68}
1e12d1ff 69
fe369c70 70/* end of get globals */
71
91c27aee 72/***************************************************************/
73/* Finally, display whatever page we are supposed to show now. */
74/***************************************************************/
75
876fdb60 76displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
91c27aee 77
78
79/**
80 * Change the column order of a mailbox
81 *
82 * @param array $index_order (reference) contains an ordered list with columns
83 * @param string $method action to take, move, add and remove are supported
84 * @param int $num target column
85 * @param int $pos positions to move a column in the index_order array
86 * @return bool $r A change in the ordered list took place.
87 */
88function change_columns_list(&$index_order,$method,$num,$pos=0) {
89 $r = false;
90 switch ($method) {
91 case 'move': $r = sqm_array_move_value($index_order,$num,$pos); break;
1043bfcb 92 case 'add':
0883f15d 93 $index_order[] = (int) $num;
94 $r = true;
91c27aee 95 /**
96 * flush the cache in order to retrieve the new columns
97 */
98 sqsession_unregister('mailbox_cache');
99 break;
100 case 'remove':
101 if(in_array($num, $index_order)) {
102 unset($index_order[array_search($num, $index_order)]);
103 $index_order = array_values($index_order);
104 $r = true;
32f4e318 105 }
91c27aee 106 break;
107 default: break;
32f4e318 108 }
91c27aee 109 return $r;
110}
91e0dccc 111
91c27aee 112/**
113 * Column to string translation array
114 */
115$available[SQM_COL_CHECK] = _("Checkbox");
116$available[SQM_COL_FROM] = _("From");
117$available[SQM_COL_DATE] = _("Date");
118$available[SQM_COL_SUBJ] = _("Subject");
119$available[SQM_COL_FLAGS] = _("Flags");
120$available[SQM_COL_SIZE] = _("Size");
121$available[SQM_COL_PRIO] = _("Priority");
122$available[SQM_COL_ATTACHMENT] = _("Attachments");
123$available[SQM_COL_INT_DATE] = _("Received");
124$available[SQM_COL_TO] = _("To");
125$available[SQM_COL_CC] = _("Cc");
9bc67baa 126$available[SQM_COL_BCC] = _("Bcc");
91c27aee 127
128if (change_columns_list($index_order,$method,$num,$pos)) {
32f4e318 129 if ($method) {
91c27aee 130 // TODO, bound index_order to mailbox and make a difference between the global index_order and mailbox bounded index_order
131 setPref($data_dir, $username, 'index_order', serialize($index_order));
32f4e318 132 }
91c27aee 133}
134
135
136$opts = array();
137if (count($index_order) != count($available)) {
138 for ($i=0; $i < count($available); $i++) {
139 if (!in_array($i,$index_order)) {
140 $opts[$i] = $available[$i];
141 }
32f4e318 142 }
91c27aee 143}
144
546d6deb 145// FIXME: why are we using this? $PHP_SELF is already a global var processed (and therefore trustworthy) by init.php
176dafe1 146sqgetGlobalVar('PHP_SELF', $PHP_SELF, SQ_SERVER);
147$x = isset($mailbox) && $mailbox ? '&amp;mailbox='.urlencode($mailbox) : '';
91e0dccc 148
176dafe1 149$oTemplate->assign('fields', $available);
150$oTemplate->assign('current_order', $index_order);
151$oTemplate->assign('not_used', $opts);
152$oTemplate->assign('always_show', array(SQM_COL_SUBJ, SQM_COL_FLAGS));
134e4174 153
546d6deb 154// FIXME: (related to the above) $PHP_SELF might already have a query string... don't assume otherwise here by adding the ? sign!!
176dafe1 155$oTemplate->assign('move_up', $PHP_SELF .'?method=move&amp;positions=-1'. $x .'&amp;num=');
156$oTemplate->assign('move_down', $PHP_SELF .'?method=move&amp;positions=1'. $x .'&amp;num=');
157$oTemplate->assign('remove', $PHP_SELF .'?method=remove'. $x .'&amp;num=');
fda44c83 158$oTemplate->assign('add', $PHP_SELF.'?method=add'.$x.'&amp;num=');
176dafe1 159$oTemplate->assign('addField_action', $PHP_SELF);
91c27aee 160
176dafe1 161$oTemplate->display('options_order.tpl');
e7db48af 162
5c4ff7bf 163$oTemplate->display('footer.tpl');
918fcc1d 164?>