<?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 tracker where Functional_Reporting='$fetch1[Employee_Number]'");
$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>Add Project</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-4 py-2">
				
					<div class="wallet-footer mb-2 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 Project Details</h6>
<?php
if (isset($_POST['projSub'])) {

	$query = mysqli_query($connpe, "INSERT INTO vc_projects(ProjCreatedBy, project_name, project_location, status)
	VALUES('".$_POST['ProjCreatedBy']."', '".$_POST['project_name']."', '".$_POST['project_location']."', '".$_POST['status']."')");

	if ($query == true) {
		echo "<script>window.location.href='';</script>"; exit;
		echo "<div class='col-md-12 text-center btn btn-success'>Details submitted successfully! </div>"; }
	else {
		echo "Error: " . $query . "<br>" . mysqli_error($connpe);
		echo "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong!</div>"; }
}
?>
					<form class="form-horizontal" name="vcprojects" action="" method="post" enctype="multipart/form-data">
						<div class="row bg-warning text-white rounded py-2 mb-4">
						<input class="form-control" type="hidden" name="ProjCreatedBy" value="<?php echo $fetch1['empid']; ?>" >
						
						<div class="col-md-4 col-sm-4"><label><b>Project Name*</b></label>
							<input class="form-control" type="text" name="project_name" placeholder="Enter Project Name" required oninput="removeSpecialChars(this)">
						</div>

						<div class="col-md-4 col-sm-4"><label><b>Project Location*</b></label>
							<input class="form-control" type="text" name="project_location" placeholder="Project Location" required oninput="removeSpecialChars(this)">
						</div>
						<div class="col-md-4 col-sm-4 text-center"><br>
							<input class="form-control" type="hidden" name="status" value="Active">
							<button name="projSub" class="btn btn-success">Submit</button>
						</div>
						</div>
					</form>
					
					<div class="row stat-box py-2">
						<h5 class="text-center">Projects List</h5>
						<div class="table">
							<table id=" " class="table table-striped table-bordered">
							<thead>
							<tr class="small">
								<th>ID</th>
								<th>Project Name</th>
								<th>Client Location</th>
								<th>Status</th>
								<th>Date</th>
							</thead>
							<tbody>
							<?php
							$query="select * from vc_projects where ProjCreatedBy='$fetch1[empid]' ORDER BY pid DESC";
							$result=mysqli_query($connpe,$query);
							while($data=mysqli_fetch_assoc($result))
							{
							@$sn++;
							?>
							<tr class="small">
								<td><?php echo $data['pid'] ?></td>
								<td><?php echo $data['project_name'] ?></td>
								<td><?php echo $data['project_location'] ?></td>
								<td><?php echo $data['status'] ?></td>
								<td><?php echo $data['created_at'] ?></td>
							</tr>
							<?php    }    ?> 
							</tbody>
							</table>		
						</div>
					</div>
				</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');	?>