You are here

function notifications_page_unsubscribe in Notifications 6.4

Same name and namespace in other branches
  1. 5 notifications.admin.inc \notifications_page_unsubscribe()
  2. 6 notifications.pages.inc \notifications_page_unsubscribe()
  3. 6.2 notifications.pages.inc \notifications_page_unsubscribe()
  4. 6.3 notifications.pages.inc \notifications_page_unsubscribe()

Menu callback for unsubscribe page

Parameters

$type: Either 'sid' or 'uid' (for unsubscribe all)

$id: Subscription id or user id, depending on type

1 string reference to 'notifications_page_unsubscribe'
notifications_menu in ./notifications.module
Implementation of hook_menu().

File

./notifications.pages.inc, line 122
User pages for Notifications

Code

function notifications_page_unsubscribe($type = NULL, $id = NULL) {

  // Determine subscription and user depending on type
  if (!$type) {

    // Go to generic unsubscribe page with some more options
    return notifications_page_unsubscribe_overview();
  }
  elseif ($type == 'subscription' && is_numeric($id) && ($subscription = notifications_load_subscription($id))) {
    $account = NULL;
    $owner = $subscription->uid;
  }
  elseif ($type == 'user' && is_numeric($id) && ($account = user_load($id)) && $account->uid) {
    $subscription = NULL;
    $owner = $account->uid;
  }

  // Check permissions and present confirmation form or not depending on parameters
  if (($account || $subscription) && notifications_page_check_access($owner)) {

    // Skip confirmation page when requested and the signature is ok
    if (notifications_page_check_confirmation()) {
      if ($subscription) {
        notifications_subscription_delete($subscription->sid);
        drupal_set_message(t('Your subscription has been removed.'));
      }
      elseif ($account) {
        notifications_delete_subscriptions(array(
          'uid' => $account->uid,
        ));
        drupal_set_message(t('All your subscriptions have been removed.'));
      }
      drupal_goto();
    }
    elseif ($account && !db_result(db_query("SELECT COUNT(*) FROM {notifications} WHERE uid = %d", $account->uid))) {
      return t("You don't have any subscription on this site.");
    }
    else {

      // Display confirmation form
      return drupal_get_form('notifications_form_unsubscribe_confirm', $subscription, $account);
    }
  }
  drupal_access_denied();
}