<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 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)
 */

/**
 * Template for Mage_Adminhtml_Block_Widget_Grid
 *
 * @var Mage_Adminhtml_Block_Widget_Grid $this
 */
$numColumns = count($this->getColumns());
?>
<?php if($this->getCollection()): ?>
    <?php if($this->canDisplayContainer()): ?>
        <?php if($this->getGridHeader()): ?>
        <div class="content-header">
            <table cellspacing="0">
                <tr>
                    <td style="width:50%;"><h2><?= $this->getGridHeader() ?></h2></td>
                </tr>
            </table>
        </div>
        <?php endif ?>

        <div id="<?= $this->getId() ?>">
    <?php else: ?>
        <?= $this->getMessagesBlock()->toHtml() ?>
    <?php endif ?>
<?php if($this->getPagerVisibility() || $this->getExportTypes() || $this->getFilterVisibility()): ?>
    <table cellspacing="0" class="actions">
        <tr>
        <?php if($this->getPagerVisibility()): ?>
            <td class="pager">
            <?= $this->__('Page') ?>

            <?php $_curPage  = $this->getCollection()->getCurPage() ?>
            <?php $_lastPage = $this->getCollection()->getLastPageNumber() ?>
            <?php if($_curPage>1): ?>
                <a href="#" title="<?= Mage::helper('core')->quoteEscape($this->__('Previous page')) ?>" onclick="<?= $this->getJsObjectName() ?>.setPage('<?= ($_curPage-1) ?>');return false;"><img src="<?= $this->getSkinUrl('images/pager_arrow_left.gif') ?>" alt="<?= Mage::helper('core')->quoteEscape($this->__('Go to Previous page')) ?>" class="arrow"/></a>
            <?php else: ?>
                <img src="<?= $this->getSkinUrl('images/pager_arrow_left_off.gif') ?>" alt="<?= Mage::helper('core')->quoteEscape($this->__('Go to Previous page')) ?>" class="arrow"/>
            <?php endif ?>

            <input type="text" name="<?= $this->getVarNamePage() ?>" value="<?= $_curPage ?>" class="input-text page" onkeypress="<?= $this->getJsObjectName() ?>.inputPage(event, '<?= $_lastPage ?>')"/>

            <?php if($_curPage < $_lastPage): ?>
                <a href="#" title="<?= Mage::helper('core')->quoteEscape($this->__('Next page')) ?>" onclick="<?= $this->getJsObjectName() ?>.setPage('<?= ($_curPage+1) ?>');return false;"><img src="<?= $this->getSkinUrl('images/pager_arrow_right.gif') ?>" alt="<?= Mage::helper('core')->quoteEscape($this->__('Go to Next page')) ?>" class="arrow"/></a>
            <?php else: ?>
                <img src="<?= $this->getSkinUrl('images/pager_arrow_right_off.gif') ?>" alt="<?= Mage::helper('core')->quoteEscape($this->__('Go to Next page')) ?>" class="arrow"/>
            <?php endif ?>

            <?= $this->__('of %s pages', $this->getCollection()->getLastPageNumber()) ?>
            <span class="separator">|</span>
            <?= $this->__('View') ?>
            <select name="<?= $this->getVarNameLimit() ?>" onchange="<?= $this->getJsObjectName() ?>.loadByElement(this)">
                <?php foreach ($this->getLimitOptions() as $pageSize): ?>
                    <option value="<?= $pageSize ?>"<?php if($this->getCollection()->getPageSize() == $pageSize): ?> selected="selected"<?php endif ?>><?= $pageSize ?></option>
                <?php endforeach ?>
            </select>
            <?= $this->__('per page') ?><span class="separator">|</span>
            <?= $this->__('Total %d records found', $this->getCollection()->getSize()) ?>
            <span id="<?= $this->getHtmlId() ?>-total-count" class="no-display"><?= $this->getCollection()->getSize() ?></span>
            <?php if($this->getRssLists()): ?>
                <?php foreach ($this->getRssLists() as $_rss): ?>
                <span class="separator">|</span><a href="<?= $_rss->getUrl() ?>" class="link-feed"><?= $_rss->getLabel() ?></a>
                <?php endforeach ?>
            <?php endif ?>
        </td>
    <?php endif ?>
    <?php if($this->getExportTypes()): ?>
        <td class="export a-right">
            <img src="<?= $this->getSkinUrl('images/icon_export.gif') ?>" alt="" class="v-middle"/>&nbsp; <?= $this->__('Export to:') ?>
            <select name="<?= $this->getId() ?>_export" id="<?= $this->getId() ?>_export" style="width:8em;">
            <?php foreach ($this->getExportTypes() as $_type): ?>
                <option value="<?= $_type->getUrl() ?>"><?= $_type->getLabel() ?></option>
            <?php endforeach ?>
            </select>
            <?= $this->getExportButtonHtml() ?>
        </td>
    <?php endif ?>
        <td class="filter-actions a-right">
            <?= $this->getMainButtonsHtml() ?>
        </td>
        </tr>
    </table>
<?php endif ?>
<?php if($this->getMassactionBlock()->isAvailable()): ?>
<?= $this->getMassactionBlockHtml() ?>
<?php endif ?>
<div class="grid">
    <div class="hor-scroll">
    <table cellspacing="0" class="data" id="<?= $this->getId() ?>_table">
        <?php foreach ($this->getColumns() as $_column): ?>
        <col <?= $_column->getHtmlProperty() ?> />
        <?php endforeach ?>
        <?php if ($this->getHeadersVisibility() || $this->getFilterVisibility()): ?>
            <thead>
                <?php if ($this->getHeadersVisibility()): ?>
                    <tr class="headings">
                    <?php foreach ($this->getColumns() as $_column): ?>
                        <th<?= $_column->getHeaderHtmlProperty() ?> data-column-id="<?= $_column->getId() ?>"><?= $_column->getHeaderHtml() ?></th>
                    <?php endforeach ?>
                    </tr>
                <?php endif ?>
                <?php if ($this->getFilterVisibility()): ?>
                    <tr class="filter">
                    <?php $i=0;foreach ($this->getColumns() as $_column): ?>
                        <th<?= $_column->getHeaderHtmlProperty() ?>><?= $_column->getFilterHtml() ?></th>
                    <?php endforeach ?>
                    </tr>
                <?php endif ?>
            </thead>
        <?php endif ?>
        <?php if ($this->getCountTotals()): ?>
            <tfoot>
                <tr class="totals">
                <?php foreach ($this->getColumns() as $_column): ?>
                    <th class="<?= $_column->getCssProperty() ?>">
                        <?php if (($_column->getType() != 'action') && ($_column->getType() != 'massaction')): ?>
                            <?= $_column->hasTotalsLabel() ? $_column->getTotalsLabel() : $_column->getRowField($_column->getGrid()->getTotals()) ?>&nbsp;
                        <?php endif ?>
                    </th>
                <?php endforeach ?>
                </tr>
            </tfoot>
        <?php endif ?>

        <tbody>
        <?php if (($this->getCollection()->getSize()>0) && (!$this->getIsCollapsed())): ?>
        <?php foreach ($this->getCollection() as $_index=>$_item): ?>
            <tr title="<?= $this->getRowUrl($_item) ?>"<?php if ($_class = $this->getRowClass($_item)):?> class="<?= $_class ?>"<?php endif ?> >
            <?php $i=0;foreach ($this->getColumns() as $_column): ?>

                <?php if ($this->shouldRenderCell($_item, $_column)):?>
                    <?php $_rowspan = $this->getRowspan($_item, $_column);?>
                    <td <?= ($_rowspan ? 'rowspan="' . $_rowspan . '" ' : '') ?>class="<?= $_column->getCssProperty() ?> <?= ++$i==$numColumns?'last':'' ?>">
                        <?= (($_html = $_column->getRowField($_item)) != '' ? $_html : '&nbsp;') ?>
                    </td>
                    <?php if ($this->shouldRenderEmptyCell($_item, $_column)):?>
                        <td colspan="<?= $this->getEmptyCellColspan($_item) ?>" class="last"><?= $this->getEmptyCellLabel() ?></td>
                    <?php endif ?>
                <?php endif ?>

            <?php endforeach ?>
            </tr>
            <?php if ($_multipleRows = $this->getMultipleRows($_item)):?>
                <?php foreach ($_multipleRows as $_i):?>
                <tr>
                    <?php $i=0;foreach ($this->getMultipleRowColumns($_i) as $_column): ?>
                        <td class="<?= $_column->getCssProperty() ?> <?= ++$i==$numColumns-1?'last':'' ?>">
                            <?= (($_html = $_column->getRowField($_i)) != '' ? $_html : '&nbsp;') ?>
                        </td>
                    <?php endforeach ?>
                </tr>
                <?php endforeach ?>
            <?php endif ?>

            <?php if ($this->shouldRenderSubTotal($_item)): ?>
                <tr class="subtotals">
                    <?php $i = 0; foreach ($this->getSubTotalColumns() as $_column): ?>
                        <td class="<?= $_column->getCssProperty() ?> <?= ++$i == $numColumns ? 'last' : '' ?>">
                            <?php echo ($_column->hasSubtotalsLabel() ? $_column->getSubtotalsLabel() :
                                $_column->getRowField($this->getSubTotalItem($_item))
                            );
                            ?>
                        </td>
                    <?php endforeach ?>
                </tr>
            <?php endif ?>
        <?php endforeach ?>
        <?php elseif ($this->getEmptyText()): ?>
            <tr>
                <td class="empty-text <?= $this->getEmptyTextClass() ?>" colspan="<?= $numColumns ?>"><?= $this->getEmptyText() ?></td>
            </tr>
        <?php endif ?>
        </tbody>

    </table>
    </div>
</div>
<?php if($this->canDisplayContainer()): ?>
</div>
<script type="text/javascript">
//<![CDATA[
    <?= $this->getJsObjectName() ?> = new varienGrid('<?= $this->getId() ?>', '<?= $this->getGridUrl() ?>', '<?= $this->getVarNamePage() ?>', '<?= $this->getVarNameSort() ?>', '<?= $this->getVarNameDir() ?>', '<?= $this->getVarNameFilter() ?>');
    <?= $this->getJsObjectName() ?>.useAjax = '<?= $this->getUseAjax() ?>';
    <?php if($this->getRowClickCallback()): ?>
        <?= $this->getJsObjectName() ?>.rowClickCallback = <?= $this->getRowClickCallback() ?>;
    <?php endif ?>
    <?php if($this->getCheckboxCheckCallback()): ?>
        <?= $this->getJsObjectName() ?>.checkboxCheckCallback = <?= $this->getCheckboxCheckCallback() ?>;
    <?php endif ?>
    <?php if($this->getRowInitCallback()): ?>
        <?= $this->getJsObjectName() ?>.initRowCallback = <?= $this->getRowInitCallback() ?>;
        <?= $this->getJsObjectName() ?>.initGridRows();
    <?php endif ?>
    <?php if($this->getMassactionBlock()->isAvailable()): ?>
    <?= $this->getMassactionBlock()->getJavaScript() ?>
    <?php endif ?>
    <?= $this->getAdditionalJavaScript() ?>
//]]>
</script>
<?php endif ?>
<?php endif ?>
