<?php
/**
 * OpenMage
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available at https://opensource.org/license/afl-3-0-php
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://www.openmage.org)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('catalog')->__('Add Product To Websites') ?></h4>
    </div>
    <fieldset id="grop_fields">
    <?php foreach ($this->getWebsiteCollection() as $_website): ?>
    <div>
        <div class="website-name">
            <input name="add_website_ids[]" value="<?php echo $_website->getId() ?>" <?php if($this->getWebsitesReadonly()): ?>disabled="disabled"<?php endif ?> class="checkbox website-checkbox" id="add_product_website_<?php echo $_website->getId() ?>" type="checkbox" />
            <big><strong><label for="add_product_website_<?php echo $_website->getId() ?>"><?php echo $this->escapeHtml($_website->getName()) ?></label></strong></big>
        </div>
        <div class="webiste-groups" id="add_product_website_<?php echo $_website->getId() ?>_data">
        <?php foreach ($this->getGroupCollection($_website) as $_group): ?>
            <h4><?php echo $this->escapeHtml($_group->getName()) ?></h4>
            <div class="group-stores">
            <table>
            <?php foreach ($this->getStoreCollection($_group) as $_store): ?>
                <tr>
                    <td><?php echo $this->escapeHtml($_store->getName()) ?></td>
                    <td>&nbsp;</td>
                </tr>
            <?php endforeach ?>
            </table>
            </div>
        <?php endforeach ?>
        </div>
    </div>
    <?php endforeach ?>
    </fieldset>
</div>

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('catalog')->__('Remove Product From Websites') ?></h4>
    </div>
    <fieldset id="grop_fields">
        <ul class="messages">
            <li class="notice-msg">
                <ul>
                    <li><?php echo Mage::helper('catalog')->__("Items that you do not want to show in the catalog or search results should have status 'Disabled' in the desired store.") ?></li>
                </ul>
            </li>
        </ul>
    <?php foreach ($this->getWebsiteCollection() as $_website): ?>
    <div>
        <div class="website-name">
            <input name="remove_website_ids[]" value="<?php echo $_website->getId() ?>" <?php if($this->getWebsitesReadonly()): ?>disabled="disabled"<?php endif ?> class="checkbox website-checkbox" id="remove_product_website_<?php echo $_website->getId() ?>" type="checkbox"/>
            <big><strong><label for="remove_product_website_<?php echo $_website->getId() ?>"><?php echo $this->escapeHtml($_website->getName()) ?></label></strong></big>
        </div>
        <div class="webiste-groups" id="remove_product_website_<?php echo $_website->getId() ?>_data">
        <?php foreach ($this->getGroupCollection($_website) as $_group): ?>
            <h4><?php echo $this->escapeHtml($_group->getName()) ?></h4>
            <div class="group-stores">
            <table>
            <?php foreach ($this->getStoreCollection($_group) as $_store): ?>
                <tr>
                    <td><?php echo $this->escapeHtml($_store->getName()) ?></td>
                    <td>&nbsp;</td>
                </tr>
            <?php endforeach ?>
            </table>
            </div>
        <?php endforeach ?>
        </div>
    </div>
    <?php endforeach ?>
    </fieldset>
</div>
<script type="text/javascript">
//<![CDATA[
    var productWebsiteCheckboxes = $$('.website-checkbox');

    for(var i=0;i<productWebsiteCheckboxes.length;i++){
        Event.observe(productWebsiteCheckboxes[i], 'click', toggleStoreFromChoosers);
    }

    function toggleStoreFromChoosers(event){
        var element = Event.element(event);
        var selects = $(element.id+'_data').getElementsBySelector('select');
        var selectBlocks = $(element.id+'_data').getElementsByClassName('website-'+element.value+'-select');
        for (var i=0; i<selects.length; i++) {
            selects[i].disabled=!element.checked;
        }
        for (var i=0; i<selectBlocks.length; i++) {
            if (element.checked) {
                selectBlocks[i].show();
            }
            else {
                selectBlocks[i].hide();
            }
        }
    }
//]]>
</script>
