You are here

function library_history in Library 5.2

Same name and namespace in other branches
  1. 6.2 library.pages.inc \library_history()
  2. 6 library.pages.inc \library_history()
  3. 7 library.pages.inc \library_history()

Menu callback; show the transaction history of a single node.

1 string reference to 'library_history'
library_menu in ./library.module
Implementation of hook_menu().

File

./library.pages.inc, line 261

Code

function library_history($node) {
  $duedate_enabled = library_duedates_enabled($node->type);
  global $user;
  $user_has_access = user_access('administer transactions') && patron_access('view', $node, $user);
  if ($node->type == 'patron') {
    $is_patron = TRUE;
  }
  else {
    $is_patron = FALSE;
  }
  if ($is_patron && !$user_has_access) {
    drupal_set_message(t('You do not have permission to view patron information.'));
    $form_state['redirect'] = 'library-items';
  }
  if (library_item_in_library($node) || $is_patron) {
    $header = array(
      t('Date'),
      t('Transaction'),
      t('Notes'),
    );
    if ($duedate_enabled) {
      $header[] = t('Due Date');
    }
    if ($user_has_access) {
      $header[] = t('Actions');
    }
    $rows = array();
    $transactions = library_get_transactions_by_node($node);
    if (!empty($transactions[0])) {
      foreach ($transactions as $value) {
        $last_item = '';
        foreach ($value as $transaction) {
          $detail_link = '';
          $action_link = '';
          $cur_item = $transaction->item_id;
          $created = format_date($transaction->created, 'small');
          if ($duedate_enabled && $cur_item != $last_item && !empty($transaction->duedate)) {
            $duedate = format_date($transaction->duedate, 'small');
          }
          elseif ($duedate_enabled) {
            $duedate = '';
          }
          if ($user_has_access) {
            $detail_link = l('View Details', 'library-items/transaction/view/' . $transaction->tid);
            if ($cur_item != $last_item) {
              $item = array(
                'id' => $transaction->item_id,
                'library_status' => $transaction->library_status,
                'last_patron_id' => $transaction->patron_id,
                'in_circulation' => $transaction->in_circulation,
              );
              $links = library_get_action_links($item);
              if (!empty($links)) {
                $action_link = ' | ' . implode(" | ", $links);
              }
            }
          }
          $temp_array = array(
            $created,
            $transaction->action_name,
            $transaction->notes,
          );
          if (isset($duedate)) {
            $temp_array[] = $duedate;
          }
          if (!empty($detail_link) || !empty($action_link)) {
            $temp_array[] = $detail_link . $action_link;
          }
          $rows[] = $temp_array;
          $last_item = $cur_item;
        }
      }
      return theme('table', $header, $rows);
    }
    else {
      if ($is_patron) {
        return "<p>This patron has not performed any actions.</p>";
      }
      else {
        return "<p>No actions have been performed on this item.</p>";
      }
    }
  }
  else {
    return "<p>This item type is not part of the library.</p>";
  }
}