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