<?php
$lpType = "";
$lpTypeParam = !empty($_GET["intgrtn_lpType"]) ? $_GET["intgrtn_lpType"] : null;
$lpTypeArray = ["3steps"];
if (in_array($lpTypeParam, $lpTypeArray)) {
    $lpType = $lpTypeParam;
}
$baseHref = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
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">

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<head>
    <!-- Core tags -->
    <meta charset="UTF-8">
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- #Core tags -->
	<base href="<?= $baseHref; ?>">

	<link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
    <!-- CSS Core -->
    <link rel="stylesheet" href="css/build.min.css">
    <link rel="stylesheet" href="css/animate.min.css">
    <!-- #CSS Core -->
    <link rel="stylesheet" href="css/all.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i&amp;display=swap"
          rel="stylesheet">
    <link rel="stylesheet" href="uislider/nouislider.min.css">
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/intgrtn.css">
    <!-- scripts-->
    <script src="js/jquery.min.js"></script>
    <!-- fonts -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans&amp;display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Noto+Sans|Roboto&amp;display=swap" rel="stylesheet">

    <title>BitSignal App</title>

    <script>
        window.intgrtnInit = function () {
            var path = "/";
            if (window.location.pathname.split("/")[1]) {
                path = "/" + window.location.pathname.split("/")[1] + "/";
            }
            window.intgrtn.setOptions({
                <?php if ($lpType == "3steps") { ?>
                forms: {
                    signup: {
                        buttons: {
                            generatePassword: {
                                show: true,
                            },
                        },
                        fields: {
                            passwordConfirm: {
                                show: false,
                                required: false,
                            },
                        },
                    },
                },
                <?php } ?>
                cookies: {
                    path: path
                },
            });

            window.intgrtn.events.on("get.project.details.success", function (response) {
            });
            window.intgrtn.events.on("parse.data.tags.form.signup.success", function (form) {
                $(form).find('.intgrtn-input-holder.intgrtn-input-holder-password').hide();
                $(form).find('[name="password"]').val(window.intgrtn.generatePassword());
            });
        };
        (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.getDay().toString() + date.getHours().toString();
            d.getElementsByTagName("head")[0].appendChild(s);
        }(document));
    </script>
