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

<?php
if(isset($_POST['send']))
{
	$targetDir = "uploads/property/"; 
	$fileNames = array_filter($_FILES['pic']['name']); 
	if(!empty($fileNames))
	{ 
        foreach($_FILES['pic']['name'] as $key=>$val)
        { 
            // File upload path 
            $fileName = basename($_FILES['pic']['name'][$key]); 
            $targetFilePath = $targetDir . $fileName; 
         
            // Upload file to server 
            if(move_uploaded_file($_FILES["pic"]["tmp_name"][$key], $targetFilePath))
            { 
                // Image db insert sql 
                $sql_insert = "INSERT INTO `pd_property_photos` SET `property_id` = '".$_POST['hid_pid']."',`photo` = '".$fileName."',`photo_status` = 'Active'";
                $exe_insert = mysqli_query($connection,$sql_insert);
            }
        }
	}
	header("location: add-property-complete.php?pid=".$_POST['hid_pid']);
	exit;
}
?>

		<!-- 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 Property Photos</h1>
						<p class="text-left" style="color:#ff8e00;">Step 2 of 2</p>
						<p class="text-left" style="color:#ff0000;">[Each file size should not be greater than 2MB]</p>
						<form id="" action="" method="post" class="contact-form" enctype="multipart/form-data" onsubmit="return form_validation();">
						    <input type="hidden" name="hid_pid" id="hid_pid" value="<?php echo $_REQUEST['pid'];?>">
						<div class="row">
							<?php for($i=1;$i<=12;$i++) { ?>
							<div class="col-lg-6 form-group">
							    <p style="text-align:left;">Upload Photo</p>
								<input type="file" name="pic[]" id="pic[]">
							</div>
							<?php } ?>
							<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;">Complete</button>
							</div>
						</div>
						<input type="hidden" name="send" id="send" value="1" />
						</form>	
					</div>
				</div>
			</div>	
		</section>
		<!-- content area end -->

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