<?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['company_id'])) {

    $companyid = mysqli_real_escape_string($db,$_POST['company_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 valuesbycompany (
      companyid,
      valuename,
      value,
      valuestartdate,
      valueenddate
      ) VALUES (
      '$companyid',
      '$value_type',
      '$value',
      '$start_date',
      '$end_date');";


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

      $employeeUpdate = "User added to company value ";

      logEvent($db,"Company Values updated",$employeeUpdate,$last_id);
      
      header("location: companysettings.php");

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

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

?>