- Fix URL for Read Receipts being incorrect in some cases (#1177518).
[squirrelmail.git] / src / options_order.php
CommitLineData
221ca7bf 1<?php
895905c0 2
35586184 3/**
4 * options_order.php
5 *
1c159927 6 * Displays messagelist column order options
35586184 7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
ca479ad1 12 * @subpackage prefs
35586184 13 */
14
30967a1e 15/**
202bcbcc 16 * Include the SquirrelMail initialization file.
30967a1e 17 */
202bcbcc 18require('../include/init.php');
86725763 19
20/* SquirrelMail required files. */
202bcbcc 21require_once(SM_PATH . 'functions/forms.php');
22require_once(SM_PATH . 'functions/arrays.php');
221ca7bf 23
fe369c70 24/* get globals */
91c27aee 25if (sqgetGlobalVar('num', $num, SQ_GET)) {
26 $num = (int) $num;
27} else {
28 $num = false;
29}
30if (!sqgetGlobalVar('method', $method)) {
31 $method = '';
32} else {
33 $method = htmlspecialchars($method);
34}
35if (!sqgetGlobalVar('positions', $pos, SQ_GET)) {
36 $pos = 0;
37} else {
38 $pos = (int) $pos;
39}
40
41if (!sqgetGlobalVar('account', $account, SQ_GET)) {
42 $iAccount = 0;
43} else {
44 $iAccount = (int) $account;
45}
46
47if (sqgetGlobalVar('mailbox', $mailbox, SQ_GET)) {
48 $aMailboxPrefs = unserialize(getPref($data_dir, $username, "pref_".$iAccount.'_'.urldecode($mailbox)));
49 if (isset($aMailboxPrefs[MBX_PREF_COLUMNS])) {
50 $index_order = $aMailboxPrefs[MBX_PREF_COLUMNS];
51 }
52} else {
53 $index_order_ser = getPref($data_dir, $username, 'index_order');
54 if ($index_order_ser) {
55 $index_order=unserialize($index_order_ser);
56 }
57}
58if (!isset($index_order)) {
59 if (isset($internal_date_sort) && $internal_date_sort == false) {
60 $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
61 } else {
62 $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 63 }
91c27aee 64}
65
66if (!sqgetGlobalVar('account', $account, SQ_GET)) {
67 $account = 0; // future work, multiple imap accounts
68} else {
69 $account = (int) $account;
70}
1e12d1ff 71
fe369c70 72/* end of get globals */
73
91c27aee 74/***************************************************************/
75/* Finally, display whatever page we are supposed to show now. */
76/***************************************************************/
77
78displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
79
80
81/**
82 * Change the column order of a mailbox
83 *
84 * @param array $index_order (reference) contains an ordered list with columns
85 * @param string $method action to take, move, add and remove are supported
86 * @param int $num target column
87 * @param int $pos positions to move a column in the index_order array
88 * @return bool $r A change in the ordered list took place.
89 */
90function change_columns_list(&$index_order,$method,$num,$pos=0) {
91 $r = false;
92 switch ($method) {
93 case 'move': $r = sqm_array_move_value($index_order,$num,$pos); break;
1043bfcb 94 case 'add':
0883f15d 95 $index_order[] = (int) $num;
96 $r = true;
91c27aee 97 /**
98 * flush the cache in order to retrieve the new columns
99 */
100 sqsession_unregister('mailbox_cache');
101 break;
102 case 'remove':
103 if(in_array($num, $index_order)) {
104 unset($index_order[array_search($num, $index_order)]);
105 $index_order = array_values($index_order);
106 $r = true;
32f4e318 107 }
91c27aee 108 break;
109 default: break;
32f4e318 110 }
91c27aee 111 return $r;
112}
91e0dccc 113
91c27aee 114/**
115 * Column to string translation array
116 */
117$available[SQM_COL_CHECK] = _("Checkbox");
118$available[SQM_COL_FROM] = _("From");
119$available[SQM_COL_DATE] = _("Date");
120$available[SQM_COL_SUBJ] = _("Subject");
121$available[SQM_COL_FLAGS] = _("Flags");
122$available[SQM_COL_SIZE] = _("Size");
123$available[SQM_COL_PRIO] = _("Priority");
124$available[SQM_COL_ATTACHMENT] = _("Attachments");
125$available[SQM_COL_INT_DATE] = _("Received");
126$available[SQM_COL_TO] = _("To");
127$available[SQM_COL_CC] = _("Cc");
9bc67baa 128$available[SQM_COL_BCC] = _("Bcc");
91c27aee 129
130if (change_columns_list($index_order,$method,$num,$pos)) {
32f4e318 131 if ($method) {
91c27aee 132 // TODO, bound index_order to mailbox and make a difference between the global index_order and mailbox bounded index_order
133 setPref($data_dir, $username, 'index_order', serialize($index_order));
32f4e318 134 }
91c27aee 135}
136
137
138$opts = array();
139if (count($index_order) != count($available)) {
140 for ($i=0; $i < count($available); $i++) {
141 if (!in_array($i,$index_order)) {
142 $opts[$i] = $available[$i];
143 }
32f4e318 144 }
91c27aee 145}
146
91e0dccc 147
134e4174 148
91c27aee 149viewOrderForm($available, $index_order,$opts,urldecode($mailbox));
150
151
91c27aee 152// FOOD for html designers
153function viewOrderForm($aColumns, $aOrder, $aOpts, $mailbox) {
154 global $color;
155?>
156
157 <table align="center" width="95%" border="0" cellpadding="1" cellspacing="0">
158 <tr>
159 <td align="center" bgcolor="<?php echo $color[0];?>">
160 <b> <?php echo _("Options");?> - <?php echo _("Index Order");?> </b>
161 <table width="100%" border="0" cellpadding="8" cellspacing="0">
162 <tr>
163 <td align="center" bgcolor="<?php echo $color[4];?>">
164 <table width="65%" border="0" cellpadding="0" cellspacing="0">
165 <tr>
166 <td>
167 <?php 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.");?>
168 </td>
169 </tr>
170 </table>
171 <br>
172
173<?php if (count($aOrder)) { ?>
174 <table cellspacing="0" cellpadding="0" border="0">
175<?php foreach($aOrder as $i => $iCol) {
176 $sQuery = "&amp;num=$iCol";
177 if (isset($mailbox) && $mailbox) {
178 $sQuery .= '&amp;mailbox='.urlencode($mailbox);
179 }
180
181?>
182 <tr>
183<?php if ($i) { ?>
184 <td><small><a href="options_order.php?method=move&amp;positions=-1&amp;num=<?php echo $sQuery; ?>"> <?php echo _("up");?> </a></small></td>
185<?php } else { ?>
186 <td>&nbsp;</td>
187<?php } // else ?>
188 <td><small>&nbsp;|&nbsp;</small></td>
189<?php if ($i < count($aOrder) -1) { ?>
190 <td><small><a href="options_order.php?method=move&amp;positions=1&amp;num=<?php echo $sQuery; ?>"> <?php echo _("down");?> </a></small></td>
191<?php } else { ?>
192 <td>&nbsp;</td>
193<?php } // else ?>
194 <td><small>&nbsp;|&nbsp;</small></td>
195<?php
196 /* Always show the subject */
0883f15d 197 if ($iCol !== SQM_COL_SUBJ && $iCol !== SQM_COL_FLAGS) {
91c27aee 198?>
199 <td><small><a href="options_order.php?method=remove&amp;num=<?php echo $sQuery; ?>"> <?php echo _("remove");?> </a></small></td>
200<?php } else { ?>
201 <td>&nbsp;</td>
202<?php } // else ?>
203 <td><small>&nbsp;|&nbsp;</small></td>
204 <td><?php echo $aColumns[$iCol]; ?></td>
205 </tr>
206<?php
207 } // foreach
208 } // if
209?>
210 </table>
211
212<?php
213 if (count($aOpts)) {
214 echo addForm('options_order.php', 'get', 'f');
215 echo addSelect('num', $aOpts, '', TRUE);
64c9e87e 216 echo addHidden('method', 'add');
91c27aee 217 if (isset($mailbox) && $mailbox) {
218 echo addHidden('mailbox', urlencode($mailbox));
219 }
134e4174 220 echo addSubmit(_("Add"), 'submit');
32f4e318 221 echo '</form>';
222 }
221ca7bf 223?>
91c27aee 224 <p><a href="../src/options.php"><?php echo _("Return to options page");?></a></p><br>
225 </td></tr>
226 </table>
e7db48af 227 </td></tr>
91c27aee 228 </table>
e7db48af 229
91c27aee 230<?php
231}
5c4ff7bf 232$oTemplate->display('footer.tpl');
91c27aee 233?>