<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$headerScriptRoot = dirname(__FILE__, 2);
if ($root == $headerScriptRoot) {
	$baseHref = '/';
} else {
	$baseHref = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "/", 1) + 1);
}
$baseHref = str_replace("\\", "/", $baseHref);
setcookie("intgrtn_language", $requestedPageTranslationIso, time() + (86400 * 30), $baseHref);
$contentType = "";
$availableContentTypes = array("nopwd", "genpwd");
if (!empty($_GET["intgrtn_contentType"])) {
	if (in_array($_GET["intgrtn_contentType"], $availableContentTypes)) {
		$contentType = $_GET["intgrtn_contentType"];
	}
}
$lpType = !empty($_GET["intgrtn_lpType"]) ? $_GET["intgrtn_lpType"] : "";
function getRegistrationForm($lpType) {
    switch ($lpType) {
        case "1step":
            $formType = "one-step-signup.php";
            break;
        case "2steps":
            $formType = "two-steps-signup.php";
            break;
        default:
            $formType = "one-step-signup.php";
    }
    return __DIR__ . "/../common/" . $formType;
}
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">
    <title>Tesler</title>
    <base href="<?= $baseHref; ?>">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="Tesler">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/style.css">
    <link rel="shortcut icon" href="img/ico.png" type="image/png">

    <script type="text/javascript">
        function today(delta) {
            var ld = new Date(Date.now() + (86400000 * delta));
            return document.write(ld.toLocaleDateString());
        }
    </script>

    <script src="js/jquery.min.js"></script>

	<link rel="stylesheet" href="js/videojs/video-js.css">
	<script type="text/javascript" src="js/videojs/video.js"></script>
	<link rel="stylesheet" href="css/intgrtn.css?v=2">
