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

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

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

  if (isset($_POST['employee_id'])) {

    $employeeid = mysqli_real_escape_string($db,$_POST['employee_id']);
    $value_type = mysqli_real_escape_string($db,$_POST['value_type']);
    $value = mysqli_real_escape_string($db,$_POST['value']);
    $start_date = mysqli_real_escape_string($db,$_POST['effective_start_date']);
    $end_date = mysqli_real_escape_string($db,$_POST['effective_end_date']);


    $sqlAddValue = "INSERT INTO valuesbyemployee (
      employeeid,
      valuename,
      value,
      valuestartdate,
      valueenddate
      ) VALUES (
      '$employeeid',
      '$value_type',
      '$value',
      '$start_date',
      '$end_date');";


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

      $employeeUpdate = "User added to employee value ";

      logEvent($db,"Employee Values updated",$employeeUpdate,$employeeid);
      
      header("location: viewEmployee.php?employeeID=$employeeid");

      } else {
         echo "Error: " . mysqli_error($db);
    }

    } else {
    echo "Employee not selected!!!";
   }
 
}

?>