source: github/program/steps/settings/save_prefs.inc @ 5879c09

HEADcourier-fixdev-browser-capabilitiespdorelease-0.8
Last change on this file since 5879c09 was 5879c09, checked in by thomascube <thomas@…>, 17 months ago

Use proper timezones from PHP's internal timezonedb (#1485592)

  • Property mode set to 100644
File size: 8.9 KB
Line 
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-2009, The Roundcube Dev Team                       |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Save user preferences to DB and to the current session              |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22$CURR_SECTION = get_input_value('_section', RCUBE_INPUT_POST);
23
24$a_user_prefs = array();
25
26// set options for specified section
27switch ($CURR_SECTION)
28{
29  case 'general':
30    $a_user_prefs = array(
31      'language'     => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'],
32      'timezone'     => isset($_POST['_timezone']) ? get_input_value('_timezone', RCUBE_INPUT_POST) : $CONFIG['timezone'],
33      'date_format'  => isset($_POST['_date_format']) ? get_input_value('_date_format', RCUBE_INPUT_POST) : $CONFIG['date_format'],
34      'time_format'  => isset($_POST['_time_format']) ? get_input_value('_time_format', RCUBE_INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
35      'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
36      'skin'         => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
37    );
38
39    // compose derived date/time format strings
40    if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
41      $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
42      $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format'];
43    }
44
45  break;
46
47  case 'mailbox':
48    $a_user_prefs = array(
49      'preview_pane'         => isset($_POST['_preview_pane']) ? TRUE : FALSE,
50      'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
51      'autoexpand_threads'   => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
52      'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
53      'keep_alive'           => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
54      'check_all_folders'    => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
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      'prefer_html'     => isset($_POST['_prefer_html']) ? TRUE : FALSE,
63      'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
64      'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
65      'display_next'    => isset($_POST['_display_next']) ? TRUE : FALSE,
66      'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST),
67    );
68
69  break;
70
71  case 'compose':
72    $a_user_prefs = array(
73      'htmleditor'         => intval($_POST['_htmleditor']),
74      'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
75      'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
76      'force_7bit'         => isset($_POST['_force_7bit']) ? TRUE : FALSE,
77      'mdn_default'        => isset($_POST['_mdn_default']) ? TRUE : FALSE,
78      'dsn_default'        => isset($_POST['_dsn_default']) ? TRUE : FALSE,
79      'reply_same_folder'  => isset($_POST['_reply_same_folder']) ? TRUE : FALSE,
80      'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE,
81      'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']) ? TRUE : FALSE,
82      'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']) ? TRUE : FALSE,
83      'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']) ? TRUE : FALSE,
84      'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
85      'top_posting'        => !empty($_POST['_top_posting']),
86      'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
87      'sig_above'          => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
88      'default_font'       => get_input_value('_default_font', RCUBE_INPUT_POST),
89    );
90
91  break;
92
93  case 'addressbook':
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,
97      'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
98    );
99
100  break;
101
102  case 'server':
103    $a_user_prefs = array(
104      'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
105      'skip_deleted'      => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
106      'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
107      'delete_always'     => isset($_POST['_delete_always']) ? TRUE : FALSE,
108      'logout_purge'      => isset($_POST['_logout_purge']) ? TRUE : FALSE,
109      'logout_expunge'    => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
110    );
111
112  break;
113
114  case 'folders':
115    $a_user_prefs = array(
116      'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST, true),
117      'sent_mbox'   => get_input_value('_sent_mbox', RCUBE_INPUT_POST, true),
118      'junk_mbox'   => get_input_value('_junk_mbox', RCUBE_INPUT_POST, true),
119      'trash_mbox'  => get_input_value('_trash_mbox', RCUBE_INPUT_POST, true),
120    );
121
122  break;
123}
124
125$plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
126  array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
127
128$a_user_prefs = $plugin['prefs'];
129
130// don't override these parameters
131foreach ((array)$CONFIG['dont_override'] as $p)
132  $a_user_prefs[$p] = $CONFIG[$p];
133
134
135// verify some options
136switch ($CURR_SECTION)
137{
138  case 'general':
139
140    // switch UI language
141    if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
142      $RCMAIL->load_language($a_user_prefs['language']);
143      $OUTPUT->command('reload', 500);
144    }
145
146    // switch skin (if valid, otherwise unset the pref and fall back to default)
147    if (!$OUTPUT->set_skin($a_user_prefs['skin']))
148      unset($a_user_prefs['skin']);
149    else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
150      $OUTPUT->command('reload', 500);
151
152    // force min size
153    if ($a_user_prefs['mail_pagesize'] < 1)
154      $a_user_prefs['mail_pagesize'] = 10;
155    if ($a_user_prefs['addressbook_pagesize'] < 1)
156      $a_user_prefs['addressbook_pagesize'] = 10;
157
158    if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize']))
159      $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
160    if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize']))
161      $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
162
163    $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
164
165  break;
166  case 'mailbox':
167
168    // force keep_alive
169    if (isset($a_user_prefs['keep_alive'])) {
170      $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
171      if (!empty($CONFIG['session_lifetime']))
172        $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
173    }
174
175  break;
176  case 'folders':
177
178    // special handling for 'default_imap_folders'
179    if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
180      foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
181        $a_user_prefs[$p] = $CONFIG[$p];
182    } else {
183      $a_user_prefs['default_imap_folders'] = array('INBOX');
184      foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
185        if ($a_user_prefs[$p])
186          $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
187      }
188    }
189
190  break;
191}
192
193// Save preferences
194if (!$plugin['abort'])
195  $saved = $RCMAIL->user->save_prefs($a_user_prefs);
196else
197  $saved = $plugin['result'];
198
199if ($saved)
200  $OUTPUT->show_message('successfullysaved', 'confirmation');
201else
202  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
203
204// display the form again
205rcmail_overwrite_action('edit-prefs');
206
Note: See TracBrowser for help on using the repository browser.