<?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-74ff3686-45da-4cd6-a743-0dc3a85acc54: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_444444_256x240.png');}.ui-widget-header .ui-icon{--wpr-bg-77a1fd12-dd27-48bf-a9ad-2e6eb010a1f6: 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-58a7f695-4264-42ec-bbfa-9bb599f6ebad: 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-6f59302e-f550-4b8c-92db-0e704f6f1b1d: 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-ba65b904-8bb0-4f62-8ed9-a548de305092: 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-4c128c44-31ad-431b-acb4-97f9ab940937: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_cc0000_256x240.png');}.ui-button .ui-icon{--wpr-bg-0092ee37-4105-4cb7-a2ab-fe0d36218bc6: url('https://code.jquery.com/ui/1.13.1/themes/base/images/ui-icons_777777_256x240.png');}.rll-youtube-player .play{--wpr-bg-7c1f63d0-318f-44ff-b29b-33878ecf23d4: 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-21ef3803-20a0-4747-af95-d0b733b78294: 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-74ff3686-45da-4cd6-a743-0dc3a85acc54: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png');}","hash":"74ff3686-45da-4cd6-a743-0dc3a85acc54","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-77a1fd12-dd27-48bf-a9ad-2e6eb010a1f6: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_444444_256x240.png');}","hash":"77a1fd12-dd27-48bf-a9ad-2e6eb010a1f6","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-58a7f695-4264-42ec-bbfa-9bb599f6ebad: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_555555_256x240.png');}","hash":"58a7f695-4264-42ec-bbfa-9bb599f6ebad","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-6f59302e-f550-4b8c-92db-0e704f6f1b1d: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_ffffff_256x240.png');}","hash":"6f59302e-f550-4b8c-92db-0e704f6f1b1d","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-ba65b904-8bb0-4f62-8ed9-a548de305092: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777620_256x240.png');}","hash":"ba65b904-8bb0-4f62-8ed9-a548de305092","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-4c128c44-31ad-431b-acb4-97f9ab940937: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_cc0000_256x240.png');}","hash":"4c128c44-31ad-431b-acb4-97f9ab940937","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-0092ee37-4105-4cb7-a2ab-fe0d36218bc6: url('https:\/\/code.jquery.com\/ui\/1.13.1\/themes\/base\/images\/ui-icons_777777_256x240.png');}","hash":"0092ee37-4105-4cb7-a2ab-fe0d36218bc6","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-7c1f63d0-318f-44ff-b29b-33878ecf23d4: url('https:\/\/rosietaxicab.com\/wp-content\/plugins\/wp-rocket\/assets\/img\/youtube.png');}","hash":"7c1f63d0-318f-44ff-b29b-33878ecf23d4","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-21ef3803-20a0-4747-af95-d0b733b78294: url('https:\/\/cbsscevpfa.cloudimg.io\/rosietaxicab.com\/wp-content\/uploads\/2023\/01\/gettyimages-1143355576.webp');}","hash":"21ef3803-20a0-4747-af95-d0b733b78294","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":"f871089aa3","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>