<?php
error_reporting(E_ERROR | E_PARSE);

if (!class_exists('Authenticate')) require_once("common_cadline_libraries/crm_test.class.php");

$session        = isset($_GET['session']) ? $_GET['session'] : '';
$authCode       = isset($_GET['authCode']) ? $_GET['authCode'] : '';
$decodedSession = base64_decode($session);

if (!crm_hardlock::isEmergencyServer($_GET['secondary'])) {
    $auth = new Authenticate();
    $auth->setAuthCode($authCode);
    $auth->setAuthSession($session);
    $auth->auth();
}

$ctrID = isset($_GET['cnt']) ? $_GET['cnt'] : '';
$param = isset($_GET['param']) ? $_GET['param'] : '';

$privatekey     = Webform::GetWebformPrivateKey();
$decoded_param  = Webform::decode($privatekey, $decodedSession, $param); // Adat decode-olása
$decoded_param  = "?{$decoded_param}";
$serial         = Webform::get_valueFromStringUrl($decoded_param, "password");
$isid           = Webform::get_valueFromStringUrl($decoded_param, "isid");
$npid           = Webform::get_valueFromStringUrl($decoded_param, "npid");
$seatID         = Webform::get_valueFromStringUrl($decoded_param, "seatid");
$se             = Webform::get_valueFromStringUrl($decoded_param, "se");

$btnClass = 'blue';

if (!crm_hardlock::isEmergencyServer($_GET['secondary']))
    $resource = new Resource($ctrID);

if ($ctrID == 36) {
    $favicon    = 'favicon_1.ico';
    $logo       = 'images/logo_hun.png';
    $webPage    = 'https://www.archline.hu/';
    $lang       = 'hu-HU';
    $langFile   = 'hun';
    $error      = CRM_Error::serverDownHun;
} else {
    $favicon    = 'favicon_2.ico';
    $logo       = 'images/logo_eng.png';
    $webPage    = 'https://www.archlinexp.com/';
    $lang       = 'en-GB';
    $langFile   = 'eng';
    $error      = CRM_Error::serverDownEng;
}

if ($se == 'LT') {
    $btnClass   = 'lt-blue';
    $logo       = '/images/2022/02/07/logo.png';
    $bodyClass  = 'lt-body';
    $inputFocus = 'lt-input-focus';
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PIN</title>

    <link href="/public/img/icons/<?= $favicon ?>" rel="shortcut icon" type="image/vnd.microsoft.icon" />

    <link href="/templates/shaper_helix3/css/template.css" rel="stylesheet" type="text/css" />
    <link href="/components/com_sppagebuilder/assets/css/sppagebuilder.css" rel="stylesheet" type="text/css" />
    <link href="/templates/shaper_helix3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="public/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css" />

    <script src="/media/jui/js/jquery.min.js?45c2abef66fd7fb09cdec63c35078ba0" type="text/javascript"></script>
    <script src="public/js/bootstrap-datepicker.min.js"></script>
    <script src="public/js/bootstrap-datepicker.hu.min.js"></script>

    <style>
        p {
            font-size: 20px;
        }

        .sppb-btn {
            font-size: 13px;
            font-weight: bold;
        }

        .logo {
            display: block;
            margin-left: auto;
            margin-right: auto;
        }

        .blue {
            background-color: #1E90FF;
            border-color: #1E90FF;
            color: white;
        }

        .blue:hover {
            color: #fff;
            background-color: #286090;
            border-color: #204d74;
        }

        .lt-blue {
            background-color: #75d3c1;
            border-color: #75d3c1;
            color: white;
        }

        .lt-blue:hover {
            background-color: #75d3c1;
            border-color: #75d3c1;
            opacity: 0.75;
        }

        #al_error {
            text-align: center;
        }

        .main-p {
            text-align: center;
            font-size: 26px;
        }
    </style>
</head>

<body>
    <div class="container">
        <br />

        <div class="row">
            <img src="<?= $logo ?>" class="logo" alt="" srcset="">
        </div>
        <br>
        <br>

        <?php if (crm_hardlock::isEmergencyServer($_GET['secondary'])) : ?>
            <h1 id="al_error"><?= $error ?></h1>
        <?php else : ?>
            <div class="row">
                <div class="col-sm-12">
                    <p class="main-p"><b><?= $resource->getDlgString('11497') ?></b></p>
                    <br>
                </div>

                <form id="login_form" action="progress.php" method="POST">
                    <input type="hidden" name="action" value="hlPin">
                    <input type="hidden" name="session" value="<?= $session ?>" />
                    <input type="hidden" name="serial" value="<?= $serial ?>">
                    <input type="hidden" name="seatID" value="<?= $seatID ?>">
                    <input type="hidden" name="secondary" value="<?= $_GET['secondary'] ?>">

                    <div class="col-sm-3"></div>

                    <div class='col-sm-1' style="margin-left: 50px;">
                        <div class="form-group" style="margin-left: 50px; margin-top: 5px">
                            <label>PIN:</label>
                        </div>
                    </div>

                    <div class='col-sm-2'>
                        <div class="form-group">
                            <input type="password" name="pin-code" id="pin-code">
                        </div>
                    </div>

                    <div class='col-sm-3' style="margin-left: 20px;">
                        <input type="submit" name="pinSubmit" id="btn-1677854427399" class="sppb-btn sppb-btn-rounded <?= $btnClass ?>" value="<?= $resource->getDlgString('11498') ?>">
                    </div>
                </form>
            </div>
        <?php endif; ?>
    </div>
</body>

<script>
    $("#pin-code").focus();
</script>

</html>