<?php
$hideLanguageDropdown = false;
$root = $_SERVER['DOCUMENT_ROOT'];
$headerScriptRoot = dirname(__FILE__, 2);//since header.php is always in subfolder, get 1 level above
if ($root == $headerScriptRoot) {
    $baseHref = '/';
} else {
    //get the first subfolder
    $baseHref = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "/", 1) + 1);
}
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 data-intgrtn-language="location" ng-app="app">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>The Wealth Matrix | Home</title>
    <base href="<?= $baseHref; ?>">

    <!-- main styles -->
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/intgrtnStyle.css">
    <link rel="stylesheet" href="css/intgrtn.css">
    <link rel="stylesheet" href="css/video-js.css">

    <link rel="shortcut icon" href="images/favicon/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon" sizes="114x114" href="images/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">

    <meta name="theme-color" content="#00b5a4">
    <meta name="msapplication-navbutton-color" content="#00b5a4">
    <meta name="apple-mobile-web-app-status-bar-style" content="#00b5a4">


    <script src="js/jquery.js"></script>
    <script src="libs/bootstrap/js/popover.js"></script>
    <script src="libs/bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <script src="js/app/angular.js" type="text/javascript"></script>
    <script src="js/app/angular-messages.js" type="text/javascript"></script>

    <script src="js/app/app.js" type="text/javascript"></script>
    <script src="js/app/HeaderController.js?v=1" type="text/javascript"></script>
    <script src="js/video.js"></script>

    <!-- BEGIN intgrtn -->
    <script>
        window.intgrtnInit = function () {
            let currentFolder;
            var reversedLocationPathArray = window.location.pathname.split("/").reverse();
            currentFolder = reversedLocationPathArray[0] !== "lp.php" ? reversedLocationPathArray[1] + "/" : "";

            var path = "/";
            if (window.location.pathname.split("/")[1]) {
                path = "/" + window.location.pathname.split("/")[1] + "/";
            }
            window.intgrtn.setOptions({
                cookies: {
                    path: path
                },
                forms: {
                    signup: {
                        onSuccess: {
                            redirectUrl: currentFolder + "thank-you2.php"
                        },
                    },
                },
            }, false);

            window.intgrtn.events.on("get.project.details.success", function (response) {
                var player = videojs('my-video', {
                    "autoplay": true,
                    "muted": true,
                    "controls": true,
                    "preload": "auto",
                    "controlBar": true,
                    "fluid": true
                });
                player.src({type: 'video/mp4', src: 'media/<?php echo $video ?>'});

            });

        };
        (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 -->
</head>
<body>
<div class="wrapper">
