function merci_validate_default_availability in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6
Same name and namespace in other branches
- 6.2 includes/api.inc \merci_validate_default_availability()
- 7.2 includes/api.inc \merci_validate_default_availability()
Validates the state change of a reservable item.
Parameters
$node: The item node.
1 call to merci_validate_default_availability()
- merci_nodeapi in ./
merci.module - Implementation of hook_nodeapi().
File
- ./
merci.module, line 1470 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_validate_default_availability($node) {
// Only perform the check if the item is set to an unavailable state.
if (in_array((int) $node->merci_default_availability, array(
MERCI_UNA_F,
MERCI_UNA_S,
))) {
// Determine CCK table and columns the date data is stored in.
$field = content_fields('field_merci_date');
$db_info = content_database_info($field);
$table = $db_info['table'];
$column_end_date = $db_info['columns']['value2']['column'];
$time = gmdate('Y-m-d H:i:s');
// Pull any incomplete reservations that use the item in question
$reservations = db_query("SELECT ctn.nid, ctn.title FROM {" . $table . "} ct INNER JOIN {merci_reservation_detail} md ON ct.vid = md.vid INNER JOIN {node} ctn ON ct.vid = ctn.vid WHERE md.item_nid = %d AND {$column_end_date} >= '%s' AND NOT (md.item_status <= %d)", $node->nid, $time, MERCI_ITEM_STATUS_AVAILABLE);
$bad_reservations = array();
while ($reservation = db_fetch_object($reservations)) {
$bad_reservations[] = l($reservation->title, "node/{$reservation->nid}/edit", array(
'query' => drupal_get_destination(),
));
}
if (!empty($bad_reservations)) {
form_set_error('merci_default_availability', t('%title can not be set to an unavailable status until it is removed from the following reservations:', array(
'%title' => $node->title,
)) . theme('item_list', $bad_reservations));
}
}
}