Aleksander Machniak
2016-04-02 6f2c007d1be866e47bf6a9f8e6900fe6ec2a6901
commit | author | age
4e17e6 1 <?php
T 2
a95874 3 /**
4e17e6 4  +-----------------------------------------------------------------------+
T 5  | program/steps/settings/save_prefs.inc                                 |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
6f2c00 8  | Copyright (C) 2005-2016, 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>                        |
6f2c00 19  | Author: Aleksander Machniak <alec@alec.pl>                            |
4e17e6 20  +-----------------------------------------------------------------------+
T 21 */
57f0c8 22
6b2b2e 23 $CURR_SECTION = rcube_utils::get_input_value('_section', rcube_utils::INPUT_POST);
f05834 24 $a_user_prefs = array();
A 25
26 // set options for specified section
d575e4 27 switch ($CURR_SECTION) {
AM 28 case 'general':
f05834 29     $a_user_prefs = array(
d575e4 30         'language'     => isset($_POST['_language']) ? rcube_utils::get_input_value('_language', rcube_utils::INPUT_POST) : $CONFIG['language'],
AM 31         'timezone'     => isset($_POST['_timezone']) ? rcube_utils::get_input_value('_timezone', rcube_utils::INPUT_POST) : $CONFIG['timezone'],
32         'date_format'  => isset($_POST['_date_format']) ? rcube_utils::get_input_value('_date_format', rcube_utils::INPUT_POST) : $CONFIG['date_format'],
33         'time_format'  => isset($_POST['_time_format']) ? rcube_utils::get_input_value('_time_format', rcube_utils::INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
6f2c00 34         'prettydate'   => isset($_POST['_pretty_date']),
d575e4 35         'refresh_interval' => isset($_POST['_refresh_interval']) ? intval($_POST['_refresh_interval'])*60 : $CONFIG['refresh_interval'],
6f2c00 36         'standard_windows' => isset($_POST['_standard_windows']),
d575e4 37         'skin'         => isset($_POST['_skin']) ? rcube_utils::get_input_value('_skin', rcube_utils::INPUT_POST) : $CONFIG['skin'],
f05834 38     );
08ffd9 39
1cc9e2 40     // compose derived date/time format strings
T 41     if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
d575e4 42         $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
AM 43         $a_user_prefs['date_long']  = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format'];
1cc9e2 44     }
f05834 45
d575e4 46     break;
d73448 47
d575e4 48 case 'mailbox':
f05834 49     $a_user_prefs = array(
6f2c00 50         'preview_pane'         => isset($_POST['_preview_pane']),
d575e4 51         'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
AM 52         'autoexpand_threads'   => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
53         'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
6f2c00 54         'check_all_folders'    => isset($_POST['_check_all_folders']),
d575e4 55         'mail_pagesize'        => is_numeric($_POST['_mail_pagesize']) ? max(2, intval($_POST['_mail_pagesize'])) : $CONFIG['mail_pagesize'],
f05834 56     );
A 57
d575e4 58     break;
d73448 59
d575e4 60 case 'mailview':
f05834 61     $a_user_prefs = array(
d575e4 62         'message_extwin'  => intval($_POST['_message_extwin']),
6f2c00 63         'message_show_email' => isset($_POST['_message_show_email']),
AM 64         'prefer_html'     => isset($_POST['_prefer_html']),
65         'inline_images'   => isset($_POST['_inline_images']),
d575e4 66         'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
6f2c00 67         'display_next'    => isset($_POST['_display_next']),
d575e4 68         'default_charset' => rcube_utils::get_input_value('_default_charset', rcube_utils::INPUT_POST),
f05834 69     );
e55ab0 70
d575e4 71     break;
d73448 72
d575e4 73 case 'compose':
f05834 74     $a_user_prefs = array(
d575e4 75         'compose_extwin'     => intval($_POST['_compose_extwin']),
AM 76         'htmleditor'         => intval($_POST['_htmleditor']),
77         'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
78         'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
6f2c00 79         'force_7bit'         => isset($_POST['_force_7bit']),
AM 80         'mdn_default'        => isset($_POST['_mdn_default']),
81         'dsn_default'        => isset($_POST['_dsn_default']),
82         'reply_same_folder'  => isset($_POST['_reply_same_folder']),
83         'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']),
84         'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']),
85         'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']),
86         'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']),
d575e4 87         'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
AM 88         'reply_mode'         => isset($_POST['_reply_mode']) ? intval($_POST['_reply_mode']) : 0,
6f2c00 89         'sig_below'          => isset($_POST['_sig_below']),
d575e4 90         'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
6f2c00 91         'sig_separator'      => isset($_POST['_sig_separator']),
d575e4 92         'default_font'       => rcube_utils::get_input_value('_default_font', rcube_utils::INPUT_POST),
AM 93         'default_font_size'  => rcube_utils::get_input_value('_default_font_size', rcube_utils::INPUT_POST),
94         'reply_all_mode'     => intval($_POST['_reply_all_mode']),
95         'forward_attachment' => !empty($_POST['_forward_attachment']),
44b47d 96         'compose_save_localstorage' => intval($_POST['_compose_save_localstorage']),
f05834 97     );
A 98
d575e4 99     break;
d73448 100
d575e4 101 case 'addressbook':
d73448 102     $a_user_prefs = array(
d575e4 103         'default_addressbook'  => rcube_utils::get_input_value('_default_addressbook', rcube_utils::INPUT_POST, true),
6f2c00 104         'autocomplete_single'  => isset($_POST['_autocomplete_single']),
d575e4 105         'addressbook_sort_col' => rcube_utils::get_input_value('_addressbook_sort_col', rcube_utils::INPUT_POST),
AM 106         'addressbook_name_listing' => intval(rcube_utils::get_input_value('_addressbook_name_listing', rcube_utils::INPUT_POST)),
107         'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
d73448 108     );
A 109
d575e4 110     break;
d73448 111
d575e4 112 case 'server':
f05834 113     $a_user_prefs = array(
6f2c00 114         'read_when_deleted' => isset($_POST['_read_when_deleted']),
AM 115         'skip_deleted'      => isset($_POST['_skip_deleted']),
116         'flag_for_deletion' => isset($_POST['_flag_for_deletion']),
117         'delete_always'     => isset($_POST['_delete_always']),
118         'delete_junk'       => isset($_POST['_delete_junk']),
119         'logout_purge'      => isset($_POST['_logout_purge']),
120         'logout_expunge'    => isset($_POST['_logout_expunge']),
f05834 121     );
A 122
d575e4 123     break;
d73448 124
d575e4 125 case 'folders':
f05834 126     $a_user_prefs = array(
6f2c00 127         'show_real_foldernames' => isset($_POST['_show_real_foldernames']),
5c253d 128         // stop using SPECIAL-USE (#4782)
AM 129         'lock_special_folders'  => !in_array('lock_special_folders', (array) $CONFIG['dont_override']),
f05834 130     );
dc0b50 131
AM 132     foreach (rcube_storage::$folder_types as $type) {
133         $a_user_prefs[$type . '_mbox'] = rcube_utils::get_input_value('_' . $type . '_mbox', rcube_utils::INPUT_POST, true);
134     };
f05834 135
d575e4 136     break;
f05834 137 }
A 138
dae34b 139 $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
d575e4 140     array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
f05834 141
dae34b 142 $a_user_prefs = $plugin['prefs'];
cc97ea 143
b19097 144 // don't override these parameters
d575e4 145 foreach ((array)$CONFIG['dont_override'] as $p) {
AM 146     $a_user_prefs[$p] = $CONFIG[$p];
147 }
4e17e6 148
f05834 149
A 150 // verify some options
d575e4 151 switch ($CURR_SECTION) {
AM 152 case 'general':
f05834 153     // switch UI language
141c9e 154     if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
d575e4 155         $RCMAIL->load_language($a_user_prefs['language']);
AM 156         $OUTPUT->command('reload', 500);
f05834 157     }
A 158
62c791 159     // switch skin (if valid, otherwise unset the pref and fall back to default)
T 160     if (!$OUTPUT->set_skin($a_user_prefs['skin']))
d575e4 161         unset($a_user_prefs['skin']);
73571d 162     else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
d575e4 163         $OUTPUT->command('reload', 500);
f05834 164
da7178 165     $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
b373fd 166
85ef03 167     if (!empty($a_user_prefs['refresh_interval']) && !empty($CONFIG['min_refresh_interval'])) {
d575e4 168         if ($a_user_prefs['refresh_interval'] < $CONFIG['min_refresh_interval']) {
AM 169             $a_user_prefs['refresh_interval'] = $CONFIG['min_refresh_interval'];
170         }
f05834 171     }
aa8359 172
AM 173     break;
174
d575e4 175 case 'mailbox':
c1d27d 176     // force min size
d575e4 177     if ($a_user_prefs['mail_pagesize'] < 1) {
AM 178         $a_user_prefs['mail_pagesize'] = 10;
179     }
c1d27d 180
d575e4 181     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize'])) {
AM 182         $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
183     }
c1d27d 184
aa8359 185     break;
AM 186
d575e4 187 case 'addressbook':
c1d27d 188     // force min size
d575e4 189     if ($a_user_prefs['addressbook_pagesize'] < 1) {
AM 190         $a_user_prefs['addressbook_pagesize'] = 10;
191     }
c1d27d 192
d575e4 193     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize'])) {
AM 194         $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
195     }
c1d27d 196
aa8359 197     break;
AM 198
d575e4 199 case 'folders':
dc0b50 200     $storage  = $RCMAIL->get_storage();
AM 201     $specials = array();
202
203     foreach (rcube_storage::$folder_types as $type) {
204         $specials[$type] = $a_user_prefs[$type . '_mbox'];
d575e4 205     }
dc0b50 206
AM 207     $storage->set_special_folders($specials);
66df08 208
aa8359 209     break;
64f20d 210 }
2a4135 211
dae34b 212 // Save preferences
A 213 if (!$plugin['abort'])
d575e4 214     $saved = $RCMAIL->user->save_prefs($a_user_prefs);
dae34b 215 else
d575e4 216     $saved = $plugin['result'];
dae34b 217
A 218 if ($saved)
d575e4 219     $OUTPUT->show_message('successfullysaved', 'confirmation');
dae34b 220 else
827159 221     $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
4e17e6 222
f05834 223 // display the form again
6b2b2e 224 $RCMAIL->overwrite_action('edit-prefs');