Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

save_prefs.inc 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. 'layout' => rcube_utils::get_input_value('_layout', rcube_utils::INPUT_POST),
  45. 'mail_read_time' => isset($_POST['_mail_read_time']) ? intval($_POST['_mail_read_time']) : $CONFIG['mail_read_time'],
  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. if ($a_user_prefs['default_charset'] && !preg_match('/^[a-zA-Z0-9-]+$/', $a_user_prefs['default_charset'])) {
  63. $a_user_prefs['default_charset'] = $CONFIG['default_charset'];
  64. }
  65. break;
  66. case 'compose':
  67. $a_user_prefs = array(
  68. 'compose_extwin' => intval($_POST['_compose_extwin']),
  69. 'htmleditor' => intval($_POST['_htmleditor']),
  70. 'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
  71. 'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
  72. 'force_7bit' => isset($_POST['_force_7bit']),
  73. 'mdn_default' => isset($_POST['_mdn_default']),
  74. 'dsn_default' => isset($_POST['_dsn_default']),
  75. 'reply_same_folder' => isset($_POST['_reply_same_folder']),
  76. 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']),
  77. 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']),
  78. 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']),
  79. 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']),
  80. 'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
  81. 'reply_mode' => isset($_POST['_reply_mode']) ? intval($_POST['_reply_mode']) : 0,
  82. 'sig_below' => isset($_POST['_sig_below']),
  83. 'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
  84. 'sig_separator' => isset($_POST['_sig_separator']),
  85. 'default_font' => rcube_utils::get_input_value('_default_font', rcube_utils::INPUT_POST),
  86. 'default_font_size' => rcube_utils::get_input_value('_default_font_size', rcube_utils::INPUT_POST),
  87. 'reply_all_mode' => intval($_POST['_reply_all_mode']),
  88. 'forward_attachment' => !empty($_POST['_forward_attachment']),
  89. 'compose_save_localstorage' => intval($_POST['_compose_save_localstorage']),
  90. );
  91. break;
  92. case 'addressbook':
  93. $a_user_prefs = array(
  94. 'default_addressbook' => rcube_utils::get_input_value('_default_addressbook', rcube_utils::INPUT_POST, true),
  95. 'autocomplete_single' => isset($_POST['_autocomplete_single']),
  96. 'addressbook_sort_col' => rcube_utils::get_input_value('_addressbook_sort_col', rcube_utils::INPUT_POST),
  97. 'addressbook_name_listing' => intval(rcube_utils::get_input_value('_addressbook_name_listing', rcube_utils::INPUT_POST)),
  98. 'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
  99. );
  100. break;
  101. case 'server':
  102. $a_user_prefs = array(
  103. 'read_when_deleted' => isset($_POST['_read_when_deleted']),
  104. 'skip_deleted' => isset($_POST['_skip_deleted']),
  105. 'flag_for_deletion' => isset($_POST['_flag_for_deletion']),
  106. 'delete_always' => isset($_POST['_delete_always']),
  107. 'delete_junk' => isset($_POST['_delete_junk']),
  108. 'logout_purge' => isset($_POST['_logout_purge']),
  109. 'logout_expunge' => isset($_POST['_logout_expunge']),
  110. );
  111. break;
  112. case 'folders':
  113. $a_user_prefs = array(
  114. 'show_real_foldernames' => isset($_POST['_show_real_foldernames']),
  115. // stop using SPECIAL-USE (#4782)
  116. 'lock_special_folders' => !in_array('lock_special_folders', (array) $CONFIG['dont_override']),
  117. );
  118. foreach (rcube_storage::$folder_types as $type) {
  119. $a_user_prefs[$type . '_mbox'] = rcube_utils::get_input_value('_' . $type . '_mbox', rcube_utils::INPUT_POST, true);
  120. };
  121. break;
  122. }
  123. $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save',
  124. array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
  125. $a_user_prefs = $plugin['prefs'];
  126. // don't override these parameters
  127. foreach ((array)$CONFIG['dont_override'] as $p) {
  128. $a_user_prefs[$p] = $CONFIG[$p];
  129. }
  130. // verify some options
  131. switch ($CURR_SECTION) {
  132. case 'general':
  133. // switch UI language
  134. if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) {
  135. $RCMAIL->load_language($a_user_prefs['language']);
  136. $OUTPUT->command('reload', 500);
  137. }
  138. // switch skin (if valid, otherwise unset the pref and fall back to default)
  139. if (!$OUTPUT->set_skin($a_user_prefs['skin']))
  140. unset($a_user_prefs['skin']);
  141. else if ($RCMAIL->config->get('skin') != $a_user_prefs['skin'])
  142. $OUTPUT->command('reload', 500);
  143. $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
  144. if (!empty($a_user_prefs['refresh_interval']) && !empty($CONFIG['min_refresh_interval'])) {
  145. if ($a_user_prefs['refresh_interval'] < $CONFIG['min_refresh_interval']) {
  146. $a_user_prefs['refresh_interval'] = $CONFIG['min_refresh_interval'];
  147. }
  148. }
  149. break;
  150. case 'mailbox':
  151. // force min size
  152. if ($a_user_prefs['mail_pagesize'] < 1) {
  153. $a_user_prefs['mail_pagesize'] = 10;
  154. }
  155. if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize'])) {
  156. $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
  157. }
  158. break;
  159. case 'addressbook':
  160. // force min size
  161. if ($a_user_prefs['addressbook_pagesize'] < 1) {
  162. $a_user_prefs['addressbook_pagesize'] = 10;
  163. }
  164. if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize'])) {
  165. $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
  166. }
  167. break;
  168. case 'folders':
  169. $storage = $RCMAIL->get_storage();
  170. $specials = array();
  171. foreach (rcube_storage::$folder_types as $type) {
  172. $specials[$type] = $a_user_prefs[$type . '_mbox'];
  173. }
  174. $storage->set_special_folders($specials);
  175. break;
  176. }
  177. // Save preferences
  178. if (!$plugin['abort'])
  179. $saved = $RCMAIL->user->save_prefs($a_user_prefs);
  180. else
  181. $saved = $plugin['result'];
  182. if ($saved)
  183. $OUTPUT->show_message('successfullysaved', 'confirmation');
  184. else
  185. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  186. // display the form again
  187. $RCMAIL->overwrite_action('edit-prefs');