<div class="right_col" role="main">
	<div class="">
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_title">
						<h2>Property Detail</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">

						<form class="form-horizontal form-label-left" method="post">

							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="roomno">Title <span class="required">*</span></label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="roomno" class="form-control col-md-7 col-xs-12" name="title" type="text">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="roomno">Short<span class="required">*</span></label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="roomno" class="form-control col-md-7 col-xs-12" name="short" type="text">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="roomno">Code<span class="required">*</span></label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="roomno" class="form-control col-md-7 col-xs-12" name="code" type="text">
								</div>
							</div>
							
						
							<div class="ln_solid"></div>
							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" name="submit" class="btn btn-success">Add</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<?php

	if(isset($_POST['submit']))
	{
	   $postTitle = $_POST['title'];
	   $postShort = $_POST['short'];
	   $postCode = $_POST['code'];
	   $adminId = isset($_SESSION['admin']['a_id']) ? $_SESSION['admin']['a_id'] : '';

	   // Debug output
	   echo '<pre style="color:blue;">';
	   echo "postTitle: ".$postTitle."\n";
	   echo "postShort: ".$postShort."\n";
	   echo "postCode: ".$postCode."\n";
	   echo "adminId: ".$adminId."\n";
	   echo '</pre>';

	   if(empty($adminId)) {
		   echo '<div style="color:red;">Error: Admin ID is missing. Please log in again or contact the administrator.</div>';
	   } else {
		   $result = mysqli_query($conn, "INSERT INTO properties (pty_title,pty_short,pty_code, a_id)
		   VALUES ('$postTitle','$postShort','$postCode',$adminId)");
		   if(!$result) {
			   echo '<div style="color:red;">MySQL Error: '.mysqli_error($conn).'</div>';
		   } else {
			   header('Location: ?pagecontent=properties');
			   exit();
		   }
	   }
		
		//TELEGRAM NOTIFICATION
		$adminUsername = $_SESSION['admin']['a_id'];
		
$messaggio = "NEW PROPERTY ADDED BY ".$adminUsername."

Title : ".$postTitle."
Short : ".$postShort."
Code : ".$postCode."

".$ipAddress;

sendMessage($chatID, $messaggio, $token);
	}
?>