<?php
session_start();
require_once '../../Server/connection.php';

    $staff_id  = $_POST['staff_id'];
	$termDate  = $_POST['termDate'];
	$remarks  = addslashes($_POST['remarks']);
	$upl_status = $_POST['upl_status'];
	
	$term_Date = date('Y-m-d', strtotime($termDate));
	
	
	
	if($upl_status=='Yes'){
  foreach ($_FILES["file"]["name"] as $key => $name){
		$newFilename = time() . "_" . $name;
		move_uploaded_file($_FILES["file"]["tmp_name"][$key],'../../files/'.$newFilename);
		$location = '../../files/' . $newFilename;
		
		$fSql12 = "INSERT INTO staffdocs (staff_id,fileName) 
				VALUES ('$staff_id','$location')";

		$resFSql12 = $conn->query($fSql12);
	          }
			
              }else{
				  
		$resFSql12 = 'Yes';
				  
			  }
			  
	 $fSql122 = "INSERT INTO staff_termination (staff_id,termination_date,remarks) 
				VALUES ('$staff_id','$term_Date','$remarks')";

	 $resFSql122 = $conn->query($fSql122);


     $sql4 = "UPDATE staff SET status_id=2 WHERE staff_id  = '$staff_id'";
	 $result4 = $conn->query($sql4);
	 
	 
	 if($resFSql12&&$result4&&$resFSql122){
		 
		$_SESSION['success_message'] = "Staff Has Been Terminated Successfully";
  header("Location: ../terminateStaff.php");
  exit();
		 
	 }
	 

?>