You are here

function merci_validate_empty_reservation_items 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_empty_reservation_items()
1 call to merci_validate_empty_reservation_items()
merci_reservation_node_validate in ./merci.module
Implementation of hook_validate().

File

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

Code

function merci_validate_empty_reservation_items($form, &$form_state) {
  $node = (object) $form_state['values'];
  $choices = $node->merci_reservation_items;
  $unselected = 0;
  foreach ($choices as $did => $item) {
    if (is_array($item)) {
      $value = $item['merci_item_nid'];
    }
    else {
      $value = $item;
    }
    if (is_numeric($did) and !$value) {
      $value = $item['type'];
    }
    if (!$value) {
      $unselected++;
    }
  }
  if ($unselected == count($choices)) {
    $choice_keys = array_keys($choices);
    $first = reset($choice_keys);
    form_set_error("merci_reservation_items][{$first}][merci_item_nid", t("You cannot create a reservation without any items selected."));
  }
}