You are here

function support_reference_block in Support Ticketing System 6

Implementation of hook_perm().

File

support_reference/support_reference.module, line 36
Support ticket references.

Code

function support_reference_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;
  switch ($op) {
    case 'list':
      $blocks = array();
      $blocks[0]['info'] = t('Support ticket references');

      // Turn off caching because the user MIGHT have access to the form.
      // We don't have sufficient control over things to do any better.
      // If we want to be more agressive, we could turn off
      // XSRF protection by setting $form['#token'] = FALSE in the
      // builder, but it's probably a bad idea for this form, which doesn't
      // have confirm page protection.
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'view':
      $block = array();
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        if ($node = node_load(arg(1))) {
          if ($node->type == 'support_ticket') {
            $view = $edit = '';
            if (user_access('view support ticket references')) {
              $result = db_query('SELECT rnid FROM {support_reference} WHERE nid = %d ORDER BY rnid DESC', $node->nid);
              $references = array();
              while ($reference = db_fetch_object($result)) {
                $reference = node_load($reference->rnid);

                // Only list reference if user viewing page has access.
                $client = support_client_load($reference->client);
                if (support_access_clients($client, $user)) {
                  $state = _support_state($reference->state);
                  $priority = _support_priorities($reference->priority);
                  $class = "support-reference state-{$state} priority-{$priority}";
                  if ($node->client != $reference->client) {
                    $class .= ' crossclient';
                  }
                  $references[$reference->nid] = '<span class="' . check_plain($class) . '">' . l(t('#!nid: !title', array(
                    '!nid' => $reference->nid,
                    '!title' => $reference->title,
                  )), "node/{$reference->nid}", array(
                    'attributes' => array(
                      'title' => t('!state !priority priority ticket.', array(
                        '!state' => ucfirst($state),
                        '!priority' => $priority,
                      )),
                    ),
                  )) . '</span>';
                }
              }
              $view = theme('item_list', $references);
            }
            if (user_access('edit support ticket references')) {
              $edit = drupal_get_form('support_reference_block_form', $node->client, $node);
            }
            $block['content'] = $view . $edit;
            $block['subject'] = t('Support ticket references');
          }
        }
      }
      return $block;
  }
}