comparison program/steps/settings/save_prefs.inc @ 0:4681f974d28b

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