<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('../include/auth.php');
include('../include/lskfjwfe.php');
include('../include/header.php');
$user=$userid;
$fid=$_GET['fid'];
if (isset($_POST['contid'])) {
        //variables to hold our submitted data with post

       
       $resid=$_POST['fid'];
       
        $contid=$_POST['contid'];
      $cancreason=$_POST['reason'];
        $action="Cancelled";
        $item="Contract";
        $details="Cancelled ".$item."id:".$contid;  
        $dateTimeZone = new DateTimeZone("Europe/Athens");
        $dateTime = new DateTime("now", $dateTimeZone);
        $timeOffset = $dateTimeZone->getOffset($dateTime);
        $date = time() + $timeOffset;
 
        
       

        $db3->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        try {
            $db3->beginTransaction();
            
            $sh = $db3->prepare("INSERT INTO reservation_log (reservation_log_id, reservation_log_res, reservation_log_user, reservation_log_date, reservation_log_action, reservation_log_item, reservation_log_details) VALUES (?, ?, ?,?, ?, ?,? )");
            $sh->execute([NULL, $resid, $user, $date, $action, $item, $details]);
        
            $sh = $db3->prepare("UPDATE contracts SET cont_cancelled=?, cont_canc_reason=? WHERE contract_id=?");
            $sh->execute([1, $cancreason, $contid]);

            $db3->commit();
            echo "<div class='alert alert-success'>Record Updated Succesfully</div><script>"; echo "window.location.replace('../reservation.php?id=$resid');";
            echo "</script>";   
        exit;
        } catch ( Exception $e ) {
            $db3->rollBack();
            echo "<div class='alert alert-danger'>Error updating record: </div>" . $e->getMessage();
        }
        $db3= null;
} ?>      