<?php

/**
 * @version        1.11.1
 * @package        Joomla
 * @subpackage     EDocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2025 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

$user = Factory::getApplication()->getIdentity();
if (count($categories))
{
	if ($categoryId && $config->show_subcategory_text)
	{
	?>
		<h2 class="edocman-heading"><i class="edicon edicon-folder-open"></i>&nbsp;<?php echo Text::_('EDOCMAN_SUB_CATEGORIES'); ?></h2>
	<?php
	}
	$rowFluidClass = $bootstrapHelper->getClassMapping('row-fluid');
	?>
    <table class="table table-condensed table-document" id="table-document">
        <thead>
            <tr>
                <th class="sr-only">
                    Category title 
                </th>
            </tr>
        </thead>
        <tbody>
            <?php
            for ($i = 0 , $n = count($categories) ; $i < $n ; $i++)
            {
                $category = $categories[$i];
                ?>
                <tr>
                    <td class="edocman-category-title-td" data-label="">
						<i class="edicon edicon-folder-open"></i>
                        <a href="<?php echo Route::_(EDocmanHelperRoute::getCategoryRoute($category->id, $Itemid)); ?>" class="edocman-category-title-link" style="display: inline-block;">
                            <?php
                            echo $category->title;
                            if ($config->show_number_documents)
                            {
                                ?>
                                <span class="number_documents">(<?php echo $category->total_documents ;?> <?php echo $category->total_documents > 1 ? Text::_('EDOCMAN_DOCUMENTS') :  Text::_('EDOCMAN_DOCUMENT') ; ?>)</span>
                                <?php
                            }
                            ?>
                        </a>
                        <?php
                        if ($config->enable_rss)
                        {
                            ?>
                            <span class="edocman-rss-icon">
								<a href="<?php echo Route::_('index.php?option=com_edocman&view=category&id='.$category->id.'&format=feed&type=rss'); ?>"><img src="<?php echo Uri::root().'/components/com_edocman/assets/images/rss.png' ?>" /></a>
							</span>
                            <?php
                        }
                        if ($categoryId > 0 && $user->authorise('edocman.manage_categories', 'com_edocman') || $user->authorise('edocman.manage_subcategories', 'com_edocman.category.'.$categoryId))
                        {
                            $url = Route::_('index.php?option=com_edocman&task=editcategory&cid[]='.$category->id.'&Itemid='.$Itemid) ;
                            ?>
                            <a class="documents_table_edit" href="<?php echo $url; ?>" title="<?php echo Text::_('EDOCMAN_EDIT'); ?>">
                                <i class="edocman-icon-pencil"></i>
                            </a>
                            <?php
                        }
                        if ($categoryId > 0 && $user->authorise('edocman.manage_categories', 'com_edocman') || $user->authorise('edocman.manage_subcategories', 'com_edocman.category.'.$categoryId))
                        {
                            ?>
                            <a class="documents_table_delete" href="javascript:deleteCategoryConfirm(<?php echo $category->id; ?>);" title="<?php echo Text::_('EDOCMAN_DELETE'); ?>">
                                <i class="edocman-icon-trash"></i>
                            </a>
                            <?php
                        }
                        ?>
                    </td>
                </tr>
                <?php
            }
            ?>
        </tbody>
    </table>
<?php
}
?>
<script type="text/javascript">
    function deleteCategoryConfirm(id) {
        var msg = "<?php echo Text::_('EDOCMAN_DELETE_CONFIRM'); ?>";
        if (confirm(msg))
        {
            location.href = "<?php echo Uri::root()?>index.php?option=com_edocman&task=deletecategory&cid[]=" + id + "&parentId=<?php echo $categoryId?>";
        }
    }
</script>
