<?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;

if (isset($_POST['nominative'])) {
        //variables to hold our submitted data with post     
       
        $fid=$_POST['fid'];
        $dateTimeZone = new DateTimeZone("Europe/Athens");
        $dateTime = new DateTime("now", $dateTimeZone);
        $timeOffset = $dateTimeZone->getOffset($dateTime);
        $date = time() + $timeOffset;
        
        $nominative=$_POST['nominative'];
        $phone=$_POST['phone'];
        $custmail=$_POST['custmail'];
        $cd_dob=$_POST['cd_dob'];
        $cd_flight=$_POST['flight'];
        $cd_hotel=$_POST['hotel'];
        $cd_hotelroom=$_POST['room'];
        $cd_dlnumber=$_POST['cd_dlnumber'];
        $cd_passnum=$_POST['cd_passnum'];
        $cd_address=$_POST['cd_address'];
        
        $oldnominative=$_POST['oldnominative'];
        $oldphone=$_POST['oldphone'];
        $oldcustmail=$_POST['oldcustmail'];
    
        $oldcd_dob=$_POST['oldcd_dob'];
$oldcd_flight=$_POST['oldcd_flight'];
$oldcd_hotel=$_POST['oldcd_hotel'];
$oldcd_hotelroom=$_POST['oldcd_hotelroom'];
$oldcd_dlnumber=$_POST['oldcd_dlnumber'];
$oldcd_address=$_POST['oldcd_address'];
$oldcd_passnum=$_POST['oldcd_passnum'];
        $action="Changed Reservation";
        $item="Customer Data";
        $details="Changed ".$item." from ".$oldnominative. " to ".$nominative.", </br>from ".$oldphone. " to ".$phone.",</br>from ".$oldcustmail. " to ".$custmail.",</br>from ".$oldcd_dob. " to ".$cd_dob.",</br>from ".$oldcd_flight. " to ".$cd_flight.",</br>from ".$oldcd_hotel. " to ".$cd_hotel.",</br>from ".$oldcd_hotelroom. " to ".$cd_hotelroom.",</br>from ".$oldcd_dlnumber. " to ".$cd_dlnumber.",</br>from ".$oldcd_passnum. " to ".$cd_passnum.",</br>from ".$oldcd_address. " to ".$cd_address;  
   
       

        $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, $fid, $user, $date, $action, $item, $details]);
        
            $sh = $db3->prepare("UPDATE jostj_vikrentcar_orders SET nominative=?, phone=?, custmail=?, cd_dob=? , cd_flight=?, cd_hotel=?, cd_hotelroom=?, cd_dlnumber=?, cd_passnum=?, cd_address=? WHERE id=?");
            $sh->execute([$nominative, $phone , $custmail , $cd_dob, $cd_flight, $cd_hotel, $cd_hotelroom, $cd_dlnumber, $cd_passnum, $cd_address, $fid]);
        
            $db3->commit();
            echo "<div class='alert alert-success'>Record Updated Succesfully</div><script>"; echo "window.location.replace('../reservation.php?id=$fid');";
            echo "</script>";   
        exit;
        } catch ( Exception $e ) {
            $db3->rollBack();
            echo "<div class='alert alert-danger'>Error updating record: </div>" . $e->getMessage();
        }
        $db3= null;
} ?>      