<?php

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

jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
if(!is_dir(Path::clean(JPATH_ROOT.'/media/com_edocman/document/medium'))){
    Folder::create(JPATH_ROOT.'/media/com_edocman/document/medium');
    File::copy(JPATH_ROOT.'/media/com_edocman/index.html',JPATH_ROOT.'/media/com_edocman/document/medium/index.html');
}
$session        = Factory::getApplication()->getSession();
$name           = $session->get('name','');
$email          = $session->get('email','');
$user           = Factory::getApplication()->getIdentity();
$userId         = $user->get('id');
$btnClass       = $bootstrapHelper->getClassMapping('btn');
$show_category  = Factory::getApplication()->getInput()->getInt('show_category',0);

if ($config->show_detail_in_popup)
{
	$popup      = 'class="edocman-modal ' . $btnClass . ' btn-primary" rel="{handler: \'iframe\', size: {x: 800, y: 500}}"';
	$popupLink  = 'class="edocman-modal" rel="{handler: \'iframe\', size: {x: 800, y: 500}}"';
	$popup_img  = ' class="edocman-modal hover-effect" rel="{handler: \'iframe\', size: {x: 800, y: 500}}" ';
}
else
{
	$popup      = ' class="' . $btnClass . ' btn-primary" ';
	$popupLink  = '';
	$popup_img  = '';
}

if( !empty($category))
{
	$numberColumns = $category->number_columns;
}
if((int) $numberColumns == 0)
{
	if (isset($config->number_columns))
	{
		$numberColumns = $config->number_columns;
	}
	else
	{
		$numberColumns = 2;
	}
}
$span           = intval(12 / $numberColumns);
$spanClass      = $bootstrapHelper->getClassMapping('span' . $span);
$rowfluidClass  = $bootstrapHelper->getClassMapping('row-fluid');

switch ($span) {
    case "2":
        $nrepeat = 6;
        break;
    case "3":
        $nrepeat = 4;
        break;
    case "4":
        $nrepeat = 3;
        break;
    case "6":
        $nrepeat = 2;
        break;
    case "12":
        $nrepeat = 1;
        break;
}

if ($config->collect_downloader_information && !$userId && ($name == '' || $email == ''))
{
	$showDownloadForm = true;
}
else
{
	$showDownloadForm = false;
}
?>
<script type="text/javascript">
	var spanClass = '<?php echo $spanClass; ?>';
	<?php
	if(EdocmanHelper::isJoomla4())
	{
		?>
		rowFluidClass = '<?php echo $bootstrapHelper->getClassMapping('span12'); ?>';
		<?php
	}
	else
	{
		?>
		rowFluidClass = '<?php echo $bootstrapHelper->getClassMapping('row-fluid'); ?>';
		<?php
	}
	?>
</script>
<style>
	h3.edocman-document-title
	{
		font-size: <?php echo ($config->document_title_font_size == '') ? '18' : $config->document_title_font_size; ?>px !important;
	}
</style>
<?php
if($config->gallery_picture_type == 1)
{
	$resized_width = 240;
	$resized_height = 360;
}
else
{
	$resized_width = 360;
	$resized_height = 240;
}
?>
<div id="edocman-documents" class="clearfix columnlayouts">
    <div class="<?php echo $rowfluidClass;?>">
	<?php
	if(count($items))
	{
		$activeItemid = $Itemid;
		$j = 0;
		$documentImagePath              = JPATH_ROOT . '/media/com_edocman/document/';
        $thumbDocumentImagePath         = $documentImagePath.'/medium/';
		for ($i = 0 , $n = count($items) ;  $i < $n ; $i++)
		{
		    $j++;
			$item = $items[$i] ;
			if( !empty($category))
			{
                $catId = $category->id;
			}
			else
			{
				$category = EdocmanHelper::getDocumentCategory($item->id);
				$catId = $category->id;
			}
			
			$Itemid = EDocmanHelperRoute::getDocumentMenuId($item->id, $catId, $activeItemid);
			if($item->image)
			{
			    if( ! is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/document/medium/'.$item->image)))
				{
                    //$width  = 360;
                   // $height = 240;
                    EDocmanHelper::resizeImage($documentImagePath . $item->image, $thumbDocumentImagePath . $item->image, $resized_width, $resized_height);
                }
				if (is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/document/medium/'.$item->image)))
				{
					$imgSrc = Uri::base().'media/com_edocman/document/medium/'.$item->image ;
				}
				else
				{
					$imgSrc = Uri::base() . 'components/com_edocman/assets/images/icons/thumbs/noimage.png';
				}
            }
			else 
			{
                if (!isset($config->show_default_document_thumbnail) || $config->show_default_document_thumbnail) 
				{
                    $ext = strtolower(EdocmanHelper::getExt($item->filename));
                    if (is_file(Path::clean(JPATH_ROOT . '/components/com_edocman/assets/images/icons/thumbs/' . $ext . '.png')) )
					{
                        $imgSrc = Uri::base() . 'components/com_edocman/assets/images/icons/thumbs/' . $ext . '.png';
                    } 
					else 
					{
                        $imgSrc = Uri::base() . 'components/com_edocman/assets/images/icons/thumbs/noimage.png';
                    }
                } 
				else 
				{
                   $imgSrc = Uri::base() . 'components/com_edocman/assets/images/icons/thumbs/noimage.png';
                }
            }
			if ($config->show_detail_in_popup)
			{
				$url = Route::_('index.php?option=com_edocman&view=document&id='.$item->id.'&catid='.$catId.'&tmpl=component&Itemid='.$Itemid);
			}
			else
			{
				$url = Route::_('index.php?option=com_edocman&view=document&id='.$item->id.'&catid='.$catId.'&Itemid='.$Itemid);
			}
			$downloadUrl = Route::_('index.php?option=com_edocman&task=document.download&id='.$item->id.'&Itemid='.$Itemid) ;
			//$canDownload = $user->authorise('edocman.download', 'com_edocman.document.'.$item->id) ;
			$canEdit	= $user->authorise('core.edit',			'com_edocman.document.'.$item->id);
			$canDelete	= $user->authorise('core.delete',			'com_edocman.document.'.$item->id);
			if(!$canDelete){
				$canDelete	= $user->authorise('edocman.deleteown',	'com_edocman.document.'.$item->id) && $item->created_user_id == $userId;
			}
			$canCheckin	= $user->authorise('core.admin', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
			$canEditOwn	= $user->authorise('core.edit.own',		'com_edocman.document.'.$item->id) && $item->created_user_id == $userId;
			$canChange	= $user->authorise('core.edit.state',	'com_edocman.document.'.$item->id) && $canCheckin;
			//$canDownload = ($item->created_user_id == $userId && $item->created_user_id > 0) || (($item->user_ids == "" || $item->user_ids == 0) && ($canDownload || $canEdit || $canEditOwn)) || ($item->user_ids != '' && $item->user_ids != '0' && in_array($userId, explode(',', $item->user_ids))) ;
			$canDownload	= EdocmanHelper::canDownload($item->id);
            $accept_license = 0;
            $show_accept_license		= 0;
			if($config->accept_license && ($item->license_id > 0 || EdocmanHelper::getDefaultLicense() > 0))
			{
				if($config->accept_license_one_time)
				{
					$alreadyAcceptLicense	= $session->get('alreadyAcceptLicense',0);
					if($alreadyAcceptLicense == 0)
					{
						$show_accept_license = 1;
					}
					else
					{
						$show_accept_license = 0;
					}
				}
				else
				{
					$show_accept_license = 1; 
				}
			}

			if($show_accept_license == 1 || $item->download_password != "")
			{
				$accept_license = 1;
			}

            $hide_download_button = $config->hide_download_button;
            $hide_download = $category->hide_download;
            if((int)$hide_download == 1)
			{
                $hide_download_button = 1;
            }
			elseif((int)$hide_download == 2)
			{
                $hide_download_button = 0;
            }
            $show_view_button = $config->show_view_button;
            $show_view = $category->show_view;
            if((int)$show_view == 1)
			{
                $show_view_button = 1;
            }
			elseif((int)$show_view == 2)
			{
                $show_view_button = 0;
            }
			if($item->document_url != "")
			{
				if($config->external_download_link == 1)
				{
					$target = "_blank";
				}
				else
				{
					$target = "_self";
				}
			}
			else
			{
				$target = "_self";
			}
			?>
			<div class="<?php echo $spanClass; ?>">
				<div class="edocman-document">
					<?php
					if($imgSrc != '')
					{
					?>
						<?php
						if ($config->use_download_link_instead_of_detail_link && $canDownload && ($accept_license == 0))
						{
							if ($showDownloadForm)
							{
								
								
								?>
									<a data-toggle="modal" data-document-title="<?php echo $item->title; ?>" title="<?php echo $item->title; ?>"  id="<?php echo $item->id; ?>" class="edocmancollectdownloadbtn edocman-document-title-link" href="<?php echo Uri::root(true); ?>/index.php?option=com_edocman&view=document&layout=modal&tmpl=component&id=<?php echo $item->id;?>&direct=1" aria-label="<?php echo $item->title; ?>">
								<?php
							}
							else
							{
								if($item->document_url != "")
								{
									$downloadUrl = $item->document_url;
								}
								?>
								
								<a href="<?php echo $downloadUrl; ?>" title="<?php echo $item->title; ?>" class="edocman-document-title-link" aria-label="<?php echo $item->title; ?>" target="<?php echo $target;?>">
								<?php
							}
						}
						else
						{
							?>
							<a href="<?php echo $url; ?>" title="<?php echo $item->title; ?>" aria-label="<?php echo $item->title; ?>" <?php echo $popup_img; ?>>
							<?php
						}
						?>
							<img src="<?php echo $imgSrc; ?>" alt="<?php echo sprintf(Text::_('EDOCMAN_PHOTO_OF_DOCUMENT'),$item->title); ?>">
						</a>
					<?php } ?>
					<?php
					if(!$canDownload && $config->show_no_download_permission_alert)
					{
						?>
						<div class="no_download_permission_alert clearfix">
							<?php
							echo Text::_('EDOCMAN_YOU_DO_NOT_HAVE_PERMISSION_TO_DOWNLOAD_THIS_DOCUMENT');
							?>
						</div>
						<?php
					}		
					?>
					<div class="edocman-taskbar clearfix">
						<ul>
							<?php
							if ($canDownload && $hide_download_button !=  1  && ($accept_license == 0))
							{
								if ($showDownloadForm)
								{
									?>
									<li>
										<?php
										
											?>
											<a data-toggle="modal" data-document-title="<?php echo $item->title; ?>"  id="<?php echo $item->id; ?>" class="edocmancollectdownloadbtn" href="<?php echo Uri::root(true); ?>/index.php?option=com_edocman&view=document&layout=modal&tmpl=component&id=<?php echo $item->id;?>&direct=1" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>">
											<?php
										?>
											<?php if($item->document_url != ""){?>
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-link-45deg" viewBox="0 0 16 16">
												  <path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1 1 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4 4 0 0 1-.128-1.287z"/>
												  <path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243z"/>
												</svg>
												
											<?php }else{ ?>
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
												  <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>
												  <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/>
												</svg>
											<?php } ?>
											<?php
											if($config->show_number_downloads)
											{
												echo "(".$item->downloads.")";
											}
											?>
										</a>
									</li>
									<?php
								}
								else
								{
									if($item->document_url != "")
									{
										$downloadUrl = $item->document_url;
									}
									?>
									<li>
										<a class="" href="<?php echo $downloadUrl; ?>" target="<?php echo $target;?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>">
											<?php if($item->document_url != ""){?>
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-link-45deg" viewBox="0 0 16 16">
												  <path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1 1 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4 4 0 0 1-.128-1.287z"/>
												  <path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243z"/>
												</svg>
											<?php }else{ ?>
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
												  <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>
												  <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/>
												</svg>
											<?php } ?>
											<?php
											if($config->show_number_downloads)
											{
												echo "(".$item->downloads.")";
											}
											?>
										</a>
									</li>
									<?php
								}
							}
							elseif(!$canDownload && $hide_download_button != 1 && $config->login_to_download && (int)$userId == 0)
							{
								?>
								<li>
									<?php
									if($config->edocman_login == 1)
									{
										EdocmanHelper::generateJoomlaLogin($btnClass);
									}
									else
									{
										
										$return = base64_encode(Uri::getInstance()->toString());
										?>
										<a data-toggle="modal" class="logintodownload" href="<?php echo Uri::root();?>index.php?option=com_edocman&view=document&layout=login&id=<?php echo $item->id;?>&tmpl=component&return=<?php echo $return;?>" aria-label="<?php echo Text::_('EDOCMAN_LOGIN_TO_DOWNLOAD'); ?>" title="<?php echo Text::_('EDOCMAN_LOGIN_TO_DOWNLOAD'); ?>">
	
											<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-person" viewBox="0 0 16 16">
											  <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"/>
											</svg>
											
										</a>
										<?php
									}
									?>
								</li>
								<?php
							}
							elseif($canDownload && $hide_download_button != 1 && ($accept_license == 1))
							{
								?>
								<li>
									<a class="" href="<?php echo $url; ?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?> <?php echo $item->title; ?>">
										<?php if($item->document_url != ""){?>
											<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-link-45deg" viewBox="0 0 16 16">
  <path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1 1 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4 4 0 0 1-.128-1.287z"/>
  <path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243z"/>
</svg>
										<?php }else{ ?>
											<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
											  <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>
											  <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/>
											</svg>
										<?php } ?>
										<?php
										if($config->show_number_downloads)
										{
											echo "(".$item->downloads.")";
										}
										?>
									</a>
								</li>
								<?php
							}
							if(EDocmanHelper::massDownloadShowing($canDownload, $config, $item))
							{
								if(EDocmanHelper::isAlreadyInMassList($item->id))
								{
									$disabled = "disabled";
								}
								else
								{
									$disabled = "";
								}
								?>
								<li>
									
									<a href="javascript:void(0);" id="btnMassDownload_<?php echo $item->id; ?>"  class="edocmandownloadlink btn mass-download-btn <?php echo $disable_download_button;?>" aria-label="<?php echo Text::_('EDOCMAN_CLICK_HERE_TO_ADD_DOCUMENT_TO_MASS_DOWNLOAD_LIST'); ?>" <?php echo $disabled;?>  data-id="<?php echo $item->id; ?>" data-name="<?php echo $item->title; ?>" data-type="<?php echo $ext;?>" data-size="<?php $item->data->size; ?>" title="<?php echo Text::_('EDOCMAN_ADD_TO_MASS_DOWNLOAD_LIST'); ?>">

										<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-cloud-arrow-down-fill" viewBox="0 0 16 16">
  <path d="M8 2a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 6.095 0 7.555 0 9.318 0 11.366 1.708 13 3.781 13h8.906C14.502 13 16 11.57 16 9.773c0-1.636-1.242-2.969-2.834-3.194C12.923 3.999 10.69 2 8 2m2.354 6.854-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 9.293V5.5a.5.5 0 0 1 1 0v3.793l1.146-1.147a.5.5 0 0 1 .708.708"/>
</svg>
									</a>
								</li>
								<?php
							}
							if ($canDownload && $show_view_button == 1 && $item->canView)
							{
								$playextension	= EdocmanHelper::returnPlayExtension();
								$showModal		= EdocmanHelper::viewable($item);
								$ext			= strtolower(EDocmanHelper::getExt($item)) ;
								if((in_array($ext,$playextension) || $item->view_url != "") && $showModal && !EDocmanHelper::isDropBoxTurnedOn() && !EDocmanHelper::isAmazonS3TurnedOn())
								{
									$viewUrl = Uri::root()."index.php?option=com_edocman&view=play&id=".$item->id."&tmpl=component";
									$audio_player = EdocmanHelper::generateAudioPlayer($item, $showModal);
									?>
									<li>
										<?php
										if($config->view_option == 0)
										{
											?>
											<a href="<?php echo $viewUrl; ?>" class="edocmanplayerbtn" data-toggle="modal" <?php echo $audio_player;?> aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" rel="nofollow" >
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-eye" viewBox="0 0 16 16">
  <path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8M1.173 8a13 13 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5s3.879 1.168 5.168 2.457A13 13 0 0 1 14.828 8q-.086.13-.195.288c-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5s-3.879-1.168-5.168-2.457A13 13 0 0 1 1.172 8z"/>
  <path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5M4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0"/>
</svg>
											</a>
											<?php
										}
										else
										{
											?>
											<a href="<?php echo $viewUrl; ?>" class="" target="_blank" aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>"  rel="nofollow" >
												<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-eye" viewBox="0 0 16 16">
  <path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8M1.173 8a13 13 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5s3.879 1.168 5.168 2.457A13 13 0 0 1 14.828 8q-.086.13-.195.288c-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5s-3.879-1.168-5.168-2.457A13 13 0 0 1 1.172 8z"/>
  <path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5M4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0"/>
</svg>
											</a>
											<?php
										}
										?>
									</li>
									<?php
								}
								else 
								{

									if($item->view_url != "")
									{
										$viewUrl = $item->view_url;
									}
									else
									{
										if (in_array($ext, ['pdf']) && $config->use_googleviewer == 0 && $config->pdf_view_option == 0 && $config->pdf_view_type == 0)
											{
												$viewUrl		= Route::_('index.php?option=com_edocman&task=document.viewdoc&tmpl=component&id=' . $item->id );

												$extraViewClass = 'pdfviewer';
												$target         = '';
											}
											else
											{
												$viewUrl = Route::_('index.php?option=com_edocman&task=document.viewdoc&id=' . $item->id . '&Itemid=' . $Itemid);

												$extraViewClass = '';
												$target         = 'target="_blank"';
											}
									}
									?>
									<li>
										<a class="<?php echo $extraViewClass;?>" <?php echo $target; ?> href="<?php echo $viewUrl; ?>"
										   target="_blank" aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" title="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" rel="nofollow" >
											<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-eye" viewBox="0 0 16 16">
  <path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8M1.173 8a13 13 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5s3.879 1.168 5.168 2.457A13 13 0 0 1 14.828 8q-.086.13-.195.288c-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5s-3.879-1.168-5.168-2.457A13 13 0 0 1 1.172 8z"/>
  <path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5M4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0"/>
</svg>
										</a>
									</li>
									<?php
								}
							}
							
							$pass_lock = true;
							if($config->lock_function){ //lock function is turned on
								if(($item->locked_by != $user->id) && ($item->is_locked == 1)){
									$pass_lock = false;
								}
							}
							if (($canEdit || $canEditOwn) && ($pass_lock))
							{
								$return = EdocmanHelper::currentUrl();
								$edit_url = Route::_('index.php?option=com_edocman&task=document.edit&id='.$item->id.'&return='.$return.'&Itemid='.$Itemid) ;
								?>
								<li>
									<a class="" href="<?php echo $edit_url; ?>" aria-label="<?php echo Text::_('EDOCMAN_EDIT_DOCUMENT'); ?>" title="<?php echo Text::_('EDOCMAN_EDIT_DOCUMENT'); ?>">
										<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
  <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
  <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5z"/>
</svg>
									</a>
								</li>
								<?php
							}
							if ($canDelete)
							{
								?>
								<li>
									<a class="" href="javascript:deleteConfirm(<?php echo $item->id; ?>);" aria-label="<?php echo Text::_('EDOCMAN_DELETE'); ?>" title="<?php echo Text::_('EDOCMAN_DELETE'); ?>">
										<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
  <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z"/>
  <path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z"/>
</svg>
									</a>
								</li>
								<?php
							}
							if ($canChange)
							{
								if ($item->published)
								{
									$text = Text::_('EDOCMAN_UNPUBLISH');
									$url = "javascript:publishConfirm($item->id, 0)";
									$class = 'edocman-icon-remove';
								}
								else
								{
									$url = $url = "javascript:publishConfirm($item->id, 1)";
									$text = Text::_('EDOCMAN_PUBLISH');
									$class = 'edocman-icon-ok';
								}
								?>
								<li>
									<a href="<?php echo $url; ?>" class="" title="<?php echo $text;?>">
										<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-power" viewBox="0 0 16 16">
  <path d="M7.5 1v7h1V1z"/>
  <path d="M3 8.812a5 5 0 0 1 2.578-4.375l-.485-.874A6 6 0 1 0 11 3.616l-.501.865A5 5 0 1 1 3 8.812"/>
</svg>
									</a>
								</li>
								<?php
							}
							?>
						</ul>
					</div>

					<div class="mobile-document-title clearfix">
						<?php
						if($item->indicators != '' || !empty($item->new_indicator) || !empty($item->update_indicator) || $item->published == 0)
						{
							$indicators = explode(',', $item->indicators);
							?>
							
							<?php
							if(in_array('featured', $indicators))
							{
								?>
								<span class="label-featured label label-success">
										<?php echo Text::_('EDOCMAN_FEATURED');?>
								</span>
								<?php
							}
							?>
							
							<?php
							if (!empty($item->new_indicator))
							{
								?>
								<span class="label-status label-new label label-default">
									<?php echo Text::_('EDOCMAN_NEW');?>
								</span>
								<?php
							}
							if(in_array('hot', $indicators))
							{
								?>
								<span class="label label-default label-hot">
									<?php echo Text::_('EDOCMAN_HOT');?>
								</span>
								<?php
							}
							if($item->published == 0)
							{
								?>
								<span  class="label label-default label-color-202">
									<?php echo Text::_('JUNPUBLISHED');?>
								</span>
								<?php
							}
							
						}	
						?>
						<div class="page-title">
							<?php echo $item->title; ?>
						</div>

						<?php
						if( $config->show_creation_user || $config->show_publish_date){
						?>
							<div class="sub-title">
								<?php
								$created_user_id = $item->created_user_id;
								if ($config->show_creation_user  && (int)$created_user_id > 0)
								{
									?>
									<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person" viewBox="0 0 16 16">
  <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"/>
</svg>
											
											<?php
											$created_user = Factory::getUser($created_user_id);
											echo $created_user->name;
											?>
										&nbsp;
									<?php
								}
								if ($config->show_publish_date) {
									?>
									<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar2-date" viewBox="0 0 16 16">
  <path d="M6.445 12.688V7.354h-.633A13 13 0 0 0 4.5 8.16v.695c.375-.257.969-.62 1.258-.777h.012v4.61zm1.188-1.305c.047.64.594 1.406 1.703 1.406 1.258 0 2-1.066 2-2.871 0-1.934-.781-2.668-1.953-2.668-.926 0-1.797.672-1.797 1.809 0 1.16.824 1.77 1.676 1.77.746 0 1.23-.376 1.383-.79h.027c-.004 1.316-.461 2.164-1.305 2.164-.664 0-1.008-.45-1.05-.82zm2.953-2.317c0 .696-.559 1.18-1.184 1.18-.601 0-1.144-.383-1.144-1.2 0-.823.582-1.21 1.168-1.21.633 0 1.16.398 1.16 1.23"/>
  <path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5M2 2a1 1 0 0 0-1 1v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1z"/>
  <path d="M2.5 4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5z"/>
</svg>
											
											<?php
											echo HTMLHelper::_('date', $item->created_time, $config->date_format, null);
											?>
										&nbsp;
									<?php
								}
								if ($config->show_modify_date) {
									?>
									<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar2-date" viewBox="0 0 16 16">
  <path d="M6.445 12.688V7.354h-.633A13 13 0 0 0 4.5 8.16v.695c.375-.257.969-.62 1.258-.777h.012v4.61zm1.188-1.305c.047.64.594 1.406 1.703 1.406 1.258 0 2-1.066 2-2.871 0-1.934-.781-2.668-1.953-2.668-.926 0-1.797.672-1.797 1.809 0 1.16.824 1.77 1.676 1.77.746 0 1.23-.376 1.383-.79h.027c-.004 1.316-.461 2.164-1.305 2.164-.664 0-1.008-.45-1.05-.82zm2.953-2.317c0 .696-.559 1.18-1.184 1.18-.601 0-1.144-.383-1.144-1.2 0-.823.582-1.21 1.168-1.21.633 0 1.16.398 1.16 1.23"/>
  <path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5M2 2a1 1 0 0 0-1 1v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1z"/>
  <path d="M2.5 4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5z"/>
											
											<?php
											echo HTMLHelper::_('date', $item->modified_time, $config->date_format, null);
											?>
										&nbsp;
									<?php
								}
								?>
							</div>
						<?php } ?>
					</div>

					<?php
					if($config->show_description_in_columns)
					{
					?>
					<div class="item-body table-cell">
						<div class="body-left table-cell">
							<div class="info-row">
								
								<span class="edocman-description-column">
									<?php
									if (!$item->short_description)
									{
										$item->short_description = $item->description;
									}
									if((int)$config->number_words > 0)
									{
										$description = strip_tags($item->short_description);
										$descriptionArr = explode(" ",$description);
										if(count($descriptionArr) > (int)$config->number_words)
										{
											for($d = 0;$d < (int)$config->number_words - 1;$d++)
											{
												echo $descriptionArr[$d]." ";
											}
											echo "..";
										}
										else
										{
											echo $description;
										}
									}
									else
									{
										echo $item->short_description;
									}
									?>
								</span>
								
							</div>
						</div>
					</div>
					<?php } ?>
				</div>
			</div>
		    <?php
			if ($j == $nrepeat)
			{
			    $j = 0;
			    ?>
				</div>
                <div class="<?php echo $rowfluidClass?>">
			    <?php
			}
		}
	}
	else
	{
		if($config->show_no_document_available_text)
		{
			echo Text::_('EDOCMAN_NO_AVAILABLE_DOCUMENTS');
		}
	}
	?>
    </div>
</div>

<?php
if ($showDownloadForm && !EdocmanHelper::isJoomla4())
{
	echo EDocmanHelperHtml::loadCommonLayout('common/modal.php', array('bootstrapHelper' => $bootstrapHelper,'config' => $config));
}
if((!$canDownload && $hide_download_button != 1 && $config->login_to_download && (int)$userId == 0) && !EdocmanHelper::isJoomla4())
{
	echo EDocmanHelperHtml::loadCommonLayout('common/login.php', array('bootstrapHelper' => $bootstrapHelper));
}
echo EDocmanHelperHtml::loadCommonLayout('common/player.php', array());
echo EDocmanHelperHtml::loadCommonLayout('common/download.php', array());

if($config->login_to_download && (int)$userId == 0)
{
	echo EDocmanHelperHtml::loadCommonLayout('common/modallogin.php', array());
	?>
	<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/login.js" type="text/javascript"></script>
	<?php
}
?>
<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/player.js" type="text/javascript"></script>
<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/download.js" type="text/javascript"></script>