You are here

function _getdirections_direction_form in Get Directions 7.3

2 calls to _getdirections_direction_form()
getdirections_direction_form in ./getdirections.module
Function to setup the form
getdirections_fields_direction_form in modules/getdirections_fields/getdirections_fields.module
The getdirections form

File

./getdirections.module, line 587
Fetches google map directions.

Code

function _getdirections_direction_form($defaults, $misc, $mapid, $fromto = '', $loc = '', $country = '', $latlon = '') {
  $islocation = module_exists('location');
  $isgetlocations_fields = module_exists('getlocations_fields');
  if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$defaults['advanced_autocomplete']) {
    $default_country = $islocation ? variable_get('location_default_country', '') : variable_get('site_default_country', '');
    $countries = array(
      '#type' => 'select',
      '#title' => t('Country'),
      '#options' => array_merge(array(
        '' => t('Please select'),
      ), $islocation ? _location_supported_countries() : getlocations_fields_get_countries_list()),
      '#default_value' => $default_country,
    );
  }

  // weights
  if ($defaults['use_advanced']) {
    $from_country_weight = 1;
    $from_weight = 2;
    $to_country_weight = 3;
    $to_weight = 4;
  }
  else {
    $from_weight = 1;
    $from_country_weight = 2;
    $to_weight = 3;
    $to_country_weight = 4;
  }
  $form = array(
    '#action' => '#',
    '#attributes' => array(
      'class' => array(
        'getdirections_form',
      ),
    ),
  );
  if ($fromto == 'from') {
    $form['from_' . $mapid] = array(
      '#type' => 'hidden',
      '#value' => $latlon,
    );
    if (empty($loc)) {
      if (empty($country)) {
        $mfrom = t('Starting point');
      }
      else {
        $mfrom = drupal_strtoupper($country);
      }
    }
    else {
      $mfrom = $loc;
      $form['from_address_' . $mapid] = array(
        '#type' => 'hidden',
        '#value' => $loc,
      );
    }
    $form['mfrom'] = array(
      '#type' => 'item',
      '#title' => t('From'),
      '#markup' => $mfrom,
    );
  }
  else {
    $from_desc = t('Enter the address, postcode and/or city and country from where you want to start your journey.');
    if ($defaults['use_advanced'] && $defaults['advanced_autocomplete']) {
      $from_desc = t('Start typing the address of your starting point, then select from the dropdown menu.');
    }
    if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$defaults['advanced_autocomplete']) {
      $form['country_from_' . $mapid] = $countries;
      $form['country_from_' . $mapid]['#weight'] = $from_country_weight;
      $from_desc = t('Enter the address, postcode and/or city from where you want to start your journey.');
    }
    $form['from_' . $mapid] = array(
      '#type' => 'textfield',
      '#title' => t('Starting from'),
      '#size' => $defaults['from_width'],
      '#required' => TRUE,
      '#description' => $from_desc,
      '#weight' => $from_weight,
    );
  }
  if ($fromto == 'to') {
    $form['to_' . $mapid] = array(
      '#type' => 'hidden',
      '#value' => $latlon,
    );
    if (empty($loc)) {
      if (empty($country)) {
        $mto = t('Destination');
      }
      else {
        $mto = drupal_strtoupper($country);
      }
    }
    else {
      $mto = $loc;
      $form['to_address_' . $mapid] = array(
        '#type' => 'hidden',
        '#value' => $loc,
      );
    }
    $form['mto'] = array(
      '#type' => 'item',
      '#title' => t('To'),
      '#markup' => $mto,
    );
  }
  else {
    $to_desc = t('Enter the address, postcode and/or city and country of your journey destination.');
    if ($defaults['use_advanced'] && $defaults['advanced_autocomplete']) {
      $to_desc = t('Start typing the address of your destination, then select from the dropdown menu.');
    }
    if ($defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$defaults['advanced_autocomplete']) {
      $form['country_to_' . $mapid] = $countries;
      $form['country_to_' . $mapid]['#weight'] = $to_country_weight;
      $to_desc = t('Enter the address, postcode and/or city of your journey destination.');
    }
    $form['to_' . $mapid] = array(
      '#type' => 'textfield',
      '#title' => t('Destination'),
      '#size' => $defaults['to_width'],
      '#required' => TRUE,
      '#description' => $to_desc,
      '#weight' => $to_weight,
    );
  }
  $wt = 6;
  if ($defaults['travelmode_show']) {
    $form['travelmode_' . $mapid] = array(
      '#type' => 'select',
      '#title' => t('Travel mode'),
      '#options' => array(
        'driving' => t('Driving'),
        'walking' => t('Walking'),
        'bicycling' => t('Bicycling'),
        'transit' => t('Public transport'),
      ),
      '#default_value' => 'driving',
      '#weight' => $wt,
    );
    $wt = $wt + 2;
    if (module_exists('date_popup')) {
      $form['transit_date_select_' . $mapid] = array(
        '#type' => 'select',
        '#title' => t('Date select'),
        '#options' => array(
          'depart' => t('Departure time'),
          'arrive' => t('Arrival time'),
        ),
        '#default_value' => 'depart',
        '#prefix' => '<div id="getdirections_transit_dates_wrapper_' . $mapid . '">',
        '#weight' => $wt,
      );
      $wt = $wt + 2;
      if ($defaults['transit_date_format'] == 'int') {
        $fmt = 'j/n/Y H:i';
      }
      else {
        $fmt = 'n/j/Y H:i';
      }
      $form['transit_dates_' . $mapid] = array(
        '#type' => 'date_popup',
        '#default_value' => '',
        '#date_year_range' => '-0:+1',
        '#date_format' => $fmt,
        '#mindate' => "+0",
        '#suffix' => '</div>',
        '#weight' => $wt,
      );
      $wt = $wt + 2;
    }
  }
  if ($defaults['travelextras_show']) {
    $form['travelextras_' . $mapid] = array(
      '#type' => 'checkboxes',
      '#title' => t('Travel options'),
      '#options' => array(
        'avoidhighways' => t('Avoid Highways'),
        'avoidtolls' => t('Avoid Tolls'),
        'avoidferries' => t('Avoid Ferries'),
        'altroute' => t('Alternative routes'),
      ),
      '#weight' => $wt,
    );
    $wt = $wt + 2;
  }
  if ($defaults['use_advanced'] && $defaults['advanced_autocomplete'] && $defaults['waypoints'] > 0 && $defaults['advanced_autocomplete_via'] && !$defaults['advanced_alternate']) {
    for ($ct = 1; $ct <= $defaults['waypoints']; $ct++) {
      $form['via_autocomplete_' . $mapid . '_' . $ct] = array(
        '#type' => 'textfield',
        '#title' => t('Via !c', array(
          '!c' => $ct,
        )),
        '#size' => $defaults['advanced_autocomplete_via_width'],
        '#weight' => $wt,
      );
      $wt = $wt + 2;
    }
  }
  if ($misc['switchfromto'] && !$fromto && !$defaults['use_advanced']) {
    $form['switchfromto_' . $mapid] = array(
      '#type' => 'markup',
      '#markup' => '<input type="button" id="getdirections_togglefromto_' . $mapid . '" class="switchfromto" name="op" value="' . t('Switch From/To') . '">',
      '#weight' => $wt,
    );
    $wt = $wt + 2;
  }

  // mapid for use in theme
  $form['mapid'] = array(
    '#type' => 'value',
    '#value' => $mapid,
  );
  if ($defaults['use_advanced'] && !$defaults['advanced_autocomplete']) {
    $form['next_' . $mapid] = array(
      '#type' => 'button',
      '#value' => t('Next'),
      '#attributes' => array(
        'onclick' => 'Drupal.getdirections.nextbtn(); return false;',
      ),
      '#weight' => $wt,
    );
    $wt = $wt + 2;
  }
  $form['submit_' . $mapid] = array(
    '#type' => 'button',
    '#value' => t('Get Directions'),
    '#weight' => $wt,
  );
  return $form;
}