You are here

function comment_notify_unsubscribe_submit in Comment Notify 5.2

Same name and namespace in other branches
  1. 5 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()

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

File

./comment_notify.module, line 484
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} 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} cn INNER JOIN {comments} c ON cn.cid = c.cid SET cn.notify = 0 WHERE c.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} cn INNER JOIN {comments} c ON cn.cid = c.cid SET cn.notify = 0 WHERE c.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."));
  }
}