<?php
require_once __DIR__ . "/../Febe.php";
$febe = new Febe;
$febe->setCurrentSubFolderLanguageCookie();
$contentType = "";
$availableContentTypes = array("nopwd");
if (!empty($_GET["intgrtn_contentType"])) {
    if (in_array($_GET["intgrtn_contentType"], $availableContentTypes)) {
        $contentType = $_GET["intgrtn_contentType"];
    }
}
function getTrackingUrl(): string
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://server.4markets.net/api/v2/offers/tracking-domain");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Referer: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    ]);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($httpCode != 200) {
        return "";
    }
    if (empty($response)) {
        return "";
    }

    $responseTrackingDomainJson = json_decode($response);

    if (empty($responseTrackingDomainJson)) {
        return "";
    }

    return $responseTrackingDomainJson->details->endpoint;
}

$trackingUrl = getTrackingUrl();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="theme-color" content="#081047">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Loading...</title>
    <base href="<?= $febe->getHref(); ?>">

    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="robots" content="">
    <link rel="stylesheet" href="css/animate.min.css">
    <link id="aos-style-link" href="content/aos.css" rel="stylesheet">
    <link rel="stylesheet" href="content/style.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="trades/trades.css">
    <link rel="stylesheet" href="content/custom.css">
    <link rel="stylesheet" href="js/videojs/video-js.css">
    <link rel="stylesheet" href="css/intgrtn.css">

    <!-- BEGIN intgrtn -->
    <script>
        window.intgrtnInit = function () {
            var path = "/";
            if (window.location.pathname.split("/")[1]) {
                path = "/" + window.location.pathname.split("/")[1] + "/";
            }
            window.intgrtn.setOptions({
                cookies: {
                    path: path
                },
            });
            window.intgrtn.events.on("get.project.details.success", function (response) {
                $(document).prop('title', response.data.project.name);
                $('#advisors').hide();
                $('.partners').hide();
            });
        };
        (function (d) {
            if (window.intgrtn) {
                return;
            }
            var s = d.createElement("script");
            var date = new Date();
            s.src = "<?php echo $trackingUrl ?>/api/v2/integration/app.js?v=2" + date.getFullYear().toString() + date.getMonth().toString() + date.getDate().toString() + date.getHours().toString() + Math.round(date.getMinutes() / 10).toString();
            d.getElementsByTagName("head")[0].appendChild(s);
        }(document));
    </script>
    <!-- END intgrtn -->
