function support_subscribe_user in Support Ticketing System 6
Same name and namespace in other branches
- 7 support.module \support_subscribe_user()
 
Subscribe a user to a ticket.
3 calls to support_subscribe_user()
- support_comment in ./
support.module  - Implementation of hook_comment().
 - support_nodeapi in ./
support.module  - Implementation of hook_nodeapi().
 - _support_autosubscribe in ./
support.module  - Autosubscribe users to new client ticket.
 
File
- ./
support.module, line 1631  - support.module
 
Code
function support_subscribe_user($nid, $uid, $subscribe = 1) {
  $clid = db_result(db_query('SELECT client FROM {support_ticket} WHERE nid = %d', $nid));
  $client = support_client_load($clid);
  $account = user_load(array(
    'uid' => $uid,
  ));
  if (support_access_clients($client, $account)) {
    if ($subscribe) {
      @db_query('INSERT INTO {support_assigned} (nid, uid) VALUES(%d, %d)', $nid, $uid);
    }
    else {
      db_query('DELETE FROM {support_assigned} WHERE nid = %d AND uid = %d', $nid, $uid);
    }
  }
  else {
    // If this user doesn't have permission to receive ticket updates,
    // be sure they are unsubscribed.
    db_query('DELETE FROM {support_assigned} WHERE nid = %d AND uid = %d', $nid, $uid);
  }
}