<?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\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\String\StringHelper;

$session	    = Factory::getApplication()->getSession();
if(!$config->onetime_collect){
	$session->set('name','');
	$session->set('email','');
}
$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 btn btn-primary" rel="{handler: \'iframe\', size: {x: 800, y: 500}}"';
	$popupLink  = 'class="edocman-modal" rel="{handler: \'iframe\', size: {x: 800, y: 500}}"';
}
else
{
	$popup      = ' class="btn btn-primary" ';
	$popupLink  = '';
}
if( !empty($category))
{
	$numberColumns = $category->number_documents_in_grid;
}
if((int) $numberColumns == 0)
{
	if (isset($config->number_documents_in_grid))
	{
		$numberColumns = $config->number_documents_in_grid;
	}
	else
	{
		$numberColumns = 2;
	}
}
$span      = intval(12 / $numberColumns);
$spanClass = $bootstrapHelper->getClassMapping('span' . $span);


if ($config->collect_downloader_information && !$userId && ($name == '' || $email == ''))
{
	$showDownloadForm = true;
}
else
{
	$showDownloadForm = false;
}
?>
<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/jquery.cookie.js" type="text/javascript"></script>
<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/layout.js" type="text/javascript"></script>

<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>

<div class="<?php echo $bootstrapHelper->getClassMapping('row-fluid'); ?>">
	<div id="edocman-documents" class="<?php echo $bootstrapHelper->getClassMapping('span12'); ?>">
		<?php
		if(count($items))
		{
			require_once JPATH_ROOT.'/components/com_edocman/helper/file.class.php' ;
			$activeItemid       = $Itemid;
			for ($i = 0 , $n = count($items) ;  $i < $n ; $i++)
			{
				if( !empty($category))
				{
					$catId      = $category->id;
				}
				else
				{
					$catId = 0;
				}
				$item           = $items[$i] ;
				$Itemid         = EDocmanHelperRoute::getDocumentMenuId($item->id, $catid, $activeItemid);
				$item->data     = new EDocman_File($item->id,$item->filename, $config->documents_path);
				$imgSrc         = '';
				if ($item->image && is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/document/thumbs/'.$item->image)))
				{
                    $modal_url = $imgSrc = Uri::base().'media/com_edocman/document/'.$item->image ;
					$imgSrc     = Uri::base().'media/com_edocman/document/thumbs/'.$item->image ;
				}
				else
				{
                    $modal_url = "";
					if (!isset($config->show_default_document_thumbnail) || $config->show_default_document_thumbnail)
					{
						//$imgSrc = '<i class="'.$item->data->fileicon.'"></i>';
					}
					else
					{
						$imgSrc = '' ;
					}
				}
				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);
				}

				$document_details = $url;
				$downloadUrl    = Route::_('index.php?option=com_edocman&task=document.download&id='.$item->id.'&Itemid='.$Itemid) ;
				if($item->document_url != "")
				{
					$downloadUrl = $item->document_url;
				}
				//$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)) || ($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";
				}
				if ($i % $numberColumns == 0)
				{
				?>
					<div class="clearfix <?php echo $bootstrapHelper->getClassMapping('row-fluid'); ?>">
				<?php
				}
				?>
				<div class="edocman-document <?php echo $bootstrapHelper->getClassMapping('span12'); ?>">
					<div class="edocman-box-heading clearfix">
						<div class="edocman-box-heading-title">
							<h3 class="edocman-document-title pull-left">
								<?php
									//check 3 options below: 
									//1. Use Download Link instead of Details link
									//2. Check Download permission
									//3. In case user should Accept License before they can download, all link must be go to document details
									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; ?>"  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 Text::_('EDOCMAN_DOWNLOAD'); ?>">
											<?php										
											?>
													<?php
													if($config->show_icon_beside_title){
														EDocmanHelperHtml::showFileIcon($item->data);
													} ?>
													<?php echo $item->title; ?>
												</a>
										<?php
										}
										else
										{
											if($item->document_url != "")
											{
												$downloadUrl = $item->document_url;
											}
											?>
											<a href="<?php echo $downloadUrl; ?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>" class="edocman-document-title-link" target="<?php echo $target;?>">
												<?php
												if($config->show_icon_beside_title){
													EDocmanHelperHtml::showFileIcon($item->data);
												}
												?>
												<?php echo $item->title; ?>
											</a>
											<?php
										}
									}
									else
									{
									?>
										<a href="<?php echo $url; ?>" title="<?php echo $item->title; ?>" <?php echo $popupLink; ?> class="edocman-document-title-link" aria-label="<?php echo $item->title; ?>">
											<?php
											if($config->show_icon_beside_title)
											{
												EDocmanHelperHtml::showFileIcon($item->data);
											} ?>
											<?php echo $item->title; ?>
										</a>
									<?php
									}
									if($item->indicators != '' || !empty($item->new_indicator) || !empty($item->update_indicator) || $item->published == 0)
									{
										$indicators = explode(',', $item->indicators);
									?>
										<span class="indicators">
											<?php
											if (!empty($item->new_indicator))
											{
											?>
												<span class="edocman_new">
														<?php echo Text::_('EDOCMAN_NEW');?>
												</span>
											<?php
											}elseif(!empty($item->update_indicator)){
												?>
												<span class="edocman_updated">
														<?php echo Text::_('EDOCMAN_UPDATED');?>
												</span>
												<?php
											}
											if(in_array('featured', $indicators))
											{
											?>
												<span class="edocman_featured">
														<?php echo Text::_('EDOCMAN_FEATURED');?>
												</span>
											<?php
											}
											if(in_array('hot', $indicators))
											{
											?>
												<span  class="edocman_hot">
													<?php echo Text::_('EDOCMAN_HOT');?>
												</span>
											<?php
											}
											if($item->published == 0)
											{
												?>
												<span  class="edocman_unpublished">
													<?php echo Text::_('JUNPUBLISHED');?>
												</span>
												<?php
											}
											?>
										</span>
									<?php
									}
									?>
									<div class="clearfix"></div>
									<?php
									if($config->show_number_downloaded && $item->downloads > 0)
									{
										?>
										<div class="downloadinformation">
											<i class="edicon edicon-download2"></i>&nbsp;<?php echo $item->downloads?> <?php echo Text::_('EDOCMAN_DOWNLOADS');?>
										</div>
										<?php
									}
									if($config->category_table_show_filesize == 1 && trim($item->data->size) != "")
									{
										$tempArr[] = $item->data->size;
										?>
										<div class="sizeinformation">
											<i class="edicon edicon-database"></i>&nbsp;<?php echo $item->data->size; ?>
										</div>
										<?php
									}
									if ($config->show_publish_date)
									{
										?>
										<div class="dateinformation">
											<i class="edicon edicon-calendar"></i>&nbsp;<span class="date-label"><?php echo Text::_('EDOCMAN_CREATED_DATE'); ?>:</span>&nbsp;<?php echo HTMLHelper::_('date', $item->created_time, $config->date_format, true); ?>
										</div>
										<?php
									}

									if ($config->show_modify_date)
									{
										?>
										<div class="dateinformation">
											<i class="edicon edicon-calendar"></i>&nbsp;<span class="date-label"><?php echo Text::_('EDOCMAN_LAST_UPDATED'); ?>:</span>&nbsp;<?php echo HTMLHelper::_('date', $item->modified_time, $config->date_format, true); ?>
										</div>
										<?php
									}
									
									if ($config->enable_rating)
									{
										?>
										<div class="ratinginformation">
											<?php
											EdocmanHelper::showDocumentRating($item->id, 1);
											?>
										</div>
										<?php
									}
									?>
							</h3>
						</div>
						<?php
						if((!$config->use_download_link_instead_of_detail_link && !$config->show_detail_in_popup && $config->hide_details_button !== '1') || EDocmanHelper::massDownloadShowing($canDownload, $config, $item) || $canEdit || $canEditOwn)
						{				
						?>
							<div class="edocman-box-heading-tasks documents-dropdown-<?php echo $item->id;?>">
								<div class="edocman-documents-default-title-dropdown-menu-icon" onclick="toggleMenu('<?php echo $item->id;?>')">
									<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
									  <path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/>
									</svg>
								</div>
								<div class="edocman-document-default-title-dropdown-menu-popup" id="menuPopup_document_<?php echo $item->id;?>">
									<?php
									if(!$config->use_download_link_instead_of_detail_link && !$config->show_detail_in_popup && $config->hide_details_button !== '1')
									{
										?>
										<a href="<?php echo $url ?>" class="edocman-category-gallery-title-link" target="_blank" title="<?php echo $item->title;?>">
											<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
											  <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
											  <path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/>
											</svg>	&nbsp;
											<?php echo Text::_('EDOCMAN_OPEN_DOCUMENT_IN_NEW_TAB')?></a>
										<?php
									}
										
									if(EDocmanHelper::massDownloadShowing($canDownload, $config, $item))
									{
										if(EDocmanHelper::isAlreadyInMassList($item->id))
										{
											$disabled = "disabled";
										}
										else
										{
											$disabled = "";
										}
										?>
										
										<a href="javascript:void(0);" class="edocman-category-gallery-title-link mass-download-btn <?php echo $disable_download_button;?> <?php echo $disabled_class; ?>" id="btnMassDownload_<?php echo $item->id; ?>"  <?php echo $disabled; ?> aria-label="<?php echo $item->title; ?>" data-id="<?php echo $item->id; ?>" data-name="<?php echo $item->title; ?>" data-type="<?php echo $ext;?>" data-size="<?php $item->data->size; ?>">
											<i class="edicon edicon-box-add"></i>&nbsp;
											<?php echo Text::_('EDOCMAN_ADD_TO_MASS_DOWNLOAD_LIST'); ?>
										</a>
										
										<?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) ;
										?>
										
											<a class="edocman-category-gallery-title-link" href="<?php echo $edit_url; ?>" aria-label="<?php echo Text::_('EDOCMAN_EDIT'); ?>" title="<?php echo Text::_('EDOCMAN_EDIT'); ?>">
												<i class="edocman-icon-pencil"></i>&nbsp;
												<?php echo Text::_('EDOCMAN_EDIT'); ?>
											</a>
										
										<?php
									}
									if ($canDelete)
									{
									?>
										
											<a class="edocman-category-gallery-title-link" href="javascript:deleteConfirm(<?php echo $item->id; ?>);" aria-label="<?php echo Text::_('EDOCMAN_DELETE'); ?>" title="<?php echo Text::_('EDOCMAN_DELETE'); ?>">
												<i class="edocman-icon-trash"></i>&nbsp;
												<?php echo Text::_('EDOCMAN_DELETE'); ?>
											</a>
										
									<?php
									}
									if ($canChange)
									{
										if ($item->published)
										{
											$text = Text::_('EDOCMAN_UNPUBLISH');
											$purl = "javascript:publishConfirm($item->id, 0)";
											$class = 'edocman-icon-remove';
										}
										else
										{
											$purl = "javascript:publishConfirm($item->id, 1)";
											$text = Text::_('EDOCMAN_PUBLISH');
											$class = 'edocman-icon-ok';
										}
									?>
									
										<a href="<?php echo $purl; ?>" class="edocman-category-gallery-title-link" title="<?php echo $text; ?>">
											<i class="<?php echo $class; ?>"></i>&nbsp;
											<?php echo $text; ?>
										</a>
									<?php
									}
									if($config->show_bookmark_in_list)
									{
										?>
											<a href="javascript:void(0);" onclick="javascript:addBookmark('<?php echo Uri::root()?>',<?php echo $item->id?>);" class="edocman-category-gallery-title-link" href="#" title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-document-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-original-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>"  id="<?php echo $item->id; ?>" aria-label="<?php echo Text::_('EDOCMAN_BOOKMARK'); ?>">
												<i class="edicon edicon-bookmark"></i>&nbsp;
												<?php
												echo Text::_('EDOCMAN_BOOKMARK');
												?>
											</a>
										<?php
									}
									?>
								</div>
								<script>
								// Close menu when clicking outside
								document.addEventListener("click", function(event) {
									var menuContainer = document.querySelector(".documents-dropdown-<?php echo $item->id;?>");
									if (!menuContainer.contains(event.target)) {
										document.getElementById("menuPopup_document_<?php echo $item->id?>").style.display = "none";
									}
								});
								</script>
							</div>
						<?php } ?>
					</div>
					<div class="edocman-description clearfix">
						<div class="edocman-description-details clearfix">
							<?php
								if ($imgSrc)
								{
								?>
									<div style="float:left;margin-right:10px;">
                                        <?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; ?>"  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 Text::_('EDOCMAN_DOWNLOAD'); ?>">
														<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>" class="edocman-thumb-left img-polaroid" />
													</a>
											<?php
											}
											else
											{
												if($item->document_url != "")
												{
													$downloadUrl = $item->document_url;
												}
												?>
												<a href="<?php echo $downloadUrl; ?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>" class="edocman-document-title-link" target="<?php echo $target;?>">
													<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>" class="edocman-thumb-left img-polaroid" />
												</a>
												<?php
											}
										}
										else
										{
										?>
											<a href="<?php echo $url; ?>" title="<?php echo $item->title; ?>" <?php echo $popupLink; ?> class="edocman-document-title-link" aria-label="<?php echo $item->title; ?>">
												<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>" class="edocman-thumb-left img-polaroid" />
											</a>
										<?php
										}
                                        ?>
									</div>
								<?php
								}

								if((int)$show_category == 1)
								{
									$category_url = EDocmanHelperRoute::getCategoryRoute($item->category->id,$activeItemid);
									?>
									<strong><?php echo Text::_('EDOCMAN_CATEGORY');?>:</strong>
									<a href="<?php echo Route::_($category_url)?>" title="<?php echo $item->category->title;?>">
									<?php
									echo $item->category->title;
									?>
									</a>
									<br />
									<?php
								}

								//output event description
								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;
								}
							?>
						</div>
						<div class="clearfix"></div>
						<?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>
											<a data-toggle="modal" data-document-title="<?php echo $item->title; ?>"  id="<?php echo $item->id; ?>" class="edocmancollectdownloadbtn btn btn-primary" 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 if($item->document_url != "")
													  {
												?>
													<i class="edicon edicon-link"></i>
													<?php echo Text::_('EDOCMAN_OPEN_DOCUMENT'); ?>
												<?php 
													}else{ 
												?>
													<i class="edicon edicon-cloud-download"></i>
													<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>
												<?php 
												} ?>
												<?php
												if($config->show_number_downloads)
												{
													echo "(".$item->downloads.")";
												}
												?>
											</a>
										</li>
									<?php
									}
									else
									{
									?>
										<li>
											<?php
											if($item->document_url != "")
											{
												$downloadUrl = $item->document_url;
											}
											?>
											<a class="<?php echo $btnClass; ?>" href="<?php echo $downloadUrl; ?>" target="<?php echo $target;?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?>">
												<?php 
												if($item->document_url != "")
												{
												?>
													<i class="edicon edicon-link"></i>
												<?php 
												}
												else
												{ 
												?>
													<i class="edicon edicon-cloud-download"></i>
												<?php 
												} 
												?>
												<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>
												<?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('btn btn-secondary');
										}
										else
										{
											$return = base64_encode(Uri::getInstance()->toString());
											?>
											<a data-toggle="modal" class="logintodownload btn btn-secondary" 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'); ?>">
												<i class="edicon edicon-user"></i>
												<?php
												echo Text::_('EDOCMAN_LOGIN_TO_DOWNLOAD'); ?>
											</a>
											<?php
										}
										?>
									</li>
									<?php
								}
								elseif($canDownload && $hide_download_button != 1 && $accept_license == 1)
								{
									?>
										<li>
											<a class="<?php echo $btnClass; ?>" href="<?php echo $url; ?>" aria-label="<?php echo Text::_('EDOCMAN_DOWNLOAD_DOCUMENT'); ?>">
												<?php if($item->document_url != ""){?>
													<i class="edicon edicon-link"></i>
												<?php }else{ ?>
													<i class="edicon edicon-cloud-download"></i>
												<?php } ?>
												<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>
												<?php
												if($config->show_number_downloads)
												{
													echo "(".$item->downloads.")";
												}
												?>
											</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="<?php echo $btnClass; ?> edocmanplayerbtn" data-toggle="modal" <?php echo $audio_player;?> aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" rel="nofollow" title="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>">
													<i class="edicon edicon-eye"></i>
													<?php echo Text::_('EDOCMAN_VIEW'); ?>
												</a>
											<?php
											}
											else
											{
											?>
												<a href="<?php echo $viewUrl; ?>" class="<?php echo $btnClass; ?>" target="_blank" aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" rel="nofollow" title="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>">
													<i class="edicon edicon-eye"></i>
													<?php echo Text::_('EDOCMAN_VIEW'); ?>
												</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"';
											}

											//$viewUrl = Route::_('index.php?option=com_edocman&task=document.viewdoc&id=' . $item->id . '&Itemid=' . $Itemid);
										}
										?>
										<li>
											<a class="<?php echo $btnClass . ' '. $extraViewClass; ?>" href="<?php echo $viewUrl; ?>"
											  <?php echo $target; ?> aria-label="<?php echo Text::_('EDOCMAN_CLICK_TO_VIEW_CONTENT_DOCUMENT'); ?>" rel="nofollow" >
												<i class="edicon edicon-eye"></i>
												<?php echo Text::_('EDOCMAN_VIEW'); ?>
											</a>
										</li>
										<?php
									}
								}

								if ($config->hide_details_button !== '1')
								{
								?>
									<li>
										<a href="<?php echo $document_details; ?>" <?php echo $popup; ?> aria-label="<?php echo Text::_('EDOCMAN_DETAILS'); ?>">
											<?php echo Text::_('EDOCMAN_DETAILS'); ?>
										</a>
									</li>
								<?php
								}
								?>
							</ul>
						</div>
					</div>
				</div>
			<?php
				if (($i + 1) % $numberColumns == 0)
				{
				?>
					</div>
				<?php
				}
			}
			if ($i % $numberColumns != 0)
			{
				echo "</div>" ;
			}
		}
		else
		{
			if($config->show_no_document_available_text)
		{
			echo Text::_('EDOCMAN_NO_AVAILABLE_DOCUMENTS');
		}
		}
		?>
	</div>
</div>

<script type="text/javascript">
function addBookmark(live_site, id)
{
	jQuery.ajax({
		type: 'POST',
		url: live_site + 'index.php?option=com_edocman',
		data: 'task=document.bookmark&id=' + id + '&tmpl=component',
		dataType: 'json',
		success: function(response)
		{
			alert(response.result);
		}
	});
}
/*
function addMassDownload(live_site,id)
{
	jQuery('#btnMassDownload_' + id).attr('disabled','disabled');
	var data = {
		'task'	:	'document.store_mass_download',
		'document_id' : id
	};
	jQuery.ajax({
		type: 'POST',
		url: live_site + 'index.php?option=com_edocman',
		data: data,
		dataType: 'html',
		success: function(response)
		{
			responseDiv = document.getElementById('massDownloadDiv');
			jQuery('#massDownloadDiv').html(response);
			responseDiv.style.display = 'block';

			setTimeout(function() {
				responseDiv.style.display = 'none';
			  }, 30000);
		}
	});
}
*/
function toggleMenu(documentId) 
{
	var menu = document.getElementById("menuPopup_document_" + documentId);
	menu.style.display = (menu.style.display === "block") ? "none" : "block";
}
</script>
<?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>