You are here

function location_search_form_alter in Location 7.5

Same name and namespace in other branches
  1. 5.3 contrib/location_search/location_search.module \location_search_form_alter()
  2. 6.3 contrib/location_search/location_search.module \location_search_form_alter()
  3. 7.3 contrib/location_search/location_search.module \location_search_form_alter()
  4. 7.4 contrib/location_search/location_search.module \location_search_form_alter()

File

contrib/location_search/location_search.module, line 206
Location search interface.

Code

function location_search_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_form' && arg(1) == 'location' && user_access('use advanced search')) {

    // @@@ Cache this.
    $result = db_query('SELECT DISTINCT country FROM {location}', array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    $countries = array(
      '' => '',
    );
    foreach ($result as $row) {
      if (!empty($row['country'])) {
        $country = $row['country'];
        location_standardize_country_code($country);
        $countries[$country] = location_country_name($country);
      }
    }
    ksort($countries);
    drupal_add_js(drupal_get_path('module', 'location') . '/location_autocomplete.js');

    // Keyword boxes:
    $form['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced search'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array(
        'class' => array(
          'search-advanced',
        ),
      ),
    );
    $form['advanced']['country'] = array(
      '#type' => 'select',
      '#title' => t('Country'),
      '#options' => $countries,
      // Used by province autocompletion js.
      '#attributes' => array(
        'class' => array(
          'location_auto_country',
        ),
      ),
    );
    $form['advanced']['province'] = array(
      '#type' => 'textfield',
      '#title' => t('State/Province'),
      '#autocomplete_path' => 'location/autocomplete/' . variable_get('location_default_country', 'us'),
      // Used by province autocompletion js.
      '#attributes' => array(
        'class' => array(
          'location_auto_province',
        ),
      ),
    );
    $form['advanced']['city'] = array(
      '#type' => 'textfield',
      '#title' => t('City'),
    );
    $form['advanced']['proximity'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Proximity'),
    );
    $form['advanced']['proximity']['map'] = array();
    if (variable_get('location_search_map_address', 1)) {
      $form['advanced']['proximity']['locpick_address'] = array(
        '#type' => 'textfield',
        '#title' => t('Locate Address'),
      );
    }
    $form['advanced']['proximity']['latitude'] = array(
      '#type' => 'textfield',
      '#title' => t('Latitude'),
    );
    $form['advanced']['proximity']['longitude'] = array(
      '#type' => 'textfield',
      '#title' => t('Longitude'),
    );
    $form['advanced']['proximity']['distance'] = array(
      '#type' => 'fieldset',
      '#title' => t('Distance'),
    );
    $form['advanced']['proximity']['distance']['distance'] = array(
      '#type' => 'textfield',
      '#size' => 5,
      '#maxlength' => 5,
    );
    $form['advanced']['proximity']['distance']['units'] = array(
      '#type' => 'select',
      '#options' => array(
        'mi' => t('mi'),
        'km' => t('km'),
      ),
    );
    if (variable_get('location_search_map', 1)) {
      $map_fields = array(
        'latitude' => 'latitude',
        'longitude' => 'longitude',
      );
      if (variable_get('location_search_map_address', 1)) {
        $map_fields['address'] = 'locpick_address';
      }
      if (module_exists('gmap')) {
        $form['advanced']['proximity']['map']['#value'] = gmap_set_location(variable_get('location_search_map_macro', '[gmap |behavior=+collapsehack]'), $form['advanced']['proximity'], $map_fields);
      }
    }
    $form['advanced']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Advanced search'),
      '#prefix' => '<div class="action">',
      '#suffix' => '</div>',
    );
    $form['#validate'][] = 'location_search_validate';
  }
}