<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 *
 */
// no direct access

defined('_JEXEC') or die;

use Joomla\CMS\Factory;

//Joomla\CMS\HTML\HTMLHelper::_('bootstrap.tooltip');

$user = Factory::getUser();
$listOrder = strtolower($this->state->get('list.ordering'));
$listDirn = strtolower($this->state->get('list.direction'));
$saveOrder = ($listOrder == 'a.ordering' && $listDirn == 'asc');
$assoc = JLanguageAssociations::isEnabled();
JLoader::register('JHtmlDJCatalog2', JPATH_ADMINISTRATOR . '/components/com_djcatalog2/helpers/html/djcatalog2.php');

if ($saveOrder && !empty($this->items))
{
	$saveOrderingUrl = 'index.php?option=com_djcatalog2&task=categories.saveOrderAjax&tmpl=component&' . Joomla\CMS\Session\Session::getFormToken() . '=1';
	Joomla\CMS\HTML\HTMLHelper::_('draggablelist.draggable');
}

?>
<form action="<?php echo JRoute::_('index.php?option=com_djcatalog2&view=categories'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
    <?php if (!empty($this->sidebar) /*&& !JHtmlDJCatalog2::isJoomla4()*/): ?>
    <div id="j-sidebar-container" class="col-md-2">
        <?php echo $this->sidebar; ?>
    </div>
    <div id="j-main-container" class="col-md-10">
        <?php else : ?>
        <div id="j-main-container">
            <?php endif; ?>
            
            <?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
            
            <div class="clearfix"></div>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th width="1%" class="hidden-phone">
                        <input type="checkbox" name="checkall-toggle" value=""
                               title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)"/>
                    </th>
                    <th scope="col" class="w-1 text-center d-none d-md-table-cell">
						<?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
					</th>
                    <th width="75" align="center">
                        <?php echo JText::_('COM_DJCATALOG2_IMAGE'); ?>
                    </th>
                    <th>
                        <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'COM_DJCATALOG2_NAME', 'a.name', $listDirn, $listOrder); ?>
                    </th>
                    <?php if ($assoc) : ?>
                        <th width="15%">
                        	<?php echo JText::_('COM_DJCATALOG2_ASSOCIATIONS'); ?>
                        </th>
                    <?php endif; ?>
                    <th width="10%">
                    	<?php 
                    	echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'COM_DJCATALOG2_LANGUAGE', 'a.language', $listDirn, $listOrder); ?>
                    </th>
                    <th width="5%" class="nowrap hidden-phone">
                        <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $listDirn, $listOrder); ?>
                    </th>
                    <th width="5%">
                        <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JPUBLISHED', 'a.published', $listDirn, $listOrder); ?>
                    </th>
                    <?php /*?>
                    <th width="10%">
                        <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ORDERING', 'a.ordering', $listDirn, $listOrder); ?>
                        <?php if ($saveOrder) : ?>
                            <?php echo Joomla\CMS\HTML\HTMLHelper::_('grid.order', $this->items, 'filesave.png', 'categories.saveorder'); ?>
                        <?php endif; ?>
                    </th>
                    <?php */ ?>
                    <th width="1%" class="nowrap">
                        <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
                    </th>
                </tr>
                </thead>
               
                <tbody<?php if ($saveOrder) : ?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo $listDirn; ?>" data-nested="true"<?php endif; ?>>
                <?php
                $i = 0;
                foreach ($this->items as $item) :
                    $item->max_ordering = 0;
                    $canCheckin = $canChange = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->get('id') || $item->checked_out == 0;
                    ?>
                    <tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parent_id; ?>">
							
                        <td class="center">
                            <?php echo Joomla\CMS\HTML\HTMLHelper::_('grid.id', $i, $item->id); ?>
                        </td>
                        <td class="text-center d-none d-md-table-cell">
							<?php
							$iconClass = '';
							if (!$canChange)
							{
								$iconClass = ' inactive';
							}
							elseif (!$saveOrder)
							{
								$iconClass = ' inactive" title="' . JText::_('JORDERINGDISABLED');
							}
							?>
							<span class="sortable-handler<?php echo $iconClass ?>">
								<span class="icon-ellipsis-v" aria-hidden="true"></span>
							</span>
							<?php if ($canChange && $saveOrder) : ?>
								<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
							<?php endif; ?>
						</td>
                        <td align="center">
                            <?php
                            if ($item->item_image) { ?><img alt="<?php echo $item->image_caption; ?>"
                                                            src="<?php echo DJCatalog2ImageHelper::getImageUrl($item->image_fullpath, 'thumb'); ?>"/><?php } else { ?>
                                <img
                                src="<?php echo str_replace('/administrator', '', JURI::base()) . 'components/com_djcatalog2/assets/images/noimage.jpg'; ?>"
                                alt="" /><?php } ?>
                        </td>
                        <td>
                            <?php if ($item->checked_out) : ?>
                                <?php echo Joomla\CMS\HTML\HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'categories.', $canCheckin); ?>
                            <?php endif; ?>
                            <?php if (!$canCheckin): ?>
                                <?php echo $item->name; ?>
                            <?php else : ?>
                                <span class="editlinktip hasTip"
                                      title="<?php echo JText::_('COM_DJCATALOG2_EDIT_CATEGORY_TOOLTIP'); ?>::<?php echo $this->escape($item->name); ?>">
						<?php echo str_repeat('<span class="gi">|&mdash;</span>', (count($this->categories->get($item->id)->getPath()))); ?>
						<a href="<?php echo JRoute::_('index.php?option=com_djcatalog2&task=category.edit&id=' . $item->id); ?>">
							<?php echo $item->name; ?></a>
						</span>
                            <?php endif; ?>

                            <p class="smallsub"><?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?></p>
                        </td>
                        <?php if ($assoc) : ?>
                            <td align="center">
                                <?php if ($item->association) : ?>
                                    <?php echo Joomla\CMS\HTML\HTMLHelper::_('DJCatalog2.associationCategory', $item->id); ?>
                                <?php endif; ?>
                            </td>
                        <?php endif; ?>
                        <td align="center">
                            <?php echo JLayoutHelper::render('joomla.content.language', $item); ?>
                        </td>
                        <td class="small hidden-phone">
                            <?php echo $this->escape($item->access_level); ?>
                        </td>
                        <td class="center">
                            <?php echo Joomla\CMS\HTML\HTMLHelper::_('jgrid.published', $item->published, $i, 'categories.', true, 'cb'); ?>
                        </td>
                        <?php /*?>
                        <td class="order">
                            <div class="input-prepend">
                                <?php $disabled = ''; ?>
                                <?php if ($saveOrder && $listDirn == 'asc') : ?>
                                    <span class="add-on"><?php echo $this->pagination->orderUpIcon($i, isset($this->ordering[$item->parent_id][$orderkey - 1]), 'categories.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
                                    <span class="add-on"><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, isset($this->ordering[$item->parent_id][$orderkey + 1]), 'categories.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
                                <?php else: $disabled = 'disabled="disabled"';
                                    echo "<span class=\"add-on tip\" title=\"" . JText::_('JDISABLED') . "\"><i class=\"icon-ban-circle\"></i></span>"; ?>
                                <?php endif; ?>
                                <input type="text" name="order[]" size="5"
                                       value="<?php echo $item->ordering; ?>" <?php echo $disabled ?>
                                       class="width-20 text-area-order"/>
                            </div>
                        </td>
                        <?php */ ?>
                        <td class="center">
                            <?php echo (int)$item->id; ?>
                        </td>
                    </tr>
                    <?php $i++; endforeach; ?>
                </tbody>
                
                 <tfoot>
                <tr>
                    <td colspan="9">
                        <?php echo $this->pagination->getListFooter(); ?>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
        <div>

            <?php echo Joomla\CMS\HTML\HTMLHelper::_(
                'bootstrap.renderModal',
                'collapseModal',
                array(
                    'title'  => JText::_('COM_DJCATALOG2_BATCH_TITLE'),
                    'footer' => $this->loadTemplate('batch_footer'),
                ),
                $this->loadTemplate('batch_body')
            ); ?>

            <input type="hidden" name="task" value=""/>
            <input type="hidden" name="boxchecked" value="0"/>
            <?php echo Joomla\CMS\HTML\HTMLHelper::_('form.token'); ?>
        </div>
</div>
</form>
