You are here

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

The Event Manager Form.

1 string reference to 'rooms_availability_event_manager_form'
rooms_availability_event_manager_page in modules/rooms_availability/rooms_availability.module
The EventManager page shows when clicking on an event in the availability calendar - will allow a user to manipulate that event.

File

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

Code

function rooms_availability_event_manager_form($form, $form_state, $unit, $event_id, $start_date, $end_date) {
  $form = array();
  $new_event_id = $event_id;
  if (isset($form_state['values']['change_event_status'])) {
    $new_event_id = $form_state['values']['change_event_status'];
  }
  $state_options = rooms_unit_state_options();
  $form['#attributes']['class'][] = 'rooms-management-form rooms-event-form';

  // This entire form element will be replaced whenever 'changethis' is updated.
  $form['#prefix'] = '<div id="replace_textfield_div">';
  $form['#suffix'] = '</div>';
  $form['unit_id'] = array(
    '#type' => 'hidden',
    '#value' => $unit->unit_id,
  );
  $form['event_id'] = array(
    '#type' => 'hidden',
    '#value' => $event_id,
  );
  $form['rooms_start_date'] = array(
    '#type' => 'hidden',
    '#value' => $start_date,
  );
  $form['rooms_end_date'] = array(
    '#type' => 'hidden',
    '#value' => $end_date,
  );
  if ($event_id == -2) {
    $form['event_title'] = array(
      '#prefix' => '<h2>',
      '#markup' => check_plain($unit->name),
      '#suffix' => '</h2>',
    );
  }
  else {
    $form['event_title'] = array(
      '#prefix' => '<h2>',
      '#markup' => t('@unit_name is @status', array(
        '@unit_name' => $unit->name,
        '@status' => $state_options[$new_event_id],
      )),
      '#suffix' => '</h2>',
    );
  }
  $date_format = variable_get('rooms_date_format', 'd-m-Y');
  $form['event_details'] = array(
    '#prefix' => '<div class="event-details">',
    '#markup' => t('Duration: @startdate to @enddate', array(
      '@startdate' => $start_date
        ->format($date_format),
      '@enddate' => $end_date
        ->format($date_format),
    )),
    '#suffix' => '</div>',
  );
  unset($state_options[$new_event_id]);
  $form['change_event_status'] = array(
    '#title' => t('Change the state for this event to:') . ' ',
    '#type' => 'select',
    '#options' => $state_options,
    '#ajax' => array(
      'callback' => 'rooms_availability_ajax_event_status_change',
      'wrapper' => 'replace_textfield_div',
    ),
    '#empty_option' => t('- Select -'),
  );
  if (module_exists('rooms_booking') && $new_event_id != 89) {
    $booking_types = rooms_booking_get_types();
    foreach ($booking_types as $type) {
      $book_end_date = clone $end_date;

      // If we select one day from the calendar, postpone the departure date.
      if ($start_date == $end_date) {
        $book_end_date = $book_end_date
          ->add(new DateInterval('P1D'));
      }
      $form['order']['order_link'][$type->type] = array(
        '#type' => 'markup',
        '#markup' => '<div>' . l(t('Create @booking_type', array(
          '@booking_type' => $type->label,
        )), 'admin/rooms/bookings/add/' . $type->type, array(
          'query' => array(
            'startdate' => $start_date
              ->getTimestamp(),
            'enddate' => $book_end_date
              ->getTimestamp(),
            'unitid' => $unit->unit_id,
          ),
        )) . '</div>',
      );
    }
  }
  return $form;
}