<?php

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

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;

class EDocmanViewBookmarkHtml extends OSViewHtml
{

	function display($tpl = null)
	{
		$config                 = EDocmanHelper::getConfig();
		// Calculate default item ids
		$views                  = array('categories', 'category', 'document');
		$itemId                 = 0;
		foreach ($views as $view)
		{
			if ($itemId = EDocmanHelperRoute::findView($view, 0))
			{
				break;
			}
		}
		$filter_order           = Factory::getApplication()->getInput()->getString('filter_order');
		$filter_order_array		= ['tbl.id','tbl.title'];
		if(!in_array($filter_order,$filter_order_array))
		{
			$filter_order		= 'tbl.title';
		}
		$filter_order_Dir       = Factory::getApplication()->getInput()->getString('filter_order_Dir');
		$filter_order_Dir_array = ['asc','desc'];
		if(!in_array($filter_order_Dir,$filter_order_Dir_array))
		{
			$filter_order_Dir	= 'asc';
		}
        $this->state            = $this->model->getState();
        $this->state->set('filter_order',$filter_order);
        $this->state->set('filter_order_Dir',$filter_order_Dir);

		$this->Itemid           = Factory::getApplication()->getInput()->getInt('Itemid', 0);
		$this->items            = $this->model->getData();
		if ($config->show_view_button && count($this->items))
		{
			$extsForView = explode(',', $config->exts_for_view);
			for ($i = 0, $n = count($extsForView); $i < $n; $i++)
			{
				$extsForView[$i] = strtolower(trim($extsForView[$i]));
			}
			foreach ($this->items as $item)
			{
				$fileName = $item->filename;
				$fileExt  = strtolower(EdocmanHelper::getExt($fileName));
				if (in_array($fileExt, $extsForView) || ($item->view_url != ''))
				{
					$item->canView = 1;
				}
				else
				{
					$item->canView = 0;
				}
			}
		}
		$this->pagination       = $this->model->getPagination();

		$this->defaultItemid    = $itemId ? $itemId : $this->Itemid;
		$this->path             = EDocmanHelper::getConfigValue('documents_path');
		$this->config	        = $config;
		$this->bootstrapHelper  = new EDocmanHelperBootstrap($config->twitter_bootstrap_version);
		parent::display($tpl);
	}
}
