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