You are here

function comment_notify_unsubscribe_submit in Comment Notify 6

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

Based on admin submit, do the actual unsubscribe from notifications.

File

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

Code

function comment_notify_unsubscribe_submit($form, &$form_state) {
  $email = trim($form_state['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} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid WHERE c.uid = %d AND cn.notify > 0", $result));
    db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM  {comments} WHERE uid = %d)", $result);
  }
  else {
    $comments = db_result(db_query("SELECT COUNT(1) FROM {comments} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid WHERE c.mail = '%s' AND cn.notify > 0", $email));
    db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM {comments} 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."));
  }
}