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