You are here

function library_history in Library 6

Same name and namespace in other branches
  1. 5.2 library.pages.inc \library_history()
  2. 6.2 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 286
Functions for generating page displays related to the library module

Code

function library_history($node) {
  $duedate_enabled = library_duedates_enabled($node->type);
  global $user;
  if ($node->type == 'patron') {
    $is_patron = TRUE;
  }
  else {
    $is_patron = FALSE;
  }
  if (library_item_in_library($node) || $is_patron) {
    $header = array(
      t('Date'),
      t('Transaction'),
      t('Notes'),
    );
    if ($duedate_enabled) {
      $header[] = t('Due Date');
    }
    $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_access('administer transactions')) {
            $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;
          }
          elseif (!empty($action_link)) {
            $temp_array[] = $action_link;
          }
          elseif (!empty($detail_link)) {
            $temp_array[] = $detail_link;
          }
          else {
            $temp_array[] = '';
          }
          $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>";
  }
}