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

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Configuration_LogsClearing_Form */

$urlComponents = Mage::helper('M2ePro/Component')->getEnabledComponents();
$componentForUrl = count($urlComponents) == 1 ? array_shift($urlComponents) : Ess_M2ePro_Helper_Component_Ebay::NICK;

?>
<div id="block_notice_configuration_logs_clearing" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Logs &amp; Notifications'); ?>">
    <?php echo Mage::helper('M2ePro')->__(
        'Here you can set up an automatic <a href="%url%" target="_blank">Log clearing</a> and configure Notifications.<br>
        Click <strong>Save Config</strong> if you make any changes.',
        Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, "global-settings")
    ); ?>
</div>

<script type="text/javascript">

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

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

    M2ePro.translator.add(<?php echo json_encode(array(
        'Please enter a valid value greater than 14 days.' => Mage::helper('M2ePro')->__('Please enter a valid value greater than 14 days.')
    )); ?>);

    Event.observe(window, 'load', function() {
        LogClearingObj = new ConfigurationLogClearing();

        LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>');
        LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>');
        LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>');

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

</script>

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

    .columns .form-list td:nth-child(3) {
        width: 16px;
    }

    .columns .form-list td:nth-child(4) {
        width: 90px;
    }
</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" />

    <div class="entry-edit" id="magento_block_configuration_logs_clearing_listings">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Listings Log Clearing'); ?></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 id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_mode_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS;
                            ?>_log_mode"><?php echo Mage::helper('M2ePro')->__('Enabled'); ?>: </label>
                        </td>
                        <td class="value">
                            <?php $mode = isset($this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS]) ? $this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS] : 1; ?>
                            <select id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_mode" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_mode" onchange="LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>');">
                                <option value="0"<?php if ($mode == 0) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                                <option value="1"<?php if ($mode == 1) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Enables automatic clearing of Log data. Can help reduce Database size.'); ?></span>
                            </p>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_button_run_now_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('run_now_'.Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS); ?>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_button_clear_all_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('clear_all_'.Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS); ?>
                        </td>
                    </tr>

                    <tr id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_days_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS;
                            ?>_log_days"><?php echo Mage::helper('M2ePro')->__('Keep For (days)'); ?>: <span class="required">*</span></label>
                        </td>
                        <td class="value">
                            <input id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_days" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS; ?>_log_days" value="<?php echo $this->days[Ess_M2ePro_Model_Log_Clearing::LOG_LISTINGS]; ?>" type="text" class="M2ePro-required-when-visible M2ePro-logs-clearing-interval input-text" />
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Specify for how long you want to keep Log data before it is automatically cleared.'); ?></span>
                            </p>
                        </td>
                        <td colspan="2">

                        </td>
                    </tr>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

    <div class="entry-edit" id="magento_block_configuration_logs_clearing_synch">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Synchronization Log Clearing'); ?></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 id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_mode_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo
                            Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_mode"><?php echo Mage::helper('M2ePro')->__('Enabled'); ?>: </label>
                        </td>
                        <td class="value">
                            <?php $mode = isset($this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS]) ? $this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS] : 1; ?>
                            <select id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_mode" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_mode" onchange="LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>');">
                                <option value="0"<?php if (0 == $mode) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                                <option value="1"<?php if (1 == $mode) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Enables automatic clearing of Log data. Can help reduce Database size.'); ?></span>
                            </p>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_button_run_now_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('run_now_'.Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS); ?>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_button_clear_all_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('clear_all_'.Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS); ?>
                        </td>
                    </tr>

                    <tr id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_days_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo
                            Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_days"><?php echo Mage::helper('M2ePro')->__('Keep For (days)'); ?>: <span class="required">*</span></label>
                        </td>
                        <td class="value">
                            <input id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_days" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS; ?>_log_days" value="<?php echo $this->days[Ess_M2ePro_Model_Log_Clearing::LOG_SYNCHRONIZATIONS]; ?>" type="text" class="M2ePro-required-when-visible M2ePro-logs-clearing-interval input-text" />
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Specify for how long you want to keep Log data before it is automatically cleared.'); ?></span>
                            </p>
                        </td>
                        <td colspan="2">

                        </td>
                    </tr>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

    <div class="entry-edit" id="magento_block_logs_configuration_clearing_orders">

        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Orders Log Clearing'); ?></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 id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_mode_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo
                            Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_mode"><?php echo Mage::helper('M2ePro')->__('Enabled'); ?>: </label>
                        </td>
                        <td class="value">
                            <?php $mode = isset($this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS]) ? $this->modes[Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS] : 1; ?>
                            <select id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_mode" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_mode" onchange="LogClearingObj.changeModeLog('<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>');">
                                <option value="0"<?php if (0 == $mode) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                                <option value="1"<?php if (1 == $mode) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Enables automatic clearing of Log data. Can help reduce Database size.'); ?></span>
                            </p>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_button_run_now_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('run_now_'.Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS); ?>
                        </td>
                        <td id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_button_clear_all_container" class="value">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <?php echo $this->getChildHtml('clear_all_'.Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS); ?>
                        </td>
                    </tr>

                    <tr id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_days_container">
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for="<?php echo
                            Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_days"><?php echo Mage::helper('M2ePro')->__('Keep For (days)'); ?>: <span class="required">*</span></label>
                        </td>
                        <td class="value">
                            <input id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_days" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS; ?>_log_days" value="<?php echo $this->days[Ess_M2ePro_Model_Log_Clearing::LOG_ORDERS]; ?>" type="text" disabled="disabled" class="M2ePro-required-when-visible M2ePro-logs-clearing-interval input-text" />
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Specify for how long you want to keep Log data before it is automatically cleared.'); ?></span>
                            </p>
                        </td>
                        <td colspan="2">

                        </td>
                    </tr>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

    <div class="entry-edit" id="magento_block_logs_configuration_notification_orders">

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

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

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

                    <tbody>

                    <tr>
                        <td style="width: 225px;" class="label">
                            <label style="width: 225px;" for=<?php echo
                            Ess_M2ePro_Model_Log_Clearing::LOG_ORDER_NOTIFICATION; ?>"_mode"><?php echo Mage::helper('M2ePro')->__('Notify about Not Created Magento orders'); ?>: </label>
                        </td>
                        <td class="value" colspan="2">
                            <select id="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDER_NOTIFICATION; ?>_mode" name="<?php echo Ess_M2ePro_Model_Log_Clearing::LOG_ORDER_NOTIFICATION; ?>_mode">
                                <option value="<?php echo Ess_M2ePro_Helper_Order_Notification::NOTIFICATIONS_DISABLED; ?>"<?php if (!$this->getOrderNotificationHelper()->isNotificationDisabled()) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('Do not notify'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Order_Notification::NOTIFICATIONS_EXTENSION_PAGES; ?>"<?php if ($this->getOrderNotificationHelper()->isNotificationExtensionPages()) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('On each M2E Pro page'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Order_Notification::NOTIFICATIONS_MAGENTO_PAGES; ?>"<?php if ($this->getOrderNotificationHelper()->isNotificationMagentoPages()) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->__('On each Magento page'); ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Specify where to show the notifications about Magento orders that сould not be created or disable notifications.'); ?></span>
                            </p>
                        </td>
                    </tr>

                    </tbody>

                </table>

            </div>
        </div>

    </div>

</form>