<?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>VC Admin</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="wallet-footer mb-2 p-1">
					<div class="row text-center">
						<div class="col-12">
							<h6>VC Projects</h6><a href="vc-proj-add.php" class="btn btn-warning text-white btn-sm">Add VC Project</a>
						</div>
					</div>
                </div>
				<div class="wallet-footer p-1">
                    <h6 class="text-center">Manage VC</h6>
					<div class="row text-center">
						<div class="col-4"><a href="vc-admin.php" class="btn btn-primary btn-sm">Pending</a></div>
						<div class="col-4"><a href="vc-approved.php" class="btn btn-success btn-sm">Approved</a></div>
						<div class="col-4"><a href="vc-rejected.php" class="btn btn-danger btn-sm">Rejected</a></div>
					</div>
                </div>
				<div class="row mb-4">
				<h6 class="text-center mt-2 alert alert-primary">Pending VC Details</h6>
				<form class="form-horizontal" name="ams" method='post' action='' enctype="multipart/form-data" autocomplete="off"><?php echo $alert; ?>
					<p>
						<input type='submit' value='Click to Approve' class="btn btn-success" name='approve_update'>
						<input type='submit' value='Click to Reject' class="btn btn-danger" name='reject_update'>
					</p>
					<div class="table">
					<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
						<tr style='background: whitesmoke;'>
							<th><!--<input type='checkbox' id='checkAll' >--> Select</th>
							<th>Image</th>
							<th>Employee Code/Name</th>
							<th>Client Name</th>
							<th>Client Mobile</th>
							<th>Client Email</th>
							<th>Project Name</th>
							<th>Created Date</th>
						</tr>
						<?php
						function mask_mobile($mobile) {
							return '******' . substr($mobile, -4);
						}
						function mask_email($email) {
							$parts = explode('@', $email);
							return substr($parts[0], 0, 2) . '*****@' . $parts[1];
						}
						
						$cm = date('Y-m');
						//$query = "SELECT * FROM vc_client_details where Status='Pending' AND DateFrom LIKE '%$cm%' order by cid asc";
						$query = "SELECT * FROM vc_client_details where ProjCreatedBy='$fetch1[empid]' AND status='Pending' order by cid asc";
						$result = mysqli_query($connpe,$query);
						while($row = mysqli_fetch_array($result) )
						{
						@$sn++;	
						$cid = $row['cid'];
						?>
						<tr>
							<td><input type='checkbox' name='update[]' value='<?= $cid ?>' ></td>
							<input type='hidden' name='id_<?= $cid ?>' value='<?= $cid ?>' readonly>
							<td>
								<a href="../vcscreenshot/<?php echo $row['vcscreenshot'] ?>" target="_blank">
									<img src="../vcscreenshot/<?php echo $row['vcscreenshot'] ?>" style="width:50px; height:50px;">
								</a>
							</td>
							<td><?php echo $row['empid'] ?>-<?php echo $row['Employee_Full_Name'] ?></td>
							<td><?php echo $row['client_name'] ?></td>
							<td><?php echo mask_mobile($row['client_mobile']) ?></td>
							<td><?php echo mask_email($row['client_email']) ?></td>
							<td><?php echo $row['project_name'] ?></td>
							<td><?php echo $row['created_date'] ?></td>
						</tr>
						<?php
						}
						if(@$sn == 0) 
						{	echo "<div class='col-md-12 text-center btn btn-success btn-sm'><strong>You have No Pending Request!</strong></div>";	}
						?>
					</table>
					</div>
				</form>
				<?php
				$alert= "";
					if(isset($_POST['approve_update'])){
						if(isset($_POST['update'])){
							foreach($_POST['update'] as $updateid){	$updateUser = "UPDATE vc_client_details SET status='Approved' WHERE cid=".$updateid;
									mysqli_query($connpe,$updateUser);
							}
							echo "<script>window.location.href='vc-admin.php';</script>";	exit; 
							$alert = '<div class="alert alert-success" role="alert">Records successfully updated</div>';
						}
					}
					if(isset($_POST['reject_update'])){
						if(isset($_POST['update'])){
							foreach($_POST['update'] as $updateid){	$updateUser = "UPDATE vc_client_details SET status='Rejected' WHERE cid=".$updateid;
									mysqli_query($connpe,$updateUser);
							}
							echo "<script>window.location.href='vc-admin.php';</script>";	exit; 
							$alert = '<div class="alert alert-success" role="alert">Records successfully updated</div>';
						}
					}
				?>
				</div>
				
            </div>
        </div>
	
<script type="text/javascript">
	$(document).ready(function(){
		$('#checkAll').change(function(){
			if($(this).is(':checked')){
				$('input[name="update[]"]').prop('checked',true);
			}else{
				$('input[name="update[]"]').each(function(){	$(this).prop('checked',false);	}); 
			}
		});
		$('input[name="update[]"]').click(function(){
			var total_checkboxes = $('input[name="update[]"]').length;
			var total_checkboxes_checked = $('input[name="update[]"]:checked').length;
			if(total_checkboxes_checked == total_checkboxes){
				$('#checkAll').prop('checked',true);
			}else{	$('#checkAll').prop('checked',false);	}
		});
	});
</script>
	
	
	<?php	include ('include/copyright.php');	?>
	</div>
	
	<?php	include ('footer.php');	?>