<?php

session_start(); 
    $u_uname = '';
    if (isset($_COOKIE['auth_token']))
    {
        $u_uname = $_COOKIE['auth_token'];
    }else{
        header("location:../login.php");
    }
    
    
    include('../include/connection.php');

    $empId = $_GET['empId'];

    $empName = $_POST['empName'];
    $empAddr = $_POST['empAddr'];
    $empPhone = $_POST['empPhone'];
    $empPhoneAlt = $_POST['empPhoneAlt'];
    $empEmail= $_POST['empEmail'];
    $empAadhar = $_POST['empAadhar'];
    $empPAN = $_POST['empPAN'];
    $empDOB = $_POST['empDOB'];
    $empMarital = $_POST['empMarital'];
    $empEmName = $_POST['empEmName'];
    $empEmAddr = $_POST['empEmAddr'];
    $empEmPhone = $_POST['empEmPhone'];
    $empEmPhoneAlt = $_POST['empEmPhoneAlt'];
    $empEmRel = $_POST['empEmRel'];
    $salary = $_POST['salary'];
    $joiningDate = $_POST['joiningDate'];

    if($empMarital=='married'){
        $empSpouse = $_POST['empSpouse'];
        $empSpousePhone = $_POST['empSpousePhone'];
        $empNoOfChildren = $_POST['empNoOfChildren'];
        $sql = "UPDATE `employee` SET `empName`='$empName',`empAddr`='$empAddr',`empPhone`='$empPhone',`empPhoneAlt`='$empPhoneAlt',`empEmail`='$empEmail',`empAadhar`='$empAadhar',`empPAN`='$empPAN',`empDOB`='$empDOB',`empMarital`='$empMarital',`empSpouse`='$empSpouse',`empSpousePhone`='$empSpousePhone',`empNoOfChidren`=$empNoOfChildren,`empEmName`='$empEmName',`empEmAddr`='$empEmAddr',`empEmPhone`='$empEmPhone',`empEmPhoneAlt`='$empEmPhoneAlt',`empEmRel`='$empEmRel',`salary`='$salary',`joiningDate`='$joiningDate' WHERE empId=$empId";
    }
    else{
        $sql = "UPDATE `employee` SET `empName`='$empName',`empAddr`='$empAddr',`empPhone`='$empPhone',`empPhoneAlt`='$empPhoneAlt',`empEmail`='$empEmail',`empAadhar`='$empAadhar',`empPAN`='$empPAN',`empDOB`='$empDOB',`empMarital`='$empMarital',`empEmName`='$empEmName',`empEmAddr`='$empEmAddr',`empEmPhone`='$empEmPhone',`empEmPhoneAlt`='$empEmPhoneAlt',`empEmRel`='$empEmRel',`salary`='$salary',`joiningDate`='$joiningDate' WHERE empId=$empId";
    }

    $result = $link->query($sql);
    if($result){
        header('Location:../allemployees.php?status=1');
    }
?>