<?php
date_default_timezone_set('Asia/Kolkata'); 
//echo $date = date("Y-m-d", time());
include ('../config.php');
@session_start();
@$user_id1=$_SESSION['user_id1'];
@$idvfied1=$_SESSION['idverified1'];
@$namevfied1=$_SESSION['namevfied1'];
if(!isset($_SESSION['user_id1'])){
	header("Location: index.php");
}

$timeout = 60 * 60 * 24 * 365;
$s_name = session_name();
if(isset( $_COOKIE[ $s_name ] )) {
  setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
}

$sel1=mysqli_query($conn,"select * from hr_dump where empid='".@$user_id1."'");
$fetch1=mysqli_fetch_array($sel1);

$queryFR=mysqli_query($conn,"select * from hr_dump where Functional_Reporting='$fetch1[Employee_Number]' AND Status='Active' ");
$dataFR=mysqli_fetch_array($queryFR);

/* $queryFR=mysqli_query($conn,"select * from emp_leave where Functional_Reporting='$fetch1[Employee_Number]'");
$dataFR=mysqli_fetch_array($queryFR); */
?>

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Open Project Add</title>
	
	<?php	include ('header.php');	?>
	
	<div id="appCapsule">
        <div class="section wallet-card-section pt-1">
            <div class="wallet-card">
				
				<?php	include ('include/wallet-balance.php');	?>
				<div class="mb-2 py-2">
					<div class="wallet-footer p-2">
						<div class="text-center">
							<a href="vc-admin.php" class="btn btn-primary btn-sm">Back to Admin Home</a>
						</div>
					</div>
					<h6 class="text-center">Enter Open Project Details</h6>
<?php
if(isset($_POST['submit']))
{   
	$PPT = uniqid() .'-'. $_FILES['PPT']['name'];  
	$Brochure = uniqid() .'-'. $_FILES['Brochure']['name'];  
	
	$query=mysqli_query($connpe,"INSERT INTO proj_open(`Developer`, `Project`, `cityID_proj`, `Location`, `Closing_Manager`, `Closing_Manager_Number`, `Closing_Manager_Email`, `category_name`, `Available_Inventory`, `Available_Size`, `Rate`, `Brokerage_Slab`, `PPT`, `Brochure`, `ICRM_Name`, `ICRM_Email`, `ICRM_Phone`, `Project_Status`, `created_by`) 

    VALUES ('".$_POST['Developer']."','".$_POST['Project']."', '".$_POST['cityID_proj']."', '".$_POST['Location']."', '".$_POST['Closing_Manager']."', '".$_POST['Closing_Manager_Number']."', '".$_POST['Closing_Manager_Email']."','".$_POST['category_name']."','".$_POST['Available_Inventory']."','".$_POST['Available_Size']."', '".$_POST['Rate']."','".$_POST['Brokerage_Slab']."', '$PPT', '$Brochure', '".$_POST['ICRM_Name']."','".$_POST['ICRM_Email']."','".$_POST['ICRM_Phone']."', '".$_POST['Project_Status']."', '".$_POST['created_by']."')");
	
	$att="../uploads/PPT/".$PPT;
	move_uploaded_file($_FILES['PPT']['tmp_name'],$att);
	
	$att="../uploads/Brochure/".$Brochure;
	move_uploaded_file($_FILES['Brochure']['tmp_name'],$att);
	
     //echo "<pre>"; print_r($_POST); exit;
    if($query==true)
        { echo "<div class='col-md-12 col-sm-12 mt5 text-center btn btn-success'>Data Inserted Successfully! </div>"; }
	else
	echo "<div class='col-md-12 col-sm-12 mt5 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong!</div>";
}
?>
			<form class="" name="ept" action="" method="post" enctype="multipart/form-data">
				<div class="row bg-light rounded p-2">
					<div class="col-md-3 col-sm-3"><label>Developer Name</label>
						<input class="form-control" name="Developer" type="text" required>
					</div>
					<div class="col-md-3 col-sm-3"><label>Project Name</label>
						<input class="form-control" name="Project" type="text" required>
					</div>
					<?php
						$query = "SELECT * FROM proj_cities ORDER BY City_Name ASC"; 
						$result = $connpe->query($query); 
					?>
					<div class="col-md-3 col-sm-3">
						<label><span class="red">City Name*</span>:</label>
						<select name="cityID_proj" id="city" class="form-control">
							<option value="">-Select City-</option>
							<?php 
							if($result->num_rows > 0){ 
								while($row = $result->fetch_assoc()){ 
									echo '<option value="'.$row['cityID_proj'].'">'.$row['City_Name'].'</option>'; 
								}
							}else{	echo '<option value="">City not available</option>';	}
							?>
						</select>
					</div>
					<!-- *************************************************************************************************** -->
					<?php
						$cat_q = $connpe->query("select * from porj_locations ORDER BY Location ASC");
						$catCount = $cat_q->num_rows;
					?>
					<div class="col-md-3 col-sm-3">
						<label><span class="red">Location Name*</span>:</label>
						<select name="Location" id="open_proj_loc" required class="form-control">
							<option value="">-Select City First-</option>
						</select>
					</div>
					<script>
					$(document).ready(function(){
						$('#city').on('change', function(){
							var cityID_proj = $(this).val();
							if(cityID_proj){
								$.ajax({
									type:'POST',
									url:'vc-open-proj-loc-search.php',
									data:'cityID_proj='+cityID_proj,
									success:function(html){
										$('#open_proj_loc').html(html);
									}
								}); 
							}else{	$('#open_proj_loc').html('<option value="">-Select City First-</option>');	}
						});
					});
					</script>
					<div class="col-md-3 col-sm-3"><label>Closing Manager</label>
						<input class="form-control" name="Closing_Manager" type="text">
					</div>
					<div class="col-md-3 col-sm-3"><label>Closing Manager Number</label>
						<input class="form-control" name="Closing_Manager_Number" type="text" maxlength="10" required oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" placeholder="Only 10 Digits Mobile No">
					</div>
					<div class="col-md-3 col-sm-3"><label>Closing Manager Email</label>
						<input class="form-control" name="Closing_Manager_Email" type="email" required>
					</div>
					<?php
						$catq = "SELECT * FROM proj_category ORDER BY category_name ASC"; 
						$catr = $connpe->query($catq); 
					?>
					<div class="col-md-3 col-sm-3">
						<label><span class="red">Project Category</span>:</label>
						<select name="category_name" id="city" class="form-control">
							<option value="">-Select Category-</option>
							<?php 
							if($catr->num_rows > 0){ 
								while($rowc = $catr->fetch_assoc()){ 
									echo '<option value="'.$rowc['category_name'].'">'.$rowc['category_name'].'</option>'; 
								}
							}else{	echo '<option value="">Category not available</option>';	}
							?>
						</select>
					</div>
					<div class="col-md-3 col-sm-3"><label>Available Inventory</label>
						<input class="form-control" name="Available_Inventory" type="text">
					</div>
					<div class="col-md-3 col-sm-3"><label>Available Size</label>
						<input class="form-control" name="Available_Size" type="text">
					</div>
					<div class="col-md-3 col-sm-3"><label>Rate</label>
						<input class="form-control" name="Rate" type="text">
					</div>
					<div class="col-md-3 col-sm-3"><label>Brokerage Slab</label>
						<input class="form-control" name="Brokerage_Slab" type="text">
					</div>
					
					<div class="col-md-6 col-sm-6"><label>Upload PPT</label>
						<input class="form-control" name="PPT" type="file">
					</div>
					<div class="col-md-6 col-sm-6"><label>Upload Brochure</label>
						<input class="form-control" name="Brochure" type="file">
					</div>

					<div class="col-md-12 col-sm-12 text-center"><hr><h5>IC Relationship Manager</h5><hr></div>
					
					<div class="col-md-4 col-sm-4"><label>IC RM Name</label>
						<input class="form-control" name="ICRM_Name" type="text" required>
					</div>
					<div class="col-md-4 col-sm-4"><label>IC RM Email</label>
						<input class="form-control" name="ICRM_Email" type="email" required>
					</div>
					<div class="col-md-4 col-sm-4"><label>IC RM Phone</label>
						<input class="form-control" name="ICRM_Phone" type="text" maxlength="10" required oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" placeholder="Only 10 Digits Mobile No">
					</div>

					<input class="form-control" name="Project_Status" value="Active" type="hidden">
					<input class="form-control" name="created_by" value="<?php echo $fetch1['empid']; ?>" type="hidden">

					<div class="col-md-12 col-sm-12 text-center">
						<!--<button  class="btn btn-success" value="submit" name="submit">Submit Details</button> -->
					</div>
				</div>
			</form>

				</div>
            </div>
        </div>
		
		<script type="text/javascript">
		function removeSpecialChars(element) {
			element.value = element.value.replace(/[^a-zA-Z0-9\s]/g, '');
		}
		</script>
		<!--</?php	include ('include/quik_links.php');	?>
		</?php	include ('include/extra_links.php');	?>-->
	
	<?php	include ('include/copyright.php');	?>
	</div>
	
	<?php	include ('footer.php');	?>