function library_transaction_form in Library 7
Same name and namespace in other branches
- 5.2 library.pages.inc \library_transaction_form()
- 6.2 library.pages.inc \library_transaction_form()
- 6 library.pages.inc \library_transaction_form()
The library transaction form.
Parameters
array $form: A regular form array (unused).
array $form_state: A regular form_state array (unused).
int $aid: The action id to perform
null $item: The item to perform the action on, if it should not be searched for.
Return value
array The form array to display.
1 string reference to 'library_transaction_form'
- library_menu in ./
library.module - Implements hook_menu().
File
- ./
library.pages.inc, line 23 - Functions for generating page displays related to the library module.
Code
function library_transaction_form($form, $form_state, $aid, $item = NULL) {
$patron_uid = arg(4);
global $user;
$librarian = user_access('access user profiles', $user) && user_access('administer transactions', $user);
if ($patron_uid && $patron_uid == $user->uid) {
$patron = $user;
}
elseif ($patron_uid && is_numeric($patron_uid) && $librarian) {
$patron = user_load($patron_uid);
}
elseif ($librarian == FALSE) {
$patron = $user;
}
if ($aid) {
$action = library_get_action($aid);
if ($action && $action->name) {
drupal_set_title($action->name);
}
else {
drupal_set_message(t('Invalid action.'), 'error');
drupal_goto('');
}
}
else {
drupal_set_message(t('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'),
'#markup' => $item->title,
);
}
else {
$form['item_id'] = library_autocomplete_input($item);
}
if (isset($patron)) {
$form['patron_uid'] = array(
'#type' => 'value',
'#value' => $patron->uid,
);
$form['patron_uid_set'] = array(
'#type' => 'value',
'#value' => $patron->uid,
);
$form['patron_display'] = array(
'#type' => 'item',
'#markup' => $patron->name,
'#title' => t('Patron'),
);
if ($librarian && $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>',
);
}
}
elseif (variable_get('library_disable_patron_autocomplete', 0) == 1) {
$form['patron_uid'] = array(
'#type' => 'textfield',
'#title' => t('Patron'),
'#default_value' => '',
'#required' => TRUE,
);
}
else {
$form['patron_uid'] = array(
'#type' => 'textfield',
'#title' => t('Patron'),
'#default_value' => isset($patron) ? $patron->name . ' [uid:' . $patron->uid . ']' : '',
'#autocomplete_path' => 'library-items/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',
// @todo Could this be solved better?
'#value' => t($action->name),
);
$form['#validate'][] = 'library_transaction_form_validate';
$form['#submit'][] = 'library_transaction_form_submit';
return $form;
}