<?php

/**
 * @version		   1.10.0
 * @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\Router\Route;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;

$user = Factory::getApplication()->getIdentity();
$default_style = $this->config->default_style;
if($this->category->id > 0 && $this->category->documents_layout != 2)
{
	$default_style = $this->category->documents_layout;
}
$extralayoutCss = ((int)$this->config->theme_type == 1 ? "dark_layout" : "");
?>
<script type="text/javascript">
	var cookieVar = 'default_layout';
	<?php
    if((int) $default_style == 0)
    {
        ?>
        var defaultCookieLayout = 'list';
        <?php
    }else{
        ?>
        var defaultCookieLayout = 'grid';
        <?php
    }
    ?>
</script>
<style>
.edocman-page-heading
{
	font-size: <?php echo ($this->config->heading_font_size == '') ? '30' : $this->config->heading_font_size; ?>px !important;
}
</style>
<div id="edocman-category-page-default" class="edocman-container <?php echo $this->category->css_class." ".$extralayoutCss; ?>">
	<form method="post" name="adminForm" id="edocman_form" action="<?php echo Route::_('index.php?option=com_edocman&view=category&layout=default&id='.$this->category->id.'&Itemid='.$this->Itemid); ?>">
		<?php
		$imgUrl = '';
		if ($this->category)
		{
			if ($this->category->image && is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/category/thumbs/'.$this->category->image)))
			{
				$imgUrl = Uri::base().'media/com_edocman/category/thumbs/'.$this->category->image;
			}
			else
			{
			}
		?>
			<div id="edocman-category">
				
				<h1 class="edocman-page-heading">
					<?php
					if($imgUrl == ''){
						?>
						<i class="edicon edicon-folder-open"></i>
						<?php
					}
					echo $this->category->title;
					if($this->config->enable_rss)
					{
					?>
						<span class="edocman-rss-icon"><a href="<?php echo Route::_('index.php?option=com_edocman&view=category&id='.$this->category->id.'&format=feed&type=rss&Itemid='.$this->Itemid); ?>"><img src="<?php echo Uri::root().'/components/com_edocman/assets/images/rss.png' ?>" /></a></span>
					<?php
					}
					?>
				</h1>
				<?php
				if (($user->authorise('core.create', 'com_edocman.category.'.$this->category->id)) || ($user->authorise('edocman.manage_subcategories', 'com_edocman.category.'.$this->category->id) && $this->config->show_add_sub_categories))
				{
				?>
					<div class="edocman-page-sub-heading">
						<?php
						if ($user->authorise('core.create', 'com_edocman.category.'.$this->category->id))
						{
						?>
							<a href="<?php echo Route::_('index.php?option=com_edocman&view=document&layout=edit&newdocument=1&catid=' . $this->category->id . '&Itemid=' . $this->Itemid.'&return='.EdocmanHelper::currentUrl()); ?>" class="edocman_upload_link btn btn-primary"><i class="edicon edicon-upload"></i>&nbsp;<?php echo Text::_('EDOCMAN_UPLOAD'); ?></a>
						<?php
						}
						if ($user->authorise('edocman.manage_subcategories', 'com_edocman.category.'.$this->category->id) && $this->config->show_add_sub_categories)
						{
							$return = base64_encode(Uri::getInstance()->toString());
							?>
							<a href="<?php echo Route::_('index.php?option=com_edocman&view=editcategory&catid=' . $this->category->id . '&addsubcat=1&return='.$return.'&Itemid=' . $this->Itemid); ?>" class="edocman_upload_link btn btn-primary"><i class="edicon edicon-upload"></i>&nbsp;<?php echo Text::_('EDOCMAN_ADD_SUBCATEGORY'); ?></a>
							<?php
						}
						?>
					</div>
				<?php
				}			
				?>
				<div class="edocman-page-sub-box">
					<?php
					if ($imgUrl)
					{
					?>
						<img class="edocman-thumb-left img-polaroid" src="<?php echo $imgUrl; ?>" alt="<?php echo $this->category->title; ?>" />
					<?php
					}
					if($this->category->description != '')
					{
					?>
						<div class="edocman-description"><?php echo $this->category->description;?></div>
					<?php
					}
					?>
				</div>
			</div>
			<div class="clearfix"></div>
		<?php
		}
		else
		{
			if (is_object($this->menu)) 
			{
				if ($this->params->get('show_page_heading', 0))
				{
				?>
					<h1 class="edocman-page-heading"><?php echo $this->params->get('page_heading'); ?></h1>
				<?php
				}
			}
		}
		?>
		<div id="massDownloadDiv"></div>
		<?php
		$this->categories = (array) $this->categories;
		if (count($this->categories) && $this->combine_categories == 0)
		{
			echo EDocmanHelperHtml::loadCommonLayout('common/categories.php', array('categories' => $this->categories, 'categoryId' => $this->category->id, 'config' => $this->config, 'bootstrapHelper' => $this->bootstrapHelper, 'Itemid' => $this->Itemid, 'subscat' => $this->show_subcat));
		}
		if ($this->config->show_sort_options && count($this->items))
		{
			echo EDocmanHelperHtml::loadCommonLayout('common/category_header.php', array('lists' => $this->lists, 'showLayoutswitcher' => true, 'bootstrapHelper' => $this->bootstrapHelper));
		}
		//if (count($this->items))
		//{
			echo EDocmanHelperHtml::loadCommonLayout('common/documents_default.php', array('items' => $this->items, 'config' => $this->config, 'Itemid' => $this->Itemid, 'category' => $this->category, 'bootstrapHelper' => $this->bootstrapHelper));
		//}
		if ($this->pagination->total > $this->pagination->limit)
		{
		?>
			<div class="pagination">
				<?php echo $this->pagination->getPagesLinks(); ?>
			</div>
		<?php
		}
		?>
		<script type="text/javascript">
			function changeDirection(newDirection) {
				var form = document.getElementById('edocman_form') ;
				form.direction.value = newDirection ;
				form.submit();
			}
			function deleteConfirm(id) {
				var msg = "<?php echo Text::_('EDOCMAN_DELETE_CONFIRM'); ?>";
				if (confirm(msg)) {
					var form = document.getElementById('edocman_form') ;
					form.task.value = 'documents.delete';
					document.getElementById('document_id').value = id;
					form.submit();
				}
			}

			function publishConfirm(id, published) {
				var msg, task ;
				if (published) {
					msg = "<?php echo Text::_("EDOCMAN_PUBLISH_CONFIRM"); ?>";
					task = "documents.publish" ;
				} else {
					msg = "<?php echo Text::_("EDOCMAN_UNPUBLISH_CONFIRM"); ?>";
					task = "documents.unpublish" ;
				}
				if (confirm(msg)) {
					var form = document.getElementById('edocman_form') ;
					form.task.value = task ;
					document.getElementById('document_id').value = id;
					form.submit();
				}
			}
		</script>
		<input type="hidden" name="direction" value="<?php echo $this->state->filter_order_Dir; ?>" />
		<input type="hidden" name="cid[]" value="0" id="document_id" />
		<input type="hidden" name="category_id" value="<?php echo $this->category->id ; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="return" id="return" value="<?php echo EdocmanHelper::currentUrl();?>" />
		<?php echo HTMLHelper::_('form.token'); ?>
	</form>
</div>
<?php
echo EDocmanHelperHtml::loadCommonLayout('common/massdownload.php');
?>
