<?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'] : '';
$date   = '';
$format = '';

$btnClass = 'blue';

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

if ($ctrID == 36) {
    $date       = date('Y-m-d', strtotime(date('Y-m-d') . ' + 1 days'));
    $format     = 'yyyy-mm-dd';
    $logo       = 'https://archlinexp.com/public/img/icons/ARCHLineXP_logo_yellow_gray_web_2.png';
    $favicon    = 'favicon_1.ico';
    $locale     = 'hu';
    $error      = CRM_Error::serverDownHun;
} else {
    $date       = date('d-m-Y', strtotime(date('d-m-Y') . ' + 1 days'));
    $format     = 'dd-mm-yyyy';
    $logo       = 'https://archlinexp.com/public/img/icons/ARCHLineXP_logo_ARCHITECT_2017_cube_with_text.png';
    $favicon    = 'favicon_2.ico';
    $locale     = '';
    $error      = CRM_Error::serverDownEng;
}

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

if (!crm_hardlock::isEmergencyServer($_GET['secondary'])) {
    $query = "SELECT * FROM `" . SYNCADATBAZIS . "`.`floating_licenses` WHERE seatID = ?";
    Database::getInstance()->query($query, array('s', $seatID));
    $floatingLic = Database::getInstance()->fetchNext();

    $isOffline = !empty($floatingLic) && $floatingLic['offline_expiration_date'] != '' && $floatingLic['offline_expiration_date'] >= date('Y-m-d');

    $resource = new Resource($ctrID);

    if ($isOffline) {
        if ($ctrID == 36)
            $date = date('Y-m-d', strtotime($floatingLic['offline_expiration_date']));
        else
            $date = date("d-m-Y", strtotime($floatingLic['offline_expiration_date']));
    }
}
?>

<!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>Floating License</title>

    <link href="https://<?= $_SERVER['SERVER_NAME'] ?>/public/img/icons/<?= $favicon ?>" rel="shortcut icon" type="image/vnd.microsoft.icon" />

    <link href="https://<?= $_SERVER['SERVER_NAME'] ?>/templates/shaper_helix3/css/template.css" rel="stylesheet" type="text/css" />
    <link href="https://<?= $_SERVER['SERVER_NAME'] ?>/components/com_sppagebuilder/assets/css/sppagebuilder.css" rel="stylesheet" type="text/css" />
    <link href="https://<?= $_SERVER['SERVER_NAME'] ?>/templates/shaper_helix3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="https://<?= $_SERVER['SERVER_NAME'] ?>/maintenance/webform/public/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css" />

    <script src="https://<?= $_SERVER['SERVER_NAME'] ?>/media/jui/js/jquery.min.js?45c2abef66fd7fb09cdec63c35078ba0" type="text/javascript"></script>
    <script src="https://<?= $_SERVER['SERVER_NAME'] ?>/maintenance/webform/public/js/bootstrap-datepicker.min.js"></script>
    <script src="https://<?= $_SERVER['SERVER_NAME'] ?>/maintenance/webform/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('11481') ?></b></p>
                    <br>
                </div>

                <form action="progress.php" method="POST">
                    <input type="hidden" name="action" value="offlineFloating" />
                    <input type="hidden" name="session" value="<?= $session ?>" />
                    <input type="hidden" name="seatID" value="<?= $seatID ?>" />
                    <input type="hidden" name="serial" value="<?= $serial ?>" />

                    <div class="row">
                        <div class="col-sm-2">
                            <p class="main-p"><b><?= $resource->getDlgString('12626') ?>:</b></p>
                        </div>

                        <div class='col-sm-3'>
                            <div class="form-group">
                                <div id="filterDate2">
                                    <div class="input-group date" data-date-format="<?= $format ?>">
                                        <input type="text" class="form-control" name="actDate" value="<?= $date ?>" placeholder="<?= $format ?>">
                                        <div class="input-group-addon">
                                            <span class="glyphicon glyphicon-th"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class='col-sm-3'>
                            <input type="submit" name="actSubmit" id="btn-1677854427399" class="sppb-btn sppb-btn-rounded <?= $btnClass ?>" value="<?= $resource->getDlgString('11483') ?>">
                        </div>
                    </div>

                </form>
            </div>

            <?php if ($isOffline) : ?>
                <div class="row">
                    <form action="progress.php" method="POST">
                        <input type="hidden" name="action" value="removeOffline" />
                        <input type="hidden" name="session" value="<?= $session ?>" />
                        <input type="hidden" name="seatID" value="<?= $seatID ?>" />
                        <input type="hidden" name="serial" value="<?= $serial ?>" />

                        <div class='col-sm-3'>
                            <input type="submit" name="actSubmit" id="btn-1677854427400" class="sppb-btn sppb-btn-danger sppb-btn-rounded" value="<?= $resource->getDlgString('11484') ?>">
                        </div>
                    </form>
                </div>
            <?php endif; ?>

            <div class="row">
                <div class="col-sm-12">
                    <br>
                    <p><?= $resource->getDlgString('11482', '', true) ?></p>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <script>
        $('.input-group.date').datepicker({
            format: "<?= $format ?>",
            language: '<?= $locale ?>',
            startDate: '+1d',
            endDate: '+15d'
        });
    </script>
</body>

</html>