<?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['status'])) {
        //variables to hold our submitted data with post     
       
     

        $dateTimeZone = new DateTimeZone("Europe/Athens");
        $dateTime = new DateTime("now", $dateTimeZone);
        $timeOffset = $dateTimeZone->getOffset($dateTime);
        $date = time() + $timeOffset;
        $status= $_POST['status'];
        $webid= $_POST['webid'];
        $days = $_POST['days'];
        $source=$_POST['source'];
        $employee = $_POST['employee'];
        $nominative =$_POST['nominative'];
        $phone =$_POST['phone'];
        $custmail = $_POST['custmail'];
        $custdata = $_POST['custdata'];
        $ritiro = $_POST['ritiro'];					 
        $idplace = $_POST['idplace'];
        $idcar = $_POST['idcar'];
        $idtar=$_POST['idtar'];
        $optionals=$_POST['optionals'];
        $consegna = $_POST['consegna'];
        $idreturnplace = $_POST['idreturnplace'];					 
        $order_total = $_POST['order_total'];
        $totpaid = $_POST['totpaid'];
        $cust_cost = $_POST['cust_cost'];
        $extracosts = $_POST['extracosts'];      
        $idpayment = $_POST['idpayment'];
        $adminnotes = $_POST['adminnotes'];      
        $email_text = $_POST['email_text'];

        $ts = $_POST['ts'];      
        $dob=$_POST['Date_of_Birth']; 
       $dvln= $_POST['Driving_License_Number']; 
       $passn= $_POST['Passport_Number']; 
        $hotel=$_POST['Hotel'];
        $hotelroom=$_POST['Room'];
        $flight=$_POST['Flight_Number'];
        $address=$_POST['Address'];
        $zip=$_POST['Zip_Code'];
        $city=$_POST['City'];
        $country=$_POST['Country'];
      $addrescomb=$address.", ".$city.", ".$zip.", ".$country;

        $custdata=preg_replace('/\r?\n$/', ' ', $custdata);
        $adminnotes=preg_replace('/\r?\n$/', ' ', $adminnotes);
        $email_text=preg_replace('/\r?\n$/', ' ', $email_text);
   
        $status = $db2->real_escape_string($status);

        $db3->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        try {
            $db3->beginTransaction();          
        
            $sh = $db3->prepare("INSERT INTO jostj_vikrentcar_orders (id, custdata, ts, status, idcar, days, ritiro, consegna, idtar, optionals, custmail, idplace, idreturnplace, totpaid, idpayment, order_total, phone, nominative, adminnotes, cust_cost, extracosts, source, employee,  webid, cd_flight, cd_hotel, cd_dob, cd_address, cd_passnum, cd_dlnumber, cd_hotelroom) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ? )");
            $sh->execute([NULL, $custdata, $ts, $status, $idcar, $days, $ritiro, $consegna, $idtar, $optionals, $custmail, $idplace, $idreturnplace, $totpaid, $idpayment, $order_total, $phone, $nominative, $adminnotes, $cust_cost, $extracosts, $source, $employee, $webid, $flight, $hotel, $dob, $addrescomb, $passn, $dvln, $hotelroom]);

            $fid=$db3->lastInsertId();
           
        
            $db4->beginTransaction();
        
            $sh = $db4->prepare("UPDATE jos8r_vikrentcar_orders SET backoffice=?  WHERE id=?");
            $sh->execute([1, $webid]);
        
            $db3->commit();
            $db4->commit();
          
            echo "<div class='alert alert-success'>Record Updated Succesfully</div><script>"; echo "window.location.replace('../reservation.php?id=$fid');";
            echo "</script>";   
        exit;
        } catch ( PDOException  $e ) {
            $db3->rollBack();
            echo "<div class='alert alert-danger'>Error updating record: </div>" . $e->getMessage();
        }
        $db3= null;
    }
    ?>      