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

// 6 jegyű hardlock | segment(3);
if (isset($_GET["hlnum"])) $hlnum = $_GET["hlnum"];
else $hlnum = $_GET['serial'];

$ver    = $_GET['ver']; // akt: 2016 | segment(6);
$isid   = $_GET['isid'];
$npid   = $_GET['npid'];
$isTwTw = $_GET['twtw'];
$seatID = $_GET['seatid'];
$build  = $_GET['build'];

$isTwTw = $isTwTw == 'true';

crm_database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`p_versions` WHERE verName LIKE '%" . $ver . "%' LIMIT 1;");
$tmp = crm_database::getInstance()->fetchNext();
$ver = $tmp;

crm_database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum='" . $hlnum . "' AND prVerID='" . $ver['verID'] . "' LIMIT 1;");
$prog = crm_database::getInstance()->fetchNext();

if (empty($prog) == false) {
    if ($isid != '' && isset($isid)) {
        $softwarekey = Codegen::IsSoftwareKey($prog['prPass']);
        if ($softwarekey == false) // A regisztracional a gepazonositot kuldi a program, ez hardware kulcsnal nem alkalmazhato
            $isid = crm_hardlock::GetIsidFromPasswordForHardwareKeys($prog['prPass']);

        crm_hardlock::RegisterProgram($prog['prPass'], $isid, "", $npid, "", $isTwTw, $seatID, $build);
    }
    print $prog['prPass'];
}
