<?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);
            if ($thisDest != $fromPlace && !in_array($thisDest, $arrDispDestinations)) {
                $arrDispDestinations[] = $thisDest;
            }
        }
    }
}
$arrDispDestinations = array_unique($arrDispDestinations);
//echo '<pre>'; print_r($arrDispDestinations); exit;
/**
 *	Hotel Search
 */
if (empty($toDate) || $fromDate == $toDate) {
    $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);