<?php
ini_set('display_errors', 'true');
error_reporting(E_ALL);
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    // Retrieve form data
    $pattern = '/(([^)]+))/';
    preg_match($pattern, $_POST['DepartureCity'], $departure);
    preg_match($pattern, $_POST['ArrivalCity'], $destination);
    $departureDate = urlencode($_POST['DepartureDate']);
    $DepartureCity = $departure[1];
    $ArrivalCity = $destination[1];
    $url = 'https://tracker.flightview.com/RMServices/ConnectionBuilder/Connections.ashx';
    $requestData = array(
        'destinationCriteria' => $ArrivalCity,
        'destinationCriteriaLocationType' => 'A',
        'maxCT1' => 400,
        'maxCircuity' => 200,
        'maxElapsedTime' => 2400,
        'originCriteria' => $DepartureCity,
        'originCriteriaLocationType' => 'A',
        'requestDate' => $departureDate,
        'requestTime' => '00:01:00',
        'rtnRequestTime' => '00:01:00',
        'sortOrder' => 'D',
        'via1CriteriaLocationType' => 'A',
        'via2CriteriaLocationType' => 'A',
        'operatingCarrierOnly' => true,
        'numberOfStops' => 1,
        'includeRoutes' => true,
        'includeResults' => true,
        'includeMarkers' => true,
        'requestType' => 'outbound',
        'language' => 'en',
        'description' => 'outbound-connections',
        'includeCodeShare' => false,
        'nonStopDirect' => false,
        'dateFormat' => null,
        'timeFormat' => 'HH:mm',
    );
    $jsonData = json_encode($requestData);
    // Set up the HTTP headers
    $options = [
        'http' => [
            'header'  => "Content-type: application/jsonrn",
            'method'  => 'POST',
            'content' => $jsonData,
        ],
    ];
    $context  = stream_context_create($options);
    // Make the POST request
    $response = file_get_contents($url, false, $context);
    $flightData = json_decode($response, true);
}
$counter = 0
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        table {
            border-collapse: collapse;
            width: 60%;
        }
        th,
        td {
            border: 1px solid #dddddd;
            text-align: left;
            padding: 8px;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
<style id="wpr-lazyload-bg-container"></style><style id="wpr-lazyload-bg-exclusion"></style>
<noscript>
<style id="wpr-lazyload-bg-nostyle">.ui-icon,.ui-widget-content .ui-icon{--wpr-bg-cdef887e-a6a0-41ed-bec5-56e3749d203d: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_444444_256x240.png');}.ui-widget-header .ui-icon{--wpr-bg-c4d90d13-64c0-4726-9b5a-3eb985b006f0: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_444444_256x240.png');}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{--wpr-bg-8c2c6f84-9070-4e16-b49c-59826ef87b5c: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_555555_256x240.png');}.ui-state-active .ui-icon,.ui-button:active .ui-icon{--wpr-bg-554b90b8-d10f-407b-8fa2-93cd6d8aab37: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_ffffff_256x240.png');}.ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{--wpr-bg-405ce555-0c35-49c9-b487-70d0a4d4ee75: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_777620_256x240.png');}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{--wpr-bg-c68572f7-7a76-4c63-adc2-b90d94675aea: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_cc0000_256x240.png');}.ui-button .ui-icon{--wpr-bg-141a81a8-4987-4657-9d76-ba101ba8b677: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_777777_256x240.png');}.rll-youtube-player .play{--wpr-bg-446c143a-2134-4323-95b7-9d32702a7235: url('https://rosietaxicab.com/wp-content/plugins/wp-rocket/assets/img/youtube.png');}.elementor-130085 .elementor-element.elementor-element-2a36eac>.elementor-background-overlay{--wpr-bg-e3bd57ad-6e47-4f7d-a038-092f8d624452: url('https://cbsscevpfa.cloudimg.io/rosietaxicab.com/wp-content/uploads/2023/01/gettyimages-1143355576.webp');}</style>
</noscript>
<script type="application/javascript">const rocket_pairs = [{"selector":".ui-icon,.ui-widget-content .ui-icon","style":".ui-icon,.ui-widget-content .ui-icon{--wpr-bg-cdef887e-a6a0-41ed-bec5-56e3749d203d: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png');}","hash":"cdef887e-a6a0-41ed-bec5-56e3749d203d","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png"},{"selector":".ui-widget-header .ui-icon","style":".ui-widget-header .ui-icon{--wpr-bg-c4d90d13-64c0-4726-9b5a-3eb985b006f0: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png');}","hash":"c4d90d13-64c0-4726-9b5a-3eb985b006f0","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png"},{"selector":".ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button .ui-icon","style":".ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{--wpr-bg-8c2c6f84-9070-4e16-b49c-59826ef87b5c: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_555555_256x240.png');}","hash":"8c2c6f84-9070-4e16-b49c-59826ef87b5c","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_555555_256x240.png"},{"selector":".ui-state-active .ui-icon,.ui-button .ui-icon","style":".ui-state-active .ui-icon,.ui-button:active .ui-icon{--wpr-bg-554b90b8-d10f-407b-8fa2-93cd6d8aab37: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_ffffff_256x240.png');}","hash":"554b90b8-d10f-407b-8fa2-93cd6d8aab37","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_ffffff_256x240.png"},{"selector":".ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon","style":".ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{--wpr-bg-405ce555-0c35-49c9-b487-70d0a4d4ee75: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777620_256x240.png');}","hash":"405ce555-0c35-49c9-b487-70d0a4d4ee75","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777620_256x240.png"},{"selector":".ui-state-error .ui-icon,.ui-state-error-text .ui-icon","style":".ui-state-error .ui-icon,.ui-state-error-text .ui-icon{--wpr-bg-c68572f7-7a76-4c63-adc2-b90d94675aea: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_cc0000_256x240.png');}","hash":"c68572f7-7a76-4c63-adc2-b90d94675aea","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_cc0000_256x240.png"},{"selector":".ui-button .ui-icon","style":".ui-button .ui-icon{--wpr-bg-141a81a8-4987-4657-9d76-ba101ba8b677: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777777_256x240.png');}","hash":"141a81a8-4987-4657-9d76-ba101ba8b677","url":"https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777777_256x240.png"},{"selector":".rll-youtube-player .play","style":".rll-youtube-player .play{--wpr-bg-446c143a-2134-4323-95b7-9d32702a7235: url('https:\/\/rosietaxicab.com\/wp-content\/plugins\/wp-rocket\/assets\/img\/youtube.png');}","hash":"446c143a-2134-4323-95b7-9d32702a7235","url":"https:\/\/rosietaxicab.com\/wp-content\/plugins\/wp-rocket\/assets\/img\/youtube.png"},{"selector":".elementor-130085 .elementor-element.elementor-element-2a36eac>.elementor-background-overlay","style":".elementor-130085 .elementor-element.elementor-element-2a36eac>.elementor-background-overlay{--wpr-bg-e3bd57ad-6e47-4f7d-a038-092f8d624452: url('https:\/\/cbsscevpfa.cloudimg.io\/rosietaxicab.com\/wp-content\/uploads\/2023\/01\/gettyimages-1143355576.webp');}","hash":"e3bd57ad-6e47-4f7d-a038-092f8d624452","url":"https:\/\/cbsscevpfa.cloudimg.io\/rosietaxicab.com\/wp-content\/uploads\/2023\/01\/gettyimages-1143355576.webp"}]; const rocket_excluded_pairs = [];</script></head>
<body>
        <h1>Flight Search Results | Connections <?= $flightData['flightsCount']; ?></h1>
        <ul>
            <?php foreach ($flightData['results'] as $flight) : ?>
                <li>
                    <h3>Aircraft Name: <?= $flight['aircraftName']; ?></h3>
                    <ul>
                        <li>
                            <h3 style="display: flex; align-items:center;"><img decoding="async" src="https://tracker.flightview.com/FVAccess3/tools/routemapper/img/tail_logos/<?= $flight['operatedBy']; ?>.png" alt="Avatar"><?= '  ' . $flight['airline'] . ' - ' . $flight['operatedBy'] . $flight['flightNo']; ?></h3>
                            <table>
                                <thead>
                                    <tr>
                                        <th>routes</th>
                                        <th>Departure</th>
                                        <th>Arrival</th>
                                        <!-- Add more columns as needed -->
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($flightData['routes'] as $routes) : ?>
                                        <tr>
                                            <td><?= $routes['key']; ?></td>
                                            <td><?= $flight['departPortName'] . ' ✈️ ' . $flight['departureDateAsString'] . ' - ' . $flight['departureTimeAsString']; ?></td>
                                            <td><?= $flight['arrivalPortName'] . ' ✈️ ' . $flight['arrivalDateAsString'] . ' - ' . $flight['arrivalTimeAsString']; ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </li>
                    </ul>
                </li>
            <?php endforeach; ?>
        </ul>
<script>var rocket_beacon_data = {"ajax_url":"https:\/\/rosietaxicab.com\/wp-admin\/admin-ajax.php","nonce":"71139d0b9f","url":"https:\/\/rosietaxicab.com\/elementor-136759","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":null,"status":{"atf":true,"lrc":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800}</script><script data-name="wpr-wpr-beacon" src='https://rosietaxicab.com/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script><script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement("span"),this.deviceMode.id="elementor-device-mode-wpr",this.deviceMode.setAttribute("class","elementor-screen-only"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,":after").content.replace(/"/g,"");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(".elementor-invisible[data-settings]").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if("none"===n)return void t.classList.remove("elementor-invisible");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove("elementor-invisible"),t.classList.add("animated",n),this._removeAnimationSettings(t,e)},i);window.addEventListener("rocket-startLoading",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t="mobile"){const e=[""];switch(t){case"mobile":e.unshift("_mobile");case"tablet":e.unshift("_tablet");case"desktop":e.unshift("_desktop")}const i=[];return["animation","_animation"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener("DOMContentLoaded",RocketElementorAnimation.run);</script></body>
</html>