alecpl
2010-09-25 e019f2d0f2dc2fbfa345ab5d7ae85e67bfdd76b8
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/save_prefs.inc                                 |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
A 8  | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 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 */
57f0c8 21
f05834 22 $CURR_SECTION = get_input_value('_section', RCUBE_INPUT_POST);
b19097 23
f05834 24 $a_user_prefs = array();
A 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,
bc4960 43       'preview_pane'         => isset($_POST['_preview_pane']) ? TRUE : FALSE,
T 44       'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
f52c93 45       'autoexpand_threads'   => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
f05834 46       'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
A 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,
e55ab0 58       'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST),
f05834 59     );
e55ab0 60
f05834 61
A 62   break;
63   case 'compose':
64     $a_user_prefs = array(
65       'htmleditor'         => isset($_POST['_htmleditor']) ? TRUE : FALSE,
66       'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
67       'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
47ad83 68       'force_7bit'         => isset($_POST['_force_7bit']) ? TRUE : FALSE,
0207c4 69       'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
T 70       'top_posting'        => !empty($_POST['_top_posting']),
71       'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
655bd9 72       'sig_above'          => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
f05834 73     );
A 74
75   break;
76   case 'server':
77     $a_user_prefs = array(
78       'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
79       'skip_deleted'      => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
80       'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
b7f952 81       'delete_always'       => isset($_POST['_delete_always']) ? TRUE : FALSE,
f05834 82       'logout_purge'      => isset($_POST['_logout_purge']) ? TRUE : FALSE,
A 83       'logout_expunge'    => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
84     );
85
86   break;
87   case 'folders':
88     $a_user_prefs = array(
89       'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST),
90       'sent_mbox'   => get_input_value('_sent_mbox', RCUBE_INPUT_POST),
91       'junk_mbox'   => get_input_value('_junk_mbox', RCUBE_INPUT_POST),
92       'trash_mbox'  => get_input_value('_trash_mbox', RCUBE_INPUT_POST),
93     );
94
95   break;
96 }
97
e6ce00 98 $data = rcmail::get_instance()->plugins->exec_hook('preferences_save',
f05834 99   array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
A 100
cc97ea 101 $a_user_prefs = $data['prefs'];
T 102
b19097 103 // don't override these parameters
T 104 foreach ((array)$CONFIG['dont_override'] as $p)
105   $a_user_prefs[$p] = $CONFIG[$p];
4e17e6 106
f05834 107
A 108 // verify some options
109 switch ($CURR_SECTION)
110 {
111   case 'general':
112
113     // switch UI language
141c9e 114     if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
f05834 115       $RCMAIL->load_language($a_user_prefs['language']);
141c9e 116       $OUTPUT->command('reload', 500);
f05834 117     }
A 118
62c791 119     // switch skin (if valid, otherwise unset the pref and fall back to default)
T 120     if (!$OUTPUT->set_skin($a_user_prefs['skin']))
121       unset($a_user_prefs['skin']);
f05834 122
A 123     // force min size
124     if ($a_user_prefs['pagesize'] < 1)
125       $a_user_prefs['pagesize'] = 10;
126
127     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
128       $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
129
130   break;
131   case 'mailbox':
132
133     // force keep_alive
134     if (isset($a_user_prefs['keep_alive'])) {
135       $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
136       if (!empty($CONFIG['session_lifetime']))
137         $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
138     }
139
140   break;
141   case 'folders':
142
143     // special handling for 'default_imap_folders'
144     if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
145       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
141c9e 146         $a_user_prefs[$p] = $CONFIG[$p];
f05834 147     } else {
A 148       $a_user_prefs['default_imap_folders'] = array('INBOX');
149       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
141c9e 150         if ($a_user_prefs[$p])
f05834 151           $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
141c9e 152       }
f05834 153     }
A 154   
155   break;
64f20d 156 }
2a4135 157
fba1f5 158 if ($USER->save_prefs($a_user_prefs))
f11541 159   $OUTPUT->show_message('successfullysaved', 'confirmation');
4e17e6 160
f05834 161 // display the form again
A 162 rcmail_overwrite_action('edit-prefs');
4e17e6 163
b25dfd 164