You are here

function merci_add_settings_form in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2

Same name and namespace in other branches
  1. 7.2 merci.module \merci_add_settings_form()
1 call to merci_add_settings_form()
merci_form_alter in ./merci.module
Implementation of hook_form_alter().

File

./merci.module, line 1407
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_add_settings_form(&$form, $form_state) {

  // Only admin can edit these values.
  if (!user_access('administer MERCI')) {
    return;
  }
  $type = array_key_exists('old_type', $form) ? $form['old_type']['#value'] : $form['type']['#value'];

  //$merci_settings = mnerci_content_types($type);

  //if(!$merci_settings) return;
  if (merci_is_merci_type($type)) {
    $settings = merci_load_item_settings($type);
  }
  else {
    $settings = new stdClass();
    $settings->merci_type_setting = 'disabled';
    $settings->merci_active_status = MERCI_STATUS_ACTIVE;
    $settings->merci_max_hours_per_reservation = 0;
    $settings->merci_allow_overnight = 0;
    $settings->merci_allow_weekends = 0;
    $settings->merci_rate_per_hour = 0;
    $settings->merci_late_fee_per_hour = 0;
    $settings->merci_fee_free_hours = 0;
    $settings->merci_min_cancel_hours = 0;
    $settings->merci_autocheckout = 0;
    $settings->merci_autocheckin = 0;
    $settings->merci_selfcheckout = 0;
  }
  if ($form['#id'] == 'node-type-form') {
    $node = $settings;
  }
  else {
    $node = (object) $form['#node'];
    if (empty($node->merci_type_setting)) {
      if (merci_is_merci_type($node->type)) {
        foreach ($settings as $key => $value) {
          if (!isset($node->{$key})) {
            $node->{$key} = $value;
          }
        }
      }
    }
  }

  //merci_load_item_settings($node);

  // New nodes are always sub type item.
  $sub_type = isset($node->merci_sub_type) ? $node->merci_sub_type : MERCI_SUB_TYPE_ITEM;
  if (empty($form['merci'])) {
    $form['merci'] = array(
      '#type' => 'fieldset',
      '#title' => t('MERCI settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
  }

  // Bucket item nodes have no individual pricing, so just zero these values out.
  // Althought you can override them on the reserervation nodes.
  if ($form['#id'] == 'node-type-form' or $sub_type == MERCI_SUB_TYPE_RESERVATION or $node->merci_type_setting == 'resource') {
    $form['merci']['merci_rate_per_hour'] = array(
      '#type' => 'textfield',
      '#title' => t('Rate per hour'),
      '#size' => 10,
      '#default_value' => $node->merci_rate_per_hour,
      '#element_validate' => array(
        'merci_is_numeric_validate',
      ),
      '#description' => t('The per hour rental fee for the item.'),
    );
    $form['merci']['merci_late_fee_per_hour'] = array(
      '#type' => 'textfield',
      '#title' => t('Late fee per hour'),
      '#size' => 10,
      '#default_value' => $node->merci_late_fee_per_hour,
      '#element_validate' => array(
        'merci_is_numeric_validate',
      ),
      '#description' => t('The per hour fee for returning the item late.'),
    );
    $form['merci']['merci_fee_free_hours'] = array(
      '#type' => 'textfield',
      '#title' => t('Fee free hours'),
      '#size' => 10,
      '#default_value' => $node->merci_fee_free_hours,
      '#element_validate' => array(
        'merci_is_numeric_validate',
      ),
      '#description' => t('The number of hours the item can be used before fees are charged.'),
    );
  }
  if ($form['#id'] == 'node-type-form' or $node->merci_type_setting == 'resource' and $sub_type == MERCI_SUB_TYPE_ITEM) {
    $form['merci']['merci_min_cancel_hours'] = array(
      '#type' => 'textfield',
      '#title' => t('Minimum hours for cancelation without No Show'),
      '#size' => 10,
      '#default_value' => $node->merci_min_cancel_hours,
      '#element_validate' => array(
        'merci_is_numeric_validate',
      ),
      '#description' => t('Minimum number of hours before the start time a user may cancel a reservation for the item.'),
    );
    $form['merci']['merci_autocheckout'] = array(
      '#type' => 'checkbox',
      '#title' => t('Auto checkout'),
      '#default_value' => $node->merci_autocheckout,
      '#description' => t('Automatically check this item out when the Reservation starts.'),
    );
    $form['merci']['merci_autocheckin'] = array(
      '#type' => 'checkbox',
      '#title' => t('Auto checkin'),
      '#default_value' => $node->merci_autocheckin,
      '#description' => t('Automatically check this item in when the Reservation ends.'),
    );
    $form['merci']['merci_selfcheckout'] = array(
      '#type' => 'checkbox',
      '#title' => t('Self checkout'),
      '#default_value' => $node->merci_selfcheckout,
      '#description' => t('Manage checkout with additional code.'),
    );
  }
}