You are here

function comment_notify_unsubscribe_submit in Comment Notify 5

Same name and namespace in other branches
  1. 5.2 comment_notify.module \comment_notify_unsubscribe_submit()
  2. 6 comment_notify.module \comment_notify_unsubscribe_submit()
  3. 7 comment_notify.module \comment_notify_unsubscribe_submit()

Actual unsubscribe of users.

File

./comment_notify.module, line 367
This module provides comment follow-up e-mail notification for anonymous and registered users.

Code

function comment_notify_unsubscribe_submit($form_id, $form_values) {
  $email = trim($form_values['email_to_unsubscribe']);

  // If they have a uid, use that, otherwise update comments directly
  $result = db_result(db_query_range("SELECT uid FROM {users} WHERE mail = '%s'", $email, 0, 1));
  if ($result > 0) {
    $comments = db_result(db_query("SELECT COUNT(1) FROM {comments} WHERE uid = %d AND notify = 1", $result));
    db_query("UPDATE {comments} SET notify = 0 WHERE uid = %d", $result);
  }
  else {
    $comments = db_result(db_query("SELECT COUNT(1) FROM {comments} WHERE mail = '%s' AND notify = 1", $email));
    db_query("UPDATE {comments} SET notify = 0 WHERE mail = '%s'", $email);
  }

  // Update the admin about the state of this comment notification subscription.
  if ($comments == 0) {
    drupal_set_message(t("There were no active comment notifications for that email."));
  }
  else {
    drupal_set_message(format_plural($comments, "Email unsubscribed from 1 comment notification.", "Email unsubscribed from @count comment notifications."));
  }
}