| [3] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/settings/save_prefs.inc | |
|---|
| 6 | | | |
|---|
| [3989] | 7 | | This file is part of the Roundcube Webmail client | |
|---|
| [4410] | 8 | | Copyright (C) 2005-2009, The Roundcube Dev Team | |
|---|
| [8] | 9 | | Licensed under the GNU GPL | |
|---|
| [3] | 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 | |
|---|
| [2830] | 22 | $CURR_SECTION = get_input_value('_section', RCUBE_INPUT_POST); |
|---|
| [3] | 23 | |
|---|
| [2830] | 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; |
|---|
| [4811] | 40 | |
|---|
| [2830] | 41 | case 'mailbox': |
|---|
| 42 | $a_user_prefs = array( |
|---|
| [3479] | 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'], |
|---|
| [3367] | 45 | 'autoexpand_threads' => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0, |
|---|
| [2830] | 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; |
|---|
| [4811] | 52 | |
|---|
| [2830] | 53 | case 'mailview': |
|---|
| 54 | $a_user_prefs = array( |
|---|
| 55 | 'prefer_html' => isset($_POST['_prefer_html']) ? TRUE : FALSE, |
|---|
| 56 | 'inline_images' => isset($_POST['_inline_images']) ? TRUE : FALSE, |
|---|
| 57 | 'show_images' => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0, |
|---|
| 58 | 'display_next' => isset($_POST['_display_next']) ? TRUE : FALSE, |
|---|
| [3327] | 59 | 'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST), |
|---|
| [2830] | 60 | ); |
|---|
| 61 | |
|---|
| 62 | break; |
|---|
| [4811] | 63 | |
|---|
| [2830] | 64 | case 'compose': |
|---|
| 65 | $a_user_prefs = array( |
|---|
| [4054] | 66 | 'htmleditor' => intval($_POST['_htmleditor']), |
|---|
| [2830] | 67 | 'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0, |
|---|
| 68 | 'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0, |
|---|
| [3301] | 69 | 'force_7bit' => isset($_POST['_force_7bit']) ? TRUE : FALSE, |
|---|
| [4012] | 70 | 'mdn_default' => isset($_POST['_mdn_default']) ? TRUE : FALSE, |
|---|
| [4059] | 71 | 'dsn_default' => isset($_POST['_dsn_default']) ? TRUE : FALSE, |
|---|
| [4169] | 72 | 'reply_same_folder' => isset($_POST['_reply_same_folder']) ? TRUE : FALSE, |
|---|
| [4816] | 73 | 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE, |
|---|
| [3089] | 74 | 'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1, |
|---|
| 75 | 'top_posting' => !empty($_POST['_top_posting']), |
|---|
| 76 | 'strip_existing_sig' => isset($_POST['_strip_existing_sig']), |
|---|
| [3091] | 77 | 'sig_above' => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']), |
|---|
| [2830] | 78 | ); |
|---|
| 79 | |
|---|
| 80 | break; |
|---|
| [4811] | 81 | |
|---|
| 82 | case 'addressbook': |
|---|
| 83 | $a_user_prefs = array( |
|---|
| [4813] | 84 | 'default_addressbook' => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true), |
|---|
| [4811] | 85 | ); |
|---|
| 86 | |
|---|
| 87 | break; |
|---|
| 88 | |
|---|
| [2830] | 89 | case 'server': |
|---|
| 90 | $a_user_prefs = array( |
|---|
| 91 | 'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE, |
|---|
| 92 | 'skip_deleted' => isset($_POST['_skip_deleted']) ? TRUE : FALSE, |
|---|
| 93 | 'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE, |
|---|
| [3326] | 94 | 'delete_always' => isset($_POST['_delete_always']) ? TRUE : FALSE, |
|---|
| [2830] | 95 | 'logout_purge' => isset($_POST['_logout_purge']) ? TRUE : FALSE, |
|---|
| 96 | 'logout_expunge' => isset($_POST['_logout_expunge']) ? TRUE : FALSE, |
|---|
| 97 | ); |
|---|
| 98 | |
|---|
| 99 | break; |
|---|
| [4811] | 100 | |
|---|
| [2830] | 101 | case 'folders': |
|---|
| 102 | $a_user_prefs = array( |
|---|
| [4813] | 103 | 'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST, true), |
|---|
| 104 | 'sent_mbox' => get_input_value('_sent_mbox', RCUBE_INPUT_POST, true), |
|---|
| 105 | 'junk_mbox' => get_input_value('_junk_mbox', RCUBE_INPUT_POST, true), |
|---|
| 106 | 'trash_mbox' => get_input_value('_trash_mbox', RCUBE_INPUT_POST, true), |
|---|
| [2830] | 107 | ); |
|---|
| 108 | |
|---|
| 109 | break; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| [4641] | 112 | $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save', |
|---|
| [2830] | 113 | array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION)); |
|---|
| 114 | |
|---|
| [4641] | 115 | $a_user_prefs = $plugin['prefs']; |
|---|
| [2401] | 116 | |
|---|
| [388] | 117 | // don't override these parameters |
|---|
| 118 | foreach ((array)$CONFIG['dont_override'] as $p) |
|---|
| 119 | $a_user_prefs[$p] = $CONFIG[$p]; |
|---|
| [3] | 120 | |
|---|
| 121 | |
|---|
| [2830] | 122 | // verify some options |
|---|
| 123 | switch ($CURR_SECTION) |
|---|
| 124 | { |
|---|
| 125 | case 'general': |
|---|
| [3] | 126 | |
|---|
| [2830] | 127 | // switch UI language |
|---|
| [2873] | 128 | if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) { |
|---|
| [2830] | 129 | $RCMAIL->load_language($a_user_prefs['language']); |
|---|
| [2873] | 130 | $OUTPUT->command('reload', 500); |
|---|
| [2830] | 131 | } |
|---|
| [1540] | 132 | |
|---|
| [3974] | 133 | // switch skin (if valid, otherwise unset the pref and fall back to default) |
|---|
| 134 | if (!$OUTPUT->set_skin($a_user_prefs['skin'])) |
|---|
| 135 | unset($a_user_prefs['skin']); |
|---|
| [938] | 136 | |
|---|
| [2830] | 137 | // force min size |
|---|
| 138 | if ($a_user_prefs['pagesize'] < 1) |
|---|
| 139 | $a_user_prefs['pagesize'] = 10; |
|---|
| [727] | 140 | |
|---|
| [2830] | 141 | if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize'])) |
|---|
| 142 | $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize']; |
|---|
| 143 | |
|---|
| [4429] | 144 | $a_user_prefs['timezone'] = $_SESSION['timezone'] = (string) $a_user_prefs['timezone']; |
|---|
| 145 | |
|---|
| [2830] | 146 | break; |
|---|
| 147 | case 'mailbox': |
|---|
| 148 | |
|---|
| 149 | // force keep_alive |
|---|
| 150 | if (isset($a_user_prefs['keep_alive'])) { |
|---|
| 151 | $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']); |
|---|
| 152 | if (!empty($CONFIG['session_lifetime'])) |
|---|
| 153 | $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | break; |
|---|
| 157 | case 'folders': |
|---|
| 158 | |
|---|
| 159 | // special handling for 'default_imap_folders' |
|---|
| 160 | if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) { |
|---|
| 161 | foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) |
|---|
| [2873] | 162 | $a_user_prefs[$p] = $CONFIG[$p]; |
|---|
| [2830] | 163 | } else { |
|---|
| 164 | $a_user_prefs['default_imap_folders'] = array('INBOX'); |
|---|
| 165 | foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) { |
|---|
| [2873] | 166 | if ($a_user_prefs[$p]) |
|---|
| [2830] | 167 | $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p]; |
|---|
| [2873] | 168 | } |
|---|
| [2830] | 169 | } |
|---|
| 170 | |
|---|
| 171 | break; |
|---|
| [2013] | 172 | } |
|---|
| 173 | |
|---|
| [4641] | 174 | // Save preferences |
|---|
| 175 | if (!$plugin['abort']) |
|---|
| 176 | $saved = $USER->save_prefs($a_user_prefs); |
|---|
| 177 | else |
|---|
| 178 | $saved = $plugin['result']; |
|---|
| 179 | |
|---|
| 180 | if ($saved) |
|---|
| [543] | 181 | $OUTPUT->show_message('successfullysaved', 'confirmation'); |
|---|
| [4641] | 182 | else |
|---|
| 183 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
|---|
| [3] | 184 | |
|---|
| [2830] | 185 | // display the form again |
|---|
| 186 | rcmail_overwrite_action('edit-prefs'); |
|---|
| [3] | 187 | |
|---|