]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_prefs.inc
7d72bfa93d9b057adaea9e86c7a12d5f926b899f
[roundcube.git] / program / steps / settings / save_prefs.inc
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, Roundcube Dev. - Switzerland                 |
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: save_prefs.inc 4643 2011-04-11 12:24:00Z alec $
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
27 switch ($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']) ? (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       'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
36       'skin'         => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
37     );
38
39   break;
40   case 'mailbox':
41     $a_user_prefs = array(
42       'focus_on_new_message' => isset($_POST['_focus_on_new_message']) ? TRUE : FALSE,
43       'preview_pane'         => isset($_POST['_preview_pane']) ? TRUE : FALSE,
44       'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
45       'autoexpand_threads'   => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
46       'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
47       'keep_alive'           => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
48       'check_all_folders'    => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
49     );
50
51   break;
52   case 'mailview':
53     $a_user_prefs = array(
54       'prefer_html'     => isset($_POST['_prefer_html']) ? TRUE : FALSE,
55       'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
56       'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
57       'display_next'    => isset($_POST['_display_next']) ? TRUE : FALSE,
58       'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST),
59     );
60
61   break;
62   case 'compose':
63     $a_user_prefs = array(
64       'htmleditor'         => intval($_POST['_htmleditor']),
65       'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
66       'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
67       'force_7bit'         => isset($_POST['_force_7bit']) ? TRUE : FALSE,
68       'mdn_default'        => isset($_POST['_mdn_default']) ? TRUE : FALSE,
69       'dsn_default'        => isset($_POST['_dsn_default']) ? TRUE : FALSE,
70       'reply_same_folder'  => isset($_POST['_reply_same_folder']) ? TRUE : FALSE,
71       'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
72       'top_posting'        => !empty($_POST['_top_posting']),
73       'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
74       'sig_above'          => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
75     );
76
77   break;
78   case 'server':
79     $a_user_prefs = array(
80       'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
81       'skip_deleted'      => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
82       'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
83       'delete_always'     => isset($_POST['_delete_always']) ? TRUE : FALSE,
84       'logout_purge'      => isset($_POST['_logout_purge']) ? TRUE : FALSE,
85       'logout_expunge'    => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
86     );
87
88   break;
89   case 'folders':
90     $a_user_prefs = array(
91       'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST),
92       'sent_mbox'   => get_input_value('_sent_mbox', RCUBE_INPUT_POST),
93       'junk_mbox'   => get_input_value('_junk_mbox', RCUBE_INPUT_POST),
94       'trash_mbox'  => get_input_value('_trash_mbox', RCUBE_INPUT_POST),
95     );
96
97   break;
98 }
99
100 $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
101   array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
102
103 $a_user_prefs = $plugin['prefs'];
104
105 // don't override these parameters
106 foreach ((array)$CONFIG['dont_override'] as $p)
107   $a_user_prefs[$p] = $CONFIG[$p];
108
109
110 // verify some options
111 switch ($CURR_SECTION)
112 {
113   case 'general':
114
115     // switch UI language
116     if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
117       $RCMAIL->load_language($a_user_prefs['language']);
118       $OUTPUT->command('reload', 500);
119     }
120
121     // switch skin (if valid, otherwise unset the pref and fall back to default)
122     if (!$OUTPUT->set_skin($a_user_prefs['skin']))
123       unset($a_user_prefs['skin']);
124
125     // force min size
126     if ($a_user_prefs['pagesize'] < 1)
127       $a_user_prefs['pagesize'] = 10;
128
129     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
130       $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
131
132     $a_user_prefs['timezone'] = $_SESSION['timezone'] = (string) $a_user_prefs['timezone'];
133
134   break;
135   case 'mailbox':
136
137     // force keep_alive
138     if (isset($a_user_prefs['keep_alive'])) {
139       $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
140       if (!empty($CONFIG['session_lifetime']))
141         $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
142     }
143
144   break;
145   case 'folders':
146
147     // special handling for 'default_imap_folders'
148     if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
149       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
150         $a_user_prefs[$p] = $CONFIG[$p];
151     } else {
152       $a_user_prefs['default_imap_folders'] = array('INBOX');
153       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
154         if ($a_user_prefs[$p])
155           $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
156       }
157     }
158   
159   break;
160 }
161
162 // Save preferences
163 if (!$plugin['abort'])
164   $saved = $USER->save_prefs($a_user_prefs);
165 else
166   $saved = $plugin['result'];
167
168 if ($saved)
169   $OUTPUT->show_message('successfullysaved', 'confirmation');
170 else
171   $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
172
173 // display the form again
174 rcmail_overwrite_action('edit-prefs');
175