You are here

function support_unsubscribe_user in Support Ticketing System 7

Same name and namespace in other branches
  1. 6 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 589
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_delete('support_assigned')
        ->condition('uid', $account->uid)
        ->condition('nid', $node->nid)
        ->execute();
      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_delete('support_assigned')
          ->condition('uid', $account->uid)
          ->execute();
        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('');
}