You are here

function update_availability_calendar_form_submit in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

@todo Need to figure out what to do when we cancel an existing booking.

1 string reference to 'update_availability_calendar_form_submit'
update_availability_calendar_form in modules/rooms_availability/rooms_availability.module
A basic form that allows us to update the state of the calendar.

File

modules/rooms_availability/rooms_availability.module, line 483
Manages availability for Bookable Units and displaying dates on the jquery FullCalendar plugin.

Code

function update_availability_calendar_form_submit(&$form, &$form_state) {
  list($start_date, $end_date) = rooms_form_input_get_start_end_dates($form_state);
  $event_id = $form_state['values']['unit_state'];
  $unit_id = $form_state['values']['unit_id'];

  // Consider right START DATE and END DATE for all events.
  $end_date
    ->sub(new DateInterval('P1D'));

  // Create a new Booking Event.
  $be = new BookingEvent($unit_id, $event_id, $start_date, $end_date);
  $events = array(
    $be,
  );
  $rc = new UnitCalendar($unit_id);
  $response = $rc
    ->updateCalendar($events);
  if ($response[$event_id] == ROOMS_BLOCKED) {
    drupal_set_message(t('Could not update calendar because a locked event is blocking the update - you need to unlock any locked events in that period.'), 'warning');
  }
  elseif ($response[$event_id] == ROOMS_UPDATED) {
    drupal_set_message(t('Calendar Updated'));
  }
}