<div class="right_col" role="main">
	<div class="">
		<div class="page-title">
			<div class="title_left">
				<h3>Apartment list (for Email Parser) | <a href="index.php?pagecontent=??"><button type="button" class="btn btn-dark">Add ??</button></a></h3>
						
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_content">
						<table id="datatable" class="table table-striped table-bordered">
							<thead>
								<tr>
									<th>Title</th>
									<th>Room to Match</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								<?php
									$result=mysqli_query($conn, "SELECT * FROM ep_apartments") or die (mysql_error());
									while($row = mysqli_fetch_array($result))
									{
								?>
								<tr>
									<td><?php echo $row['apt_title'];?></td>
									<td><?php echo getDetailByTable('rooms',$row['r_id'])['r_no']; ?></td>
						
									<td>
										<a href="?pagecontent=ep_apartments&id=<?php echo $row['pty_id']; ?>"><button class="btn btn-xs btn-primary">Update</button></a>
										
										<a href="?pagecontent=ep_apartments&remove=<?php echo $row['pty_id']; ?>"><button class="btn btn-xs btn-danger">Remove</button></a>
									</td>
								</tr>
								<?php
									}
								?>
						</table>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>

<?php
	if(isset($_REQUEST['remove'])){
		$apartmentId = $_REQUEST['remove']; 
		
				//TELEGRAM NOTIFICATION
		$adminUsername = $_SESSION['admin']['a_username'];
		
$messaggio = "EP APARTMENT REMOVED BY ".$adminUsername."

Title : ".getDetailByTable('ep_apartments',$apartmentId)['pty_title']."
Short : ".getDetailByTable('properties',$apartmentId)['pty_short']."
Code : ".getDetailByTable('properties',$apartmentId)['pty_code']."

".$ipAddress;

sendMessage($chatID, $messaggio, $token);
		
		mysqli_query($conn,"DELETE FROM ep_apartments WHERE apt_id=$apartmentId");
		header('Location: ?pagecontent=properties'); 
	}
?>