<?php
//DB Connect
require_once('../../db.php');
//Data
$page_link    = mysqli_escape_string($conn, $_POST['page_link']);
$searching    = mysqli_escape_string($conn, $_POST['searching']);
//Data for search
$destino      = mysqli_escape_string($conn, $_POST['destination']);
$ota_id       = mysqli_escape_string($conn, $_POST['ota_id']);
$ota_priority = mysqli_escape_string($conn, $_POST['ota_priority']);
$element_type = mysqli_escape_string($conn, $_POST['element_type']);
$element_id   = mysqli_escape_string($conn, $_POST['element_original_id']);
//aditional data
require_once('../data-bgo/booking-data-in.php');
require_once('../data-bgo/booking-data-send.php');

if ($element_type == '1') { //element 1 is the hotel
    $mapa          = mysqli_query($conn, "SELECT hotel_name, longitud, latitud FROM hotels WHERE hotel_id = '$element_id' ");
    $mapaData      = mysqli_fetch_array($mapa);
    $hotelname     = $mapaData['hotel_name'];
    $hotellongitud = $mapaData['longitud'];
    $hotellatitud  = $mapaData['latitud'];
    $hotelcity     = '';
    header('Location: ../../hotel.php?hotelid=' . $ota_id . '&hotelname=' . $hotelname . '&ota_priority=' . $ota_priority . '&element_id=' . $element_id . '&longitud=' . $mapaData['longitud'] . '&latitud=' . $mapaData['latitud'] . '&guests=' . $guests . '&' . $datosbusqueda);
    
} elseif ($element_type == '2') { //element 2 is the city
    header('Location: ../../hotel-list.php?sort=pricelow&typesort=price&destino=' . $destino . '&city_id=' . $element_id . '&' . $datosbusqueda);
} else {
    $element_type         = 2;
    //search active inventory
    $inventarioactivo     = mysqli_query($conn, "SELECT inve_code FROM inventory WHERE inve_active = '1' ");
    $inventarioactivoData = mysqli_fetch_array($inventarioactivo);
    $codigoinventario     = $inventarioactivoData['inve_code'];
    //find the element id of the city in our database
    $ciudadlocal          = mysqli_query($conn, "SELECT element_name, element_id from approved_inventory WHERE microsite_inventory_code = '$codigoinventario' AND element_type = '2' AND active = '1' AND publish = '1' AND deleted = '0' AND element_name like '%" . $destino . "%' LIMIT 1 ");
    $ciudadlocalData      = mysqli_fetch_array($ciudadlocal);
    $element_id           = $ciudadlocalData['element_id'];
    $destino              = $ciudadlocalData['element_name'];
    header('Location: ../../hotel-list.php?sort=pricelow&typesort=price&destino=' . $destino . '&city_id=' . $element_id . '&' . $datosbusqueda);
}
?>