function notifications_page_unsubscribe in Notifications 6.3
Same name and namespace in other branches
- 5 notifications.admin.inc \notifications_page_unsubscribe()
- 6.4 notifications.pages.inc \notifications_page_unsubscribe()
- 6 notifications.pages.inc \notifications_page_unsubscribe()
- 6.2 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 282 - User pages for Notifications
Code
function notifications_page_unsubscribe($type, $id) {
global $user;
// Check signature if present
$signed = !empty($_GET['signature']) && $_GET['signature'] == _notifications_signature(array(
'unsubscribe',
$type,
$id,
), !empty($_GET['confirm']));
// Determine subscription and user depending on type
if ($type == 'sid' && is_numeric($id) && ($subscription = notifications_load_subscription($id))) {
$account = NULL;
$uid = $subscription->uid;
}
elseif ($type == 'uid' && is_numeric($id) && ($account = user_load($id)) && $account->uid) {
$subscription = NULL;
$uid = $account->uid;
}
// Check permissions and present confirmation form or not depending on parameters
if (($account || $subscription) && $uid && (user_access('administer notifications') || $user->uid == $uid || $signed)) {
// Skip confirmation page when requested and the signature is ok
if (!empty($_GET['confirm']) && $signed) {
if ($subscription) {
notifications_delete_subscription($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();
}