<?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\HTML\HTMLHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;

if (version_compare(JVERSION, '4.0.0-dev', 'lt'))
{
	HTMLHelper::_('behavior.formvalidation');
	HTMLHelper::_('behavior.tooltip');
}
else
{
	HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', ['placement' => 'left']);
}
$customOptions = array(
	'filtersHidden'       => true,
	'defaultLimit'        => Factory::getApplication()->get('list_limit', 20),
	'searchFieldSelector' => '#filter_search'
);
HTMLHelper::_('searchtools.form', '#adminForm', $customOptions);
HTMLHelper::_('script','system/multiselect.js',false,true);
$listOrder	= $this->state->filter_order;
$listDirn	= $this->state->filter_order_Dir;
$config     = EDocmanHelper::loadConfig();

if(EdocmanHelper::isJoomla4())
{
	$searchBtnClass = "btn-primary";
	$cancelSearchBtnClass = "btn-secondary";
}
else
{
	$searchBtnClass = "";
	$cancelSearchBtnClass = "";
}
$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=downloadlogs'); ?>" method="post" name="adminForm" id="adminForm">
	<div class="<?php echo $rowFluidClass;?>">
		<div id="filter-bar" class="btn-toolbar">
			<div class="filter-search btn-group pull-left">
				<div class="input-group input-append">
					<input placeholder="<?php echo Text::_('JSEARCH_FILTER');?>" type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->filter_search); ?>" title="<?php echo Text::_('Search'); ?>" class="search-query form-control" />
					
					<div class="js-stools-field-filter">
						<?php echo HTMLHelper::_('calendar', Factory::getApplication()->getInput()->getString('start_date',''), 'start_date', 'start_date','%Y-%m-%d', array('class' => 'input-small form-control ishort','placeholder' => Text::_('EDOCMAN_START_TIME'))) ; ?>
					</div>
					<div class="js-stools-field-filter">
						<?php echo HTMLHelper::_('calendar', Factory::getApplication()->getInput()->getString('end_date',''), 'end_date', 'end_date','%Y-%m-%d', array('class' => 'input-small form-control ishort', 'placeholder' => Text::_('EDOCMAN_END_TIME'))) ; ?>
					</div>

					<button type="submit" class="btn <?php echo $searchBtnClass;?>" title="<?php echo Text::_('JSEARCH_FILTER_SUBMIT');?>"><i class="icon icon-search"></i></button>
					<button type="button" class="btn <?php echo $cancelSearchBtnClass;?> js-stools-btn-clear" onclick="document.getElementById('filter_search').value='';document.getElementById('start_date').value='';document.getElementById('end_date').value='';this.form.submit();" title="<?php echo Text::_('JSEARCH_FILTER_CLEAR');?>"><i class="icon icon-delete"></i></button>

				</div>
			</div>
		</div>
	</div>
	<div class="<?php echo $rowFluidClass;?>">
		<div class="<?php echo $span12Class;?>">
			<table class="table table-striped">
				<thead>
					<tr>				
						<th class="title" style="text-align: left;">
							<?php echo HTMLHelper::_('grid.sort',  Text::_('Document'), 'b.title', $listDirn, $listOrder); ?>
						</th>
						<?php
							if ($config->get('collect_downloader_information'))
							{
							?>
								<th width="12%" style="text-align: left;">
									<?php echo HTMLHelper::_('grid.sort',  Text::_('Name'), 'tbl.name', $listDirn, $listOrder); ?>
								</th>
								<th width="15%" style="text-align: left;">
									<?php echo HTMLHelper::_('grid.sort',  Text::_('Email'), 'tbl.email', $listDirn, $listOrder); ?>
								</th>
							<?php
							}
							else
							{
							?>
								<th width="12%" style="text-align: left;">
									<?php echo HTMLHelper::_('grid.sort',  Text::_('Username'), 'c.username', $listDirn, $listOrder); ?>
								</th>
								<th width="15%" style="text-align: left;">
									<?php echo HTMLHelper::_('grid.sort',  Text::_('Email'), 'c.email', $listDirn, $listOrder); ?>
								</th>
							<?php
							}
						?>
						<th width="12%">
							<?php echo HTMLHelper::_('grid.sort',  Text::_('Download Time'), 'tbl.download_time', $listDirn, $listOrder); ?>
						</th>    			
						<th width="10%" style="text-align: center;">
							<?php echo HTMLHelper::_('grid.sort',  Text::_('User IP'), 'tbl.user_ip', $listDirn, $listOrder); ?>
						</th>
						<th width="8%" style="text-align: center;">
							<?php echo HTMLHelper::_('grid.sort',  Text::_('Browser'), 'tbl.browser', $listDirn, $listOrder); ?>
						</th>
						<th width="8%" style="text-align: center;">
							<?php echo HTMLHelper::_('grid.sort',  Text::_('OS'), 'tbl.os', $listDirn, $listOrder); ?>
						</th>    														               
					</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="7">
							<?php echo $this->pagination->getListFooter(); ?>
						</td>
					</tr>
				</tfoot>
				<tbody>
				<?php foreach ($this->items as $i => $item) :								
					?>
					<tr class="row<?php echo $i % 2; ?>">				       
						<td>
							<?php echo $item->title ; ?>
						</td>
						<?php
							if ($config->get('collect_downloader_information') && !$item->user_id)
							{
							?>
								<td>
									<?php echo $item->name ; ?>
								</td>
								<td>
									<?php echo $item->email ; ?>
								</td>
							<?php
							}
							else
							{
							?>
								<td>
									<?php echo $item->downloader_username ; ?>
								</td>
								<td>
									<?php echo $item->downloader_email ; ?>
								</td>
							<?php
							}
						?>
						<td class="center">
							<?php echo HTMLHelper::_('date', $item->download_time, 'm-d-Y H:i:s'); ?>
						</td>                               
						<td class="center">
							<?php echo $item->user_ip ; ?>
						</td>               
						<td class="center">
							<?php echo $item->browser; ; ?>
						</td>
						<td class="center">
							<?php echo $item->os; ; ?>
						</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 $listOrder; ?>" />
			<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
			<?php echo HTMLHelper::_('form.token'); ?>
		</div>
	</div>
</form>
