function merci_build_reservation_table_form in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.module \merci_build_reservation_table_form()
- 7.2 merci.module \merci_build_reservation_table_form()
Builds the table of existing reserved items.
Parameters
$form_state: Current form state.
$node: The reservation node.
$edit_page: TRUE if the table is on the edit page for the reservation, FALSE otherwise.
Return value
The form array.
1 call to merci_build_reservation_table_form()
- merci_form in ./
merci.module - Implementation of hook_form().
1 string reference to 'merci_build_reservation_table_form'
- merci_view in ./
merci.module - Implementation of hook_view().
File
- ./
merci.module, line 1275 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_build_reservation_table_form(&$form_state, $node, $edit_page = FALSE) {
global $user;
$table = array();
$table['#theme'] = 'merci_build_reservation_table_form';
$table['#node'] = $node;
$table['#tree'] = TRUE;
$table['#table'] = array();
$table['#header'] = array(
t('Item'),
);
if (!isset($node->merci_reservation_items)) {
return $table;
}
$items = $node->merci_reservation_items;
$table['#header'][] = t('Type');
foreach ($items as $did => $item) {
if (!is_numeric($did)) {
continue;
}
$form = array();
foreach ($item as $key => $value) {
$form[$key] = array(
'#type' => 'value',
'#value' => $value,
);
}
$form['display_name']['#value'] = $form['name']['#value'];
$form['display_item_title']['#value'] = $form['item_title']['#value'];
if (user_access("manage reservations")) {
if (merci_has_accessories($item['type'])) {
$placeholder_node = node_load($item['merci_placeholder_nid']);
if (!in_array(t('Accessories'), $table['#header'])) {
$table['#header'][] = t('Accessories');
}
if ($edit_page) {
if ($node->merci_reservation_status == MERCI_STATUS_CHECKED_OUT) {
$collapsed = FALSE;
}
else {
$collapsed = TRUE;
}
// Container for just the item selector.
$form['accessories'] = array(
'#type' => 'fieldset',
'#title' => t('Add accessories'),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#prefix' => '<div id="merci-accessories-' . $placeholder_node->nid . '">',
'#suffix' => '</div>',
'choices' => merci_build_accessory_form($form_state, $placeholder_node, $did),
);
}
else {
$accessories = '';
$terms = taxonomy_node_get_terms($placeholder_node);
if (!empty($terms)) {
foreach ($terms as $accessory) {
$accessories .= $accessory->name . ', ';
}
}
$form['accessories'] = array(
'#type' => 'markup',
'#title' => t('Accessories'),
'#value' => $accessories,
);
}
//$operations .= ' ' . l(t('edit'), "node/$item->merci_placeholder_nid/edit", array('query' => drupal_get_destination()));
// Only allow editing or deletion if unconfirmed or confirmed.
if ($edit_page && $node->merci_reservation_status >= MERCI_STATUS_CHECKED_OUT) {
foreach ($form['accessories']['choices'] as $vid => $values) {
$form['accessories']['choices'][$vid]['#disabled'] = TRUE;
}
$form['accessories']['#title'] = t('Accessories');
}
}
}
// Only allow editing or deletion if unconfirmed or confirmed.
if ($edit_page && $node->merci_reservation_status < MERCI_STATUS_CHECKED_OUT) {
if (!in_array(t('Operations'), $table['#header'])) {
$table['#header'][] = t('Operations');
}
//@TODO: Should users be able to remove items from confirmed reservations?
if (user_access("manage reservations") || $node->uid == $user->uid) {
if (!in_array(t('Operations'), $table['#header'])) {
$table['#header'][] = t('Operations');
}
$operations = ' ' . l(t('delete'), "node/" . $item['merci_placeholder_nid'] . "/delete", array(
'query' => drupal_get_destination(),
));
}
$operations .= ' ' . l(t('edit'), "node/" . $item['merci_placeholder_nid'] . "/edit", array(
'query' => drupal_get_destination(),
));
$form['ops']['#value'] = $operations;
}
$type_setting = merci_type_setting($item['type']);
if ($edit_page && $type_setting == 'bucket') {
// Only users with manage reservations permission can change the bucket item assignment.
if (user_access('manage reservations')) {
$options = array(
0 => t('<Select>'),
);
$options += merci_get_available_bucket_items($node, $item['type']);
$form['merci_item_nid'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $item['merci_item_nid'],
);
if ($node->merci_reservation_status >= MERCI_STATUS_CHECKED_OUT) {
$form['merci_item_nid']['#disabled'] = true;
}
}
}
//$form['#table'][$did]['accessories'] = $accessories;
$table[$did] = $form;
}
return $table;
}