4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_prefs.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Save user preferences to DB and to the current session |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: save_prefs.inc 5543 2011-12-05 07:24:36Z alec $
22 $CURR_SECTION = get_input_value('_section', RCUBE_INPUT_POST);
24 $a_user_prefs = array();
26 // set options for specified section
27 switch ($CURR_SECTION)
30 $a_user_prefs = array(
31 'language' => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'],
32 'timezone' => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'],
33 'dst_active' => isset($_POST['_dst_active']) ? TRUE : FALSE,
34 'pagesize' => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'],
35 'date_format' => isset($_POST['_date_format']) ? get_input_value('_date_format', RCUBE_INPUT_POST) : $CONFIG['date_format'],
36 'time_format' => isset($_POST['_time_format']) ? get_input_value('_time_format', RCUBE_INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
37 'prettydate' => isset($_POST['_pretty_date']) ? TRUE : FALSE,
38 'skin' => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
41 // compose derived date/time format strings
42 if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
43 $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
44 $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format'];
50 $a_user_prefs = array(
51 'preview_pane' => isset($_POST['_preview_pane']) ? TRUE : FALSE,
52 'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
53 'autoexpand_threads' => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
54 'mdn_requests' => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
55 'keep_alive' => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
56 'check_all_folders' => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
62 $a_user_prefs = array(
63 'prefer_html' => isset($_POST['_prefer_html']) ? TRUE : FALSE,
64 'inline_images' => isset($_POST['_inline_images']) ? TRUE : FALSE,
65 'show_images' => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
66 'display_next' => isset($_POST['_display_next']) ? TRUE : FALSE,
67 'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST),
73 $a_user_prefs = array(
74 'htmleditor' => intval($_POST['_htmleditor']),
75 'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
76 'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
77 'force_7bit' => isset($_POST['_force_7bit']) ? TRUE : FALSE,
78 'mdn_default' => isset($_POST['_mdn_default']) ? TRUE : FALSE,
79 'dsn_default' => isset($_POST['_dsn_default']) ? TRUE : FALSE,
80 'reply_same_folder' => isset($_POST['_reply_same_folder']) ? TRUE : FALSE,
81 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE,
82 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']) ? TRUE : FALSE,
83 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']) ? TRUE : FALSE,
84 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']) ? TRUE : FALSE,
85 'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
86 'top_posting' => !empty($_POST['_top_posting']),
87 'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
88 'sig_above' => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
94 $a_user_prefs = array(
95 'default_addressbook' => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true),
96 'autocomplete_single' => isset($_POST['_autocomplete_single']) ? TRUE : FALSE,
102 $a_user_prefs = array(
103 'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
104 'skip_deleted' => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
105 'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
106 'delete_always' => isset($_POST['_delete_always']) ? TRUE : FALSE,
107 'logout_purge' => isset($_POST['_logout_purge']) ? TRUE : FALSE,
108 'logout_expunge' => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
114 $a_user_prefs = array(
115 'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST, true),
116 'sent_mbox' => get_input_value('_sent_mbox', RCUBE_INPUT_POST, true),
117 'junk_mbox' => get_input_value('_junk_mbox', RCUBE_INPUT_POST, true),
118 'trash_mbox' => get_input_value('_trash_mbox', RCUBE_INPUT_POST, true),
124 $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
125 array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
127 $a_user_prefs = $plugin['prefs'];
129 // don't override these parameters
130 foreach ((array)$CONFIG['dont_override'] as $p)
131 $a_user_prefs[$p] = $CONFIG[$p];
134 // verify some options
135 switch ($CURR_SECTION)
139 // switch UI language
140 if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
141 $RCMAIL->load_language($a_user_prefs['language']);
142 $OUTPUT->command('reload', 500);
145 // switch skin (if valid, otherwise unset the pref and fall back to default)
146 if (!$OUTPUT->set_skin($a_user_prefs['skin']))
147 unset($a_user_prefs['skin']);
148 else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
149 $OUTPUT->command('reload', 500);
152 if ($a_user_prefs['pagesize'] < 1)
153 $a_user_prefs['pagesize'] = 10;
155 if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
156 $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
158 $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
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']);
173 // special handling for 'default_imap_folders'
174 if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
175 foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
176 $a_user_prefs[$p] = $CONFIG[$p];
178 $a_user_prefs['default_imap_folders'] = array('INBOX');
179 foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
180 if ($a_user_prefs[$p])
181 $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
189 if (!$plugin['abort'])
190 $saved = $USER->save_prefs($a_user_prefs);
192 $saved = $plugin['result'];
195 $OUTPUT->show_message('successfullysaved', 'confirmation');
197 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
199 // display the form again
200 rcmail_overwrite_action('edit-prefs');