]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_prefs.inc
Imported Upstream version 0.2~stable
[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-2007, 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 2115 2008-12-04 10:21:34Z alec $
19
20 */
21
22 $a_user_prefs = array(
23   'language'     => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'],
24   'timezone'     => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'],
25   'dst_active'   => isset($_POST['_dst_active']) ? TRUE : FALSE,
26   'pagesize'     => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'],
27   'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
28   'prefer_html'  => isset($_POST['_prefer_html']) ? TRUE : FALSE,
29   'htmleditor'   => isset($_POST['_htmleditor']) ? TRUE : FALSE,
30   'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
31   'preview_pane' => isset($_POST['_preview_pane']) ? TRUE : FALSE,
32   'focus_on_new_message' => isset($_POST['_focus_on_new_message']) ? TRUE : FALSE,
33   'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
34   'skip_deleted' => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
35   'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
36   'logout_purge' => isset($_POST['_logout_purge']) ? TRUE : FALSE,
37   'logout_expunge' => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
38   'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
39   'show_images' => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
40   'keep_alive' => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
41   'check_all_folders' => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
42   'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
43   'mdn_requests' => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
44   'skin' => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
45   'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST),
46   'sent_mbox' => get_input_value('_sent_mbox', RCUBE_INPUT_POST),
47   'junk_mbox' => get_input_value('_junk_mbox', RCUBE_INPUT_POST),
48   'trash_mbox' => get_input_value('_trash_mbox', RCUBE_INPUT_POST),
49   );
50
51 // don't override these parameters
52 foreach ((array)$CONFIG['dont_override'] as $p)
53   $a_user_prefs[$p] = $CONFIG[$p];
54
55 // special handling for 'default_imap_folders'
56 if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
57   foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
58     $a_user_prefs[$p] = $CONFIG[$p];
59 }
60 else {
61   $a_user_prefs['default_imap_folders'] = array('INBOX');
62   foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
63     if ($a_user_prefs[$p])
64       $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
65   }
66 }
67
68 // switch UI language
69 if (isset($_POST['_language'])) {
70   $RCMAIL->load_language($a_user_prefs['language']);
71 }
72
73 // switch skin
74 $OUTPUT->set_skin($a_user_prefs['skin']);
75
76 // force min size
77 if ($a_user_prefs['pagesize'] < 1)
78   $a_user_prefs['pagesize'] = 10;
79
80 if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
81   $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
82
83 // force keep_alive
84 if (isset($a_user_prefs['keep_alive'])) {
85     $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
86     if (!empty($CONFIG['session_lifetime']))
87       $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
88 }
89
90
91 if ($USER->save_prefs($a_user_prefs))
92   $OUTPUT->show_message('successfullysaved', 'confirmation');
93
94 // go to next step
95 rcmail_overwrite_action('preferences');
96
97 ?>