fix some bugs found by grepping for urlencode/urldecode
[squirrelmail.git] / src / options_order.php
1 <?php
2 /**
3 * options_order.php
4 *
5 * Displays messagelist column order options
6 *
7 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @version $Id$
10 * @package squirrelmail
11 * @subpackage prefs
12 */
13
14 /**
15 * Include the SquirrelMail initialization file.
16 */
17 require('../include/init.php');
18
19 /* SquirrelMail required files. */
20 require_once(SM_PATH . 'functions/forms.php');
21
22 /* get globals */
23 if (sqgetGlobalVar('num', $num, SQ_GET)) {
24 $num = (int) $num;
25 } else {
26 $num = false;
27 }
28 if (!sqgetGlobalVar('method', $method)) {
29 $method = '';
30 } else {
31 $method = htmlspecialchars($method);
32 }
33 if (!sqgetGlobalVar('positions', $pos, SQ_GET)) {
34 $pos = 0;
35 } else {
36 $pos = (int) $pos;
37 }
38
39 if (!sqgetGlobalVar('account', $account, SQ_GET)) {
40 $iAccount = 0;
41 } else {
42 $iAccount = (int) $account;
43 }
44
45 if (sqgetGlobalVar('mailbox', $mailbox, SQ_GET)) {
46 $aMailboxPrefs = unserialize(getPref($data_dir, $username, "pref_".$iAccount.'_'.$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 }
56 if (!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);
61 }
62 }
63
64 if (!sqgetGlobalVar('account', $account, SQ_GET)) {
65 $account = 0; // future work, multiple imap accounts
66 } else {
67 $account = (int) $account;
68 }
69
70 /* end of get globals */
71
72 /***************************************************************/
73 /* Finally, display whatever page we are supposed to show now. */
74 /***************************************************************/
75
76 displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
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 */
88 function 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;
92 case 'add':
93 $index_order[] = (int) $num;
94 $r = true;
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;
105 }
106 break;
107 default: break;
108 }
109 return $r;
110 }
111
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");
126 $available[SQM_COL_BCC] = _("Bcc");
127
128 if (change_columns_list($index_order,$method,$num,$pos)) {
129 if ($method) {
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));
132 }
133 }
134
135
136 $opts = array();
137 if (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 }
142 }
143 }
144
145 // FIXME: why are we using this? $PHP_SELF is already a global var processed (and therefore trustworthy) by init.php
146 sqgetGlobalVar('PHP_SELF', $PHP_SELF, SQ_SERVER);
147 $x = isset($mailbox) && $mailbox ? '&amp;mailbox='.urlencode($mailbox) : '';
148
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));
153
154 // FIXME: (related to the above) $PHP_SELF might already have a query string... don't assume otherwise here by adding the ? sign!!
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=');
158 $oTemplate->assign('add', $PHP_SELF.'?method=add'.$x.'&amp;num=');
159 $oTemplate->assign('addField_action', $PHP_SELF);
160
161 $oTemplate->display('options_order.tpl');
162
163 $oTemplate->display('footer.tpl');
164 ?>