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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. 'list_cols',
  27. 'collapsed_folders',
  28. 'collapsed_abooks',
  29. );
  30. $whitelist_sess = array(
  31. 'list_attrib/columns',
  32. );
  33. $whitelist = array_merge($whitelist, $RCMAIL->plugins->allowed_prefs);
  34. $whitelist_sess = array_merge($whitelist_sess, $RCMAIL->plugins->allowed_session_prefs);
  35. if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) {
  36. rcube::raise_error(array('code' => 500, 'type' => 'php',
  37. 'file' => __FILE__, 'line' => __LINE__,
  38. 'message' => sprintf("Hack attempt detected (user: %s)", $RCMAIL->get_user_name())),
  39. true, false);
  40. $OUTPUT->reset();
  41. $OUTPUT->send();
  42. }
  43. // save preference value
  44. $RCMAIL->user->save_prefs(array($name => $value));
  45. // update also session if requested
  46. if ($sessname) {
  47. // Support multidimensional arrays...
  48. $vars = explode('/', $sessname);
  49. // ... up to 3 levels
  50. if (count($vars) == 1)
  51. $_SESSION[$vars[0]] = $value;
  52. else if (count($vars) == 2)
  53. $_SESSION[$vars[0]][$vars[1]] = $value;
  54. else if (count($vars) == 3)
  55. $_SESSION[$vars[0]][$vars[1]][$vars[2]] = $value;
  56. }
  57. $OUTPUT->reset();
  58. $OUTPUT->send();