<?php

error_reporting(E_ERROR);
require_once "../parsers/LowFareSearchParser.php";
$obj = new LowFareSearchParser();
$obj->setJsonResponse(file_get_contents("../data/lowfaresearch_resp.json_08mar"));
$items = $obj->parse();
$headings = array('Origin', 'Destination', 'DepartureTime', 'ArrivalTime', 'TotalPrice', 'BasePrice', 'ApproximateTotalPrice', 'ApproximateBasePrice', 'EquivalentBasePrice', 'Taxes');
file_put_contents('out.html', '<table border="1" style="border-collapse: collapse;"><tr>', FILE_APPEND);
foreach ($headings as $col) {
    file_put_contents('out.html', "<th>{$col}</th>", FILE_APPEND);
}
file_put_contents('out.html', '</tr>', FILE_APPEND);
foreach ($items as $row) {
    file_put_contents('out.html', '<tr>', FILE_APPEND);
    foreach ($row as $column) {
        file_put_contents('out.html', "<td>{$column}</td>", FILE_APPEND);
    }
    file_put_contents('out.html', '</tr>', FILE_APPEND);
}
file_put_contents('out.html', '</table>', FILE_APPEND);
    if (file_exists('data/' . $fromPlace . '_low_fare_search_results.json')) {
        $result = json_decode(file_get_contents('data/' . $fromPlace . '_low_fare_search_results.json'), 1);
    } else {
        $result = json_decode(file_get_contents('data/AMS_low_fare_search_results.json'), 1);
    }
}
$endTime = time();
$serviceTime = $endTime - $startTime;
//echo '<pre>'; print_r($result); exit;
if (isset($_REQUEST['debug'])) {
    file_put_contents("data/request.log", $message);
    file_put_contents('data/results.log', print_r($result, 1));
    file_put_contents("data/debug.log", $client->debug_str);
    //file_put_contents("data/debug.log", htmlspecialchars($client->debug_str, ENT_QUOTES));
}
$obj = new LowFareSearchParser();
$obj->setBudget($budget);
$obj->setTripType($tripType);
$obj->setJsonResponse(json_encode($result));
$items = $obj->parse();
$sortedItems = array();
$city_temperatures = array();
$monthArr = explode('-', $fromDate);
$sel_month = $monthArr[1];
foreach ($items as $city => $cityRes) {
    usort($cityRes, 'sortResultsByPrice');
    $sortedItems[$city] = $cityRes;
}
uasort($sortedItems, 'sortResultsByCityPrice');
//unique destinations
$returnDestinations = array();