source: github/program/steps/settings/save_prefs.inc @ 7fe3811

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

Changed license to GNU GPLv3+ with exceptions for skins and plugins

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