You are here

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

A basic form that allows us to update the state of the calendar.

1 string reference to 'update_unit_pricing_form'
rooms_pricing_page in modules/rooms_pricing/rooms_pricing.module
Callback for admin/rooms/units/unit/%pricing_unit/pricing.

File

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

Code

function update_unit_pricing_form($form, &$form_state, $unit_id) {
  $form['#attributes']['class'][] = 'rooms-management-form unit-pricing-form';
  $form['rooms_update_pricing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update Unit Pricing'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Careful - this will overwrite any existing pricing info.'),
  );
  $form['rooms_update_pricing']['unit_id'] = array(
    '#type' => 'hidden',
    '#value' => $unit_id,
  );
  $form['rooms_update_pricing']['rooms_date_range'] = array(
    '#type' => 'fieldset',
  );
  $form['rooms_update_pricing']['rooms_date_range'] += rooms_date_range_fields();

  // Unset a js setting that is not relevant for pricing.
  drupal_add_js(array(
    'rooms' => array(
      'roomsBookingStartDay' => 0,
    ),
  ), 'setting');
  $day_options = array(
    '1' => t('Sun'),
    '2' => t('Mon'),
    '3' => t('Tue'),
    '4' => t('Wed'),
    '5' => t('Thu'),
    '6' => t('Fri'),
    '7' => t('Sat'),
  );
  $form['rooms_update_pricing']['day_options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Days of the Week applicable'),
    '#options' => $day_options,
    '#default_value' => array_keys($day_options),
  );
  $form['rooms_update_pricing']['op'] = array(
    '#type' => 'fieldset',
  );
  $price_options = rooms_price_options_options();
  unset($price_options[ROOMS_ADD_DAILY]);
  unset($price_options[ROOMS_SUB_DAILY]);
  $form['rooms_update_pricing']['op']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#options' => $price_options,
    '#default_value' => 'replace',
  );
  $form['rooms_update_pricing']['op']['amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Amount'),
    '#default_value' => '',
    '#size' => '5',
    '#description' => t('Amount to apply for rule'),
    '#maxlength' => 10,
    '#required' => TRUE,
  );
  $form['rooms_update_pricing']['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 400,
  );

  // We add the form's #submit array to this button along with the actual submit
  // handler to preserve any submit handlers added by a form callback_wrapper.
  $submit = array();
  if (!empty($form['rooms_update_pricing']['#submit'])) {
    $submit += $form['rooms_update_pricing']['#submit'];
  }
  $form['rooms_update_pricing']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Unit Pricing'),
    '#submit' => $submit + array(
      'update_unit_pricing_form_submit',
    ),
  );

  // We append the validate handler to #validate in case a form callback_wrapper
  // is used to add validate handlers earlier.
  $form['#validate'][] = 'rooms_form_start_end_dates_validate';
  $form['#validate'][] = 'update_unit_pricing_form_validate';
  return $form;
}