You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

save_prefs.inc 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/settings/save_prefs.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2016, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Save user preferences to DB and to the current session |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. | Author: Aleksander Machniak <alec@alec.pl> |
  19. +-----------------------------------------------------------------------+
  20. */
  21. $CURR_SECTION = rcube_utils::get_input_value('_section', rcube_utils::INPUT_POST);
  22. $a_user_prefs = array();
  23. // set options for specified section
  24. switch ($CURR_SECTION) {
  25. case 'general':
  26. $a_user_prefs = array(
  27. 'language' => isset($_POST['_language']) ? rcube_utils::get_input_value('_language', rcube_utils::INPUT_POST) : $CONFIG['language'],
  28. 'timezone' => isset($_POST['_timezone']) ? rcube_utils::get_input_value('_timezone', rcube_utils::INPUT_POST) : $CONFIG['timezone'],
  29. 'date_format' => isset($_POST['_date_format']) ? rcube_utils::get_input_value('_date_format', rcube_utils::INPUT_POST) : $CONFIG['date_format'],
  30. 'time_format' => isset($_POST['_time_format']) ? rcube_utils::get_input_value('_time_format', rcube_utils::INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
  31. 'prettydate' => isset($_POST['_pretty_date']),
  32. 'refresh_interval' => isset($_POST['_refresh_interval']) ? intval($_POST['_refresh_interval'])*60 : $CONFIG['refresh_interval'],
  33. 'standard_windows' => isset($_POST['_standard_windows']),
  34. 'skin' => isset($_POST['_skin']) ? rcube_utils::get_input_value('_skin', rcube_utils::INPUT_POST) : $CONFIG['skin'],
  35. );
  36. // compose derived date/time format strings
  37. if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
  38. $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
  39. $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format'];
  40. }
  41. break;
  42. case 'mailbox':
  43. $a_user_prefs = array(
  44. 'preview_pane' => isset($_POST['_preview_pane']),
  45. 'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'],
  46. 'autoexpand_threads' => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0,
  47. 'mdn_requests' => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
  48. 'check_all_folders' => isset($_POST['_check_all_folders']),
  49. 'mail_pagesize' => is_numeric($_POST['_mail_pagesize']) ? max(2, intval($_POST['_mail_pagesize'])) : $CONFIG['mail_pagesize'],
  50. );
  51. break;
  52. case 'mailview':
  53. $a_user_prefs = array(
  54. 'message_extwin' => intval($_POST['_message_extwin']),
  55. 'message_show_email' => isset($_POST['_message_show_email']),
  56. 'prefer_html' => isset($_POST['_prefer_html']),
  57. 'inline_images' => isset($_POST['_inline_images']),
  58. 'show_images' => isset($_POST['_show_images']) ? intval($_POST['_show_images']) : 0,
  59. 'display_next' => isset($_POST['_display_next']),
  60. 'default_charset' => rcube_utils::get_input_value('_default_charset', rcube_utils::INPUT_POST),
  61. );
  62. break;
  63. case 'compose':
  64. $a_user_prefs = array(
  65. 'compose_extwin' => intval($_POST['_compose_extwin']),
  66. 'htmleditor' => intval($_POST['_htmleditor']),
  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,
  69. 'force_7bit' => isset($_POST['_force_7bit']),
  70. 'mdn_default' => isset($_POST['_mdn_default']),
  71. 'dsn_default' => isset($_POST['_dsn_default']),
  72. 'reply_same_folder' => isset($_POST['_reply_same_folder']),
  73. 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']),
  74. 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']),
  75. 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']),
  76. 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']),
  77. 'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
  78. 'reply_mode' => isset($_POST['_reply_mode']) ? intval($_POST['_reply_mode']) : 0,
  79. 'sig_below' => isset($_POST['_sig_below']),
  80. 'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
  81. 'sig_separator' => isset($_POST['_sig_separator']),
  82. 'default_font' => rcube_utils::get_input_value('_default_font', rcube_utils::INPUT_POST),
  83. 'default_font_size' => rcube_utils::get_input_value('_default_font_size', rcube_utils::INPUT_POST),
  84. 'reply_all_mode' => intval($_POST['_reply_all_mode']),
  85. 'forward_attachment' => !empty($_POST['_forward_attachment']),
  86. 'compose_save_localstorage' => intval($_POST['_compose_save_localstorage']),
  87. );
  88. break;
  89. case 'addressbook':
  90. $a_user_prefs = array(
  91. 'default_addressbook' => rcube_utils::get_input_value('_default_addressbook', rcube_utils::INPUT_POST, true),
  92. 'autocomplete_single' => isset($_POST['_autocomplete_single']),
  93. 'addressbook_sort_col' => rcube_utils::get_input_value('_addressbook_sort_col', rcube_utils::INPUT_POST),
  94. 'addressbook_name_listing' => intval(rcube_utils::get_input_value('_addressbook_name_listing', rcube_utils::INPUT_POST)),
  95. 'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
  96. );
  97. break;
  98. case 'server':
  99. $a_user_prefs = array(
  100. 'read_when_deleted' => isset($_POST['_read_when_deleted']),
  101. 'skip_deleted' => isset($_POST['_skip_deleted']),
  102. 'flag_for_deletion' => isset($_POST['_flag_for_deletion']),
  103. 'delete_always' => isset($_POST['_delete_always']),
  104. 'delete_junk' => isset($_POST['_delete_junk']),
  105. 'logout_purge' => isset($_POST['_logout_purge']),
  106. 'logout_expunge' => isset($_POST['_logout_expunge']),
  107. );
  108. break;
  109. case 'folders':
  110. $a_user_prefs = array(
  111. 'show_real_foldernames' => isset($_POST['_show_real_foldernames']),
  112. // stop using SPECIAL-USE (#4782)
  113. 'lock_special_folders' => !in_array('lock_special_folders', (array) $CONFIG['dont_override']),
  114. );
  115. foreach (rcube_storage::$folder_types as $type) {
  116. $a_user_prefs[$type . '_mbox'] = rcube_utils::get_input_value('_' . $type . '_mbox', rcube_utils::INPUT_POST, true);
  117. };
  118. break;
  119. }
  120. $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
  121. array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
  122. $a_user_prefs = $plugin['prefs'];
  123. // don't override these parameters
  124. foreach ((array)$CONFIG['dont_override'] as $p) {
  125. $a_user_prefs[$p] = $CONFIG[$p];
  126. }
  127. // verify some options
  128. switch ($CURR_SECTION) {
  129. case 'general':
  130. // switch UI language
  131. if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
  132. $RCMAIL->load_language($a_user_prefs['language']);
  133. $OUTPUT->command('reload', 500);
  134. }
  135. // switch skin (if valid, otherwise unset the pref and fall back to default)
  136. if (!$OUTPUT->set_skin($a_user_prefs['skin']))
  137. unset($a_user_prefs['skin']);
  138. else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
  139. $OUTPUT->command('reload', 500);
  140. $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
  141. if (!empty($a_user_prefs['refresh_interval']) && !empty($CONFIG['min_refresh_interval'])) {
  142. if ($a_user_prefs['refresh_interval'] < $CONFIG['min_refresh_interval']) {
  143. $a_user_prefs['refresh_interval'] = $CONFIG['min_refresh_interval'];
  144. }
  145. }
  146. break;
  147. case 'mailbox':
  148. // force min size
  149. if ($a_user_prefs['mail_pagesize'] < 1) {
  150. $a_user_prefs['mail_pagesize'] = 10;
  151. }
  152. if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize'])) {
  153. $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
  154. }
  155. break;
  156. case 'addressbook':
  157. // force min size
  158. if ($a_user_prefs['addressbook_pagesize'] < 1) {
  159. $a_user_prefs['addressbook_pagesize'] = 10;
  160. }
  161. if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize'])) {
  162. $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
  163. }
  164. break;
  165. case 'folders':
  166. $storage = $RCMAIL->get_storage();
  167. $specials = array();
  168. foreach (rcube_storage::$folder_types as $type) {
  169. $specials[$type] = $a_user_prefs[$type . '_mbox'];
  170. }
  171. $storage->set_special_folders($specials);
  172. break;
  173. }
  174. // Save preferences
  175. if (!$plugin['abort'])
  176. $saved = $RCMAIL->user->save_prefs($a_user_prefs);
  177. else
  178. $saved = $plugin['result'];
  179. if ($saved)
  180. $OUTPUT->show_message('successfullysaved', 'confirmation');
  181. else
  182. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  183. // display the form again
  184. $RCMAIL->overwrite_action('edit-prefs');