You are here

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

Form to manage the room units pricing.

See also

rooms_pricing_bulk_pricing_management()

1 string reference to 'rooms_pricing_update_form'
rooms_pricing_bulk_pricing_management in modules/rooms_pricing/rooms_pricing.module
Page callback for Bulk Pricing Management.

File

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

Code

function rooms_pricing_update_form($form, &$form_state, $month, $year, $type, $rooms_units) {
  $form['#attributes']['class'][] = 'rooms-management-form rooms-bulk-pricing-form';
  $form['rooms_pricing_update'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update Pricing'),
    '#description' => t('Apply a pricing adjustment in bulk to the units selected below for the specified date range.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['rooms_pricing_update']['curr_month'] = array(
    '#type' => 'hidden',
    '#value' => $month,
  );
  $form['rooms_pricing_update']['curr_year'] = array(
    '#type' => 'hidden',
    '#value' => $year,
  );
  $form['rooms_pricing_update']['curr_type'] = array(
    '#type' => 'hidden',
    '#value' => $type,
  );
  $form['rooms_pricing_update']['rooms_date_range'] = rooms_date_range_fields($year, $month);
  $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_pricing_update']['day_options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Days of the Week applicable'),
    '#options' => $day_options,
    '#default_value' => array_keys($day_options),
  );
  $form['rooms_pricing_update']['op'] = array(
    '#type' => 'fieldset',
  );
  $price_options = rooms_price_options_options();
  unset($price_options[ROOMS_ADD_DAILY]);
  unset($price_options[ROOMS_SUB_DAILY]);
  $form['rooms_pricing_update']['op']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#options' => $price_options,
    '#default_value' => 'replace',
  );
  $form['rooms_pricing_update']['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_pricing_update']['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 400,
  );
  $form['rooms_pricing_update']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Unit Pricing'),
  );
  $form['#validate'][] = 'rooms_pricing_update_form_validate';
  $form['#validate'][] = 'rooms_form_start_end_dates_validate';
  $form['rooms_data'] = array(
    '#prefix' => '<table class="rooms-month-manager">',
    '#type' => 'container',
    '#suffix' => '</tbody></table>',
  );
  if (count($rooms_units) > 0) {
    $date = new DateTime();
    $date
      ->setDate($year, $month, '01');
    $form['rooms_data']['select-all'] = array(
      '#type' => 'select',
      '#prefix' => '<thead><tr><th class="unit-bulk-select">',
      '#options' => array(
        ROOMS_THIS_PAGE => t('All (this page)'),
        ROOMS_ALL_PAGES => t('All (all pages)'),
        ROOMS_NONE => t('None'),
      ),
      '#empty_option' => t('- Select -'),
      '#suffix' => '</th><th class="month-name"><div class="fc-header-title"><h2>' . format_date($date
        ->getTimestamp(), 'custom', 'F Y') . '</h2></div></th></tr></thead><tbody>',
    );
  }
  foreach ($rooms_units as $key => $value) {
    $form['rooms_data']['rooms-' . $value->unit_id] = array(
      '#type' => 'checkbox',
      '#title' => $value->name,
      '#prefix' => '<tr><th class="unit-name">',
      '#suffix' => '</th><td class="unit-days"><div id="calendar' . $key . '"></div></td></tr>',
    );
  }
  return $form;
}