You are here

function merci_validate_default_availability in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2

Same name and namespace in other branches
  1. 6.2 includes/api.inc \merci_validate_default_availability()
  2. 6 merci.module \merci_validate_default_availability()

Validates the state change of a reservable item.

Parameters

$node: The item node.

1 string reference to 'merci_validate_default_availability'
merci_form_alter in ./merci.module
Implementation of hook_form_alter().

File

includes/api.inc, line 312
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_validate_default_availability($element, &$form_state) {

  // Only perform the check if the item is set to an unavailable state.
  if (in_array((int) $element['#value'], array(
    MERCI_UNA_F,
    MERCI_UNA_S,
  ))) {
    $bad_reservations = merci_incomplete_reservations_for_item_nid($form_state['values']['nid']);
    if (!empty($bad_reservations)) {
      $output = '<ul>';
      foreach ($bad_reservations as $node) {
        $output .= '<li>' . $node . '</li>';
      }
      $output .= '</ul>';
      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' => $form_state['values']['title'],
      )) . $output);
    }
  }
}