save.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Elgg notifications
  4. *
  5. * @package ElggNotifications
  6. */
  7. $current_user = elgg_get_logged_in_user_entity();
  8. $guid = (int) get_input('guid', 0);
  9. if (!$guid || !($user = get_entity($guid))) {
  10. forward();
  11. }
  12. if (($user->guid != $current_user->guid) && !$current_user->isAdmin()) {
  13. forward();
  14. }
  15. $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
  16. $subscriptions = array();
  17. foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
  18. $personal[$method] = get_input($method.'personal');
  19. set_user_notification_setting($user->guid, $method, ($personal[$method] == '1') ? true : false);
  20. $collections[$method] = get_input($method.'collections');
  21. $metaname = 'collections_notifications_preferences_' . $method;
  22. $user->$metaname = $collections[$method];
  23. $subscriptions[$method] = get_input($method.'subscriptions');
  24. remove_entity_relationships($user->guid, 'notify' . $method, false, 'user');
  25. }
  26. // Add new ones
  27. foreach ($subscriptions as $method => $subscription) {
  28. if (is_array($subscription) && !empty($subscription)) {
  29. foreach ($subscription as $subscriptionperson) {
  30. elgg_add_subscription($user->guid, $method, $subscriptionperson);
  31. }
  32. }
  33. }
  34. system_message(elgg_echo('notifications:subscriptions:success'));
  35. forward(REFERER);