You are here

function getlocations_search_allinfo in Get Locations 7.2

Same name and namespace in other branches
  1. 7 modules/getlocations_search/getlocations_search.module \getlocations_search_allinfo()

Return value

json format $output Returns search result to getlocations_search.js

1 string reference to 'getlocations_search_allinfo'
getlocations_search_menu in modules/getlocations_search/getlocations_search.module
Implements hook_menu().

File

modules/getlocations_search/getlocations_search.module, line 1312
getlocations_search.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_search_allinfo() {
  $lat = $_GET['lat'];
  $lon = $_GET['lon'];
  $getlocations_search_defaults = getlocations_search_defaults();
  $distance = $getlocations_search_defaults['search_distance'];
  if (isset($_GET['distance']) && is_numeric($_GET['distance'])) {
    $distance = $_GET['distance'];

    // sanity check
    if (!$distance > 0) {
      $distance = $getlocations_search_defaults['search_distance'];
    }
  }
  $units = $getlocations_search_defaults['search_units'];
  if (isset($_GET['units'])) {
    $units = $_GET['units'];

    // sanity check
    $unitsarr = array(
      'km',
      'm',
      'mi',
      'yd',
      'nmi',
    );
    if (!in_array($units, $unitsarr)) {
      $units = $getlocations_search_defaults['search_units'];
    }
  }
  $type = $getlocations_search_defaults['search_type'];
  if (isset($_GET['type'])) {
    $type = $_GET['type'];

    // sanity check
    // use entity_get_info to find all the fieldable types available
    $entity_allinfo = entity_get_info();
    $typarr = array(
      'all',
    );
    foreach ($entity_allinfo as $entity_type => $entity_info) {
      if ($entity_info['fieldable']) {
        $typarr[] = $entity_type;
      }
    }
    if (!in_array($type, $typarr)) {
      $type = $getlocations_search_defaults['search_type'];
    }
  }
  $dosort = FALSE;
  if (isset($_GET['limits']) && is_numeric($_GET['limits'])) {
    $limits = $_GET['limits'];

    // sanity check
    if ($limits < 0) {
      $limits = 0;
    }
    if ($limits > 0) {
      $dosort = TRUE;
    }
  }

  // sanity check
  if ($latlon = getlocations_latlon_check($lat . ',' . $lon)) {
    $ll = explode(',', $latlon);
    $lat = $ll[0];
    $lon = $ll[1];
    $output = getlocations_search_info_sql($lat, $lon, $distance, $units, $type, $dosort, $limits);
    drupal_json_output($output);
  }
}