alecpl
2012-04-08 1b30a710cfe7fb2917ed337c52b06bb2236e1a05
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/save_prefs.inc                                 |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
4e17e6 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Save user preferences to DB and to the current session              |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20
21  $Id$
22
23 */
57f0c8 24
f05834 25 $CURR_SECTION = get_input_value('_section', RCUBE_INPUT_POST);
b19097 26
f05834 27 $a_user_prefs = array();
A 28
29 // set options for specified section
30 switch ($CURR_SECTION)
31 {
32   case 'general':
33     $a_user_prefs = array(
34       'language'     => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'],
5879c0 35       'timezone'     => isset($_POST['_timezone']) ? get_input_value('_timezone', RCUBE_INPUT_POST) : $CONFIG['timezone'],
1cc9e2 36       'date_format'  => isset($_POST['_date_format']) ? get_input_value('_date_format', RCUBE_INPUT_POST) : $CONFIG['date_format'],
T 37       'time_format'  => isset($_POST['_time_format']) ? get_input_value('_time_format', RCUBE_INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
f05834 38       'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
A 39       'skin'          => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
40     );
08ffd9 41
1cc9e2 42     // compose derived date/time format strings
T 43     if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
44       $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
45       $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format'];
46     }
f05834 47
A 48   break;
d73448 49
f05834 50   case 'mailbox':
A 51     $a_user_prefs = array(
bc4960 52       'preview_pane'         => isset($_POST['_preview_pane']) ? TRUE : FALSE,
T 53       'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
f52c93 54       'autoexpand_threads'   => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
f05834 55       'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
A 56       'keep_alive'           => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
57       'check_all_folders'    => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
08ffd9 58       'mail_pagesize'        => is_numeric($_POST['_mail_pagesize']) ? max(2, intval($_POST['_mail_pagesize'])) : $CONFIG['mail_pagesize'],
f05834 59     );
A 60
61   break;
d73448 62
f05834 63   case 'mailview':
A 64     $a_user_prefs = array(
65       'prefer_html'     => isset($_POST['_prefer_html']) ? TRUE : FALSE,
66       'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
67       'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
68       'display_next'    => isset($_POST['_display_next']) ? TRUE : FALSE,
e55ab0 69       'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST),
f05834 70     );
e55ab0 71
f05834 72   break;
d73448 73
f05834 74   case 'compose':
A 75     $a_user_prefs = array(
868deb 76       'htmleditor'         => intval($_POST['_htmleditor']),
f05834 77       'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
A 78       'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
47ad83 79       'force_7bit'         => isset($_POST['_force_7bit']) ? TRUE : FALSE,
b3660b 80       'mdn_default'        => isset($_POST['_mdn_default']) ? TRUE : FALSE,
f22ea7 81       'dsn_default'        => isset($_POST['_dsn_default']) ? TRUE : FALSE,
eeb85f 82       'reply_same_folder'  => isset($_POST['_reply_same_folder']) ? TRUE : FALSE,
1d5779 83       'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE,
66df08 84       'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']) ? TRUE : FALSE,
A 85       'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']) ? TRUE : FALSE,
86       'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']) ? TRUE : FALSE,
0207c4 87       'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
T 88       'top_posting'        => !empty($_POST['_top_posting']),
89       'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
655bd9 90       'sig_above'          => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
7e263e 91       'default_font'       => get_input_value('_default_font', RCUBE_INPUT_POST),
f05834 92     );
A 93
94   break;
d73448 95
A 96   case 'addressbook':
97     $a_user_prefs = array(
08ffd9 98       'default_addressbook'  => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true),
A 99       'autocomplete_single'  => isset($_POST['_autocomplete_single']) ? TRUE : FALSE,
438753 100       'addressbook_sort_col' => get_input_value('_addressbook_sort_col', RCUBE_INPUT_POST),
f9a967 101       'addressbook_name_listing' => intval(get_input_value('_addressbook_name_listing', RCUBE_INPUT_POST)),
08ffd9 102       'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
d73448 103     );
A 104
105   break;
106
f05834 107   case 'server':
A 108     $a_user_prefs = array(
109       'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
110       'skip_deleted'      => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
111       'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
b7f952 112       'delete_always'       => isset($_POST['_delete_always']) ? TRUE : FALSE,
1b30a7 113       'delete_junk'       => isset($_POST['_delete_junk']) ? TRUE : FALSE,
f05834 114       'logout_purge'      => isset($_POST['_logout_purge']) ? TRUE : FALSE,
A 115       'logout_expunge'    => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
116     );
117
118   break;
d73448 119
f05834 120   case 'folders':
A 121     $a_user_prefs = array(
d9641b 122       'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST, true),
A 123       'sent_mbox'   => get_input_value('_sent_mbox', RCUBE_INPUT_POST, true),
124       'junk_mbox'   => get_input_value('_junk_mbox', RCUBE_INPUT_POST, true),
125       'trash_mbox'  => get_input_value('_trash_mbox', RCUBE_INPUT_POST, true),
f05834 126     );
A 127
128   break;
129 }
130
dae34b 131 $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
f05834 132   array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
A 133
dae34b 134 $a_user_prefs = $plugin['prefs'];
cc97ea 135
b19097 136 // don't override these parameters
T 137 foreach ((array)$CONFIG['dont_override'] as $p)
138   $a_user_prefs[$p] = $CONFIG[$p];
4e17e6 139
f05834 140
A 141 // verify some options
142 switch ($CURR_SECTION)
143 {
144   case 'general':
145
146     // switch UI language
141c9e 147     if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
f05834 148       $RCMAIL->load_language($a_user_prefs['language']);
141c9e 149       $OUTPUT->command('reload', 500);
f05834 150     }
A 151
62c791 152     // switch skin (if valid, otherwise unset the pref and fall back to default)
T 153     if (!$OUTPUT->set_skin($a_user_prefs['skin']))
154       unset($a_user_prefs['skin']);
73571d 155     else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
A 156       $OUTPUT->command('reload', 500);
f05834 157
da7178 158     $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
b373fd 159
f05834 160   break;
A 161   case 'mailbox':
162
163     // force keep_alive
164     if (isset($a_user_prefs['keep_alive'])) {
165       $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
166       if (!empty($CONFIG['session_lifetime']))
167         $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
168     }
169
c1d27d 170     // force min size
A 171     if ($a_user_prefs['mail_pagesize'] < 1)
172       $a_user_prefs['mail_pagesize'] = 10;
173
174     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize']))
175       $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
176
177   break;
178   case 'addressbook':
179
180     // force min size
181     if ($a_user_prefs['addressbook_pagesize'] < 1)
182       $a_user_prefs['addressbook_pagesize'] = 10;
183
184     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize']))
185       $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
186
f05834 187   break;
A 188   case 'folders':
189
c321a9 190     // special handling for 'default_folders'
T 191     if (in_array('default_folders', (array)$CONFIG['dont_override'])) {
f05834 192       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
141c9e 193         $a_user_prefs[$p] = $CONFIG[$p];
f05834 194     } else {
c321a9 195       $a_user_prefs['default_folders'] = array('INBOX');
f05834 196       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
141c9e 197         if ($a_user_prefs[$p])
c321a9 198           $a_user_prefs['default_folders'][] = $a_user_prefs[$p];
141c9e 199       }
f05834 200     }
66df08 201
f05834 202   break;
64f20d 203 }
2a4135 204
dae34b 205 // Save preferences
A 206 if (!$plugin['abort'])
a90ad2 207   $saved = $RCMAIL->user->save_prefs($a_user_prefs);
dae34b 208 else
A 209   $saved = $plugin['result'];
210
211 if ($saved)
f11541 212   $OUTPUT->show_message('successfullysaved', 'confirmation');
dae34b 213 else
A 214   $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
4e17e6 215
f05834 216 // display the form again
A 217 rcmail_overwrite_action('edit-prefs');
b25dfd 218