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

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

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

    $period_id = mysqli_real_escape_string($db,$_POST['period_id']);
    $period_name = mysqli_real_escape_string($db,$_POST['period_name']);
    $start_date = mysqli_real_escape_string($db,$_POST['start_date']);
    $end_date = mysqli_real_escape_string($db,$_POST['end_date']);
    $workingDays = mysqli_real_escape_string($db,$_POST['workingDays']);

    $sqlUpdatePayroll = "UPDATE periods
    SET periodName = '$period_name',
    startDate = '$start_date',
    endDate = '$end_date',
    workingDays = '$workingDays'
    WHERE periodid = '$period_id';";

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

      $payrollUpdate = "User edited payroll " . $payroll_startdate . " to " . $payroll_enddate;

      $last_id = mysqli_insert_id($db);

      logEvent($db,"Payroll Edited",$payrollUpdate);
      
      header("location: payrolls.php");
      } else {
         echo "Error: " . mysqli_error($db);
    }
 
}

?>