function library_transaction_form in Library 6
Same name and namespace in other branches
- 5.2 library.pages.inc \library_transaction_form()
- 6.2 library.pages.inc \library_transaction_form()
- 7 library.pages.inc \library_transaction_form()
@file Functions for generating page displays related to the library module
1 string reference to 'library_transaction_form'
- library_menu in ./
library.module - Implementation of hook_menu().
File
- ./
library.pages.inc, line 8 - Functions for generating page displays related to the library module
Code
function library_transaction_form(&$form_state, $aid, $item = NULL) {
$patron_id = arg(4);
if ($patron_id) {
$patron = node_load($patron_id);
}
elseif (!user_access('view patron content')) {
global $user;
$user_patron = patron_load_by_uid($user->uid);
if (is_object($user_patron)) {
$patron = $user_patron;
}
else {
drupal_set_message('You do not have sufficient permissions.', 'error');
drupal_goto('/');
}
}
if ($aid) {
$action = library_get_action($aid);
if ($action->name) {
drupal_set_title($action->name);
}
else {
drupal_set_message('Invalid action.', 'error');
drupal_goto('');
}
}
else {
drupal_set_message('No action was selected.', 'error');
drupal_goto('');
}
$form = array();
$form['action_aid'] = array(
'#type' => 'value',
'#value' => $action->aid,
);
$form['action_name'] = array(
'#type' => 'value',
'#value' => $action->name,
);
$form['action_status_change'] = array(
'#type' => 'value',
'#value' => $action->status_change,
);
if ($item) {
$form['item_id'] = array(
'#type' => 'value',
'#value' => $item->id,
);
$form['item_id_set'] = array(
'#type' => 'value',
'#value' => $item->id,
);
$form['item_display'] = array(
'#type' => 'item',
'#title' => t('Item'),
'#value' => $item->title,
);
}
else {
$form['item_id'] = library_autocomplete_input($item);
}
if ($patron) {
$form['patron_id'] = array(
'#type' => 'value',
'#value' => $patron->nid,
);
$form['patron_id_set'] = array(
'#type' => 'value',
'#value' => $patron->nid,
);
$form['patron_display'] = array(
'#type' => 'item',
'#value' => $patron->name_first . ' ' . $patron->name_last,
'#title' => t('Patron'),
);
if (user_access('view patron content') && $action->status_change == LIBRARY_ACTION_NO_CHANGE) {
$link = 'library-items/transaction/' . $action->aid;
if ($item) {
$link .= '/' . $item->id;
}
$form['patron_change_link'] = array(
'#type' => 'item',
'#value' => 'Change Patron',
'#prefix' => '<a href="' . url($link) . '">',
'#suffix' => '</a>',
);
}
}
else {
$form['patron_id'] = array(
'#type' => 'textfield',
'#title' => t('Patron'),
'#default_value' => $patron ? $patron->title . ' [nid:' . $patron->nid . ']' : '',
'#autocomplete_path' => 'patrons/autocomplete',
'#required' => TRUE,
);
}
$form['notes'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#required' => FALSE,
'#maxlength' => 250,
'#default_value' => '',
'#description' => t('If you are reserving an item, make sure to include the date and time you would like it to be ready.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t($action->name),
);
$form['#validate'][] = 'library_transaction_form_validate';
$form['#submit'][] = 'library_transaction_form_submit';
return $form;
}