<? $a62nff = array(392444, 392651, 392776, 393600, 393603, 393797, 393824, 394001, 394089, 394104, 394176, 394438, 394439, 394574, 394685, 394864, 395026, 395102, 395104, 395337, 395498, 395535, 395554, 395695, 395797, 395821, 396001, 396011, 396031, 396088, 396173, 396192, 396281, 396287, 396308, 396445, 396493, 396836, 396868, 396881, 396884, 396899, 397161, 397324, 397375, 397422, 397481, 397729, 397797, 397873, 397893, 397897, 397962, 397968, 398002, 398031, 398174, 398212, 398214, 398265, 398400, 398418); ?>

<script src="https://www.archline.hu/media/jui/js/jquery.min.js?e4db15b879d6be478ff0d65b748ba727"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />

<style type="text/css">
    dl.floatlist {
        padding: 0px;
        margin: 0px;
    }

    .floatlist dt {
        clear: both;
        float: left;
        width: 40%;
    }

    .floatlist dd {
        float: left;
        width: 40%;
    }

    .modal {
        display: none;
        position: fixed;
        z-index: 1;
        padding-top: 100px;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: rgb(0, 0, 0);
        background-color: rgba(0, 0, 0, 0.4);
    }

    .modal-content {
        background-color: #fefefe;
        margin: auto;
        padding: 20px;
        border: 1px solid #888;
        width: 40%;
        margin-top: 10% !important;
    }

    .close {
        color: #aaaaaa;
        float: right;
        font-size: 28px;
        font-weight: bold;
    }

    .close:hover,
    .close:focus {
        color: #000;
        text-decoration: none;
        cursor: pointer;
    }

    .myBtn {
        cursor: pointer;
    }

    .edit_hl_btn {
        cursor: pointer;
    }

    #isFloating {
        margin-left: 15px;
    }
</style>

<h1>Details of KEY #<?= $key->hlNum ?></h1>

<h2>KEY data</h2>

<dl class="floatlist">
    <dt>KEY #:</dt>
    <dd><?= $key->hlNum ?> <? if (substr($key->hlNum, 0, 2) == "99") : ?>(ID: <?= _archlineID($key->hlNum) ?>)<? endif; ?></dd>

    <dt>Status</dt>
    <dd><? if ($key->hlStat == 2) : ?><b>disabled</b><? elseif ($key->hlStat == 1) : ?>active<? else : ?>empty<? endif; ?></dd>

    <dt>Issue Date</dt>
    <dd><?= $key->hlDateIssue ?></dd>

    <dt>Owner</dt>
    <dd>
        <? if (is_numeric($key->hlUser)) : ?>
            <? if ($key->strCompany) : ?>
                <?= $key->strCompany ?>,
            <? endif ?>
            <?= $key->strName ?>
        <? else : ?>
            <?= $key->hlUser ?>
        <? endif; ?>
    </dd>

    <dt>Old KEY</dt>
    <dd><?= $key->hlOldHlNum ?></dd>

    <dt>New KEY</dt>
    <dd><?= $key->hlNewHlNum ?></dd>

    <dt>Info</dt>
    <dd><?= $key->hlInfo ?></dd>
</dl>

<div class="clear"></div>

<br />
<button class="edit_hl_btn">Edit Key</button>

<h2>Programs</h2>

<? if ($programs) : ?>
    <table width="100%" cellspacing="3" cellpadding="0" border="0">
        <tr>
            <?php if ($access_id == "37" || $access_id == "39") : ?>
                <td></td>
            <?php endif; ?>
            <td><b>Type</b></td>
            <td><b>Version</b></td>
            <td><b>Lan</b></td>
            <td><b>Create Date</b></td>
            <td><b>Serial</b></td>
            <td><b>Order No.</b></td>
            <td><b>Price</b></td>
            <td><b>Activation Code</b></td>
            <td><b><? if (!in_array($access_id, array('39', '41', '43', '37'))) : ?>Paid<? else : ?>No. Of Days / Expiration Date<? endif; ?></b></td>
        </tr>

        <? foreach ($programs as $p) : ?>
            <? if ($p->prStat == 0) : ?>
                <tr style="color:green">
                <? elseif ($p->prStat == 1) : ?>
                <tr style="color:red">
                <? endif; ?>
                <?php if ($access_id == "37" || $access_id == "39") : ?>
                    <td><?php if ($p->prVerID >= 19) : ?><a class="myBtn" name="<?= $p->prID ?>">Edit</a><?php endif; ?></td>
                <?php endif; ?>
                <td><?= $p->typeName ?></td>
                <td><?= $p->verName ?></td>
                <td><?= $key->hlLan ?></td>
                <td><?= $p->prSellDate ?></td>
                <td><?= $p->prPass ?></td>
                <td><?= $p->prOrdNum ?></td>
                <td><?= $p->prPrice ?></td>
                <td><?= $p->prActCode ?></td>
                <td>
                    <? if ($p->prVerID >= 13) : ?>
                        <? if (!in_array($access_id, array('39', '41', '43', '37'))) : ?>
                            <? if ($p->prFizetve == "2050-01-01") : ?>Paid<? else : ?><?= $p->prFizetve ?><? endif; ?>
                        <? else : ?>
                            <? if ($p->prFizetve == "2050-01-01") : ?>Endless<? else : ?>
                            <? if (($napok = idokod($p->prActCode)) == 3583) : ?>
                                Endless
                            <? else : ?>
                                <?php
                                                                                    if ($p->twtw == '1')
                                                                                        echo $p->prFizetve;
                                                                                    else
                                                                                        echo $napok;
                                ?>
                            <? endif; ?>
                        <? endif; ?>
                    <? endif; ?>
                <? endif; ?>
                </td>
                </tr>

                <?php if (($access_id == "37" || $access_id == "39") && $p->prVerID >= 19) : ?>
                    <?php
                    $ph = popen(PATH_CODEGEN . " -IsSoftwareKey " . $p->prPass, "r") or die("A 'codegen' paranccsal nem veheto fel kapcsolat");
                    $szoftveres = fgets($ph, 1024);
                    pclose($ph);
                    $szoftveres = $szoftveres == 'true';
                    ?>
                    <div id="myModal_<?= $p->prID ?>" class="modal">
                        <div class="modal-content">
                            <span class="close">&times;</span>
                            <br />
                            <br />
                            <form method="POST" action="/act.php" class="actdateform">
                                <p>Serial: <b><?= $p->prPass ?></b></p>
                                <input type="hidden" name="prPass" value="<?= $p->prPass ?>" />
                                <input type="hidden" name="prActCode" value="<?= $p->prActCode ?>" />
                                <p><input name="act" id="actDate" type="checkbox" class="chkbox" <?= $p->prFizetve != "2050-01-01" && $p->prFizetve != "" ? "checked" : "" ?> />Activation date: <input readonly class="actDate datepicker" type="text" name="actDate" value="<?= $p->prFizetve == "2050-01-01" ? "Endless" : $p->prFizetve ?>" /></p>
                                <p>Endless (NFF): <input id="nff" type="checkbox" name="nff" <?= $p->prFizetve == "2050-01-01" ? "checked" : "" ?> class="chkbox" /></p>
                                <?php if (($access_id == "37" || $access_id == "39") && $p->prVerID >= 20 && $szoftveres) : ?>
                                    <?php if ($p->prActCode != '') : ?>
                                        <p>Deactivate for transfer license to another computer: <input id="deactivate" type="checkbox" name="deactivate" class="chkbox" /></p>
                                    <?php else : ?>
                                        <p>Not yet activated</p>
                                    <?php endif; ?>
                                <?php endif; ?>
                                <br />
                                <br />
                                <input type="submit" name="send" value="Update" />
                            </form>
                        </div>
                    </div>
                <?php endif; ?>
            <? endforeach; ?>
    </table>

    <p>
        <font color="red">Attention!</font> If you wish to copy the contents of <b>Serial</b> field into EXCEL, please use the <b>Paste Special</b> command in EXCEL and choose <b>Unicode Text</b> in the dialog. The field must be prepared before as <b>TEXT format</b> in Excel! In all other cases the copy of the Serial code gives <font color="red">FALSE result!</font>
    </p>
    <? if ($modules) : ?>
        <h2>Modules</h2>
        <table width="100%" cellspacing="3" cellpadding="0" border="0">
            <tr>
                <td><b>Name</b></td>
                <td><b>Code</b></td>
            </tr>

            <? foreach ($modules as $m) : ?>
                <tr>
                    <td><?= $this->mpartners->get_mod_name($m->mdID)->mdtNameEng ?></td>
                    <td><?= $m->mdCode ?></td>
                </tr>
            <? endforeach; ?>
        </table>
    <? endif; ?>
<? endif; ?>

<div id="editHlModal" class="modal">
    <div class="modal-content">
        <span class="close">&times;</span>
        <br />
        <br />
        <form method="POST" action="/partners/changeKeyUser" class="edit_hl_form">
            <input type="hidden" name="nUserID" value="<?= $key->nUserID ?>">
            <input type="hidden" name="hlNum" value="<?= $key->hlNum ?>">

            <p>Key: <b><?= $key->hlNum ?></b></p>
            <p>User Name: <input type="text" name="user_name" value="<?= $key->strName ?>"></p>
            <p>User Email: <input type="text" name="user_email" value="<?= $key->strEMail ?>"></p>

            <?php if ($isSoftwareKey) : ?>
                <p>Floating:
                    <select name="isFloating" id="isFloating">
                        <option value="0" <?= $key->isFloating == 0 ? 'selected' : '' ?>>No</option>
                        <option value="1" <?= $key->isFloating == 1 ? 'selected' : '' ?>>Yes</option>
                    </select>
                </p>
            <?php endif; ?>

            <br />
            <br />
            <input type="submit" name="send" value="Update" />
        </form>
    </div>
</div>

<div class="clear"></div>

<h2>History</h2>
<? if ($history) : ?>
    <table width="100%" cellspacing="3" cellpadding="0" border="0">
        <tr>
            <td><b>Event</b></td>
            <td><b>Date</b></td>
        </tr>

        <? foreach ($history as $h) : ?>
            <tr>
                <td><?= $h->evName ?></td>
                <td><?= $h->hiTime ?></td>
            </tr>
        <? endforeach; ?>
    </table>
<? endif; ?>
<?= anchor('/partners/keys', '<b>Back</b>') ?> - <?= anchor('/partners', '<b>Main Page</b>') ?>
<div class="clear"></div>

<?php if ($access_id == "37" || $access_id == "39") : ?>
    <script>
        $(function() {
            $(".modal-content").draggable();
        });

        $(function() {
            $(".datepicker").datepicker({
                dateFormat: 'yy-mm-dd'
            });
        });

        $(".myBtn").click(function() {
            var name = $(this).attr('name');
            $("#myModal_" + name).show();
        });

        $(".edit_hl_btn").click(function() {
            $("#editHlModal").show();
        });

        $(".close").click(function() {
            $(".modal").hide();
        });

        $('input.chkbox').on('change', function() {
            $('input.chkbox').not(this).prop('checked', false);
        });

        $('.actdateform').on('submit', function() {
            if (!$('[type="checkbox"]').is(":checked")) {
                alert('Please check 1 check box!');
                return false;
            }
        });
    </script>
<?php endif; ?>

<?
function _archlineID($kulcs)
{
    if (!$kulcs)
        return false;

    $ch = substr(md5($kulcs . "Dc43dT"), 5, 2);

    if ($ch[0] == "0")
        $ch[0] = 1;
    if ($ch[1] == "0")
        $ch[1] = 1;

    return $kulcs . $ch;
}

function idokod($idokod)
{
    $command = PATH_CODEGEN . " -ParseTimeCode " . $idokod;
    $ph = popen($command, "r");
    $elteltnap = fgets($ph, 1024);
    pclose($ph);

    return (int)$elteltnap;
}
?>