<?php 
require_once("header.php");
require_once("session_check.php");

//CODE FOR DELETE PROPERTY
if(isset($_GET['action']) && $_GET['action'] == "delete")
{
	$sql_banner_image1 = "SELECT * FROM `pd_property_photos` WHERE `property_id` = '".$_GET['property_id']."'";
	$exe_banner_image1 = mysqli_query($connection,$sql_banner_image1);
	while($arr_banner_image1 = mysqli_fetch_array($exe_banner_image1))
	{
		unlink("uploads/property/".$arr_banner_image1['photo']);
	}
			
	mysqli_query($connection,"DELETE FROM `pd_property_photos` WHERE `property_id` = '".$_GET['property_id']."'");
	
	$sql_banner_image = "SELECT * FROM `pd_property` WHERE `property_id` = '".$_GET['property_id']."'";
	$exe_banner_image = mysqli_query($connection,$sql_banner_image);
	$arr_banner_image = mysqli_fetch_array($exe_banner_image);
	unlink("uploads/property/".$arr_banner_image['cover_photo']);
	
	mysqli_query($connection,"DELETE FROM `pd_property` WHERE `property_id` = '".$_GET['property_id']."'");

	$_SESSION['del_succ_msg'] = 'Property deleted successfully.';
	header("location: my-property.php");
	exit;
}
?>

			<!-- page template area start -->
			<section id="about">
			    <div class="container mt-10 pb-10 pt-0">	
					<div class="row">
						<div class="col-lg-4">
							<?php require_once("user_left_panel.php");?>
						</div>
						<div class="col-lg-8">
						    <h1 class="title mt-5 mb-15" style="text-align:left;">My Property List</h1>
						<?php if(isset($_SESSION['del_succ_msg'])) { ?>
						<p><img src="images/tick.png" alt="" /> <?php echo $_SESSION['del_succ_msg'];?></p>
						<?php
						unset($_SESSION['del_succ_msg']);
						}
						?>
						<?php
						$sql_order = "SELECT * FROM `pd_property` WHERE `broker_id` = '".$_SESSION['USER_ID']."' ORDER BY `property_id` DESC";
						$exe_order = mysqli_query($connection,$sql_order);
						while($arr_order = mysqli_fetch_array($exe_order))
						{								
							if($arr_order['floor'] == 0)
    						{
    						    $flr = "Ground";
    						}
    						else
    						{
    						    $flr = $arr_order['floor'];
    						}
    						
    						$get_location = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_locations` WHERE `location_id` = '".$arr_order['location_id']."'"));
    						$get_type = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_property_type` WHERE `type_id` = '".$arr_order['type_id']."'"));
    						$get_subtype = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_property_subtype` WHERE `subtype_id` = '".$arr_order['subtype_id']."'"));
    						$get_otype = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_ownership_type` WHERE `otype_id` = '".$arr_order['otype_id']."'"));
							?>	
							<div class="col-md-12" style="background:#fff; padding:10px; margin-bottom:20px; border: 1px solid #ddd; box-shadow: -3px 5px 7px 0px #ddd; background-color:#fff; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; border-radius:5px;">
								    <div class="col-md-4"><img class="img-fullwidth mb-10" style="" alt="" src="uploads/property/<?php echo stripslashes($arr_order['cover_photo']);?>"></div>
								    <div class="col-md-8">
								        <h3 style="margin-bottom:5px; margin-top:0;"><?php echo stripslashes($get_type['type']);?> - <?php echo stripslashes($get_subtype['subtype']);?></h3>
								        <h4 class="text-left mt-0 mb-0" style="color:#008000;"><?php echo $get_location['location'];?></h4>
								        <p class="text-left mb-0" style="color:#888;"><?php echo stripslashes($get_otype['otype']);?> <?php echo stripslashes($get_subtype['subtype']);?></p>
								        <?php if($arr_order['type_id'] == 1) { ?>
								        <p class="text-left mb-0">Carpet Area : <?php echo stripslashes($arr_order['carpet_area']);?> sqft</p>
								        <p class="text-left mb-0"><?php echo stripslashes($arr_order['bhk']);?>, <?php echo $flr;?> Floor, <?php echo stripslashes($arr_order['bathroom']);?> Bathroom, <?php echo stripslashes($arr_order['balcony']);?> Balcony</p>
								        <p class="text-left mb-0" style="color:#888;"><?php echo stripslashes($arr_order['furnishing_type']);?></p>
								        <?php } ?>
								        <?php if($arr_order['type_id'] == 2) { ?>
								        <p class="text-left mb-0">Carpet Area : <?php echo stripslashes($arr_order['carpet_area']);?> sqft</p>
								        <p class="text-left mb-0"><?php echo $flr;?> Floor, <?php echo stripslashes($arr_order['bathroom']);?> Bathroom</p>
								        <p class="text-left mb-0" style="color:#888;"><?php echo stripslashes($arr_order['furnishing_type']);?></p>
								        <?php } ?>
								        <?php if($arr_order['type_id'] == 3) { ?>
								        <p class="text-left mb-0">Total Area : <?php echo stripslashes($arr_order['plot_area']);?> sqft</p>
								        <p class="text-left mb-0" style="color:#888;">Open Sides : <?php echo stripslashes($arr_order['open_sides']);?></p>
								        <?php } ?>
										<h4 class="text-left mt-0 mb-10" style="color:#e53935;">Total Price : &#8377;<?php echo stripslashes($arr_order['price']);?></h4>
								        <p><button type="button" class="btn btn-flat btn-theme-colored2 border-left-theme-color-2-4px" onclick="window.location.href='edit-property.php?property_id=<?php echo stripslashes($arr_order['property_id']);?>'">Edit</button>&nbsp;&nbsp;<a class="btn btn-colored btn-theme-colored btn-lg mt-0" href="my-property.php?property_id=<?php echo $arr_order['property_id']?>&action=delete" onclick="return confirm('Are you sure you want to delete this property?');">Delete</a>&nbsp;&nbsp;<button type="button" class="btn btn-flat btn-theme-colored2 border-left-theme-color-2-4px" onclick="window.location.href='photo-list.php?property_id=<?php echo stripslashes($arr_order['property_id']);?>'">Photos List</button></p>
								    </div>
								</div>
							<div>&nbsp;</div>
						<?php
						}
						?>										
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->
  
<?php require_once("footer.php");?>