function rooms_availability_event_manager_page in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
The EventManager page shows when clicking on an event in the availability calendar - will allow a user to manipulate that event.
1 string reference to 'rooms_availability_event_manager_page'
- rooms_availability_menu in modules/
rooms_availability/ rooms_availability.module - Implements hook_menu().
File
- modules/
rooms_availability/ rooms_availability.module, line 601 - Manages availability for Bookable Units and displaying dates on the jquery FullCalendar plugin.
Code
function rooms_availability_event_manager_page($unit, $event_id = NULL, $start_date = 0, $end_date = 0) {
// Include modal library.
ctools_include('modal');
// If any info missing we cannot load the event.
if ($event_id == NULL || $start_date == 0 || $end_date == 0) {
$output[] = ctools_modal_command_dismiss();
drupal_set_message(t('Unable to load event.'), 'error');
}
// Basic check to avoid damage from dirty input.
$event_id = check_plain($event_id);
$start_date = check_plain($start_date);
$end_date = check_plain($end_date);
// Process start and end date.
$sd = new DateTime($start_date);
$ed = new DateTime($end_date);
$booked = FALSE;
if ($event_id > 10 || $event_id < -10) {
$booked = TRUE;
}
if ($booked) {
$booking_id = rooms_availability_return_id($event_id);
$booking = rooms_booking_load($booking_id);
// For existing bookings allow to edit in the modal.
module_load_include('inc', 'rooms_booking', 'rooms_booking.admin');
$form_state = array(
'title' => t('Edit booking'),
'ajax' => TRUE,
'build_info' => array(
'args' => array(
$booking,
),
'files' => array(
'rooms_booking_admin' => array(
'module' => 'rooms_booking',
'name' => 'rooms_booking.admin',
'type' => 'inc',
),
),
),
);
// Wrap the form via ctools modal.
$output = ctools_modal_form_wrapper('rooms_booking_edit_form', $form_state);
if ($form_state['executed']) {
if (!empty($form_state['booking_deleted'])) {
// If there are messages for the form, render them.
$messages = theme('status_messages');
$output = array();
// If the form has not yet been rendered, render it.
$output[] = ctools_modal_command_display(t('Booking deleted'), $messages);
}
else {
$output = array(
ctools_modal_command_dismiss(),
);
}
}
print ajax_render($output);
exit;
}
// If the event is blocked, show an error message.
$uc = new UnitCalendar($unit->unit_id);
$mock_event = new BookingEvent($unit->unit_id, NULL, $sd, $ed);
if ($uc
->eventBlocked($mock_event)) {
drupal_set_message(t('You can not update calendar because a locked event is blocking the update. You need to unlock any locked events in that period.'), 'warning');
$output = theme('status_messages');
ctools_modal_render(t('Event Management'), $output);
return;
}
ctools_modal_render(t('Event Management'), drupal_get_form('rooms_availability_event_manager_form', $unit, $event_id, $sd, $ed));
}