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

//CODE FOR DELETE ENQUIRY
if(isset($_GET['action']) && $_GET['action'] == "delete")
{
	mysqli_query($connection,"DELETE FROM `pd_property_enquiry` WHERE `enquiry_id` = '".$_GET['enquiry_id']."'");
	
	$_SESSION['del_succ_msg'] = 'Enquiry deleted successfully.';
	header("location: property_enquiry_list.php?property_id=".$_GET['property_id']);
	exit;
}

$get_pro = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_property` WHERE `property_id` = '".$_GET['property_id']."'"));

$get_location = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_locations` WHERE `location_id` = '".$get_pro['location_id']."'"));
$get_type = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_property_type` WHERE `type_id` = '".$get_pro['type_id']."'"));
$get_subtype = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pd_property_subtype` WHERE `subtype_id` = '".$get_pro['subtype_id']."'"));
?>

<?php require_once("left_panel.php");?>
<div class="content">
	<div class="workplace">
		<?php if(isset($_SESSION['del_succ_msg'])) { ?>
			<div class="alert alert-success">                
			<b><?php echo $_SESSION['del_succ_msg'];?></b>
			</div> 
		<?php
		unset($_SESSION['del_succ_msg']);
		}
		?>
		<div class="row-fluid">
			<div class="span12">                    
				<div class="head clearfix">
					<div class="isw-grid"></div>
					<h1>Enquiry List For <?php echo stripslashes($get_type['type']);?> - <?php echo stripslashes($get_subtype['subtype']);?> in <?php echo stripslashes($get_location['location']);?></h1>                               
				</div>
				<div class="block-fluid table-sorting clearfix">
					<table cellpadding="0" cellspacing="0" width="100%" class="table" id="tSortable">
						<thead>
							<tr>
								<th width="10%">Serial No.</th>
								<th width="20%">Customer Details</th>
								<th width="30%">Phone No. & Email Address</th>
								<th width="30%">Message</th>
								<th width="10%">&nbsp;</th>
							</tr>
						</thead>
						<tbody>
						<?php
						$category_counter = 1;
						$sql_record = "SELECT * FROM `pd_property_enquiry` WHERE `property_id` = '".$_GET['property_id']."' ORDER BY `enquiry_id` DESC";
						$exe_record = mysqli_query($connection,$sql_record);
						$num_record = mysqli_num_rows($exe_record);
						if($num_record>0)
						{
							while($fetch_record = mysqli_fetch_array($exe_record))
							{
								$name = stripslashes($fetch_record['name']);
								$phone = stripslashes($fetch_record['phone']);
								$email = stripslashes($fetch_record['email']);
								$location = stripslashes($fetch_record['location']);
								$message = nl2br(stripslashes($fetch_record['enquiry']));
							?>
							<tr>
								<td><?php echo $category_counter;?></td>
								<td><b>Name : </b><?php echo $name;?><br><b>Location : </b><?php echo $location;?></td>
								<td><b>Phone No : </b><?php echo $phone;?><br><b>Email Address : </b><?php echo $email;?></td>
								<td><?php echo $message;?></td>
								<td><a href="property_enquiry_list.php?enquiry_id=<?php echo $fetch_record['enquiry_id']?>&property_id=<?php echo $_GET['property_id'];?>&action=delete" title="Delete" onclick="return confirm('Are you sure you want to delete this enquiry?');" style="float:left; display:block; margin:0 5px 0 0;"><ul class="the-icons clearfix"><i class="isb-delete"></i></ul></a></td>
							</tr>
							<?php
							$category_counter++;
							}
						}
						else
						{
						?>
						<tr>
							<td><font color="#FF0000">No enquiry found</font></td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
						<?php
						}
						?>
						</tbody>
					</table>
				</div>
			</div>                                
		</div>
	</div>
</div>

<?php require_once("footer.php"); ?>