<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="content-header">
    <table cellspacing="0">
        <tr>
            <td><h3><?= Mage::helper('adminhtml')->__($this->getTitle()) ?></h3></td><td class="form-buttons"><?= $this->getSaveButtonHtml() ?></td>
         </tr>
    </table>
</div>
<form action="<?= $this->getSaveUrl() ?>" method="post" id="config_edit_form" enctype="multipart/form-data">
    <?= $this->getBlockHtml('formkey') ?>

    <script type="text/javascript">
    function setCacheAction(id, button)
    {
        $(id).value = button.id;
        configForm.submit();
    }
    </script>

    <input type="hidden" id="catalog_action" name="catalog_action" value="" />
    <input type="hidden" id="jscss_action" name="jscss_action" value="" />

    <?= $this->getChildHtml('form') ?>
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4><?= $this->__('Catalog') ?></h4>
        </div>
        <fieldset id="catalog">
            <table cellspacing="0" class="form-list">
                <tbody>
                    <?php foreach ($this->getCatalogData() as $_item): ?>
                    <?php /* disable reindex buttons. functionality moved to index management*/?>
                    <?php if ($_item['buttons'][0]['name']!='clear_images_cache') continue;?>
                    <tr>
                        <td class="label"><label><?= $_item['label'] ?></label></td>
                        <td class="value">
                            <?php foreach ($_item['buttons'] as $_button): ?>
                                <?php $clickAction = "setCacheAction('catalog_action',this)"; ?>
                                <?php if (isset($_button['warning']) && $_button['warning']): ?>
                                    <?php $clickAction = "if (confirm('".addslashes($_button['warning'])."')) {{$clickAction}}"; ?>
                                <?php endif ?>
                                <button <?php if (!isset($_button['disabled']) || !$_button['disabled']):?>onclick="<?= $clickAction ?>"<?php endif ?> id="<?= $_button['name'] ?>" type="button" class="scalable <?php if (isset($_button['disabled']) && $_button['disabled']):?>disabled<?php endif ?>" style=""><span><?= $_button['action'] ?></span></button>
                                <?php if (isset($_button['comment'])): ?> <br /> <small><?= $_button['comment'] ?></small> <?php endif ?>
                            <?php endforeach ?>
                        </td>
                        <td><small>&nbsp;</small></td>
                    </tr>
                    <?php endforeach ?>
                </tbody>
            </table>
        </fieldset>
    </div>

    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4><?= $this->__('JavaScript/CSS') ?></h4>
        </div>

        <fieldset id="jscss">
            <table cellspacing="0" class="form-list">
                <tbody>
                    <tr>
                        <td class="label"><label><?= $this->__('JavaScript/CSS Cache') ?></label></td>
                        <td class="value">
                            <button onclick="setCacheAction('jscss_action', this)" id='jscss_action' type="button" class="scalable"><span><?= $this->__('Clear') ?></span></button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </div>
</form>
<script type="text/javascript">
    var configForm = new varienForm('config_edit_form');
</script>
