You are here

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

Submit callback for rooms_pricing_update_form form.

File

modules/rooms_pricing/rooms_pricing.module, line 542
Manages pricing for Bookable Units and displaying dates on the jquery FullCalendar plugin.

Code

function rooms_pricing_update_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'];
  $operation = $form_state['values']['operation'];
  $amount = $form_state['values']['amount'];
  $days = array_filter($form_state['values']['day_options']);
  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;
      rooms_pricing_update_calendar_event($unit_id, $amount, $start_date, $end_date, $operation, $days);
    }
  }
  else {
    foreach ($form_state['values'] as $key => $value) {
      if (strpos($key, 'rooms-') === 0 && $value == '1') {
        $unit_id = str_replace('rooms-', '', $key);
        rooms_pricing_update_calendar_event($unit_id, $amount, $start_date, $end_date, $operation, $days);
      }
    }
  }
}