<?php
if (!class_exists('crm_hardlock')) require_once("common_cadline_libraries/crm_hardlock.class.php");

session_start();
if (!isset($_SESSION["session"]) || $_SESSION["session"] == '') {
    header('Location https://www.archlinexp.com/maintenance/webform/login.php');
}

$host = $_SERVER['HTTP_HOST'];
if ($host == "www.archlinexp.com") {
    $password = 'Serial number';
    $computer_name = 'Computer name';
    $exreg = 'Exchange registration';
    $type = 'Program type';
} else {
    $password = 'Sorozatszám';
    $computer_name = 'Gépnév';
    $exreg = 'Regisztráció áthozatala';
    $type = 'Program típus';
}

$action = 'exchange_registration';

$privatekey     = Webform::GetWebformPrivateKey();
$session        = base64_decode($_SESSION["session"]);
$encoded_param  = $_SESSION["param1"] . $_SESSION["param2"]; // Encode-olt adat
$param          = crm_hardlock::decode($privatekey, $session, $encoded_param); // Adat decode-olása
$param          = "?" . $param;

$serial     = crm_hardlock::get_valueFromStringUrl($param, "password");
$type_code  = crm_hardlock::GetTypeFromPassword($serial);
$type_name  = crm_hardlock::GetTypeName($type_code);

crm_database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = '{$serial}'");
$program = crm_database::getInstance()->fetchNext();

crm_database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE id = '" . $program['computer_id'] . "'");
$computer = crm_database::getInstance()->fetchNext();
?>

<html>

<head>
    <link rel="stylesheet" href="../css/bootstrap.min.css" />

    <style>
        .prg_container {
            color: #1E90FF;
        }
    </style>
</head>

<body>
    <div class="container">
        <form method="GET" action="https://www.archlinexp.com/maintenance/webform/progress.php">
            <input type="hidden" name="action" value="<?= $action ?>" />
            <input type="hidden" name="session" value="<?= $_SESSION['session'] ?>" />
            <input type="hidden" name="param" value="<?= $encoded_param ?>" />
            <div class="prg_container">
                <b><?= $type ?>:</b> <?= $type_name ?> <br />
                <b><?= $password ?>:</b> <?= $program['serial'] ?> <br />
                <b><?= $computer_name ?>:</b> <?= $computer['computer_name'] ?>
            </div>
            <br />

            <input type="submit" name="exreg" class="btn btn-warning" value="<?= $exreg ?>" />
        </form>
    </div>
</body>

</html>