You are here

function getdirections_direction_form in Get Directions 6.2

Same name and namespace in other branches
  1. 6 getdirections.module \getdirections_direction_form()
  2. 7.3 getdirections.module \getdirections_direction_form()
  3. 7.2 getdirections.module \getdirections_direction_form()

Function to setup the form

Parameters

string $direction: Optional. The direction the supplied input applies to

string $location: Optional. The string to search with

string $country: Optional. The country

string $latlon: Optional. Comma delimited string containing latitude and longitude

Return value

Returns the form

1 string reference to 'getdirections_direction_form'
getdirections_direction in ./getdirections.module
Function to setup the map and form

File

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

Code

function getdirections_direction_form($form_state, $fromto = '', $loc = '', $country = '', $latlon = '') {
  $getdirections_defaults = getdirections_defaults();
  $location = module_exists('location');
  if ($location && !$getdirections_defaults['advanced_autocomplete']) {
    $countries = array(
      '#type' => 'select',
      '#title' => t('Country'),
      '#options' => array_merge(array(
        '' => t('Please select'),
      ), _location_supported_countries()),
      '#default_value' => variable_get('location_default_country', ''),
    );
  }
  $setdirections = "Drupal.getdirections.mygetDirections(); return false;";

  // weights
  if (getdirections_is_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' => 'getdirections_form',
      'onsubmit' => $setdirections,
    ),
  );
  if ($fromto == 'from') {
    $form['from'] = array(
      '#type' => 'hidden',
      '#value' => $latlon,
    );
    if (empty($loc)) {
      if (empty($country)) {
        $mfrom = t('Starting point');
      }
      else {
        $mfrom = drupal_strtoupper($country);
      }
    }
    else {
      $mfrom = $loc;
    }
    $form['mfrom'] = array(
      '#type' => 'item',
      '#title' => t('From'),
      '#value' => $mfrom,
    );
  }
  else {
    $from_desc = t('Enter the address, postcode and/or city and country from where you want to start your journey.');
    if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete']) {
      $from_desc = t('Start typing the address of your starting point, then select from the dropdown menu.');
    }
    if ($location && !$getdirections_defaults['advanced_autocomplete']) {
      $form['country_from'] = $countries;
      $form['country_from']['#weight'] = $from_country_weight;
      $from_desc = t('Enter the address, postcode and/or city from where you want to start your journey.');
    }
    $form['from'] = array(
      '#type' => 'textfield',
      '#title' => t('Starting from'),
      '#size' => $getdirections_defaults['from_width'],
      '#required' => TRUE,
      '#description' => $from_desc,
      '#weight' => $from_weight,
    );
  }
  if ($fromto == 'to') {
    $form['to'] = array(
      '#type' => 'hidden',
      '#value' => $latlon,
    );
    if (empty($loc)) {
      if (empty($country)) {
        $mto = t('Destination');
      }
      else {
        $mto = drupal_strtoupper($country);
      }
    }
    else {
      $mto = $loc;
    }
    $form['mto'] = array(
      '#type' => 'item',
      '#title' => t('To'),
      '#value' => $mto,
    );
  }
  else {
    $to_desc = t('Enter the address, postcode and/or city and country of your journey destination.');
    if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete']) {
      $to_desc = t('Start typing the address of your destination, then select from the dropdown menu.');
    }
    if ($location && !$getdirections_defaults['advanced_autocomplete']) {
      $form['country_to'] = $countries;
      $form['country_to']['#weight'] = $to_country_weight;
      $to_desc = t('Enter the address, postcode and/or city of your journey destination.');
    }
    $form['to'] = array(
      '#type' => 'textfield',
      '#title' => t('Destination'),
      '#size' => $getdirections_defaults['to_width'],
      '#required' => TRUE,
      '#description' => $to_desc,
      '#weight' => $to_weight,
    );
  }
  $wt = 6;
  if (variable_get('getdirections_use_v3', 0)) {
    if ($getdirections_defaults['travelmode_show']) {
      $form['travelmode'] = 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'] = 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">',
          '#weight' => $wt,
        );
        $wt = $wt + 2;
        if ($getdirections_defaults['transit_date_format'] == 'int') {
          $fmt = 'j/n/Y H:i';
        }
        else {
          $fmt = 'n/j/Y H:i';
        }
        $form['transit_dates'] = array(
          '#type' => 'date_popup',
          '#default_value' => '',
          '#date_year_range' => '-0:+1',
          '#date_format' => $fmt,
          '#mindate' => "+0",
          '#suffix' => '</div>',
          '#weight' => $wt,
        );
        $wt = $wt + 2;
      }
    }
    if ($getdirections_defaults['travelextras_show']) {
      $form['travelextras'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Travel options'),
        '#options' => array(
          'avoidhighways' => t('Avoid Highways'),
          'avoidtolls' => t('Avoid Tolls'),
          'altroute' => t('Alternative routes'),
        ),
        '#weight' => $wt,
      );
      $wt = $wt + 2;
    }
  }
  if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete'] && $getdirections_defaults['waypoints'] > 0 && $getdirections_defaults['advanced_autocomplete_via'] && !$getdirections_defaults['advanced_alternate']) {
    for ($ct = 1; $ct <= $getdirections_defaults['waypoints']; $ct++) {
      $form['via_autocomplete_' . $ct] = array(
        '#type' => 'textfield',
        '#title' => t('Via !c', array(
          '!c' => $ct,
        )),
        '#size' => $getdirections_defaults['advanced_autocomplete_via_width'],
        '#weight' => $wt,
      );
      $wt = $wt + 2;
    }
  }
  $getdirections_misc = getdirections_misc_defaults();
  if ($getdirections_misc['trafficinfo']) {
    $form['trafficinfo'] = array(
      '#type' => 'button',
      '#value' => t('Toggle traffic info'),
      '#weight' => $wt,
      '#attributes' => array(
        'onClick' => 'Drupal.getdirections.toggleTraffic(); return false;',
        'title' => t('Limited Availability'),
      ),
    );
    $wt = $wt + 2;
  }
  if (variable_get('getdirections_use_v3', 0)) {
    if ($getdirections_misc['bicycleinfo']) {
      $form['bicycleinfo'] = array(
        '#type' => 'button',
        '#value' => t('Toggle bicycling info'),
        '#weight' => $wt,
        '#attributes' => array(
          'onClick' => 'Drupal.getdirections.toggleBicycle(); return false;',
          'title' => t('Limited Availability'),
        ),
      );
      $wt = $wt + 2;
    }
    if ($getdirections_misc['transitinfo']) {
      $form['transitinfo'] = array(
        '#type' => 'button',
        '#value' => t('Toggle Public transport'),
        '#weight' => $wt,
        '#attributes' => array(
          'onClick' => 'Drupal.getdirections.toggleTransit(); return false;',
          'title' => t('Limited Availability'),
        ),
      );
      $wt = $wt + 2;
    }
    if ($getdirections_misc['panoramio_show']) {
      $form['panoramio'] = array(
        '#type' => 'button',
        '#value' => t('Toggle Panoramio'),
        '#weight' => $wt,
        '#attributes' => array(
          'onClick' => 'Drupal.getdirections.togglePanoramio(); return false;',
        ),
      );
      $wt = $wt + 2;
    }
  }
  if ($getdirections_misc['switchfromto'] && !$fromto && !getdirections_is_advanced()) {
    $form['switchfromto'] = array(
      '#type' => 'button',
      '#value' => t('Switch From/To'),
      '#weight' => $wt,
      '#attributes' => array(
        'onClick' => 'Drupal.getdirections.toggleFromto(); return false;',
      ),
    );
    $wt = $wt + 2;
  }
  if (getdirections_is_advanced()) {
    $form['next'] = array(
      '#type' => 'button',
      '#value' => t('Next'),
      '#weight' => $wt,
      '#attributes' => array(
        'onClick' => 'Drupal.getdirections.nextbtn(); return false;',
      ),
    );
    $wt = $wt + 2;
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Get Directions'),
    '#weight' => $wt,
  );
  return $form;
}