<?php

//fetch_data.php

include('../config2.php');
include('../config.php');

if(isset($_POST["action"]))

{
	$query = "
		SELECT cnf_mst_property_master.* FROM cnf_mst_property_master  
	";
	if(isset($_POST["aminity"]))
	{
		$aminity_filter = implode("','", $_POST["aminity"]);
		$query .= "left JOIN property_aminity 
	on cnf_mst_property_master.pk_property_id=property_aminity.fk_property_id 
	where property_aminity.aminityselected IN('".$aminity_filter."') ";
	}else{
		$query .= "WHERE transaction_status = '1'";
	}
	if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
	{
		$query .= "
		 AND price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
		";
	}
	if(isset($_POST["minimum_area"], $_POST["maximum_area"]) && !empty($_POST["minimum_area"]) && !empty($_POST["maximum_area"]))
	{
		$query .= "
		 AND area_no BETWEEN '".$_POST["minimum_area"]."' AND '".$_POST["maximum_area"]."'
		";
	}
	if(isset($_POST["areaunit"]))
	{
		
		$query .= "
		 AND fk_area_unit ='".$_POST['areaunit']."'
		";
	}
	if(isset($_POST["ram"]))
	{
		$ram_filter = implode("','", $_POST["ram"]);
		$query .= "
		 AND fk_service_category IN('".$ram_filter."')
		";
	}
	if(isset($_POST["bedrooms"]))
	{
		$bedrooms_filter = implode("','", $_POST["bedrooms"]);
		$query .= "
		 AND fk_bedroom_type IN('".$bedrooms_filter."')
		";
	}
	if(isset($_POST["aminity"]))
	{
		$query .= "
			GROUP BY pk_property_id
			";
		}	

echo $query;
	$statement = $con->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$total_row = $statement->rowCount();
	$output = '';
	if($total_row > 0)
	{
		foreach($result as $prow)
		{

			$sql1="select * from  cnf_mst_service_type where pk_service_code='".$prow['fk_service_type']."'";
            $result1=$conn->query($sql1);     $row1=$result1->fetch_assoc();

			$sql5="select * from  cnf_mst_bedroom_type where id='".$prow['fk_bedroom_type']."'";
			$result5=$conn->query($sql5);     $row5=$result5->fetch_assoc();

			$sql6="select * from  area_unit where id='".$prow['fk_area_unit']."'";
			$result6=$conn->query($sql6);     $row6=$result6->fetch_assoc();
			
			$sql7="select * from   utm_mst_state where pk_utm_state_id='".$prow['fk_utm_state_id']."'";
			$result7=$conn->query($sql7);     $row7=$result7->fetch_assoc();

			// $sql8="select * from   utm_mst_state where pk_utm_state_id='".$prow['fk_utm_state_id']."'";
			// $result8=$conn->query($sql8);     $row7=$result8->fetch_assoc();
			
                                                                                                
			$output .='
			<div class="col-lg-6 col-md-6 col-sm-12">
			<div class="property-listing property-2">
				
				<div class="listing-img-wrapper">
					<div class="list-img-slide">
						<div class="click">
							<div><a href="singleproperty.php?pid='. $prow['id'] .'"><img src="assets/property/demohouse.jpg" class="img-fluid mx-auto" alt="" /></a></div>
							</div>
					</div>
				</div>
				
				<div class="listing-detail-wrapper">
					<div class="listing-short-detail-wrap">
						<div class="listing-short-detail">
							<span class="property-type">Propety Type:'. $row1['service_name'] .'</span>
							<h4 class="listing-name verified"><a href="singleproperty.php?pid='.$prow['id'] .'" class="prt-link-detail">Banyon Tree Realty</a></h4>
						</div>
						<div class="listing-short-detail-flex">
							<h6 class="listing-card-info-price price" id="">'.$prow['price'].'</h6>
						</div>
					</div>
				</div>
				
				<div class="price-features-wrapper">
					<div class="list-fx-features">
						<div class="listing-card-info-icon">
							<div class="inc-fleat-icon"><img src="assets/img/bed.svg" width="13" alt="" />'.  $row5['destination_type_name'] .'</div>
						</div>
						<div class="listing-card-info-icon">
							<div class="inc-fleat-icon"><img src="assets/img/bathtub.svg" width="13" alt="" /></div>'.$prow['bathroom'].' Bath
						</div>
						<div class="listing-card-info-icon">
							<div class="inc-fleat-icon"><img src="assets/img/move.svg" width="13" alt="" /></div>Area:'. $prow['area_no'].' '. $row6['area_unit_name'] .'
												  
						</div>
					</div>
				</div>
				
				<div class="listing-detail-footer">
					<div class="footer-first">
						<div class="foot-location"><img src="assets/img/pin.svg" width="18" alt="" />'. $row7['state_name'] .'  '. $prow['fk_utm_country_id'] .'</div>
					</div>
					<div class="footer-flex">
						<a href="singleproperty.php?pid='.$prow['id'].'" class="prt-view">View</a>
					</div>
				</div>
				
			</div>
		</div>
			';
		}
	}
	else
	{
		$output = '<h3>No Data Found</h3>';
	}
	echo $output;
	echo "sds";
}

?>
	<script>
			$('.price').priceFormat({
				prefix: '₹',
				centsSeparator: '.',
				thousandsSeparator: ',',
				// centsLimit: 0,
				clearOnEmpty: true
			});
		</script>