function merci_node_type_save_validate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.module \merci_node_type_save_validate()
- 7.2 merci.module \merci_node_type_save_validate()
Validates saving of MERCI node types.
1 string reference to 'merci_node_type_save_validate'
- merci_form_alter in ./
merci.module - Implementation of hook_form_alter().
File
- ./
merci.module, line 1076 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_node_type_save_validate($form, &$form_state) {
$values = $form_state['values'];
// Only validate node types set to an inactive status.
if ($values['merci_type_setting'] != 'disabled' && (int) $values['merci_active_status'] == MERCI_STATUS_INACTIVE) {
// 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');
$type_setting = $values['merci_type_setting'];
// Pull all active reservations that use the node type.
$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 INNER JOIN {merci_{$type_setting}_node} m ON md.merci_placeholder_nid = m.nid INNER JOIN {node} mn ON m.vid = mn.vid WHERE mn.type = '%s' AND m.merci_sub_type = %d AND {$column_end_date} >= '%s' AND NOT (md.merci_item_status <= %d)", $values['old_type'], MERCI_SUB_TYPE_RESERVATION, $time, MERCI_ITEM_STATUS_CHECKED_IN);
$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_active_status', t('@type_setting can not be set to an inactive status until all @type_setting items are removed from the following reservations:', array(
'@type_setting' => $type_setting,
)) . theme('item_list', $bad_reservations));
}
}
}