<?php
/*
 * @author     M2E Pro Developers Team
 * @copyright  M2E LTD
 * @license    Commercial use is forbidden
 */

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Configuration_License_Form */

?>

<div id="block_notice_configuration_license" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Billing Info'); ?>">
    <?php echo Mage::helper('M2ePro')->__(
        'To use M2E Pro, you need:
        <ul class="list">
            <li><strong>M2E Accounts registration.</strong> You were automatically registered on <a href="%url1%" target="_blank">M2E Accounts</a> with the email used during the initial setup of M2E Pro. 
            There you can manage your Subscription and Billing information.
            <li><strong>License Key.</strong> Obtain a License Key in <a href="%url1%" target="_blank">M2E Accounts</a> to activate your M2E Pro installation.
            Find more details in <a href="%url2%" target="_blank">this article</a></li>
        </ul>
        <br>
        Click <strong>Save Config</strong> if you make any changes.
        <br><br>
        If you need assistance, contact Billing at <a href="mailto:billing@m2epro.com">billing@m2epro.com</a>.',
        Mage::helper('M2ePro/Module_Support')->getAccountsUrl(),
        Mage::helper('M2ePro/Module_Support')->getSupportUrl('/support/solutions/articles/9000206895')
    ); ?>
</div>

<script type="text/javascript">

    // General for all tabs
    //-----------------------------
    M2ePro.url.add(<?php echo json_encode(Mage::helper('M2ePro')->getControllerActions('adminhtml_configuration_license')) ?>);

    M2ePro.url.add(<?php echo json_encode(array(
        'formSubmit' => $this->getUrl('M2ePro/adminhtml_configuration_license/confirmKey')
    )); ?>);

    M2ePro.translator.add(<?php echo json_encode(array(
        'You must get valid Trial or Live Extension Key.' => Mage::helper('M2ePro')->__('You must get valid Trial or Live Extension Key.'),
        'Extension Key' => Mage::helper('M2ePro')->__('Extension Key'),
    )); ?>);

    Event.observe(window, 'load', function() {

        if (<?php echo (int)($this->key == '')?>) {
            var clientsLicenseData = $('magento_block_configuration_license_data');
            if (clientsLicenseData) clientsLicenseData.hide();
        }

        LicenseObj = new ConfigurationLicense();

        configEditForm = new varienForm('config_edit_form', '<?php echo $this->getValidationUrl(); ?>');
    });
    //-----------------------------

</script>

<style>
    .columns .form-list td.value {
        width: 280px;
    }

    #wrapper_new_license_popup, #wrapper_change_license_popup {
        margin-bottom: 1em;
    }
</style>

<form id="<?php echo $this->getForm()->getId(); ?>" action="<?php echo $this->getForm()->getData('action'); ?>" method="post" enctype="multipart/form-data">

    <input name="form_key" value="<?php echo $this->getFormKey(); ?>" type="hidden" />

    <?php if ($this->key != '' && ($this->licenseData['domain'] == '' || $this->licenseData['ip'] == '')) : ?>
        <ul style="margin-top: 5px;" class="messages">
            <li class="error-msg">
                <ul>
                    <li>
                        <?php echo Mage::helper('M2ePro')->__('Unknown Extension Key. Please check the entered value.'); ?>
                    </li>
                </ul>
            </li>
        </ul>
    <?php endif; ?>

    <div class="entry-edit" id="magento_block_configuration_license_data" collapseable="no">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('M2E Accounts'); ?></h4>
        </div>

        <div class="fieldset">
            <div class="hor-scroll">

                <table class="form-list" cellspacing="0" cellpadding="0">

                    <colgroup class="label"></colgroup>
                    <colgroup class="value"></colgroup>

                    <tbody>

                        <?php if ($this->licenseData['info']['email'] != '') { ?>
                        <tr>
                            <td class="label">
                                <label><?php echo Mage::helper('M2ePro')->__('Associated Email'); ?>: </label>
                            </td>
                            <td class="value">
                                <span><?php echo $this->licenseData['info']['email']; ?></span>
                                <p class="note">
                                    <span>
                                        <?php echo Mage::helper('M2ePro')->__('This email is the one used during M2E Pro`s initial setup, and all notifications related to M2E Pro are sent to it. <br/>
                                        Use this email to log in to <a href="%url%" target="_blank">M2E Accounts</a>.',
                                        Mage::helper('M2ePro/Module_Support')->getAccountsUrl()); ?>
                                    </span>
                                </p>
                            </td>
                        </tr>
                        <?php } ?>

                        <?php if ($this->key != '') { ?>
                        <tr>
                            <td class="label"></td>
                            <td class="value">
                                <a href="<?php echo Mage::helper('M2ePro/Module_Support')->getAccountsUrl();?>" target="_blank"><?php echo Mage::helper('M2ePro')->__('Log in to M2E Accounts'); ?></a>
                            </td>
                        </tr>
                        <?php } ?>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

    <div class="entry-edit" id="magento_block_configuration_license_valid" collapseable="no">

            <div class="entry-edit-head">
                <h4 class="icon-head head-edit-form fieldset-legend">
                    <?php echo Mage::helper('M2ePro')->__('Extension Key'); ?>
                </h4>
            </div>

            <div class="fieldset">
                <div class="hor-scroll">

                    <table class="form-list" cellspacing="0" cellpadding="0">

                        <colgroup class="label"></colgroup>
                        <colgroup class="value"></colgroup>

                        <tbody>

                            <tr>
                                <td class="label">
                                    <label><?php echo Mage::helper('M2ePro')->__('Key'); ?>: </label>
                                </td>
                                <td id="license_text_key_container" class="value">
                                    <?php echo $this->key; ?>
                                </td>
                            </tr>

                            <?php if ($this->licenseData['domain'] != '') { ?>

                                <tr>
                                    <td class="label">
                                        <label><?php echo Mage::helper('M2ePro')->__('Valid Domain'); ?>: </label>
                                    </td>
                                    <td class="value">

                                        <span <?php echo $this->licenseData['valid']['domain'] ? '' : 'style="color: red;"'?>>
                                            <?php echo $this->licenseData['domain']; ?>
                                        </span>

                                        <?php if (!$this->licenseData['valid']['domain'] &&
                                                  $this->licenseData['connection']['domain'] !== null): ?>
                                            <span> (<?php echo Mage::helper('M2ePro')->__('Your Domain') . ': ' . Mage::helper('M2ePro')->escapeHtml($this->licenseData['connection']['domain']);?>)</span>
                                        <?php endif;?>
                                    </td>
                                </tr>

                            <?php } ?>

                            <?php if ($this->licenseData['ip'] != '') { ?>

                                <tr>
                                    <td class="label">
                                        <label><?php echo Mage::helper('M2ePro')->__('Valid IP(s)'); ?>: </label>
                                    </td>
                                    <td class="value">

                                        <span <?php echo $this->licenseData['valid']['ip'] ? '' : 'style="color: red;"'?>>
                                            <?php echo $this->licenseData['ip']; ?>
                                        </span>

                                        <?php if (!$this->licenseData['valid']['ip'] &&
                                                  $this->licenseData['connection']['ip'] !== null): ?>
                                            <span> (<?php echo Mage::helper('M2ePro')->__('Your IP') . ': ' . Mage::helper('M2ePro')->escapeHtml($this->licenseData['connection']['ip']);?>)</span>
                                        <?php endif;?>

                                    </td>
                                </tr>

                            <?php } ?>

                            <tr>
                                <td class="value"></td>
                                <td class="value">
                                    <?php echo $this->getChildHtml('change_license'); ?>
                                    <?php echo $this->getChildHtml('refresh_status'); ?>
                                </td>
                            </tr>

                        </tbody>

                    </table>

                </div>
            </div>

        </div>

</form>

<script type="M2ePro/template" id="change_license_popup">
    <div id="wrapper_change_license_popup">
        <div id="block_notice_change_license" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Extension Key'); ?>" style="margin-top: 10px;">
            <?php echo Mage::helper('M2ePro')->__(
                'Enter the new License Key and click "Refresh". It will automatically associate your current IP address and domain with the new License Key. <br><br>
                Note that changing the location (IP address/domain) of your Magento server requires a new License Key.'
            ); ?>
        </div>
        <form  id="popup_change_license_form">
            <div class="fieldset">
                <div class="hor-scroll">
                    <table class="form-list" cellspacing="0" cellpadding="0" style="width: 100%; margin: auto;">
                        <tr>
                            <td class="value"><?php echo Mage::helper('M2ePro')->__('New Key'); ?>:<span class="required">*</span></td>
                            <td class="value">
                                <input type="text" class="input-text required-entry" id="new_license_key" value="<?php echo $this->key;?>"/>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
    </div>
    <div style="float: right; margin: 0 0 1em;">
        <a href="#" onclick="changeLicensePopup.close();">Close</a>
        &nbsp;
        &nbsp;
        &nbsp;
        <?php echo $this->getChildHtml('confirm_key');?>
    </div>
</script>
