<?php

/**
 * @version        1.9.7
 * @package        Joomla
 * @subpackage     EDocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2024 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */
// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;

require_once JPATH_ROOT . '/components/com_edocman/helper/helper.php';
$user	= Factory::getApplication()->getIdentity();
$userId	= $user->get('id');
$canOrder	= $user->authorise('core.edit.state', 'com_edocman');
if (version_compare(JVERSION, '3.0', 'ge')) {
	//EdocmanHelper::addSideBarmenus('licenses');
	//$sidebar = JHtmlSidebar::render();
}
?>
<?php
if(EdocmanHelper::isJoomla4())
{
	$searchBtnClass = "btn-primary";
	$cancelSearchBtnClass = "btn-secondary";
}
else
{
	$searchBtnClass = "";
	$cancelSearchBtnClass = "";
}
$customOptions = array(
	'filtersHidden'       => true,
	'defaultLimit'        => Factory::getApplication()->get('list_limit', 20),
	'searchFieldSelector' => '#filter_search'
);
HTMLHelper::_('searchtools.form', '#adminForm', $customOptions);
$bootstrapHelper	= new EDocmanHelperBootstrap(EDocmanHelperHtml::getAdminBootstrapHelper());
$rowFluidClass		= $bootstrapHelper->getClassMapping('row-fluid');
$span12Class		= $bootstrapHelper->getClassMapping('span12');
?>
<form action="<?php echo Route::_('index.php?option=com_edocman&view=tags'); ?>" method="post" name="adminForm" id="adminForm">
<div class="<?php echo $rowFluidClass; ?>">
	<div class="<?php echo $span12Class; ?>">
		<div id="filter-bar" class="btn-toolbar">
			<div class="filter-search btn-group pull-left">
				<div class="input-group input-append">
					<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo Text::_('Search'); ?>" class="search-query form-control input-medium" placeholder="<?php echo Text::_('JSEARCH_FILTER'); ?>" />
					<button type="submit" class="btn <?php echo $searchBtnClass;?>"><span class="icon-search"></span></button>
					<button type="button" class="btn <?php echo $cancelSearchBtnClass; ?> hasTooltip js-stools-btn-clear" title="<?php echo HTMLHelper::tooltipText('JSEARCH_FILTER_CLEAR'); ?>" onclick="document.getElementById('filter_search').value='';this.form.submit();"><span class="icon-remove"></span></button>
				</div>
			</div>
			<div class="filter-select pull-right btn-group">            
				<select name="filter_published" class="input-large form-select" onchange="this.form.submit()">
					<option value=""><?php echo Text::_('JOPTION_SELECT_PUBLISHED');?></option>
					<?php echo HTMLHelper::_('select.options', HTMLHelper::_('jgrid.publishedOptions', array('archived'=> false, 'trash' => false, 'all' => false)), "value", "text", $this->state->get('filter.state'), true);?>
				</select>               
			</div>
		</div>
	</div>
</div>
<div class="<?php echo $rowFluidClass;?>">
	<div class="<?php echo $span12Class;?>">
		<table class="table table-striped">
			<thead>
				<tr>
					<th width="1%">
						<input type="checkbox" name="checkall-toggle" value="" onclick="Joomla.checkAll(this);" />
					</th>
					<th class="title" style="text-align: left;">
						<?php echo HTMLHelper::_('grid.sort',  Text::_('EDOCMAN_TAG'), 'tbl.tag', $this->state->filter_order, $this->state->filter_order_Dir); ?>
					</th>
					<th class="title center">
						<?php echo Text::_('EDOCMAN_ASSIGNED_DOCUMENTS');?>
					</th>  
					<th class="title center">
						<?php echo HTMLHelper::_('grid.sort',  Text::_('EDOCMAN_PUBLISHED'), 'tbl.published', $this->state->filter_order, $this->state->filter_order_Dir); ?>
					</th>			
					<th class="title center">
						<?php echo HTMLHelper::_('grid.sort',  Text::_('EDOCMAN_ID'), 'tbl.id', $this->state->filter_order, $this->state->filter_order_Dir); ?>
					</th>											                
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="5">
						<?php echo $this->pagination->getListFooter(); ?>
					</td>
				</tr>
			</tfoot>
			<tbody>
			<?php foreach ($this->items as $i => $item) :					
				$canEdit	= $user->authorise('core.edit',			'com_edocman');			
				$canChange	= $user->authorise('core.edit.state',	'com_edocman');
				?>
				<tr class="row<?php echo $i % 2; ?>">
					<td class="center">
						<?php echo HTMLHelper::_('grid.id', $i, $item->id); ?>
					</td>        
					<td>
						<?php 
							if ($canEdit) {
							?>
								<a href="<?php echo Route::_('index.php?option=com_edocman&task=tag.edit&id='.$item->id);?>">
									<?php echo $item->tag; ?>
								</a>
							<?php    
							} 
							else 
							{
								echo $item->tag ;
							}
						?>
					</td> 
					<td class="center">
						<?php echo EdocmanHelper::countDocumentRelatedTag($item->id);?>
					</td> 
					<td class="center">
						<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, '', $canChange);?>
					</td>                               
					<td class="center">
						<?php echo $item->id; ?>
					</td>               
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $this->state->filter_order; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $this->state->filter_order_Dir; ?>" />
		<?php echo HTMLHelper::_('form.token'); ?>
	</div>
</div>
</form>
