You are here

function support_unsubscribe_user in Support Ticketing System 6

Same name and namespace in other branches
  1. 7 support.module \support_unsubscribe_user()

Unsubscribe user from tickets.

1 string reference to 'support_unsubscribe_user'
support_menu in ./support.module
Implementation of hook_menu().

File

./support.module, line 543
support.module

Code

function support_unsubscribe_user($node, $account, $key) {

  // unsubscribe from a single node
  if (is_object($node) && is_object($account)) {
    $lock = md5($account->uid . $node->nid);
    if ($key == $lock) {
      db_query('DELETE FROM {support_assigned} WHERE uid = %d AND nid = %d', $account->uid, $node->nid);
      drupal_set_message(t('%email has been unsubscribed from ticket %ticket.', array(
        '%email' => check_plain($account->mail),
        '%ticket' => check_plain($node->title),
      )));
    }
    else {
      drupal_set_message(t('Invalid key, failed to unsubscribe %email.', array(
        '%email' => check_plain($account->mail),
      )), 'error');
    }
    drupal_goto("node/{$node->nid}");
  }
  else {
    if (is_object($account)) {
      $lock = md5($account->uid);
      if ($key == $lock) {
        db_query('DELETE FROM {support_assigned} WHERE uid = %d', $account->uid);
        drupal_set_message(t('%email has been unsubscribed from all tickets.', array(
          '%email' => check_plain($account->mail),
        )));
      }
      else {
        drupal_set_message(t('Invalid key, failed to unsubscribe %email.', array(
          '%email' => check_plain($account->mail),
        )), 'error');
      }
    }
  }
  drupal_goto('');
}