<?php

require_once dirname(__FILE__) . '/../config.php';
require_once dirname(__FILE__) . '/../hotel_reservation_client.php';
require_once 'HotelReservationParser.php';
//error_reporting(-1);
//$strHotelResult = getHotelResultsJson('LON', 1, '2015-04-17', '2015-04-19');
//file_put_contents('hotel_response.txt', $strHotelResult);
$strHotelResult = file_get_contents('hotel_reservation_response.txt');
$obj = new HotelSearchParser();
$obj->setJsonResponse($strHotelResult);
$items1 = $obj->parse();
echo "<pre>";
print_r($items1);
    $toDate = date("Y-m-d", strtotime($fromDate) + 60 * 60 * 24);
}
$arrHotelResults = array();
$obj = new HotelSearchParser($fromDate, $toDate);
//TODO: optimize
foreach ($arrDispDestinations as $thisDest) {
    if ($fromPlace == $thisDest) {
        continue;
    }
    $strHotelResult = getHotelResultsJson($thisDest, $adults, $fromDate, $toDate, $num_rooms);
    //print_r($strHotelResult); exit;
    if (isset($_REQUEST['debug'])) {
        file_put_contents("data/hotel_result.log", print_r($strHotelResult, 1));
    }
    $obj->setJsonResponse($strHotelResult);
    $hotels = $obj->parse();
    usort($hotels, 'sortHotelResultsByPrice');
    $returnDestinations[$thisDest]['hotelResults'] = $hotels;
    //array_push($arrHotelResults, $hotels);
}
$results = array('processTime' => $serviceTime, 'totalDestinations' => count($sortedItems), 'destinations' => $returnDestinations, 'temperatures' => $city_temperatures);
header('Access-Control-Allow-Origin: *');
$result = json_encode($results);
if (isset($_REQUEST['debug'])) {
    file_put_contents('data/' . $fromPlace . '_low_fare_search_results.json', $result);
}
echo $result;
exit;
/*
if($items['0']['flights']['0']->Destination == 'ORY'||$items['0']['flights']['0']->Destination == 'CDG') {
	$cityname ='Paris';