Function Reference: geodir_location_ajax_handler
Summary
Handles ajax request.
Package
GeoDirectory_Location_Manager
Change Log
Since: 1.0.0
Source File
geodir_location_ajax_handler() is located in geodir_location_manager/geodir_location_hooks_actions.php [Line: 1668]
Source Code
function geodir_location_ajax_handler()
{
if(isset($_REQUEST['gd_loc_ajax_action']) && $_REQUEST['gd_loc_ajax_action'] != '')
{
switch($_REQUEST['gd_loc_ajax_action'])
{
case 'get_location' :
if(isset($_REQUEST['gd_which_location']) && $_REQUEST['gd_which_location'] != '')
{
$city_val = '';
$region_val = '';
$country_val = '';
if(isset($_REQUEST['gd_city_val']) && $_REQUEST['gd_city_val'] != '')
$city_val = $_REQUEST['gd_city_val'];
if(isset($_REQUEST['gd_region_val']) && $_REQUEST['gd_region_val'] != '')
$region_val = $_REQUEST['gd_region_val'];
if(isset($_REQUEST['gd_country_val']) && $_REQUEST['gd_country_val'] != '')
$country_val = $_REQUEST['gd_country_val'];
if(isset($_REQUEST['spage']) && $_REQUEST['spage'] != ''){
$spage = $_REQUEST['spage'];}
else{$spage = '';}
if(isset($_REQUEST['lscroll']) && $_REQUEST['lscroll'] != ''){
$no_of_records = '5';
}else{$no_of_records = '';}
$location_args =array( 'what' => $_REQUEST['gd_which_location'] ,
'city_val' => $city_val,
'region_val' => $region_val ,
'country_val' => $country_val,
'compare_operator' =>'like' ,
'country_column_name' => 'country' ,
'region_column_name' => 'region' ,
'city_column_name' => 'city' ,
'location_link_part' => true ,
'order_by' => ' asc ',
'no_of_records' => $no_of_records,
'format' => array('type' => 'array'),
'spage' => $spage
);
$location_array = geodir_get_location_array($location_args);
if(isset($_REQUEST['gd_formated_for']) && $_REQUEST['gd_formated_for'] == 'location_switcher')
{
$base_location_link = geodir_get_location_link('base');
if(!empty($location_array))
{
if($_REQUEST['gd_which_location']=='city')
$arrow_html = '' ;
else
$arrow_html = ' ' ;
foreach($location_array as $location_item)
{
$location_name = $_REQUEST['gd_which_location'] == 'country' ? __( $location_item->$_REQUEST['gd_which_location'], GEODIRECTORY_TEXTDOMAIN ) : $location_item->$_REQUEST['gd_which_location'];
echo "
" . $location_name . "$arrow_html" ;
}
}
else
echo _e("No Results" , GEODIRLOCATION_TEXTDOMAIN);
}
else
print_r($location_array);
exit();
}
break;
case 'fill_location': {
$gd_which_location = isset( $_REQUEST['gd_which_location'] ) ? trim( $_REQUEST['gd_which_location'] ) : '';
$term = isset( $_REQUEST['term'] ) ? trim( $_REQUEST['term'] ) : '';
$base_location = geodir_get_location_link( 'base' );
$current_location_array;
$selected = '';
$country_val = '';
$region_val = '';
$city_val = '';
$country_val = geodir_get_current_location( array( 'what' => 'country', 'echo' => false ) );
$region_val = geodir_get_current_location( array( 'what' => 'region', 'echo' => false ) );
$city_val = geodir_get_current_location( array( 'what' => 'city', 'echo' => false ) );
$item_set_selected = false;
if(isset($_REQUEST['spage']) && $_REQUEST['spage'] != ''){
$spage = $_REQUEST['spage'];}
else{$spage = '';}
if(isset($_REQUEST['lscroll']) && $_REQUEST['lscroll'] != ''){
$no_of_records = '5';
}else{$no_of_records = '';}
$location_switcher_list_mode = get_option( 'geodir_location_switcher_list_mode' );
if( empty( $location_switcher_list_mode ) ) {
$location_switcher_list_mode = 'drill';
}
if( $location_switcher_list_mode == 'drill' ) {
$args = array(
'what' => $gd_which_location,
'country_val' => ( strtolower( $gd_which_location ) == 'region' || strtolower( $gd_which_location ) =='city' ) ? $country_val : '',
'region_val' => ( strtolower( $gd_which_location ) == 'city' ) ? $region_val : '',
'echo' => false,
'no_of_records' => $no_of_records,
'format' => array('type' => 'array'),
'spage' => $spage
);
} else {
$args = array(
'what' => $gd_which_location ,
'echo' => false,
'no_of_records' => $no_of_records,
'format' => array('type' => 'array'),
'spage' => $spage
);
}
if( $term != '' ) {
if( $gd_which_location == 'city' ) {
$args['city_val'] = $term;
}
if( $gd_which_location == 'region' ) {
$args['region_val'] = $term;
}
if( $gd_which_location == 'country' ) {
$args['country_val'] = $term;
}
} else {
if( $gd_which_location == 'country' && $country_val != '' ) {
$args_current_location = array(
'what' => $gd_which_location,
'country_val' => $country_val,
'compare_operator' => '=',
'no_of_records' => '1',
'echo' => false,
'format' => array( 'type' => 'array' )
);
$current_location_array = geodir_get_location_array( $args_current_location, true );
}
if( $gd_which_location == 'region' && $region_val != '' ) {
$args_current_location = array(
'what' => $gd_which_location,
'country_val' => $country_val,
'region_val' => $region_val,
'compare_operator' => '=',
'no_of_records' => '1',
'echo' => false,
'format' => array( 'type' => 'array' )
);
$current_location_array = geodir_get_location_array( $args_current_location, true );
}
if( $gd_which_location == 'city' && $city_val != '' ) {
$args_current_location = array(
'what' => $gd_which_location,
'country_val' => $country_val,
'region_val' =>$region_val,
'city_val' => $city_val,
'compare_operator' => '=',
'no_of_records' => '1',
'echo' => false,
'format'=> array( 'type' => 'array' )
);
$current_location_array = geodir_get_location_array( $args_current_location, true );
}
// if not searching then set to get exact matches
$args['compare_operator']='in';
}
$location_array = geodir_get_location_array( $args, true );
// get country val in case of country search to get selected option
if( get_option( 'geodir_everywhere_in_' . $gd_which_location . '_dropdown' ) && !isset($_REQUEST['lscroll']) ) {
echo '
';
}
$selected = '' ;
$loc_echo = '';
if( !empty( $location_array ) ) {
foreach( $location_array as $locations ) {
$selected = '' ;
$with_parent = isset( $locations->label ) ? true : false;
switch( $gd_which_location ) {
case 'country':
if( strtolower( $country_val ) == strtolower( $locations->country ) ) {
$selected = 'selected="selected"';
}
$locations->country = __( $locations->country, GEODIRECTORY_TEXTDOMAIN );
break;
case 'region':
$country_iso2 = geodir_location_get_iso2( $country_val );
$country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val;
$with_parent = $with_parent && strtolower( $region_val . ', ' . $country_iso2 ) == strtolower( $locations->label ) ? true : false;
if( strtolower( $region_val ) == strtolower( $locations->region ) || $with_parent ) {
$selected = 'selected="selected"';
}
break;
case 'city':
$with_parent = $with_parent && strtolower( $city_val . ', ' . $region_val ) == strtolower( $locations->label ) ? true : false;
if( strtolower( $city_val ) == strtolower( $locations->city ) || $with_parent ) {
$selected = 'selected="selected"';
}
break;
}
echo '
';
if( !$item_set_selected && $selected != '' ) {
$item_set_selected = true;
}
}
}
if( !empty( $current_location_array ) && !$item_set_selected && !isset($_REQUEST['lscroll'])) {
foreach( $current_location_array as $current_location ) {
$selected = '' ;
$with_parent = isset( $current_location->label ) ? true : false;
switch( $gd_which_location ) {
case 'country':
if( strtolower( $country_val ) == strtolower( $current_location->country ) ) {
$selected = 'selected="selected"';
}
$current_location->country = __( $current_location->country, GEODIRECTORY_TEXTDOMAIN );
break;
case 'region':
$country_iso2 = geodir_location_get_iso2( $country_val );
$country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val;
$with_parent = $with_parent && strtolower( $region_val . ', ' . $country_iso2 ) == strtolower( $current_location->label ) ? true : false;
if( strtolower( $region_val ) == strtolower( $current_location->region ) || $with_parent ) {
$selected = 'selected="selected"';
}
break;
case 'city':
$with_parent = $with_parent && strtolower( $city_val . ', ' . $region_val ) == strtolower( $current_location->label ) ? true : false;
if( strtolower( $city_val ) == strtolower( $current_location->city ) || $with_parent ) {
$selected = 'selected="selected"';
}
break;
}
echo '
';
}
}
exit;
}
break;
case 'fill_location_on_add_listing' :
$selected = '' ;
$country_val=(isset($_REQUEST['country_val']) ) ? $_REQUEST['country_val'] : '';
$region_val=(isset($_REQUEST['region_val']) ) ? $_REQUEST['region_val'] : '';
$city_val =(isset($_REQUEST['city_val']) ) ? $_REQUEST['city_val'] : '';
$compare_operator =(isset($_REQUEST['compare_operator']) ) ? $_REQUEST['compare_operator'] : '=';
if(isset($_REQUEST['term']) && $_REQUEST['term']!='')
{
if($_REQUEST['gd_which_location'] =='region')
{
$region_val = $_REQUEST['term'];
$city_val = '';
}
else if($_REQUEST['gd_which_location'] =='city')
{
$city_val = $_REQUEST['term'];
}
}
if($_REQUEST['gd_which_location'] !='neighbourhood')
{
$args=array(
'what'=>$_REQUEST['gd_which_location'] ,
'country_val' => (strtolower($_REQUEST['gd_which_location'])=='region' || strtolower($_REQUEST['gd_which_location'])=='city') ? $country_val : '',
'region_val' =>$region_val ,
'city_val' =>$city_val ,
'echo' => false,
'compare_operator' => $compare_operator,
'format'=> array('type'=>'array')
);
$location_array= geodir_get_location_array($args);
}
else
{
geodir_get_neighbourhoods_dl($city_val) ;
exit();
}
// get country val in case of country search to get selected option
if($_REQUEST['gd_which_location']=='region')
echo '
';
else
echo '
';
if(!empty($location_array))
{
foreach( $location_array as $locations)
{
$selected = '' ;
switch($_REQUEST['gd_which_location'] )
{
case 'country':
if(strtolower($country_val)== strtolower($locations->country))
$selected=" selected='selected' ";
break;
case 'region':
if(strtolower($region_val)== strtolower($locations->region))
$selected=" selected='selected' ";
break;
case 'city':
if(strtolower($city_val)== strtolower($locations->city))
$selected=" selected='selected' ";
break;
}
echo '
' ;
}
}
else
{
if(isset($_REQUEST['term']) && $_REQUEST['term']!='')
echo '
' ;
}
exit();
break;
}
}
}