<?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>

<?php
if(isset($_POST['eptupdate']))
{	
	if(@$_FILES['PPT']['name']!='') 
	{	
		$PPT = uniqid() .'-'. $_FILES['PPT']['name'];  
		
		$PPTquery = mysqli_query($connpe,"UPDATE proj_open set Developer='".$_POST['Developer']."', Project='".$_POST['Project']."', cityID_proj='".$_POST['cityID_proj']."', Location='".$_POST['Location']."', Closing_Manager='".$_POST['Closing_Manager']."', Closing_Manager_Number='".$_POST['Closing_Manager_Number']."', Closing_Manager_Email='".$_POST['Closing_Manager_Email']."', category_name='".$_POST['category_name']."', Available_Inventory='".$_POST['Available_Inventory']."', Available_Size='".$_POST['Available_Size']."', Rate='".$_POST['Rate']."', Brokerage_Slab='".$_POST['Brokerage_Slab']."', PPT='$PPT', ICRM_Name='".$_POST['ICRM_Name']."', ICRM_Email='".$_POST['ICRM_Email']."', ICRM_Phone='".$_POST['ICRM_Phone']."', Project_Status='".$_POST['Project_Status']."', edited_by='".$_POST['edited_by']."' where SNo = '".$_GET['SNo']."' ");
		
		$att="../uploads/PPT/".$PPT;
		move_uploaded_file($_FILES['PPT']['tmp_name'],$att);
		
		if($PPTquery==true){ echo "<div class='col-md-12 text-center btn btn-success'>Details Updated Successfully! </div>"; }
		else {	echo mysqli_error($connpe);	}
	}
	elseif(@$_FILES['Brochure']['name']!='') 
	{	
		$Brochure = uniqid() .'-'. $_FILES['Brochure']['name'];  
		
		$PPTquery = mysqli_query($connpe,"UPDATE proj_open set Developer='".$_POST['Developer']."', Project='".$_POST['Project']."', cityID_proj='".$_POST['cityID_proj']."', Location='".$_POST['Location']."', Closing_Manager='".$_POST['Closing_Manager']."', Closing_Manager_Number='".$_POST['Closing_Manager_Number']."', Closing_Manager_Email='".$_POST['Closing_Manager_Email']."', category_name='".$_POST['category_name']."', Available_Inventory='".$_POST['Available_Inventory']."', Available_Size='".$_POST['Available_Size']."', Rate='".$_POST['Rate']."', Brokerage_Slab='".$_POST['Brokerage_Slab']."', Brochure='$Brochure', ICRM_Name='".$_POST['ICRM_Name']."', ICRM_Email='".$_POST['ICRM_Email']."', ICRM_Phone='".$_POST['ICRM_Phone']."', Project_Status='".$_POST['Project_Status']."', edited_by='".$_POST['edited_by']."' where SNo = '".$_GET['SNo']."' ");
		
		$att="../uploads/Brochure/".$Brochure;
		move_uploaded_file($_FILES['Brochure']['tmp_name'],$att);
		
		if($PPTquery==true){ echo "<div class='col-md-12 text-center btn btn-success'>Details Updated Successfully! </div>"; }
		else {	echo mysqli_error($connpe);	}
	}
	else
	{
		$query = mysqli_query($connpe,"update proj_open set Developer='".$_POST['Developer']."', Project='".$_POST['Project']."', cityID_proj='".$_POST['cityID_proj']."', Location='".$_POST['Location']."', Closing_Manager='".$_POST['Closing_Manager']."', Closing_Manager_Number='".$_POST['Closing_Manager_Number']."', Closing_Manager_Email='".$_POST['Closing_Manager_Email']."', category_name='".$_POST['category_name']."', Available_Inventory='".$_POST['Available_Inventory']."', Available_Size='".$_POST['Available_Size']."', Rate='".$_POST['Rate']."', Brokerage_Slab='".$_POST['Brokerage_Slab']."', ICRM_Name='".$_POST['ICRM_Name']."', ICRM_Email='".$_POST['ICRM_Email']."', ICRM_Phone='".$_POST['ICRM_Phone']."', Project_Status='".$_POST['Project_Status']."', edited_by='".$_POST['edited_by']."' where SNo = '".$_GET['SNo']."' ");
		
		if($query==true){ echo "<div class='col-md-12 text-center btn btn-success'>Details Updated Successfully! </div>"; }
		else {	echo mysqli_error($connpe);	}
	}
}
?>
<?php
	$postquery = "select * from proj_open where SNo  = '".$_GET['SNo']."' ";
	$result = mysqli_query($connpe, $postquery);
	while($datan = $result->fetch_assoc()){
?>
			
			<h6 class="text-center">Edit Open Project Details</h6>
			<form class="form-horizontal" name="ept" action="" method="post" enctype="multipart/form-data">	
				<div class="row bg-light rounded">
					<div class="col-md-3 col-sm-3"><label>Developer Name</label>
						<input class="form-control" type="text" value="<?php echo $datan['Developer']; ?>" name="Developer">
					</div>
					<div class="col-md-3 col-sm-3"><label>Project Name</label>
						<input class="form-control" type="text" value="<?php echo $datan['Project']; ?>" name="Project">
					</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="<?php echo $datan['cityID_proj']; ?>"><?php 
								$oc=mysqli_query($connpe,"select * from  proj_cities where cityID_proj='$datan[cityID_proj]' ");
								$fetchoc=mysqli_fetch_array($oc);
								echo $fetchoc['City_Name']
							?></option>
							<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="<?php echo $datan['Location']; ?>"><?php echo $datan['Location']; ?></option>
							<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>
					
					<?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="<?php echo $datan['category_name']; ?>"><?php echo $datan['category_name']; ?></option>
							<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>Closing Manager</label>
						<input class="form-control" type="text" value="<?php echo $datan['Closing_Manager']; ?>" name="Closing_Manager">
					</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');" value="<?php echo $datan['Closing_Manager_Number']; ?>" placeholder="Only 10 Digits Mobile No">
					</div>
					<div class="col-md-3 col-sm-3"><label>Closing Manager Email</label>
						<input class="form-control" type="email" value="<?php echo $datan['Closing_Manager_Email']; ?>" name="Closing_Manager_Email">
					</div>
					
					<div class="col-md-3 col-sm-3"><label>Available Inventory</label>
						<input class="form-control" type="text" value="<?php echo $datan['Available_Inventory']; ?>" name="Available_Inventory">
					</div>
					<div class="col-md-3 col-sm-3"><label>Available Size</label>
						<input class="form-control" type="text" value="<?php echo $datan['Available_Size']; ?>" name="Available_Size">
					</div>
					
					<div class="col-md-3 col-sm-3"><label>Rate</label>
						<input class="form-control" type="text" value="<?php echo $datan['Rate']; ?>" name="Rate">
					</div>
					<div class="col-md-3 col-sm-3"><label>Brokerage Slab</label>
						<input class="form-control" type="text" value="<?php echo $datan['Brokerage_Slab']; ?>" name="Brokerage_Slab">
					</div>
					<div class="col-md-6 col-sm-6"><label>PPT</label>
						<input class="form-control" type="file" name="PPT" >
						<figure>
							<?php	if($datan['PPT'] != '')	{?>
							<a href="../uploads/PPT/<?php echo $datan['PPT']; ?>" target="_blank">Click to View PPT</a>
							<?php	}	else	{	?>
							<a href="#" class="dropdown-item">Upload PPT</a>
							<?php	}	?>
						  <div class="overlay"></div>
						</figure>
					</div>
					<div class="col-md-6 col-sm-6"><label>Brochure</label>
						<input class="form-control" type="file" value="<?php echo $datan['Brochure']; ?>" name="Brochure">
						<figure>
							<?php	if($datan['Brochure'] != '')	{?>
							<a href="../uploads/Brochure/<?php echo $datan['Brochure']; ?>" target="_blank">Click to View Brochure</a>
							<?php	}	else	{	?>
							<a href="#" class="dropdown-item">Upload Brochure</a>
							<?php	}	?>
						  <div class="overlay"></div>
						</figure>
					</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>ICRM Name</label>
						<input class="form-control" type="text" value="<?php echo $datan['ICRM_Name']; ?>" name="ICRM_Name">
					</div>
					<div class="col-md-4 col-sm-4"><label>ICRM Email</label>
						<input class="form-control" type="email" value="<?php echo $datan['ICRM_Email']; ?>" name="ICRM_Email">
					</div>
					<div class="col-md-4 col-sm-4"><label>ICRM 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');" value="<?php echo $datan['ICRM_Phone']; ?>" placeholder="Only 10 Digits Mobile No">
					</div>
					<div class="col-md-2 col-sm-2"><label>Project Status</label>
						<select name="Project_Status" class="form-control">
							<option value="<?php echo $datan['Project_Status']; ?>"><?php echo $datan['Project_Status']; ?></option>
							<option value="" disabled>Select</option>
							<option value="Active">Active</option>
							<option value="Inactive">Inactive</option>
							<option value="Pending">Pending</option>
						</select>
					</div>
					<div class="col-md-2 col-sm-2"><label>Created by</label>
						<input class="form-control" value="<?php echo $datan['created_by']; ?>" disabled>
						<input class="form-control" name="edited_by" value="<?php echo $fetch1['empid']; ?>" type="hidden">
					</div>
					<div class="col-md-2 col-sm-2"><label>Created at</label>
						<input class="form-control" value="<?php echo $datan['created_at']; ?>" disabled>
					</div>
					
					<div class="col-md-12 col-sm-12 mt5 text-center">
						<!-- <button type="submit" name="eptupdate" class="btn btn-warning">Update</button> -->
					</div>
				</div>
				<?php } ?>
			</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');	?>