<?php
global $access;
if ($access != 1) {
    exit("Direct Access not allowed");
}
require_once('db.php');
$page_name = 'itinerario.php';
include('currency.php');
//Datos del formulario
if (isset($_POST['intinerary']) && ($_POST['email'])) {
    
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $email = mysqli_escape_string($conn, $_POST['email']);
    } else {
        header("Location: reservation.php?error=1");
    }
    
    if (is_numeric($_POST['intinerary'])) {
        $intinerary            = mysqli_escape_string($conn, $_POST['intinerary']);
        //verifica si el itinerario esta en nuestra base de datos
        $itinerarioactivo      = mysqli_query($conn, "SELECT * FROM itineraries AS iti JOIN transactions AS tra ON iti.itinerary_id = tra.itinerario_id WHERE iti.itinerary_id = '$intinerary' AND iti.email_owner = '$email' AND cancelled = '0' LIMIT 1 ");
        $itinerarioactivototal = mysqli_num_rows($itinerarioactivo);
        if ($itinerarioactivototal > 0) {
            $itinerarioactivoData = mysqli_fetch_array($itinerarioactivo);
            $totalrooms           = $itinerarioactivoData['rooms_number'];
            $totaladults          = $itinerarioactivoData['total_adults'];
            $totalchildren        = $itinerarioactivoData['total_children'];
            $email_client         = $email;
            $itinerary_id         = $intinerary;
            require_once('inc/libraries-bgo/view-itinerary.php');
            $id = $hotelId;
            require_once('inc/libraries-bgo/hotel-detail.php');
            require_once('inc/libraries-bgo/hotel-amenities.php');
        } elseif ($itinerarioactivototal == 0) {
            header("Location: reservation.php?error=4");
        }
        
    } else {
        header("Location: reservation.php?error=2");
    }
    
} else {
    header("Location: reservation.php?error=3");
}

include('inc/page_query.php');
?>