function merci_delete_item_validate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.module \merci_delete_item_validate()
- 7.2 merci.module \merci_delete_item_validate()
Validates if an item node can be deleted.
Parameters
$node: The item node.
$single: TRUE if a single item node deletion is being processed, FALSE otherwise.
Return value
TRUE if the item can be deleted, FALSE otherwise.
2 calls to merci_delete_item_validate()
- merci_form_alter in ./
merci.module - Implementation of hook_form_alter().
- merci_node_admin_delete_validate in includes/
api.inc - Custom validation function to protect merci nodes from mass deletion.
File
- ./
merci.module, line 1044 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_delete_item_validate($node) {
// Only validate bucket/resource items.
if ($node->type != 'merci_reservation' && $node->merci_type_setting != 'disabled' && $node->merci_sub_type == MERCI_SUB_TYPE_ITEM) {
// 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'];
// Join on nid here so that any version of the reservation that contain
// the item is caught.
// Pull any reservations that use the item in question
$reservations = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {" . $table . "} ct ON ct.vid = n.vid INNER JOIN {merci_reservation_detail} md ON ct.vid = md.vid WHERE md.merci_item_nid = %d", $node->nid);
$bad_reservations = array();
while ($reservation = db_fetch_object($reservations)) {
// Key by nid to prevent duplicate revisions from appearing.
$bad_reservations[$reservation->nid] = l($reservation->title, "node/{$reservation->nid}/edit", array(
'query' => drupal_get_destination(),
));
}
if (!empty($bad_reservations)) {
drupal_set_message(t('%title can not be deleted, because it is associated with the following reservations:', array(
'%title' => $node->title,
)) . theme('item_list', $bad_reservations), 'error');
// Lock out single deletion attempts here.
return FALSE;
}
}
return TRUE;
}