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_pref.inc 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/utils/save_pref.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2013, 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 preferences setting in database |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Aleksander Machniak <alec@alec.pl> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST);
  21. $value = rcube_utils::get_input_value('_value', rcube_utils::INPUT_POST);
  22. $sessname = rcube_utils::get_input_value('_session', rcube_utils::INPUT_POST);
  23. // Whitelisted preferences and session variables, others
  24. // can be added by plugins
  25. $whitelist = array(
  26. 'preview_pane',
  27. 'list_cols',
  28. 'collapsed_folders',
  29. 'collapsed_abooks',
  30. );
  31. $whitelist_sess = array(
  32. 'list_attrib/columns',
  33. );
  34. $whitelist = array_merge($whitelist, $RCMAIL->plugins->allowed_prefs);
  35. $whitelist_sess = array_merge($whitelist_sess, $RCMAIL->plugins->allowed_session_prefs);
  36. if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) {
  37. rcube::raise_error(array('code' => 500, 'type' => 'php',
  38. 'file' => __FILE__, 'line' => __LINE__,
  39. 'message' => sprintf("Hack attempt detected (user: %s)", $RCMAIL->get_user_name())),
  40. true, false);
  41. $OUTPUT->reset();
  42. $OUTPUT->send();
  43. }
  44. // save preference value
  45. $RCMAIL->user->save_prefs(array($name => $value));
  46. // update also session if requested
  47. if ($sessname) {
  48. // Support multidimensional arrays...
  49. $vars = explode('/', $sessname);
  50. // ... up to 3 levels
  51. if (count($vars) == 1)
  52. $_SESSION[$vars[0]] = $value;
  53. else if (count($vars) == 2)
  54. $_SESSION[$vars[0]][$vars[1]] = $value;
  55. else if (count($vars) == 3)
  56. $_SESSION[$vars[0]][$vars[1]][$vars[2]] = $value;
  57. }
  58. $OUTPUT->reset();
  59. $OUTPUT->send();