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