<?php
/* 
* Theme: PREMIUMPRESS CORE FRAMEWORK FILE
* Url: www.premiumpress.com
* Author: Mark Fail
*
* THIS FILE WILL BE UPDATED WITH EVERY UPDATE
* IF YOU WANT TO MODIFY THIS FILE, CREATE A CHILD THEME
*
* http://codex.wordpress.org/Child_Themes
*/
if (!defined('THEME_VERSION')) {	header('HTTP/1.0 403 Forbidden'); exit; }

global $CORE, $CORE_UI, $LAYOUT, $wpdb, $wp_query;

$GLOBALS['flag-filter-btn-set'] = 1;
 
 
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
 
?>
        
<input type="hidden" class="customfilter save-map-log" data-type="text" data-key="map-log" id="location-mylog" value="" />
<input type="hidden" class="customfilter save-map-lat"  data-type="text" data-key="map-lat" id="location-mylat" value="" />
<input type="hidden" class="customfilter save-map-ip-city" data-type="text" data-key="map-city" id="location-city" value=""   />
<input type="hidden" id="location-address" value="" />

<?php if(_ppt(array("maps","provider")) == "mapbox"){ ?>
<input type="hidden" class="customfilter zipcodebox" data-type="text" data-key="zipcode" data-formatted-text="<?php echo __("Location","premiumpress"); ?>" />
<input type="hidden" name="zipcode" id="location-address"  />
<?php } ?>

<input type="hidden" id="radiusf" class="hidden" name="radius"  value="0">


<?php
 
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

 if(isset($_POST['sidebar'])){ 

$title1 = __("Location","premiumpress"); 
$title2 = __("Distance","premiumpress"); 
?>

<div class="filterbox-price ppt-js-map-trigger"></div><!-- required -->

<div class="container px-0">
<div class="row">
  <div class="col-md-12 mb-3">
   
	<label class="text-600"> <?php echo $title1;  ?> </label>  

	<?php if(_ppt(array("maps","provider")) == "google"){ ?>
		<div class="position-relative locationmapgeromapbox w-100" id="locationmapgeromapbox">		 
			<input type="text" class="form-control customfilter zipcodebox"  name="zipcode" data-type="text" data-key="zipcode" data-formatted-text="<?php echo __("Location","premiumpress"); ?>" id="location-setaddress" />
		</div>
	<?php }else{ ?>
	<div class="position-relative locationmapgeromapbox w-100" id="locationmapgeromapbox"> 
		<input type="hidden"  name="zipcode" />
		<i class="fa fa-spinner fa-spin opacity-5"></i>	
	</div>
	<?php } ?> 


  </div>
  <div class="col-md-12">
    <label class="text-600">
    <?php echo $title2;  ?>
    </label>
    <div class="position-relative">
      <span class="position-absolute iconbit" style="top: 10px; right: 10px;">
     
      </span>
    </div>
  </div>
</div>
</div>

 

<input type="hidden" class="distance-slider" data-max="500" value=""  /> 
 
<input type="hidden" id="search_radius" class="hidden customfilter" data-type="text"  value=""  name="radius" data-formatted-text="<?php echo __("Radius","premiumpress"); ?>"  data-key="radius">

<script>

jQuery(document).ready(function(){
	setTimeout(function(){  
		distanceslider();
	}, 1000);

	jQuery(document).on('keypress',function(e) {
		if(e.which == 13) {
			checkzipvalupdate();
		}
	});
}); 

jQuery("#location-mylog").on('change', function(){  
 
	jQuery('.zipcodebox, .mapboxgl-ctrl-geocoder--input').removeClass('required-active');

	checkzipvalupdate(); 
});

 

function checkzipvalupdate(){

	var log = jQuery("#location-mylog").val(); 

	<?php if(_ppt(array("maps","provider")) == "mapbox"){ ?>
	if(log.length > 2){
		jQuery('.zipcodebox').val(jQuery("#location-mylog").val()+','+jQuery("#location-mylat").val());
	}
	<?php } ?>

	var g = jQuery('.zipcodebox').val();

	if(g.length > 2){

		// IF VALUE IS 0 SET A DEFAULT
		var currentVal = jQuery('#search_radius').val();
		if(currentVal == ""){

			var d = 100;
			jQuery('#search_radius').val(d);
			jQuery('.distance_unit').html(d);

			var instance = jQuery(".distance-slider").data("ionRangeSlider");

			instance.update({
			from: 100 
			});

		}

		jQuery("#filter-sortby-main").val("distance-u");

		_filter_update();
		
	}

}
function checkzipval(){ 

	if(jQuery('.zipcodebox').val() !=""){
		jQuery("#filter-sortby-main").val("distance-u");
		_filter_update();
	}else{
		jQuery('.zipcodebox, .mapboxgl-ctrl-geocoder--input').addClass('required-active');
	}
	

}
function distanceslider(){
		
		var a = jQuery(".distance-slider");
					a.each(function (a) {
									 
						jQuery(this).ionRangeSlider({
							type: "single",
							keyboard: true,
							
							min: 0,
							max: jQuery(this).attr('data-max'),
							from:0,
							to: jQuery(this).attr('data-max'),
							step:1,
							grid: false, 
							
							onChange: function (data) {							
								
								jQuery('.txt_price1').html(data.from);
								jQuery('#search_radius').val(data.from);
								jQuery('.distance_unit').html(data.from);
											 
							},onFinish: function (data) { 

								jQuery("#location-mylog").trigger("change");
								
								checkzipval();
								
							}	 
							
						});	
						
		});
	}
</script>






<?php 
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////


}else{ ?>




<div class="container mb-4 mt-2">


<div class="filter-keyword">
<input type="text" class="form-control customfilter klcc" data-type="text" data-key="zipcode" placeholder="<?php echo __("Enter town or city...","premiumpress"); ?>" />
</div>
 
<button data-ppt-btn class="btn-primary btn-block mt-1 mb-4 overflow-hidden" type="button" onclick="updateradiusfilter(500);"><?php echo __("Update Results","premiumpress"); ?></button>
 
<?php /*
<div class="p-2 text-center bg-light rounded-lg mb-4">
<div class="ipdataout"><i class="fa fa-sync fa-spin"></i></div>
</div>
*/ ?>

 
<div class="tax_wrapper search_radius">
<?php	 
 

$ratings = array(

 	0 => array(
		"name" => __("Any Distance","premiumpress"), 
	),
	10 => array(
		"name" => __("Within 10 %s","premiumpress"), 
	),
	50 => array(
		"name" => __("Within 50 %s","premiumpress"), 
	),
	100 => array(
		"name" => __("Within 100 %s","premiumpress"), 
	),
	500 => array(
		"name" => __("Within 500 %s","premiumpress"), 
	),
 
); 

foreach($ratings as $s => $r){
?>
<div onclick="updateradiusfilter(<?php echo $s; ?>);" class="rds-<?php echo $s; ?> cursor <?php if($s == 0){ ?>on<?php } ?>" data-radius-text-<?php echo $s; ?>>
<?php

if( _ppt(array('maps','mapmetric')) == "1"){

echo str_replace("%s", __("KM","premiumpress"), $r['name'] );

}else{

echo str_replace("%s",__("miles","premiumpress"), $r['name'] );

}

 ?>
</div>
<?php } ?>
</div> 
      
<script>
function updateradiusfilter(g){	

 
	jQuery('.klcc').removeClass('required-active');
	if(jQuery('.klcc').val() == ""){

		jQuery('.klcc').addClass('required-active');

	}else{

		jQuery('.search_radius .on').removeClass('on');
		jQuery(".rds-"+g).toggleClass('on'); 
		
		if(jQuery("#location-mylog").val() == ""){
			
			jQuery('#search_radius').val(g);
			_filter_update();
		
		}else{
		
			jQuery('#search_radius').val(g);
			_filter_update();
		
		} 
	}

}

</script>

<input type="hidden" id="search_radius" class="hidden customfilter" data-type="text"  value=""  name="radius" data-formatted-text="<?php echo __("Radius","premiumpress"); ?>"  data-key="radius">
 
 
</div>
 
<?php 
 

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

}

?> 