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

<?php
if(isset($_POST['send']))
{	
	//UPLOAD IMAGE
	if($_FILES['picg']['name']!="")
	{	
		$photopath = pathinfo($_FILES['picg']['name']);
		$extension = $photopath['extension'];
		$source = $_FILES['picg']['tmp_name'];
		$picg = time().".".$extension;
		$destination = "uploads/property/".$picg;
		move_uploaded_file($source,$destination);
	}
	else
	{
		$picg = '';
	}

	$sql_insert = "INSERT INTO `pd_property_photos` SET `property_id` = '".$_POST['hid_property_id']."',`photo` = '".$picg."',`photo_status` = 'Active'";
	$exe_insert = mysqli_query($connection,$sql_insert);
	
	$_SESSION['add_succ_msg6'] = 'Photo added succcessfully.';
	header("location: photo-list.php?property_id=".$_POST['hid_property_id']);
	exit;
}
?>

		<script language="javascript" type="text/javascript">
		function form_validation()
		{
			if(document.getElementById('picg').value == '')
        	{
        		alert("Please upload photo");
        		return false;
        	}
		}
		</script>

		<!-- content 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">Add Photo</h1>
						<form id="" action="" method="post" class="contact-form" enctype="multipart/form-data" onsubmit="return form_validation();">
					    <input type="hidden" name="hid_property_id" id="hid_property_id" value="<?php echo $_GET['property_id'];?>" />
						<div class="row">
							<div class="col-lg-12 form-group">
							    <p style="text-align:left;">Upload Photo *</p>
								<input name="picg" id="picg" type="file">
							</div>
							<div class="col-lg-12 form-group">
								<button class="btn btn-flat btn-theme-colored  border-left-theme-color-2-4px" type="submit" style="float: left;">Save</button>&nbsp;&nbsp;<a class="btn btn-colored btn-theme-colored2 btn-lg mt-0" href="photo-list.php?property_id=<?php echo $_GET['property_id'];?>">Back</a>
							</div>
						</div>
						<input type="hidden" name="send" id="send" value="1" />
						</form>	
					</div>
				</div>
			</div>	
		</section>
		<!-- content area end -->

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