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

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Walmart_Configuration_General_Form */

?>

<script type="text/javascript">

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

    M2ePro.translator.add(<?php echo json_encode(array(
        'Required identifier' => Mage::helper('M2ePro')->__('Required identifier')
    )); ?>);

    Event.observe(window, 'load', function() {
        editForm = new varienForm('<?php echo $this->getForm()->getId(); ?>', '<?php echo $this->getValidationUrl(); ?>');

        WalmartConfigurationGeneralObj = new WalmartConfigurationGeneral();
        WalmartConfigurationGeneralObj.setConstants('<?php echo Mage::helper('M2ePro')->getClassConstantAsJson('Ess_M2ePro_Helper_Component_Walmart'); ?>');
        WalmartConfigurationGeneralObj.setConstants('<?php echo Mage::helper('M2ePro')->getClassConstantAsJson('Ess_M2ePro_Helper_Component_Walmart_Configuration'); ?>');

        $('sku_mode').observe('change', WalmartConfigurationGeneralObj.sku_mode_change);

        $('sku_modification_mode')
            .observe('change', WalmartConfigurationGeneralObj.sku_modification_mode_change);

        $('product_id_mode').observe('change', WalmartConfigurationGeneralObj.product_id_mode_change);
    });

</script>

<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_walmart_listing_sku_settings">

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

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

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

                    <tr>
                        <td class="label">
                            <label for="sku_mode"><?php echo Mage::helper('M2ePro')->__('Source') ?>:</label>
                        </td>
                        <td class="value">
                            <input type="hidden" id="sku_custom_attribute" name="sku_custom_attribute" value="<?php echo $this->getConfigurationHelper()->getSkuCustomAttribute(); ?>" />

                            <select name="sku_mode" id="sku_mode" class="M2ePro-custom-attribute-can-be-created" allowed_attribute_types="text">
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODE_DEFAULT ?>" <?php if ($this->getConfigurationHelper()->isSkuModeDefault()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Product SKU') ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODE_PRODUCT_ID ?>" <?php if ($this->getConfigurationHelper()->isSkuModeProductId()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Product ID') ?></option>

                                <optgroup class="M2ePro-custom-attribute-optgroup" label="Magento Attribute">
                                    <?php foreach ($this->getTextAttributes() as $attribute): ?>
                                        <option attribute_code="<?php echo $attribute['code']; ?>" value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODE_CUSTOM_ATTRIBUTE ?>" <?php if ($this->getConfigurationHelper()->getSkuCustomAttribute() == $attribute['code']) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->escapeHtml($attribute['label']); ?></option>
                                    <?php endforeach ?>
                                </optgroup>
                            </select>
                            <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('SKU is a unique identifier for each Item in your catalog. Select Attribute where the SKU values are stored.<br/>
                                                                        <b>Note:</b> SKU is required when you create a new offer on Walmart. Must be less than 50 characters.'); ?>
                            </span>
                            </p>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">
                            <label for="sku_modification_mode"><?php echo Mage::helper('M2ePro')->__('Modification') ?>:</label>
                        </td>
                        <td class="value">
                            <select name="sku_modification_mode" id="sku_modification_mode">
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODIFICATION_MODE_NONE; ?>" <?php if ($this->getConfigurationHelper()->isSkuModificationModeNone()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('None'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODIFICATION_MODE_PREFIX; ?>" <?php if ($this->getConfigurationHelper()->isSkuModificationModePrefix()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Prefix'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODIFICATION_MODE_POSTFIX; ?>" <?php if ($this->getConfigurationHelper()->isSkuModificationModePostfix()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Postfix'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::SKU_MODIFICATION_MODE_TEMPLATE; ?>" <?php if ($this->getConfigurationHelper()->isSkuModificationModeTemplate()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Template'); ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__('Select one of the available options to modify the SKU value taken from the Source Attribute.'); ?></span>
                            </p>
                        </td>
                    </tr>

                    <tr id="sku_modification_custom_value_tr" <?php if ($this->getConfigurationHelper()->isSkuModificationModeNone()): ?>style="display: none;"<?php endif; ?>>
                        <td class="label">
                            <label for="sku_modification_custom_value"><?php echo Mage::helper('M2ePro')->__('Modification Value') ?>: <span class="required">*</span></label>
                        </td>
                        <td class="value">
                            <input type="text" id="sku_modification_custom_value" name="sku_modification_custom_value" class="input-text M2ePro-required-when-visible M2ePro-validate-sku-modification-custom-value M2ePro-validate-sku-modification-custom-value-max-length" value="<?php echo Mage::helper('M2ePro')->escapeHtml($this->getConfigurationHelper()->getSkuModificationCustomValue()); ?>" />
                        <td>
                    </tr>

                    <tr>
                        <td class="label">
                            <label for="generate_sku_mode"><?php echo Mage::helper('M2ePro')->__('Generate') ?>:</label>
                        </td>
                        <td class="value">
                            <select name="generate_sku_mode" id="generate_sku_mode">
                                <option value="0" <?php if (!$this->getConfigurationHelper()->isGenerateSkuModeYes()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('No') ?></option>
                                <option value="1" <?php if ($this->getConfigurationHelper()->isGenerateSkuModeYes()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Yes') ?></option>
                            </select>
                            <p class="note">
                                <span><?php echo Mage::helper('M2ePro')->__(
                                    'Enable to automatically generate another SKU value if Item SKU that you submit to the Channel already exists in your Walmart Inventory.'
                                ); ?></span>
                            </p>
                        </td>
                    </tr>

                </table>

            </div>
        </div>

    </div>

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

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

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

                <table class="form-list" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="label">
                            <label for="product_id_mode">
                                <?php echo Mage::helper('M2ePro')->__('Product ID') ?>: <span class="required">*</span>
                            </label>
                        </td>
                        <td class="value">
                            <input type="hidden" id="product_id_custom_attribute" name="product_id_custom_attribute" value="<?php echo $this->getConfigurationHelper()->getProductIdCustomAttribute();?>"/>

                            <select name="product_id_mode" class="M2ePro-walmart-required-identifier-setting M2ePro-custom-attribute-can-be-created" allowed_attribute_types="text" id="product_id_mode">
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_MODE_NOT_SET ?>" <?php if ($this->getConfigurationHelper()->isProductIdModeNotSet()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Not Set') ?></option>

                                <optgroup class="M2ePro-custom-attribute-optgroup" label="Magento Attribute">
                                    <?php if ($this->getConfigurationHelper()->isProductIdModeCustomAttribute() && !$this->getMagentoAttributeHelper()->isExistInAttributesArray($this->getConfigurationHelper()->getProductIdCustomAttribute(), $this->getTextAttributes()) && $this->getConfigurationHelper()->getProductIdCustomAttribute() != '') : ?>
                                        <?php $this->setShowWarning(true); ?>
                                        <option attribute_code="<?php echo $this->getConfigurationHelper()->getProductIdCustomAttribute(); ?>" value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_MODE_CUSTOM_ATTRIBUTE ?>" selected="selected">
                                            <?php echo Mage::helper('M2ePro')->escapeHtml($this->getMagentoAttributeHelper()->getAttributeLabel($this->getConfigurationHelper()->getProductIdCustomAttribute())) ?>
                                        </option>
                                    <?php endif; ?>
                                    <?php foreach ($this->getTextAttributes() as $attribute): ?>
                                        <option attribute_code="<?php echo $attribute['code']; ?>" value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_MODE_CUSTOM_ATTRIBUTE ?>" <?php if ($this->getConfigurationHelper()->getProductIdCustomAttribute() == $attribute['code']) echo ' selected="selected"'; ?>><?php echo Mage::helper('M2ePro')->escapeHtml($attribute['label']); ?></option>
                                    <?php endforeach ?>
                                </optgroup>
                            </select>
                        </td>

                        <td class="value">
                        <span>
                            <img class="tool-tip-image" src="<?php echo $this->getSkinUrl('M2ePro/images/tool-tip-icon.png'); ?>" alt="">
                            <span class="tool-tip-message tip-right" style="left: 538px; top: 407px; display: none;">
                                <img src="<?php echo $this->getSkinUrl('M2ePro/images/help.png'); ?>" alt="">
                                <span><?php echo Mage::helper('M2ePro')->__(
                                        'Walmart uses Product IDs to associate your Item with its catalog. Select Attribute where the Product ID values are stored.<br>
                                     <strong>Note:</strong> At least one Product ID has to be specified when you create a new offer on Walmart.'
                                    ); ?></span>
                            </span>
                        </span>
                            <?php if ($this->getShowWarning()) :?>
                                <?php $this->setShowWarning(false); ?>
                                <span id="warning_message">
                            <img src="<?php echo $this->getSkinUrl('M2ePro/images/warning.png'); ?>" class="tool-tip-image" alt="">
                            <span class="tool-tip-message" style="font-size: 12px; display: none; border-color: #ffd967; background-color: #fffbf0;">
                                <img src="<?php echo $this->getSkinUrl('M2ePro/images/i_notice.gif'); ?>" style="margin-top: -21px;" alt="">
                                <span><?php echo Mage::helper('M2ePro')->__(
                                        'Selected Magento Attribute is invalid. 
                                        Please ensure that the Attribute exists in your Magento, has a relevant Input Type and it is included in all Attribute Sets. 
                                        Otherwise, select a different Attribute from the drop-down.'
                                    ); ?></span>
                            </span>
                        </span>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="product_id_override_mode"><?php echo Mage::helper('M2ePro')->__('Product ID Override') ?>:</label>
                        </td>
                        <td class="value">

                            <select name="product_id_override_mode" id="product_id_override_mode">
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_OVERRIDE_MODE_NONE ?>" <?php if ($this->getConfigurationHelper()->isProductIdOverrideModeNode()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('None') ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_OVERRIDE_MODE_ALL ?>" <?php if ($this->getConfigurationHelper()->isProductIdOverrideModeAll()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('All products') ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::PRODUCT_ID_OVERRIDE_MODE_SPECIFIC_PRODUCTS ?>" <?php if ($this->getConfigurationHelper()->isProductIdOverrideModeSpecificProducts()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Specific products') ?></option>
                            </select>
                            <p class="note">
                                <span>
                                    <?php echo Mage::helper('M2ePro')->__(
                                        '<b>None</b> - all products will be listed with the standard Product IDs.<br/>
                                         <b>All products</b> - Product ID exemption will be applied to all products.<br/>
                                         <b>Specific products</b> - Product ID exemption will be applied to products that have a value “CUSTOM” in Product ID attribute.<br/><br/>
                                         
                                        <b>Note:</b> You must apply for Product ID exemption on Walmart first.'
                                    ); ?>
                                </span>
                            </p>
                        </td>
                    </tr>

                </table>

            </div>
        </div>
    </div>

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

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

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

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

                    <tr>
                        <td class="label">
                            <label for="option_images_url_mode"><?php echo Mage::helper('M2ePro')->__('Image(s) URL') ?>:</label>
                        </td>
                        <td class="value">
                            <select name="option_images_url_mode" id="option_images_url_mode">
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::OPTION_IMAGES_URL_MODE_ORIGINAL; ?>" <?php if ($this->getConfigurationHelper()->isOptionImagesURLOriginalMode()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Original'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::OPTION_IMAGES_URL_MODE_HTTPS; ?>" <?php if ($this->getConfigurationHelper()->isOptionImagesURLHTTPSMode()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Replace with HTTPS'); ?></option>
                                <option value="<?php echo Ess_M2ePro_Helper_Component_Walmart_Configuration::OPTION_IMAGES_URL_MODE_HTTP; ?>" <?php if ($this->getConfigurationHelper()->isOptionImagesURLHTTPMode()) echo 'selected="selected"' ?>><?php echo Mage::helper('M2ePro')->__('Replace with HTTP'); ?></option>
                            </select>
                        </td>
                    </tr>

                </table>

            </div>
        </div>

    </div>

</form>
