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

//CODE FOR DELETE PHOTO
if(isset($_GET['action']) && $_GET['action'] == "delete")
{
	$sql_banner_image = "SELECT * FROM `pd_property_photos` WHERE `photo_id` = '".$_GET['photo_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['photo']);
			
	mysqli_query($connection,"DELETE FROM `pd_property_photos` WHERE `photo_id` = '".$_GET['photo_id']."'");
	
	$_SESSION['del_succ_msg6'] = 'Photo deleted successfully.';
	header("location: photo-list.php?property_id=".$_GET['property_id']);
	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">
						    <div class="col-md-8 col-xs-6"><h1 class="title mt-5 mb-15" style="text-align:left;">Photos List</h1></div>
						    <div class="col-md-4 col-xs-6 text-right"><a class="btn btn-colored btn-theme-colored2 btn-lg mt-5 mb-15" href="add-photo.php?property_id=<?php echo $_GET['property_id']?>">Add Photo</a></div>
						    <?php if(isset($_SESSION['del_succ_msg6'])) { ?>
    						<p><img src="images/tick.png" alt="" /> <?php echo $_SESSION['del_succ_msg6'];?></p>
    						<?php
    						unset($_SESSION['del_succ_msg6']);
    						}
    						?>
    						<?php if(isset($_SESSION['add_succ_msg6'])) { ?>
    						<p><img src="images/tick.png" alt="" /> <?php echo $_SESSION['add_succ_msg6'];?></p>
    						<?php
    						unset($_SESSION['add_succ_msg6']);
    						}
    						?>
							<?php
							$sql_photo = "SELECT * FROM `pd_property_photos` WHERE `photo_status` = 'Active' AND `property_id` = '".$_REQUEST['property_id']."' ORDER BY `photo_id` ASC";
							$exe_photo = mysqli_query($connection,$sql_photo);
							while($arr_photo = mysqli_fetch_array($exe_photo))
							{									
								?>
								<div class="col-md-3">
									<div class="item" data-nav="false">
										<div class="mb-30">
											<a href="uploads/property/<?php echo $arr_photo['photo'];?>" data-title="" data-lightbox="example-set">
												<div class="thumb">
													<img class="" alt="" src="uploads/property/<?php echo $arr_photo['photo'];?>">
												</div>
											</a>
											<p style="text-align:center; margin-top:10px;"><a class="btn btn-colored btn-theme-colored btn-lg mt-0" href="photo-list.php?property_id=<?php echo $arr_photo['property_id']?>&photo_id=<?php echo $arr_photo['photo_id']?>&action=delete" onclick="return confirm('Are you sure you want to delete this photo?');">Delete</a></p>
										</div>
									</div>
								</div>
								<?php
							}
							?>									
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->
  
<?php require_once("footer.php");?>