function rooms_availability_update_status_form_submit in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Submit callback for rooms_availability_update_status_form form.
File
- modules/
rooms_availability/ rooms_availability.module, line 328 - Manages availability for Bookable Units and displaying dates on the jquery FullCalendar plugin.
Code
function rooms_availability_update_status_form_submit(&$form, &$form_state) {
list($start_date, $end_date) = rooms_form_input_get_start_end_dates($form_state);
$type = $form_state['values']['curr_type'];
$event_id = $form_state['values']['change_event_status'];
// Consider right START DATE and END DATE for all events.
$end_date
->sub(new DateInterval('P1D'));
if ($form_state['values']['select-all'] == ROOMS_ALL_PAGES) {
$query = db_select('rooms_units', 'n')
->fields('n', array(
'unit_id',
'name',
));
if ($type != 'all') {
$query
->condition('type', $type, '=');
}
$rooms_units = $query
->execute()
->fetchAll();
foreach ($rooms_units as $room) {
$unit_id = $room->unit_id;
// 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($room->name . ' - ' . 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($room->name . ' - ' . t('Calendar Updated'));
}
}
}
else {
foreach ($form_state['values'] as $key => $value) {
if (strpos($key, 'rooms-') === 0 && $value == '1') {
$unit_id = str_replace('rooms-', '', $key);
// 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($form_state['complete form']['rooms_data'][$key]['#title'] . ' - ' . 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($form_state['complete form']['rooms_data'][$key]['#title'] . ' - ' . t('Calendar Updated'));
}
}
}
}
}