function library_transaction_form in Library 6.2
Same name and namespace in other branches
- 5.2 library.pages.inc \library_transaction_form()
- 6 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_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->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_uid'] = array(
'#type' => 'value',
'#value' => $patron->uid,
);
$form['patron_uid_set'] = array(
'#type' => 'value',
'#value' => $patron->uid,
);
$form['patron_display'] = array(
'#type' => 'item',
'#value' => $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' => $patron ? $patron->name . ' [uid:' . $patron->uid . ']' : '',
'#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;
}