]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_prefs.inc
Imported Upstream version 0.3.1
[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 2983 2009-09-23 12:32:09Z 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       'index_sort'   => isset($_POST['_index_sort']) ? TRUE : FALSE,
36       'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
37       'skin'         => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
38     );
39
40   break;
41   case 'mailbox':
42     $a_user_prefs = array(
43       'focus_on_new_message' => isset($_POST['_focus_on_new_message']) ? TRUE : FALSE,
44       'preview_pane'         => isset($_POST['_preview_pane']) ? TRUE : FALSE,
45       'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
46       'keep_alive'           => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
47       'check_all_folders'    => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
48     );
49
50   break;
51   case 'mailview':
52     $a_user_prefs = array(
53       'prefer_html'     => isset($_POST['_prefer_html']) ? TRUE : FALSE,
54       'inline_images'   => isset($_POST['_inline_images']) ? TRUE : FALSE,
55       'show_images'     => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
56       'display_next'    => isset($_POST['_display_next']) ? TRUE : FALSE,
57     );
58
59   break;
60   case 'compose':
61     $a_user_prefs = array(
62       'htmleditor'         => isset($_POST['_htmleditor']) ? TRUE : FALSE,
63       'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
64       'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
65     );
66
67   break;
68   case 'server':
69     $a_user_prefs = array(
70       'read_when_deleted' => isset($_POST['_read_when_deleted']) ? TRUE : FALSE,
71       'skip_deleted'      => isset($_POST['_skip_deleted']) ? TRUE : FALSE,
72       'flag_for_deletion' => isset($_POST['_flag_for_deletion']) ? TRUE : FALSE,
73       'logout_purge'      => isset($_POST['_logout_purge']) ? TRUE : FALSE,
74       'logout_expunge'    => isset($_POST['_logout_expunge']) ? TRUE : FALSE,
75     );
76
77   break;
78   case 'folders':
79     $a_user_prefs = array(
80       'drafts_mbox' => get_input_value('_drafts_mbox', RCUBE_INPUT_POST),
81       'sent_mbox'   => get_input_value('_sent_mbox', RCUBE_INPUT_POST),
82       'junk_mbox'   => get_input_value('_junk_mbox', RCUBE_INPUT_POST),
83       'trash_mbox'  => get_input_value('_trash_mbox', RCUBE_INPUT_POST),
84     );
85
86   break;
87 }
88
89
90 $data = rcmail::get_instance()->plugins->exec_hook('save_preferences',
91   array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
92
93 $a_user_prefs = $data['prefs'];
94
95 // don't override these parameters
96 foreach ((array)$CONFIG['dont_override'] as $p)
97   $a_user_prefs[$p] = $CONFIG[$p];
98
99
100 // verify some options
101 switch ($CURR_SECTION)
102 {
103   case 'general':
104
105     // switch UI language
106     if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
107       $RCMAIL->load_language($a_user_prefs['language']);
108       $OUTPUT->command('reload', 500);
109     }
110
111     // switch skin
112     $OUTPUT->set_skin($a_user_prefs['skin']);
113
114     // force min size
115     if ($a_user_prefs['pagesize'] < 1)
116       $a_user_prefs['pagesize'] = 10;
117
118     if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
119       $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
120
121   break;
122   case 'mailbox':
123
124     // force keep_alive
125     if (isset($a_user_prefs['keep_alive'])) {
126       $a_user_prefs['keep_alive'] = max(60, $CONFIG['min_keep_alive'], $a_user_prefs['keep_alive']);
127       if (!empty($CONFIG['session_lifetime']))
128         $a_user_prefs['keep_alive'] = min($CONFIG['session_lifetime']*60, $a_user_prefs['keep_alive']);
129     }
130
131   break;
132   case 'folders':
133
134     // special handling for 'default_imap_folders'
135     if (in_array('default_imap_folders', (array)$CONFIG['dont_override'])) {
136       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p)
137         $a_user_prefs[$p] = $CONFIG[$p];
138     } else {
139       $a_user_prefs['default_imap_folders'] = array('INBOX');
140       foreach (array('drafts_mbox','sent_mbox','junk_mbox','trash_mbox') as $p) {
141         if ($a_user_prefs[$p])
142           $a_user_prefs['default_imap_folders'][] = $a_user_prefs[$p];
143       }
144     }
145   
146   break;
147 }
148
149 if ($USER->save_prefs($a_user_prefs))
150   $OUTPUT->show_message('successfullysaved', 'confirmation');
151
152 // display the form again
153 rcmail_overwrite_action('edit-prefs');
154
155 ?>