geo
<?php
/*
Template Name: Home Page
*/
get_header();
the_post();
$home_page_show_title = couponxxl_get_option( 'home_page_show_title' );
$home_page_show_search = couponxxl_get_option( 'home_page_show_search' );
$extra_body_class = '';
if( $home_page_show_title == 'no' && $home_page_show_search == 'no' ){
$extra_body_class = 'home-extra-padding';
}
?>
<script>
jQuery( document ).ready(function(){
var checklat=jQuery("#cityLat").val();
if(checklat=='')
{
var msg='Please enter your location and find the nearest coupons';
jQuery("#newcpn").html(msg);
}
jQuery("#miles").change(function(){
jQuery("#defaultCpn").hide();
jQuery("#newcpn").empty();
jQuery("#distaceWise").show();
var distance=jQuery("#miles").val();
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
val: distance
},
success: function (response) {
console.log(response);
//console.log(json_obj);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
});
});
</script>
<?php
$baseurl=get_site_url();
?>
<script>
jQuery( document ).ready(function(){
var checklat=jQuery("#cityLat").val();
if(checklat=='')
{
var visited = localStorage.getItem('visited');
if (!visited)
{
var x = document.getElementById("demo");
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
console.log(latlong);
}
else
{
x.innerHTML = "Geolocation is not supported by this browser.";
}
localStorage.setItem('visited', true);
}
}
});
function showPosition(position)
{
var lat=position.coords.latitude;
var longi=position.coords.longitude;
var distance=10;
jQuery("#cityLat").val(lat);
jQuery("#cityLng").val(longi);
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
distance:distance,
lat:lat,
longi:longi
},
success: function (response) {
console.log(response);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
}
</script>
<script>
var y = document.getElementById("demo");
function getLocation()
{
var lat=jQuery("#cityLat").val();
var longi=jQuery("#cityLng").val();
var distance=10;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
distance:distance,
lat:lat,
longi:longi
},
success: function (response) {
console.log(response);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
}
</script>
<script type="text/javascript">
jQuery(window).load(function(){
jQuery('#myModal').modal('show');
});
</script>
<style>
.checked
{
color: orange;
}
img:hover
{
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
#myModal .modal-dialog
{
width:80%;
}
@media only screen and (max-width: 768px) {
/* For mobile phones: */
#myModal .modal-dialog {
width:100%;
}
}
</style>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog" >
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<a href="<?php echo $baseurl; ?>/register/account/vendor/"> <img src="<?php echo $baseurl ;?>/wp-content/uploads/2017/11/restaupons.jpg" ></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<section class="home-search3" style="background:#FFF;padding:20px;" >
<div id="content" >
<div class="container text-center">
<form>
<div>
<style>
.input-container{
width: 550px;
border: 1px solid #F3F3F3;
float: left;
}
.input-container input:focus, .input-container input:active {
outline: none;
}
.input-container input {
width: 80%;
float: left;
border: none;
}
.input-container button {
float: right;
}
#loct
{
cursor:pointer;
text-align:center;
color:#F47A2D;
}
@media only screen and (max-width: 768px) {
/* For mobile phones: */
.locatemain {
width:100%;
}
}
</style>
<form name="detectloc" method="post">
<div class="input-container locatemain">
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBHx9BzGiJQ6m-Gy2V9w-6zZAedcU98Rh8" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
document.getElementById('city2').value = place.name;
document.getElementById('cityLat').value = place.geometry.location.lat();
document.getElementById('cityLng').value = place.geometry.location.lng();
//alert("This function is working!");
//alert(place.name);
// alert(place.address_components[0].long_name);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<input id="searchTextField" type="text" size="50" autocomplete="on" runat="server" class="form-control" /> <small id="resLocvalidatemsg" style="display:none;color:#F47A2D">Please enter your location</small>
<input type="hidden" id="city2" name="city2" />
<input type="hidden" id="cityLat" name="cityLat"/>
<input type="hidden" id="cityLng" name="cityLng" />
<span id="loct" onclick="getLocation()">SEARCH</span>
</div>
</form>
<span style="font-size:20px"><b>Find Your Coupons</b></span>
<span>
<select id="miles" style="background:#F47A2D;color:#FFF;">
<option value="10">Within 10 Miles</option>
<option value="20">Within 20 Miles</option>
<option value="30">Within 30 Miles</option>
</select>
</span>
</div>
</form>
<!------------------Myfile------------------->
<style>
li{ list-style:none}
.filter-search {
float: left;
padding: 10px 0 0;
}
.filter-search h4 {
border-bottom: 1px solid #eee;
color: #777;
padding: 0 5px 8px;
text-shadow: 1px 1px 1px #ddd;
margin-bottom:0;
}
.filter-list {
background: #fff none repeat scroll 0 0;
box-shadow: -1px 2px 4px #ccc;
margin: 0 0 50px;
padding: 10px 15px;
}
.filter-list > label {
border-bottom: 1px solid #f1f1f1;
color: #555;
display: block;
font-size: 16px;
font-weight: 500;
padding: 0 0 5px;
}
.filter-list > ul {
height: 170px;
overflow-y: scroll;
padding: 0 0 0 15px;
}
.filter-list input[type="radio"], input[type="checkbox"]{ display:none}
.filter-list li label {
font-size: 14px;
font-weight: 500;
padding: 4px 22px;
position: relative;
color:#f47a2d
}
.filter-list li label::after {
background: #f7f7f7 none repeat scroll 0 0;
border: 1px solid #ccc;
border-radius: 2px;
content: "";
height: 14px;
left: 0;
position: absolute;
top: 8px;
width: 14px;
}
.filter-list li label::before {
border: 1px solid #555;
border-top: none;
border-right: none;
content: "";
height: 4px;
left: 3px;
opacity: 0;
position: absolute;
top: 11px;
width: 8px;
z-index: 9;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.filter-list input[type=checkbox]:checked + label::before {
opacity: 1;
}
.sort-list {
float: left;
padding: 20px 0 0;
width: 100%;
}
.sort-list li {
float: left;
padding: 0 25px;
}
.sort-list .active > a {
border-bottom: 2px solid #000;
color: #000;
float: left;
font-weight: 600;
}
.sort-list li a {
color: #777 !important;
}
.coupon-box {
float: left;
padding: 20px 0 0;
width: 100%;
}
.list-coupon > a img {
border: 2px solid #ffb1b6;
border-radius: 5px 5px 0 0;
float: left;
width: 100%;
}
.content {
float: left;
}
.expiry{ float:right;}
.expiry label {
color: #f47a2d;
}
.expiry span
{
display: block;
text-align: right;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%)
}
.container1:hover .image {
opacity: 0.3;
}
.container1:hover .middle
{
opacity: 1;
}
.text
{
background-color:#F47A2D;
color: white;
font-size: 16px;
padding: 16px 32px;
}
.divImg {
position: relative;
overflow: hidden;
}
.divImg .caption {
height:100%;
width: 100%;
cursor: pointer;
position: absolute;
top:0;
transform: scaleY(0);
transform-origin: top;
transition: transform 0.35s ease;
}
.caption-text{
z-index: 5;
color: #fff;
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.blur {
background-color: rgba(0,0,0,0.5);
height: 100%;
width: 100%;
position: absolute;
top:0;
}
.square {
height: 100%;
width: 100%;
outline: 2px solid white;
outline-offset: -10px;
}
.square + .caption-text h1 {
font-size: 30px;
}
.effect2 .blur {
background-color: rgba(217,24,40,0.5);
}
.effect2:hover .caption{
transform: scaleY(1);
}
</style>
<div class="couponMain" style="padding:20px;">
<div class="row">
<div class="col-md-12">
<div id="distaceWise">
<div class="row">
<div class="col-md-12">
<div id="newcpn" >
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="home-page-body <?php echo esc_attr( $extra_body_class ) ?>" >
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php if( $home_page_show_title == 'yes' ): ?>
<div class="home-page-title">
<h1><?php echo couponxxl_get_option( 'home_page_title' ) ?></h1>
<h5>
<?php
$stores = wp_count_posts( 'store' );
$stores = $stores->publish;
$locations = wp_count_terms( 'location' );
echo str_replace( array( '%stores%', '%locations%' ), array( $stores, $locations ), couponxxl_get_option( 'home_page_subtitle' ) );
?>
</h5>
</div>
<?php endif; ?>
<?php if( $home_page_show_search == 'yes' ): ?>
<div class="home-page-search-box clearfix <?php echo $home_page_show_title == 'no' ? esc_attr( 'top-margin' ) : ''; ?>">
<?php include( couponxxl_load_path('includes/main-search-values.php') ) ?>
<form method="get" action="<?php echo esc_url( couponxxl_get_permalink_by_tpl( 'page-tpl_search' ) ) ?>" class="main-search">
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control top_bar_search" value="<?php echo esc_attr( $term_name ); ?>" placeholder="<?php echo couponxxl_get_option( 'home_page_search_location_placeholder' ) ?>">
<input type="hidden" name="<?php echo esc_attr( $couponxxl_slugs['location'] ) ?>" value="<?php echo esc_attr( $location ) ?>">
<small><?php echo couponxxl_get_option( 'home_page_search_location_desc' ) ?></small>
<div class="search_options"></div>
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control top_bar_search" value="<?php echo esc_attr( $store_name ); ?>" placeholder="<?php echo couponxxl_get_option( 'home_page_search_store_placeholder' ) ?>">
<input type="hidden" name="<?php echo esc_attr( $couponxxl_slugs['offer_store'] ) ?>" value="<?php echo esc_attr( $offer_store ) ?>">
<small><?php echo couponxxl_get_option( 'home_page_search_store_desc' ) ?></small>
<div class="search_options"></div>
</div>
</div>
</form>
</div>
<?php endif; ?>
</div>
</div>
<div class="page-content clearfix">
<?php the_content(); ?>
</div>
</div>
</section>
<?php get_footer(); ?>
function
/*-----------------------------my Distance wise search-------------------------------------------*/
if ( ! function_exists( 'couponxxl_distancewise' ) ) {
function couponxxl_distancewise() {
global $wpdb;
//$dis=mb_strtolower( esc_sql( $_POST['val'] ) );
$dis = mb_strtolower( esc_sql( $_POST['distance'] ) );
$latitude = mb_strtolower( esc_sql( $_POST['lat'] ) );
$longtitude = mb_strtolower( esc_sql( $_POST['longi'] ) );
$deal_lat= $latitude;
$deal_long=$longtitude;
$couponIdArr=array();
$couponNameArr=array();
$restNamearr=array();
$expArr=array();
$logoArr=array();
$getNearescoupsql ="SELECT marker_id,post_id,term_slug, (
(
ACOS( SIN( '$deal_lat' * PI( ) /180 ) * SIN( latitude * PI( ) /180 ) + COS( '$deal_lat' * PI( ) /180 ) * COS( latitude * PI( ) /180 ) * COS( (
'$deal_long' - longitude
) * PI( ) /180 ) ) *180 / PI( )
) *60 * 1.1515
) AS distance
FROM wp_store_markers
GROUP BY marker_id
HAVING (
distance < $dis
)";
$nearesCpnresult = $wpdb->get_results($getNearescoupsql);
$restaurantIdArr = array();
foreach( $nearesCpnresult as $couponres )
{
$dis=$couponres->distance;
$restaurantId=$couponres->post_id;
$restaurantIdArr[]=$restaurantId;
}
$restIdstr=implode(",",$restaurantIdArr);
$getcouponId = "SELECT post_id,meta_value FROM wp_postmeta WHERE meta_value IN($restIdstr)";
$couponIdresult = $wpdb->get_results($getcouponId);
foreach( $couponIdresult as $couponRes )
{
$couponIdArr[] = $couponRes->post_id;
$couponId = $couponRes->post_id;
$restRef = $couponRes->meta_value;
$getExpired = "SELECT offer_expire FROM wp_offers WHERE post_id='$couponId' AND offer_type='coupon'";
$expiredRes = $wpdb->get_results($getExpired);
foreach( $expiredRes as $expiredResult )
{
$expiredDate=$expiredResult->offer_expire;
$expired=date('m-d-Y', $expiredDate);
$today = date("m-d-Y");
$today_time = strtotime($today);
$expire_time = strtotime($expired);
$getcpnName = "SELECT p.post_title,e.offer_expire FROM wp_posts p
INNER JOIN wp_offers e
ON e.post_id=p.ID
WHERE p.ID ='$couponId' AND p.post_status='publish' AND p.post_type='offer'";
$couponRes = $wpdb->get_results($getcpnName);
foreach( $couponRes as $couponResult )
{
$couponName=$couponResult->post_title;
$expdt=$couponResult->offer_expire;
$couponNameArr[]=$couponName;
$expiredDate1=date('m-d-Y', $expdt);
$today1 = date("m-d-Y");
$today_time1 = strtotime($today1);
$expire_time1 = strtotime($expiredDate1);
$datediff1 = $today_time1 - $expire_time1;
$expiredOn1=floor($datediff1 / (60 * 60 * 24));
$expArr[]=$expiredOn1;
$getRest = "SELECT post_title FROM wp_posts WHERE ID ='$restRef' AND post_type='store'";
$restRes = $wpdb->get_results($getRest);
foreach( $restRes as $restrnt )
{
$restName=$restrnt->post_title;
$restNamearr[]=$restName;
$gettumbpid = "SELECT meta_value FROM wp_postmeta WHERE post_id ='$restRef' AND meta_key='_thumbnail_id'";
$tumbimg = $wpdb->get_results($gettumbpid);
$rcnt=$wpdb->num_rows;
if($rcnt > 0)
{
foreach($tumbimg as $tumbimgres)
{
$tumbId=$tumbimgres->meta_value;
$getrestlogo = "SELECT meta_value FROM wp_postmeta WHERE post_id ='$tumbId' AND meta_key='_wp_attached_file'";
$restlogoRes = $wpdb->get_results($getrestlogo);
foreach($restlogoRes as $logoRes)
{
$logo=$logoRes->meta_value;
$logoArr[]=get_site_url().'/wp-content/uploads/'.$logo;
}
}
}
else
{
$logoArr[]=get_site_url().'/'.'/wp-content/uploads/2017/11/pasta.png';
}
}
}
}
}
$counRes['counpon']=$couponNameArr;
$expResult['expRes']=$expArr;
$restResponce['restResonce']=$restNamearr;
$logores['logores']=$logoArr;
$couponIdRes['couponidres']=$couponIdArr;
$responce=$counRes+$expResult+$restResponce+$couponIdRes;
$cpnCnt=count($responce['counpon']);
$html=' <div class="coupon-box" style=" float: left; padding: 20px 0 0; width: 100%;">';
for($i=0;$i<$cpnCnt;$i++)
{
$restaurantName = $responce['restResonce'][$i];
$expr = $responce['expRes'][$i];
$couponId = $responce['couponidres'][$i];
$getRating="SELECT meta_value FROM wp_postmeta WHERE meta_key='ratings_average' AND post_id='$couponId'";
$ratingqry=$wpdb->get_results($getRating);
$rcnt=$wpdb->num_rows;
if($rcnt >0)
{
foreach($ratingqry as $ratingRes)
{
$rateAvg=$ratingRes->meta_value;
}
}
else
{
$rateAvg=0;
}
if($rateAvg >= 1)
{
$rate1='rating_on.gif';
}
else if($rateAvg == 0.5)
{
$rate1='rating_half.gif';
}
else
{
$rate1='rating_off.gif';
}
if($rateAvg >= 2)
{
$rate2='rating_on.gif';
}
else if($rateAvg == 1.5)
{
$rate2='rating_half.gif';
}
else
{
$rate2='rating_off.gif';
}
if($rateAvg >= 3)
{
$rate3='rating_on.gif';
}
else if($rateAvg == 2.5)
{
$rate3='rating_half.gif';
}
else
{
$rate3='rating_off.gif';
}
if($rateAvg >= 4)
{
$rate4='rating_on.gif';
}
else if($rateAvg == 3.5)
{
$rate4='rating_half.gif';
}
else
{
$rate4='rating_off.gif';
}
if($rateAvg >= 5)
{
$rate5='rating_on.gif';
}
else if($rateAvg == 4.5)
{
$rate5='rating_half.gif';
}
else
{
$rate5='rating_off.gif';
}
if($expr==3425)
{
$exprres= "Unlimited";
}
else
{
//$exprres= $expr .'Days';
$exprres=$expiredDate1;
}
$baseurl=get_site_url();
$string=$responce['counpon'][$i];
//Lower case everything
$string = strtolower($string);
//Make alphanumeric (removes all other characters)
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
//Clean up multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
//Convert whitespaces and underscore to dash
$string = preg_replace("/[\s_]/", "-", $string);
$expstr="Expires on";
$html.='<div class="col-md-4">';
$html.='<div class="list-coupon">';
$baseurl=get_site_url();
$html.='<a href='.$baseurl.'/offer/'.$string.'>';
$html.='<div class="divImg effect2 " style="float:left;">';
// $html.='<img src="'.$baseurl.'/wp-content/uploads/2017/11/pasta.png" style="height:250px; width:350px; background-position:top left;">';
$html.='<img src="'.$logoArr[$i].'" style="height:250px; width:350px; background-position:top left;">';
$html.='<div class="caption">';
$html.='<div class="blur"></div>
<div class="square"></div>';
$html.='<div class="caption-text">';
$html.='<div >'.$responce['counpon'][$i].'</div>';
$html.=' </div></div></a></div>';
$html.=' <div class="content"><label style="color:#f47a2d">' .$responce['restResonce'][$i] . '</label><p><img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate1.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate2.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate3.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate4.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate5.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
'. '</p></div>';
$html.='<div class="expiry"><label>' .$expstr. '</label><span>' .$exprres . '</span>';
$html.='</div>';
$html.='</div>';
$html.='</div>';
}
echo $html;
$html.='</div>';
die;
// echo json_encode($responce);
}
add_action( 'wp_ajax_distancewise', 'couponxxl_distancewise' );
add_action( 'wp_ajax_nopriv_distancewise', 'couponxxl_distancewise' );
}
/*-----------------------End myquery----------------------------------------------*/
/*
Template Name: Home Page
*/
get_header();
the_post();
$home_page_show_title = couponxxl_get_option( 'home_page_show_title' );
$home_page_show_search = couponxxl_get_option( 'home_page_show_search' );
$extra_body_class = '';
if( $home_page_show_title == 'no' && $home_page_show_search == 'no' ){
$extra_body_class = 'home-extra-padding';
}
?>
<script>
jQuery( document ).ready(function(){
var checklat=jQuery("#cityLat").val();
if(checklat=='')
{
var msg='Please enter your location and find the nearest coupons';
jQuery("#newcpn").html(msg);
}
jQuery("#miles").change(function(){
jQuery("#defaultCpn").hide();
jQuery("#newcpn").empty();
jQuery("#distaceWise").show();
var distance=jQuery("#miles").val();
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
val: distance
},
success: function (response) {
console.log(response);
//console.log(json_obj);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
});
});
</script>
<?php
$baseurl=get_site_url();
?>
<script>
jQuery( document ).ready(function(){
var checklat=jQuery("#cityLat").val();
if(checklat=='')
{
var visited = localStorage.getItem('visited');
if (!visited)
{
var x = document.getElementById("demo");
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
console.log(latlong);
}
else
{
x.innerHTML = "Geolocation is not supported by this browser.";
}
localStorage.setItem('visited', true);
}
}
});
function showPosition(position)
{
var lat=position.coords.latitude;
var longi=position.coords.longitude;
var distance=10;
jQuery("#cityLat").val(lat);
jQuery("#cityLng").val(longi);
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
distance:distance,
lat:lat,
longi:longi
},
success: function (response) {
console.log(response);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
}
</script>
<script>
var y = document.getElementById("demo");
function getLocation()
{
var lat=jQuery("#cityLat").val();
var longi=jQuery("#cityLng").val();
var distance=10;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'distancewise',
distance:distance,
lat:lat,
longi:longi
},
success: function (response) {
console.log(response);
jQuery("#newcpn").html(response);
},
complete: function ()
{
}
});
}
</script>
<script type="text/javascript">
jQuery(window).load(function(){
jQuery('#myModal').modal('show');
});
</script>
<style>
.checked
{
color: orange;
}
img:hover
{
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
#myModal .modal-dialog
{
width:80%;
}
@media only screen and (max-width: 768px) {
/* For mobile phones: */
#myModal .modal-dialog {
width:100%;
}
}
</style>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog" >
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<a href="<?php echo $baseurl; ?>/register/account/vendor/"> <img src="<?php echo $baseurl ;?>/wp-content/uploads/2017/11/restaupons.jpg" ></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<section class="home-search3" style="background:#FFF;padding:20px;" >
<div id="content" >
<div class="container text-center">
<form>
<div>
<style>
.input-container{
width: 550px;
border: 1px solid #F3F3F3;
float: left;
}
.input-container input:focus, .input-container input:active {
outline: none;
}
.input-container input {
width: 80%;
float: left;
border: none;
}
.input-container button {
float: right;
}
#loct
{
cursor:pointer;
text-align:center;
color:#F47A2D;
}
@media only screen and (max-width: 768px) {
/* For mobile phones: */
.locatemain {
width:100%;
}
}
</style>
<form name="detectloc" method="post">
<div class="input-container locatemain">
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBHx9BzGiJQ6m-Gy2V9w-6zZAedcU98Rh8" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
document.getElementById('city2').value = place.name;
document.getElementById('cityLat').value = place.geometry.location.lat();
document.getElementById('cityLng').value = place.geometry.location.lng();
//alert("This function is working!");
//alert(place.name);
// alert(place.address_components[0].long_name);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<input id="searchTextField" type="text" size="50" autocomplete="on" runat="server" class="form-control" /> <small id="resLocvalidatemsg" style="display:none;color:#F47A2D">Please enter your location</small>
<input type="hidden" id="city2" name="city2" />
<input type="hidden" id="cityLat" name="cityLat"/>
<input type="hidden" id="cityLng" name="cityLng" />
<span id="loct" onclick="getLocation()">SEARCH</span>
</div>
</form>
<span style="font-size:20px"><b>Find Your Coupons</b></span>
<span>
<select id="miles" style="background:#F47A2D;color:#FFF;">
<option value="10">Within 10 Miles</option>
<option value="20">Within 20 Miles</option>
<option value="30">Within 30 Miles</option>
</select>
</span>
</div>
</form>
<!------------------Myfile------------------->
<style>
li{ list-style:none}
.filter-search {
float: left;
padding: 10px 0 0;
}
.filter-search h4 {
border-bottom: 1px solid #eee;
color: #777;
padding: 0 5px 8px;
text-shadow: 1px 1px 1px #ddd;
margin-bottom:0;
}
.filter-list {
background: #fff none repeat scroll 0 0;
box-shadow: -1px 2px 4px #ccc;
margin: 0 0 50px;
padding: 10px 15px;
}
.filter-list > label {
border-bottom: 1px solid #f1f1f1;
color: #555;
display: block;
font-size: 16px;
font-weight: 500;
padding: 0 0 5px;
}
.filter-list > ul {
height: 170px;
overflow-y: scroll;
padding: 0 0 0 15px;
}
.filter-list input[type="radio"], input[type="checkbox"]{ display:none}
.filter-list li label {
font-size: 14px;
font-weight: 500;
padding: 4px 22px;
position: relative;
color:#f47a2d
}
.filter-list li label::after {
background: #f7f7f7 none repeat scroll 0 0;
border: 1px solid #ccc;
border-radius: 2px;
content: "";
height: 14px;
left: 0;
position: absolute;
top: 8px;
width: 14px;
}
.filter-list li label::before {
border: 1px solid #555;
border-top: none;
border-right: none;
content: "";
height: 4px;
left: 3px;
opacity: 0;
position: absolute;
top: 11px;
width: 8px;
z-index: 9;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.filter-list input[type=checkbox]:checked + label::before {
opacity: 1;
}
.sort-list {
float: left;
padding: 20px 0 0;
width: 100%;
}
.sort-list li {
float: left;
padding: 0 25px;
}
.sort-list .active > a {
border-bottom: 2px solid #000;
color: #000;
float: left;
font-weight: 600;
}
.sort-list li a {
color: #777 !important;
}
.coupon-box {
float: left;
padding: 20px 0 0;
width: 100%;
}
.list-coupon > a img {
border: 2px solid #ffb1b6;
border-radius: 5px 5px 0 0;
float: left;
width: 100%;
}
.content {
float: left;
}
.expiry{ float:right;}
.expiry label {
color: #f47a2d;
}
.expiry span
{
display: block;
text-align: right;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%)
}
.container1:hover .image {
opacity: 0.3;
}
.container1:hover .middle
{
opacity: 1;
}
.text
{
background-color:#F47A2D;
color: white;
font-size: 16px;
padding: 16px 32px;
}
.divImg {
position: relative;
overflow: hidden;
}
.divImg .caption {
height:100%;
width: 100%;
cursor: pointer;
position: absolute;
top:0;
transform: scaleY(0);
transform-origin: top;
transition: transform 0.35s ease;
}
.caption-text{
z-index: 5;
color: #fff;
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.blur {
background-color: rgba(0,0,0,0.5);
height: 100%;
width: 100%;
position: absolute;
top:0;
}
.square {
height: 100%;
width: 100%;
outline: 2px solid white;
outline-offset: -10px;
}
.square + .caption-text h1 {
font-size: 30px;
}
.effect2 .blur {
background-color: rgba(217,24,40,0.5);
}
.effect2:hover .caption{
transform: scaleY(1);
}
</style>
<div class="couponMain" style="padding:20px;">
<div class="row">
<div class="col-md-12">
<div id="distaceWise">
<div class="row">
<div class="col-md-12">
<div id="newcpn" >
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="home-page-body <?php echo esc_attr( $extra_body_class ) ?>" >
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php if( $home_page_show_title == 'yes' ): ?>
<div class="home-page-title">
<h1><?php echo couponxxl_get_option( 'home_page_title' ) ?></h1>
<h5>
<?php
$stores = wp_count_posts( 'store' );
$stores = $stores->publish;
$locations = wp_count_terms( 'location' );
echo str_replace( array( '%stores%', '%locations%' ), array( $stores, $locations ), couponxxl_get_option( 'home_page_subtitle' ) );
?>
</h5>
</div>
<?php endif; ?>
<?php if( $home_page_show_search == 'yes' ): ?>
<div class="home-page-search-box clearfix <?php echo $home_page_show_title == 'no' ? esc_attr( 'top-margin' ) : ''; ?>">
<?php include( couponxxl_load_path('includes/main-search-values.php') ) ?>
<form method="get" action="<?php echo esc_url( couponxxl_get_permalink_by_tpl( 'page-tpl_search' ) ) ?>" class="main-search">
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control top_bar_search" value="<?php echo esc_attr( $term_name ); ?>" placeholder="<?php echo couponxxl_get_option( 'home_page_search_location_placeholder' ) ?>">
<input type="hidden" name="<?php echo esc_attr( $couponxxl_slugs['location'] ) ?>" value="<?php echo esc_attr( $location ) ?>">
<small><?php echo couponxxl_get_option( 'home_page_search_location_desc' ) ?></small>
<div class="search_options"></div>
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control top_bar_search" value="<?php echo esc_attr( $store_name ); ?>" placeholder="<?php echo couponxxl_get_option( 'home_page_search_store_placeholder' ) ?>">
<input type="hidden" name="<?php echo esc_attr( $couponxxl_slugs['offer_store'] ) ?>" value="<?php echo esc_attr( $offer_store ) ?>">
<small><?php echo couponxxl_get_option( 'home_page_search_store_desc' ) ?></small>
<div class="search_options"></div>
</div>
</div>
</form>
</div>
<?php endif; ?>
</div>
</div>
<div class="page-content clearfix">
<?php the_content(); ?>
</div>
</div>
</section>
<?php get_footer(); ?>
function
/*-----------------------------my Distance wise search-------------------------------------------*/
if ( ! function_exists( 'couponxxl_distancewise' ) ) {
function couponxxl_distancewise() {
global $wpdb;
//$dis=mb_strtolower( esc_sql( $_POST['val'] ) );
$dis = mb_strtolower( esc_sql( $_POST['distance'] ) );
$latitude = mb_strtolower( esc_sql( $_POST['lat'] ) );
$longtitude = mb_strtolower( esc_sql( $_POST['longi'] ) );
$deal_lat= $latitude;
$deal_long=$longtitude;
$couponIdArr=array();
$couponNameArr=array();
$restNamearr=array();
$expArr=array();
$logoArr=array();
$getNearescoupsql ="SELECT marker_id,post_id,term_slug, (
(
ACOS( SIN( '$deal_lat' * PI( ) /180 ) * SIN( latitude * PI( ) /180 ) + COS( '$deal_lat' * PI( ) /180 ) * COS( latitude * PI( ) /180 ) * COS( (
'$deal_long' - longitude
) * PI( ) /180 ) ) *180 / PI( )
) *60 * 1.1515
) AS distance
FROM wp_store_markers
GROUP BY marker_id
HAVING (
distance < $dis
)";
$nearesCpnresult = $wpdb->get_results($getNearescoupsql);
$restaurantIdArr = array();
foreach( $nearesCpnresult as $couponres )
{
$dis=$couponres->distance;
$restaurantId=$couponres->post_id;
$restaurantIdArr[]=$restaurantId;
}
$restIdstr=implode(",",$restaurantIdArr);
$getcouponId = "SELECT post_id,meta_value FROM wp_postmeta WHERE meta_value IN($restIdstr)";
$couponIdresult = $wpdb->get_results($getcouponId);
foreach( $couponIdresult as $couponRes )
{
$couponIdArr[] = $couponRes->post_id;
$couponId = $couponRes->post_id;
$restRef = $couponRes->meta_value;
$getExpired = "SELECT offer_expire FROM wp_offers WHERE post_id='$couponId' AND offer_type='coupon'";
$expiredRes = $wpdb->get_results($getExpired);
foreach( $expiredRes as $expiredResult )
{
$expiredDate=$expiredResult->offer_expire;
$expired=date('m-d-Y', $expiredDate);
$today = date("m-d-Y");
$today_time = strtotime($today);
$expire_time = strtotime($expired);
$getcpnName = "SELECT p.post_title,e.offer_expire FROM wp_posts p
INNER JOIN wp_offers e
ON e.post_id=p.ID
WHERE p.ID ='$couponId' AND p.post_status='publish' AND p.post_type='offer'";
$couponRes = $wpdb->get_results($getcpnName);
foreach( $couponRes as $couponResult )
{
$couponName=$couponResult->post_title;
$expdt=$couponResult->offer_expire;
$couponNameArr[]=$couponName;
$expiredDate1=date('m-d-Y', $expdt);
$today1 = date("m-d-Y");
$today_time1 = strtotime($today1);
$expire_time1 = strtotime($expiredDate1);
$datediff1 = $today_time1 - $expire_time1;
$expiredOn1=floor($datediff1 / (60 * 60 * 24));
$expArr[]=$expiredOn1;
$getRest = "SELECT post_title FROM wp_posts WHERE ID ='$restRef' AND post_type='store'";
$restRes = $wpdb->get_results($getRest);
foreach( $restRes as $restrnt )
{
$restName=$restrnt->post_title;
$restNamearr[]=$restName;
$gettumbpid = "SELECT meta_value FROM wp_postmeta WHERE post_id ='$restRef' AND meta_key='_thumbnail_id'";
$tumbimg = $wpdb->get_results($gettumbpid);
$rcnt=$wpdb->num_rows;
if($rcnt > 0)
{
foreach($tumbimg as $tumbimgres)
{
$tumbId=$tumbimgres->meta_value;
$getrestlogo = "SELECT meta_value FROM wp_postmeta WHERE post_id ='$tumbId' AND meta_key='_wp_attached_file'";
$restlogoRes = $wpdb->get_results($getrestlogo);
foreach($restlogoRes as $logoRes)
{
$logo=$logoRes->meta_value;
$logoArr[]=get_site_url().'/wp-content/uploads/'.$logo;
}
}
}
else
{
$logoArr[]=get_site_url().'/'.'/wp-content/uploads/2017/11/pasta.png';
}
}
}
}
}
$counRes['counpon']=$couponNameArr;
$expResult['expRes']=$expArr;
$restResponce['restResonce']=$restNamearr;
$logores['logores']=$logoArr;
$couponIdRes['couponidres']=$couponIdArr;
$responce=$counRes+$expResult+$restResponce+$couponIdRes;
$cpnCnt=count($responce['counpon']);
$html=' <div class="coupon-box" style=" float: left; padding: 20px 0 0; width: 100%;">';
for($i=0;$i<$cpnCnt;$i++)
{
$restaurantName = $responce['restResonce'][$i];
$expr = $responce['expRes'][$i];
$couponId = $responce['couponidres'][$i];
$getRating="SELECT meta_value FROM wp_postmeta WHERE meta_key='ratings_average' AND post_id='$couponId'";
$ratingqry=$wpdb->get_results($getRating);
$rcnt=$wpdb->num_rows;
if($rcnt >0)
{
foreach($ratingqry as $ratingRes)
{
$rateAvg=$ratingRes->meta_value;
}
}
else
{
$rateAvg=0;
}
if($rateAvg >= 1)
{
$rate1='rating_on.gif';
}
else if($rateAvg == 0.5)
{
$rate1='rating_half.gif';
}
else
{
$rate1='rating_off.gif';
}
if($rateAvg >= 2)
{
$rate2='rating_on.gif';
}
else if($rateAvg == 1.5)
{
$rate2='rating_half.gif';
}
else
{
$rate2='rating_off.gif';
}
if($rateAvg >= 3)
{
$rate3='rating_on.gif';
}
else if($rateAvg == 2.5)
{
$rate3='rating_half.gif';
}
else
{
$rate3='rating_off.gif';
}
if($rateAvg >= 4)
{
$rate4='rating_on.gif';
}
else if($rateAvg == 3.5)
{
$rate4='rating_half.gif';
}
else
{
$rate4='rating_off.gif';
}
if($rateAvg >= 5)
{
$rate5='rating_on.gif';
}
else if($rateAvg == 4.5)
{
$rate5='rating_half.gif';
}
else
{
$rate5='rating_off.gif';
}
if($expr==3425)
{
$exprres= "Unlimited";
}
else
{
//$exprres= $expr .'Days';
$exprres=$expiredDate1;
}
$baseurl=get_site_url();
$string=$responce['counpon'][$i];
//Lower case everything
$string = strtolower($string);
//Make alphanumeric (removes all other characters)
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
//Clean up multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
//Convert whitespaces and underscore to dash
$string = preg_replace("/[\s_]/", "-", $string);
$expstr="Expires on";
$html.='<div class="col-md-4">';
$html.='<div class="list-coupon">';
$baseurl=get_site_url();
$html.='<a href='.$baseurl.'/offer/'.$string.'>';
$html.='<div class="divImg effect2 " style="float:left;">';
// $html.='<img src="'.$baseurl.'/wp-content/uploads/2017/11/pasta.png" style="height:250px; width:350px; background-position:top left;">';
$html.='<img src="'.$logoArr[$i].'" style="height:250px; width:350px; background-position:top left;">';
$html.='<div class="caption">';
$html.='<div class="blur"></div>
<div class="square"></div>';
$html.='<div class="caption-text">';
$html.='<div >'.$responce['counpon'][$i].'</div>';
$html.=' </div></div></a></div>';
$html.=' <div class="content"><label style="color:#f47a2d">' .$responce['restResonce'][$i] . '</label><p><img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate1.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate2.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate3.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate4.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
<img src="'.$baseurl.'/wp-content/plugins/wp-postratings/images/stars/'. $rate5.'" alt="2 votes, average: 4.50 out of 5" title="2 votes, average: 4.50 out of 5" class="post-ratings-image" width="15" height="15">
'. '</p></div>';
$html.='<div class="expiry"><label>' .$expstr. '</label><span>' .$exprres . '</span>';
$html.='</div>';
$html.='</div>';
$html.='</div>';
}
echo $html;
$html.='</div>';
die;
// echo json_encode($responce);
}
add_action( 'wp_ajax_distancewise', 'couponxxl_distancewise' );
add_action( 'wp_ajax_nopriv_distancewise', 'couponxxl_distancewise' );
}
/*-----------------------End myquery----------------------------------------------*/
Comments
Post a Comment