<?php
   include('session.php');
   include('connect.php');
   include('logging.php');

// start role specific 
$user_role = $_SESSION['role'];

if ($_SERVER["REQUEST_METHOD"] == "POST") {


    $employee_fileno = mysqli_real_escape_string($db,$_POST['employee_fileno']);
    $companyselectid = mysqli_real_escape_string($db,$_POST['companyselectid']);
    $employee_surname = mysqli_real_escape_string($db,$_POST['employee_surname']);
    $employee_maiden_name = mysqli_real_escape_string($db,$_POST['employee_maiden_name']);
    $employee_name = mysqli_real_escape_string($db,$_POST['employee_name']);
    $employee_nic = mysqli_real_escape_string($db,$_POST['employee_nic']);
    $employee_citizenship = mysqli_real_escape_string($db,$_POST['employee_citizenship']);
    $employee_dob = mysqli_real_escape_string($db,$_POST['employee_dob']);
    $employee_gender = mysqli_real_escape_string($db,$_POST['employee_gender']);
    $employee_joining_date = mysqli_real_escape_string($db,$_POST['employee_joining_date']);
    $employee_tan = mysqli_real_escape_string($db,$_POST['employee_tan']);
    $employee_paye_rate = mysqli_real_escape_string($db,$_POST['employee_paye_rate']);
    $employee_edf_amount = mysqli_real_escape_string($db,$_POST['employee_edf_amount']);
    $employee_edf_months = mysqli_real_escape_string($db,$_POST['employee_edf_months']);
    $employee_fulltime = mysqli_real_escape_string($db,$_POST['employee_fulltime']);
    $employee_pension = mysqli_real_escape_string($db,$_POST['employee_pension']);
    $employee_contributioncode = mysqli_real_escape_string($db,$_POST['employee_contributioncode']);



    $sqlAddEmployee = "INSERT INTO employees (
      employeefileno,
      companyid,
      employeesurname,
      employeemaidenname,
      employeename,
      employeenic,
      employee_citizen_boolean,
      employeedob,
      employeegender,
      employee_join_date,
      employee_tan_number,
      employee_paye_rate,
      employee_edf_amount,
      edf_months_value,
      employee_fulltime_boolean,
      employee_pension_boolean,
      employee_contribution_code
      ) VALUES (
      '$employee_fileno',
      '$companyselectid',
      '$employee_surname',
      '$employee_maiden_name',
      '$employee_name',
      '$employee_nic',
      '$employee_citizenship',
      '$employee_dob',
      '$employee_gender',
      '$employee_joining_date',
      '$employee_tan',
      '$employee_paye_rate',
      '$employee_edf_amount',
      '$employee_edf_months',
      '$employee_fulltime',
      '$employee_pension',
      '$employee_contributioncode');";

    if(mysqli_query($db, $sqlAddEmployee)) {

      $employeeAdd = "User added employee " . $employee_surname . " " . $employee_name;

      $last_id = mysqli_insert_id($db);

      logEvent($db,"Employee Added",$employeeAdd,$last_id);
      
      header("location: employees.php");
      } else {
         echo "Error: " . mysqli_error($db);
    }
 
}

?>