<?php
/**
 * @version        1.11.3
 * @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\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\String\StringHelper;

/* @var JDocumentHtml $document */
$document					= Factory::getApplication()->getDocument();
$rootUri					= Uri::root();
$largeImageUri				= '';
$item						= $this->item ;

//og:title
$document->setMetaData('og:title', $item->title, 'property');

//og:image
if ($item->image && is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/document/thumbs/'.$item->image)))
{
	$imgSrc					= $rootUri.'media/com_edocman/document/thumbs/'.$item->image ;
}

if ($imgSrc)
{
	$document->setMetaData('og:image', $imgSrc, 'property');
}
$document->setMetaData('og:url', Uri::getInstance()->toString(), 'property');

//og:description
$description				= !empty($item->metadesc) ? $item->metadesc : $item->metadesc;
$description				= HTMLHelper::_('string.truncate', $description, 200, true, false);
$document->setMetaData('og:description', $description, 'property');

//og:site name
$document->setMetaData('og:site_name', Factory::getApplication()->get('sitename'), 'property');


$config						= $this->config;
$session					= Factory::getApplication()->getSession();
if(!$config->onetime_collect){
	$session->set('name','');
	$session->set('email','');
}
$name						= $session->get('name','');
$email						= $session->get('email','');

$url						= Route::_(EDocmanHelperRoute::getDocumentRoute($item->id, $this->categoryId, $this->Itemid), false);
$siteUrl					= Uri::base();
$socialUrl					= Uri::getInstance()->toString();
$user						= Factory::getApplication()->getIdentity() ;
$userId						= $user->get('id');
//$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				= EdocmanHelper::canDownload($item->id);
$bootstrapHelper			= $this->bootstrapHelper;
$btnClass					= $bootstrapHelper->getClassMapping('btn');
$rowFluidClass				= $bootstrapHelper->getClassMapping('row-fluid');
$span12Class				= $bootstrapHelper->getClassMapping('span12');
require_once JPATH_ROOT.'/components/com_edocman/helper/file.class.php' ;
$accept_license				= 0;
$pass_password				= 0;
if($config->accept_license && $this->default_license > 0)
{
	$accept_license			= 1;
}
if($config->accept_license_one_time)
{
	$alreadyAcceptLicense	= $session->get('alreadyAcceptLicense',0);
	if($alreadyAcceptLicense == 0)
	{
		$accept_license		= 1;
	}
	else
	{
		$accept_license		= 0;
	}
}
if($this->item->download_password != "")
{
	$pass_password			= 1;
}
$hide_download_button		= $this->config->hide_download_button;
$hide_download = $this->category->hide_download;
if((int)$hide_download == 1){
	$hide_download_button	= 1;
}
elseif((int)$hide_download == 2)
{
	$hide_download_button	= 0;
}
$show_view_button			= $this->config->show_view_button;
$show_view					= $this->category->show_view;
if((int)$show_view == 1)
{
	$show_view_button		= 1;
}
elseif((int)$show_view == 2)
{
	$show_view_button		= 0;
}

$item->data					= new EDocman_File($item->id,$item->filename, $config->documents_path) ;
if ($config->collect_downloader_information && !$userId && ($name == '' || $email == ''))
{
	$showDownloadForm		= true;
}
else
{
	$showDownloadForm		= false;
}
$extralayoutCss				= ((int)$config->theme_type == 1 ? "dark_layout" : "");

$ext						= strtolower(EDocmanHelper::getExt($item)) ;

$indicators					= (array)$item->indicators;
?>
<style>
.edocman-page-heading
{
	font-size: <?php echo ($config->heading_font_size == '') ? '30' : $config->heading_font_size; ?>px !important;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<div id="edocman-document-page" class="edocman-container edocman-document <?php echo $extralayoutCss;?>">
	<div class="document-card">
		<div class="document-header">
			<!-- Desktop Header -->
			<div class="header-content">
				<div class="document-title-container">
					<div class="doc-icon">
						<?php EDocmanHelperHtml::showFileIcon($item->data); ?>
					</div>
					<div class="title-content">
						<div class="title-row">
							<h1 class="document-title">
								<?php echo $item->title; ?>
							</h1>
							<div class="indicators-container">
								<?php
								if (!empty($item->new_indicator))
								{
								?>
									<span class="indicator new">
											<?php echo Text::_('EDOCMAN_NEW');?>
									</span>
								<?php
								}
								if(in_array('featured', $indicators))
								{
								?>
									<span class="indicator featured"><?php echo Text::_('EDOCMAN_FEATURED');?></span>
								<?php
								}
								if(in_array('hot', $indicators))
								{
								?>
									<span class="indicator hot"><?php echo Text::_('EDOCMAN_HOT');?></span>
								<?php
								}
								?>
							</div>
						</div>
					</div>
				</div>
				<?php
				if($this->config->show_bookmark_button)
				{
					?>
					<button class="bookmark-btn" onclick="javascript:addBookmark('<?php echo Uri::root()?>',<?php echo $this->item->id?>);" href="#sharing-form" data-document-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-original-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" aria-label="<?php echo Text::_('EDOCMAN_BOOKMARK'); ?>">
						<i class="fas fa-bookmark"></i>
					</button>
					<?php
				}
				?>
			</div>
			
			<!-- Mobile Header -->
			<div class="mobile-header">
				<div class="mobile-title-row">
					<div class="mobile-title-container">
						<div class="doc-icon">
							<?php EDocmanHelperHtml::showFileIcon($item->data); ?>
						</div>
						<h1 class="document-title"><?php echo $item->title; ?></h1>
					</div>
					<?php
					if($this->config->show_bookmark_button)
					{
						?>
						<button class="bookmark-btn" onclick="javascript:addBookmark('<?php echo Uri::root()?>',<?php echo $this->item->id?>);" href="#sharing-form" data-document-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-original-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>"  id="<?php echo $this->item->id; ?>" aria-label="<?php echo Text::_('EDOCMAN_BOOKMARK'); ?>">
							<i class="fas fa-bookmark"></i>
						</button>
						<?php
					}
					?>
				</div>
				<div class="mobile-indicators">
					<div class="indicators-container">
						<?php
						if (!empty($item->new_indicator))
						{
						?>
							<span class="indicator new">
									<?php echo Text::_('EDOCMAN_NEW');?>
							</span>
						<?php
						}
						if(in_array('featured', $indicators))
						{
						?>
							<span class="indicator featured"><?php echo Text::_('EDOCMAN_FEATURED');?></span>
						<?php
						}
						if(in_array('hot', $indicators))
						{
						?>
							<span class="indicator hot"><?php echo Text::_('EDOCMAN_HOT');?></span>
						<?php
						}
						?>
					</div>
				</div>
			</div>
		</div>
		
		<div class="document-body">
			<div class="document-content">
				<?php
				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($this->config->show_default_document_thumbnail) || $this->config->show_default_document_thumbnail)
					{
						if (is_file(Path::clean(JPATH_ROOT.'/components/com_edocman/assets/images/icons/32x32/'.$ext.'.png')))
						{
							$imgSrc = Uri::base().'components/com_edocman/assets/images/icons/32x32/'.$ext.'.png' ;
						}
						else
						{
							$imgSrc = Uri::base().'components/com_edocman/assets/images/icons/32x32/generic.png';
						}
					}
					else
					{
						$imgSrc = '' ;
					}
				}
				if ($imgSrc)
				{
				?>
					<div class="document-thumbnail">
						<div class="thumbnail-container">
							<?php if (!empty($modal_url)): ?>
								<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>" class="thumbnail-image" data-modal-url="<?php echo $modal_url; ?>">
							<?php else: ?>
								<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>">
							<?php endif; ?>
						</div>
					</div>
					<?php if (!empty($modal_url)): ?>
						<!-- Modal container -->
						<div id="imageModal" class="imgmodal">
							<span class="imgclose">&times;</span>
							<img class="imgmodal-content" id="modalImage">
						</div>
					
						<script>
						document.addEventListener('DOMContentLoaded', function() {
							// Get the modal
							var modal = document.getElementById('imageModal');
							
							// Get the modal image
							var modalImg = document.getElementById('modalImage');
							
							// Get the close button
							var closeBtn = document.getElementsByClassName('imgclose')[0];
							
							// Get all thumbnail images with data-modal-url
							var thumbnails = document.getElementsByClassName('thumbnail-image');
							
							// Add click event to thumbnails
							for (var i = 0; i < thumbnails.length; i++) {
								thumbnails[i].addEventListener('click', function() {
									modal.style.display = 'block';
									modalImg.src = this.getAttribute('data-modal-url');
								});
							}
							
							// Close modal when clicking on X
							closeBtn.addEventListener('click', function() {
								modal.style.display = 'none';
							});
							
							// Close modal when clicking outside the image
							window.addEventListener('click', function(event) {
								if (event.target == modal) {
									modal.style.display = 'none';
								}
							});
						});
						</script>
					<?php endif; ?>
				<?php 
				} 
				else
				{
					?>
					<style>
					#edocman-document-page .document-card .document-content
					{
						grid-template-columns: 1fr !important;
					}
					</style>
					<?php
				}
				?>
				<div class="document-details">
					<div class="document-description">
						<h3 class="description-title"><?php echo Text::_('EDOCMAN_DESCRIPTION')?></h3>
						<p class="description-content">
							<?php echo $item->description ;?>
							<?php
							if($item->document_history != "")
							{
								echo "<BR />".$item->document_history;
							}
							?>
						</p>
						<?php
						foreach ($this->plugins as $plugin)
						{
							?>
							<h4><?php echo $plugin['title']; ?></h4>
							<?php
							echo $plugin['form'];
						}
						?>
					</div>
					
					<div class="document-meta">
						<?php
						if($item->created_time != "" && $item->created_time != "0000-00-00 00:00:00" && $this->config->show_creation_date == 1)
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_PUBLISHED_ON');?></span>
								<div class="meta-value"><?php echo HTMLHelper::_('date',$item->created_time, 'j F Y');?></div>
							</div>
						<?php
						}
						if ($this->config->show_modified_date && $item->modified_time != "" && $item->modified_time != "0000-00-00 00:00:00")
						{
						?>
						<div class="meta-group">
							<span class="meta-label"><?php echo Text::_('EDOCMAN_LAST_UPDATED'); ?></span>
							<div class="meta-value"><?php echo HTMLHelper::_('date', $item->modified_time, $this->config->date_format); ?></div>
						</div>
						<?php
						}
						if ($this->config->show_category_name)
						{
						?>
						<div class="meta-group">
							<span class="meta-label"><?php echo Text::_('EDOCMAN_CATEGORY') ?></span>
							<div class="meta-value">
								<?php
								$category = EDocmanHelper::getDocumentCategory($this->item->id);
								$link = EDocmanHelperRoute::getCategoryRoute($category->id, $this->Itemid);
								?>
								<a href="<?php echo $link?>" target="_blank" aria-label="<?php echo $category->title;?>" title="<?php echo $category->title;?>"><?php echo $category->title;?></a>
							</div>
						</div>
						<?php
						}
						if ($this->config->show_document_version && $this->item->document_version != "")
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_VERSION') ?></span>
								<div class="meta-value"><?php echo $this->item->document_version; ?></div>
							</div>
						<?php
						}
						if ($this->config->show_filesize && $this->item->document_url == "")
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_FILESIZE') ?></span>
								<div class="meta-value"><?php echo $this->item->data->size; ?></div>
							</div>
						<?php
						}
						if ($this->config->show_filetype)
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_FILE_TYPE'); ?></span>
								<div class="meta-value"><?php echo $this->item->data->mime; ?></div>
							</div>
						<?php
						}
						if ($this->config->show_hits)
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_HITS'); ?></span>
								<div class="meta-value"><?php echo $item->hits; ?>&nbsp;<?php echo Text::_('EDOCMAN_HITS'); ?></div>
							</div>
						<?php
						}
						if ($this->config->show_number_downloaded)
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_DOWNLOAD'); ?></span>
								<div class="meta-value">
									<?php echo $item->downloads; ?> <?php echo Text::_('EDOCMAN_TIMES');?>
								</div>
							</div>
						<?php
						}
						$created_user_id = $item->created_user_id;
						if (($this->config->show_creation_user) && ((int)$created_user_id > 0))
						{
						?>
							<div class="meta-group">
								<span class="meta-label"><?php echo Text::_('EDOCMAN_CREATED_USER'); ?></span>
								<div class="meta-value">
									<?php 
									$created_user = Factory::getUser($created_user_id);
									echo $created_user->name;
									?>
								</div>
							</div>
						<?php
						}
						if (count((array)$this->item->params))
						{
							foreach($this->fields as $field)
							{
								if (!empty($this->item->params[$field->fieldname]))
								{
									
								?>
									<div class="meta-group">
										<span class="meta-label"><?php echo $field->title; ?></span>
										<div class="meta-value">
											<?php 
											$fieldValue = $this->item->params[$field->fieldname]; 
											if(strpos($fieldValue, 'http') !== false)
											{
												?>
												<a href = "<?php echo $fieldValue?>" target = "_blank"><?php echo $fieldValue?></a>
												<?php
											}
											else
											{
												echo $fieldValue;
											}
											?>
										</div>
									</div>
								<?php
								}
							}
						}
						?>
						
					</div>
					<?php
					if (count($item->tags))
					{
						$tags = $item->tags;
					?>
						<div class="document-tags">
							<span class="meta-label"><?php echo Text::_('EDOCMAN_TAGS');?></span>
							<div class="tags-container">
								<?php
								foreach ($tags as $tag)
								{
								?>
									<span class="tag"><a href="<?php echo Route::_('index.php?option=com_edocman&view=search&filter_tag='.$tag->tag.'&Itemid='.$this->Itemid); ?>" title="<?php echo $tag->tag; ?>"><?php echo $tag->tag; ?></a></span>
								<?php
								}	
								?>
							</div>
						</div>
					<?php
					}	
					?>
				</div>
			</div>
			<?php
			if(!$canDownload && $config->show_no_download_permission_alert)
			{
			?>
			<div class="alert alert-danger">
				<div class="alert-icon">
					<i class="fas fa-exclamation-circle"></i>
				</div>
				<div class="alert-content">
					<div class="alert-title"><?php
						echo Text::_('EDOCMAN_YOU_DO_NOT_HAVE_PERMISSION_TO_DOWNLOAD_THIS_DOCUMENT');
						?></div>
					<div class="alert-message"><?php
						echo Text::_('EDOCMAN_PLEASE_CONTACT_TO_GET_PERMISSION');
						?>.</div>
				</div>
				<button class="alert-close" onclick="closeAlert(this)" title="<?php echo Text::_('EDOCMAN_CLOSE_ALERT');?>">
					<i class="fas fa-times"></i>
				</button>
			</div>
			<?php }
			if ($this->default_license > 0)
			{
				?>
				<div class="license-section">
                    <h3 class="license-title"><?php echo Text::_('EDOCMAN_LICENSE');?></h3>
                    <div class="license-content">
                        <?php
							echo $this->license->description;
						?>
                    </div>
					<?php
					if($accept_license)
					{
					?>
						<div class="license-checkbox">
							<input type="checkbox" name="agreeterm" id="agreeterm" value="0" onClick="javascript:agreeTerm();"/>
							<label for="agree-license"><?php echo Text::_('EDOCMAN_AGREE_TERM_AND_CONDITION');?></label>
						</div>
					<?php
					}	
					?>
                </div>
				<?php
			}

			if($pass_password)
			{
			?>
			<div class="code-unlock-section">
				<h3 class="code-unlock-title"><?php echo Text::_('EDOCMAN_ENTER_PASSWORD_FOR_DOWNLOAD');?></h3>
				<div class="code-input-container">
					<input type="text" class="code-input" name="download_password" id="download_password" placeholder="<?php echo Text::_('EDOCMAN_ENTER_DOWNLOAD_PASSWORD');?>" onkeyup="checkUnlockCode()">
					<button aria-label="<?php echo Text::_('EDOCMAN_VERIFY');?>" onClick="javascript:checkPassword('<?php echo $this->item->download_password; ?>');" class="verify-btn"><?php echo Text::_('EDOCMAN_VERIFY');?></button>
				</div>
			</div>
			<?php 
			}
			?>
			<!-- Desktop Actions -->
			<div class="document-actions desktop-actions">
				<div class="primary-actions">
					<?php
					if($accept_license || $pass_password)
					{
						$disable_download_button = "btn-disabled";
					}
					else
					{
						$disable_download_button = "";
					}
					if ($canDownload && $hide_download_button != 1)
					{
						$downloadUrl = Route::_('index.php?option=com_edocman&task=document.download&id='.$item->id.'&Itemid='.$this->Itemid) ;
						if($item->document_url != "")
						{
							$downloadUrl = $item->document_url;
						}
						if ($showDownloadForm)
						{
						?>
							<a data-toggle="modal" data-document-title="<?php echo $this->item->title; ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>"  id="<?php echo $this->item->id; ?>" class="edocmancollectdownloadbtn edocman-document-title-link btn btn-primary <?php echo $disable_download_button;?> edocmandownloadlink" href="<?php echo Uri::root(true); ?>/index.php?option=com_edocman&view=document&layout=modal&view=document&layout=modal&tmpl=component&id=<?php echo $item->id;?>&direct=1" target="<?php echo $target;?>" aria-label="<?php echo $this->item->title; ?>">
								<?php if($this->item->document_url != "")
								{
									if($config->external_download_link == 1)
									{
										$target = "_blank";
									}
									else
									{
										$target = "";
									}
								?>
									<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 } ?>
							</a>
						<?php
						}
						else
						{
						?>
							<a href="<?php echo $downloadUrl; ?>" class="edocmandownloadlink btn btn-primary <?php echo $disable_download_button;?>" target="<?php echo $target;?>" aria-label="<?php echo $this->item->title; ?>">
								<?php if($this->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 } ?>
							</a>
						<?php
						}
					}
					elseif(!$canDownload && $hide_download_button != 1 && $this->config->login_to_download && (int)$userId == 0)
					{
						?>
						
							<?php
							if($config->edocman_login == 1)
							{
								EdocmanHelper::generateJoomlaLogin('btn btn-primary');
							}
							else
							{
								$return = base64_encode(Uri::getInstance()->toString());
								?>
								<a data-toggle="modal" class="logintodownload btn btn-primary" 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
							}		
							?>
						
						<?php
					}
					if ($canDownload && $show_view_button == 1 && $item->canView)
					{
						$playextension	= EdocmanHelper::returnPlayExtension();
						$showModal		= EdocmanHelper::viewable($item);
						
						if((in_array($ext,$playextension) || $item->view_url != "") && $showModal && !EDocmanHelper::isDropBoxTurnedOn() && !EDocmanHelper::isAmazonS3TurnedOn())
						{
							if($item->view_url != "")
							{
								$viewUrl = $item->view_url;
							}
							else
							{
								$viewUrl = Uri::root()."index.php?option=com_edocman&view=play&id=".$item->id."&tmpl=component";
							}
							$audio_player = EdocmanHelper::generateAudioPlayer($item, $showModal);
							?>
							
								<?php
								if($config->view_option == 0)
								{
								?>
									<a href="<?php echo $viewUrl; ?>" class="btn btn-secondary 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="fas fa-eye"></i>
										<?php echo Text::_('EDOCMAN_VIEW'); ?>
									</a>
								<?php
								}else{
								?>
									<a href="<?php echo $viewUrl; ?>" class="btn btn-secondary" 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="fas fa-eye"></i>
										<?php echo Text::_('EDOCMAN_VIEW'); ?>
									</a>
								<?php
								}
								?>
								
							
							<?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 . '&Itemid=' . $this->Itemid);

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

									$extraViewClass = '';
									$target         = 'target="_blank"';
								}
							}
							?>
							
								<a href="<?php echo $viewUrl; ?>" <?php echo $target; ?> class="btn btn-secondary <?php echo  $extraViewClass; ?>" 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="fas fa-eye"></i>
									<?php echo Text::_('EDOCMAN_VIEW'); ?>
								</a>
							
							<?php
						}
					}

					if(EDocmanHelper::massDownloadShowing($canDownload, $config, $item))
					{
						if(EDocmanHelper::isAlreadyInMassList($item->id))
						{
							$disabled = "disabled";
						}
						else
						{
							$disabled = "";
						}
						?>
						<a href="javascript:void(0);" id="btnMassDownload" class="mass-download-btn edocmandownloadlink btn btn-light <?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 $this->item->id; ?>" data-name="<?php echo $this->item->title; ?>" data-type="<?php echo $ext;?>" data-size="<?php $this->item->data->size; ?>">
							<i class="edicon edicon-box-add"></i>
							<?php echo Text::_('EDOCMAN_ADD_TO_MASS_DOWNLOAD_LIST'); ?>
						</a>
						<?php
					}
					
					if($this->config->turn_on_sharing)
					{
					?>
						
						<a class="sharing-modal-link btn btn-dark" href="<?php echo Uri::root();?>index.php?option=com_edocman&view=document&layout=sharing&id=<?php echo $item->id;?>&tmpl=component" data-document-title="<?php echo $this->item->title; ?>" data-original-title="<?php echo Text::_('EDOCMAN_SHARE_DOCUMENT'); ?>"  id="sharing_<?php echo $this->item->id; ?>" aria-label="<?php echo Text::_('EDOCMAN_SHARE_DOCUMENT'); ?>">
							<i class="fas fa-share-alt"></i>
							<?php
							echo Text::_('EDOCMAN_SHARE_DOCUMENT'); 
							?>
						</a>
					<?php
					}
					if($this->config->show_bookmark_button)
					{
						?>
						<a href="javascript:void(0);" onclick="javascript:addBookmark('<?php echo Uri::root()?>',<?php echo $this->item->id?>);" class="btn btn-bookmark" href="#sharing-form" data-document-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-original-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>"  id="<?php echo $this->item->id; ?>" aria-label="<?php echo Text::_('EDOCMAN_BOOKMARK'); ?>">
							<i class="fas fa-bookmark"></i>
							<?php
							echo Text::_('EDOCMAN_BOOKMARK');
							?>
						</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();
						$url = Route::_('index.php?option=com_edocman&task=document.edit&id='.$item->id.'&return='.$return.'&Itemid='.$this->Itemid) ;
						//$url = JRoute::_('index.php?option=com_edocman&task=document.edit&id='.$item->id.'&Itemid='.$this->Itemid) ;
						?>
						
							<a href="<?php echo $url; ?>" class="btn btn-light" aria-label="<?php echo Text::_('EDOCMAN_EDIT'); ?>">
								<i class="fas fa-edit"></i>
								<?php echo Text::_('EDOCMAN_EDIT'); ?>
							</a>
						
						<?php
					}
					if ($canDelete)
					{
					?>
						
							<a href="javascript:deleteConfirm();" class="btn btn-danger" aria-label="<?php echo Text::_('EDOCMAN_DELETE'); ?>">
								<i class="fas fa-trash"></i>
								<?php echo Text::_('EDOCMAN_DELETE'); ?>
							</a>
						
					<?php
					}
					if ($canChange)
					{
						if ($item->published)
						{
							$text = Text::_('EDOCMAN_UNPUBLISH');
							$url = "javascript:publishConfirm('documents.unpublish')";
							$class = 'edocman-icon-remove';
						}
						else
						{
							$url = "javascript:publishConfirm('documents.publish')";
							$text = Text::_('EDOCMAN_PUBLISH');
							$class = 'edocman-icon-ok';
						}
						?>
						
							<a href="<?php echo $url; ?>" class="btn btn-warning">
								<i class="fas fa-toggle-on"></i>
								<?php echo $text; ?>
							</a>
						
					<?php
					}
					?>
				</div>
				<?php
				if ($this->config->show_social_sharing_buttons !== '0')
				{
				?>
					<div class="social-sharing">
						<span class="share-label"><?php echo Text::_('EDOCMAN_SHARE');?>:</span>
						<div class="social-icons">
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'FaceBook');
							
							echo '<a href="http://www.facebook.com/sharer.php?u=' . rawurlencode($socialUrl) . '&amp;t=' . rawurlencode($item->title) . '" title="' . $alt . '" target="blank" class="social-btn facebook">'; 
							?>
								<i class="fab fa-facebook-f"></i>
							</a>
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'Twitter');	
							echo '<a href="http://twitter.com/?status=' . rawurlencode($item->title . " " . $socialUrl) . '" title="' . $alt . '" target="blank" class="social-btn twitter">';
							?>
								<i class="fab fa-twitter"></i>
							</a>
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'LinkedIn');
							echo '<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=' . $socialUrl . '&amp;title=' . $item->title . '" title="' . $alt . '" target="_blank" class="social-btn linkedin">';
							?>
								<i class="fab fa-linkedin-in"></i>
							</a>
						</div>
					</div>
				<?php
				}	
				?>
			</div>
			
			<!-- Mobile Actions -->
			<div class="mobile-actions">
				<div class="main-actions">
					<?php
					if ($canDownload && $hide_download_button != 1)
					{
						$downloadUrl = Route::_('index.php?option=com_edocman&task=document.download&id='.$item->id.'&Itemid='.$this->Itemid) ;
						if($item->document_url != "")
						{
							$downloadUrl = $item->document_url;
						}
						if ($showDownloadForm)
						{
						?>
							<a data-toggle="modal" data-document-title="<?php echo $this->item->title; ?>" title="<?php echo Text::_('EDOCMAN_DOWNLOAD'); ?>"  id="<?php echo $this->item->id; ?>" class="edocmancollectdownloadbtn edocman-document-title-link btn btn-primary <?php echo $disable_download_button;?> edocmandownloadlink" href="<?php echo Uri::root(true); ?>/index.php?option=com_edocman&view=document&layout=modal&view=document&layout=modal&tmpl=component&id=<?php echo $item->id;?>&direct=1" target="<?php echo $target;?>" aria-label="<?php echo $this->item->title; ?>">
								<?php if($this->item->document_url != "")
								{
									if($config->external_download_link == 1)
									{
										$target = "_blank";
									}
									else
									{
										$target = "";
									}
								?>
									<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 } ?>
							</a>
						<?php
						}
						else
						{
						?>
							<a href="<?php echo $downloadUrl; ?>" class="edocmandownloadlink btn btn-primary <?php echo $disable_download_button;?>" target="<?php echo $target;?>" aria-label="<?php echo $this->item->title; ?>">
								<?php if($this->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 } ?>
							</a>
						<?php
						}
					}
					elseif(!$canDownload && $hide_download_button != 1 && $this->config->login_to_download && (int)$userId == 0)
					{
						?>
						
							<?php
							if($config->edocman_login == 1)
							{
								EdocmanHelper::generateJoomlaLogin('btn btn-primary');
							}
							else
							{
								$return = base64_encode(Uri::getInstance()->toString());
								?>
								<a data-toggle="modal" class="logintodownload btn btn-primary" 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
							}		
							?>
						
						<?php
					}
					if ($canDownload && $show_view_button == 1 && $item->canView)
					{
						$playextension	= EdocmanHelper::returnPlayExtension();
						$showModal		= EdocmanHelper::viewable($item);
						
						if((in_array($ext,$playextension) || $item->view_url != "") && $showModal && !EDocmanHelper::isDropBoxTurnedOn() && !EDocmanHelper::isAmazonS3TurnedOn())
						{
							if($item->view_url != "")
							{
								$viewUrl = $item->view_url;
							}
							else
							{
								$viewUrl = Uri::root()."index.php?option=com_edocman&view=play&id=".$item->id."&tmpl=component";
							}
							$audio_player = EdocmanHelper::generateAudioPlayer($item, $showModal);
							?>
							
								<?php
								if($config->view_option == 0)
								{
								?>
									<a href="<?php echo $viewUrl; ?>" class="btn btn-secondary edocmanplayerbtn" data-toggle="modal" <?php echo $audio_player;?> aria-label="<?php echo Text::_('EDOCMAN_VIEW'); ?>" rel="nofollow" title="<?php echo Text::_('EDOCMAN_VIEW'); ?>">
										<i class="fas fa-eye"></i>
										<?php echo Text::_('EDOCMAN_VIEW'); ?>
									</a>
								<?php
								}else{
								?>
									<a href="<?php echo $viewUrl; ?>" class="btn btn-secondary" target="_blank" aria-label="<?php echo Text::_('EDOCMAN_VIEW'); ?>" rel="nofollow" title="<?php echo Text::_('EDOCMAN_VIEW'); ?>">
										<i class="fas fa-eye"></i>
										<?php echo Text::_('EDOCMAN_VIEW'); ?>
									</a>
								<?php
								}
								?>
								
							
							<?php
						}
						else 
						{
							if($item->view_url != "")
							{
								$viewUrl = $item->view_url;
							}
							else
							{
								if($ext == 'pdf' && EdocmanHelper::isPDFViewerEnabled())
								{
									$viewUrl		= Route::_('index.php?option=com_edocman&task=document.viewdoc&tmpl=component&id=' . $item->id . '&Itemid=' . $this->Itemid);

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

									$extraViewClass = '';
									$target         = 'target="_blank"';
								}
							}
							?>
							
								<a href="<?php echo $viewUrl; ?>" <?php echo $target; ?> class="btn btn-secondary <?php echo  $extraViewClass; ?>" aria-label="<?php echo Text::_('EDOCMAN_VIEW'); ?>" rel="nofollow" title="<?php echo Text::_('EDOCMAN_VIEW'); ?>">
									<i class="fas fa-eye"></i>
									<?php echo Text::_('EDOCMAN_VIEW'); ?>
								</a>
							
							<?php
						}
					}
					?>
				</div>
				
				<div class="more-actions">
					<div class="document-details-dropdown">
						<button class="document-details-dropdown-toggle" id="mobileDropdownToggle">
							<i class="fas fa-ellipsis-h"></i> <?php echo Text::_('EDOCMAN_MORE_OPTIONS');?>
						</button>
						<div class="document-details-dropdown-menu" id="actionDropdown">
							<?php
							if($this->config->show_bookmark_button)
							{
							?>
								<a href="javascript:void(0);" onclick="javascript:addBookmark('<?php echo Uri::root()?>',<?php echo $this->item->id?>);" class="document-details-dropdown-item" href="#sharing-form" data-document-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>" data-original-title="<?php echo Text::_('EDOCMAN_BOOKMARK_THIS_FILE');?>"  id="<?php echo $this->item->id; ?>" aria-label="<?php echo Text::_('EDOCMAN_BOOKMARK'); ?>">

									<i class="fas fa-bookmark"></i> <?php echo Text::_('EDOCMAN_BOOKMARK'); ?>
								</a>
							<?php
							}
							if(EDocmanHelper::massDownloadShowing($canDownload, $config, $item))
							{
								 if(EDocmanHelper::isAlreadyInMassList($item->id))
								{
									$disabled = "disabled";
								}
								else
								{
									$disabled = "";
								}
							?>
							<a href="javascript:void(0);" id="btnMassDownload1" class="edocmandownloadlink document-details-dropdown-item <?php echo $disable_download_button;?>" aria-label="<?php echo $this->item->title; ?>" <?php echo $disabled;?>>
								<i class="fas fa-plus"></i> <?php echo Text::_('EDOCMAN_ADD_TO_MASS_DOWNLOAD_LIST'); ?>
							</a>
							<?php
							}	
							?>
							<div class="document-details-dropdown-divider"></div>
							<?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();
								$url = Route::_('index.php?option=com_edocman&task=document.edit&id='.$item->id.'&return='.$return.'&Itemid='.$this->Itemid) ;
								//$url = JRoute::_('index.php?option=com_edocman&task=document.edit&id='.$item->id.'&Itemid='.$this->Itemid) ;
								?>
								<a href="<?php echo $url; ?>" class="document-details-dropdown-item" aria-label="<?php echo Text::_('EDOCMAN_EDIT'); ?>">
									<i class="fas fa-edit"></i> <?php echo Text::_('EDOCMAN_EDIT'); ?>
								</a>
							<?php
							}
							if ($canDelete)
							{
							?>
								<a href="javascript:deleteConfirm();" class="document-details-dropdown-item" aria-label="<?php echo Text::_('EDOCMAN_DELETE'); ?>">
									<i class="fas fa-trash"></i> <?php echo Text::_('EDOCMAN_DELETE'); ?>
								</a>
							<?php
							}
							if ($canChange)
							{
								if ($item->published)
								{
									$text = Text::_('EDOCMAN_UNPUBLISH');
									$url = "javascript:publishConfirm('documents.unpublish')";
									$class = 'edocman-icon-remove';
								}
								else
								{
									$url = "javascript:publishConfirm('documents.publish')";
									$text = Text::_('EDOCMAN_PUBLISH');
									$class = 'edocman-icon-ok';
								}
								?>
								
								<a href="<?php echo $url; ?>" class="document-details-dropdown-item">
									<i class="fas fa-toggle-on"></i>
									<?php echo $text; ?>
								</a>
							<?php
							}
							?>
						</div>
					</div>
					<?php
					if ($this->config->show_social_sharing_buttons !== '0')
					{
					?>
					<div class="social-sharing">
						<div class="social-icons">
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'FaceBook');
							echo '<a href="http://www.facebook.com/sharer.php?u=' . rawurlencode($socialUrl) . '&amp;t=' . rawurlencode($item->title) . '" title="' . $alt . '" target="blank" class="social-btn facebook">'; 
							?>
								<i class="fab fa-facebook-f"></i>
							</a>
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'Twitter');	
							echo '<a href="http://twitter.com/?status=' . rawurlencode($item->title . " " . $socialUrl) . '" title="' . $alt . '" target="blank" class="social-btn twitter">';
							?>
								<i class="fab fa-twitter"></i>
							</a>
							<?php
							$alt     = Text::sprintf('EDOCMAN_SUBMIT_ITEM_IN_SOCIAL_NETWORK', $item->title, 'LinkedIn');
							echo '<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=' . $socialUrl . '&amp;title=' . $item->title . '" title="' . $alt . '" target="_blank" class="social-btn linkedin">';
							?>
								<i class="fab fa-linkedin-in"></i>
							</a>
						</div>
					</div>
					<?php } ?>
				</div>
			</div>
			<?php

			//rating
			if($this->config->enable_rating)
			{
				echo $this->loadTemplate('rating');
			}
			
			//relate
			if($this->config->show_related_documents && count($this->related_items) > 0)
			{
				echo $this->loadTemplate('relates');
			}


			if (@$this->config->jcomment_integration && file_exists(JPATH_ROOT.'/components/com_jcomments/jcomments.php'))
			{
				require_once JPATH_ROOT.'/components/com_jcomments/jcomments.php';
				?>
				<div class="edocman-comments clearfix">
					<?php  echo JComments::showComments($item->id, 'com_edocman', $item->title); ?>
				</div>
				<?php
			}
			?>
		</div>
	</div>
</div>

<form method="post" name="edocman_form" id="edocman_form" action="index.php">
	<input type="hidden" name="cid[]" value="<?php echo $item->id; ?>" id="document_id" />
	<input type="hidden" name="category_id" value="<?php echo $this->categoryId ; ?>" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
	<input type="hidden" name="option" value="com_edocman" />
	<?php echo HTMLHelper::_('form.token'); ?>

	<script type="text/javascript">
		function deleteConfirm()
		{
			var msg = "<?php echo Text::_('EDOCMAN_DELETE_CONFIRM'); ?>";
			if (confirm(msg))
			{
				var form = document.edocman_form ;
				form.task.value = 'documents.delete';
				form.submit();
			}
		}
		function publishConfirm(task) {
			var msg;
			if (task == 'documents.publish')
			{
				msg = "<?php echo Text::_('EDOCMAN_PUBLISH_CONFIRM'); ?>";
			}
			else
			{
				msg = "<?php echo Text::_('EDOCMAN_UNPUBLISH_CONFIRM'); ?>";
			}
			if (confirm(msg))
			{
				var form = document.edocman_form ;
				form.task.value = task;
				form.submit();
			}
		}
		function agreeTerm() {
			var agreeTerm = document.getElementById('agreeterm');
			if(agreeTerm.value == "0") {
				agreeTerm.value = "1";
				<?php
				if($this->config->accept_license_one_time) {
				?>
					var data = 'task=document.store_license_session';
					var xhr = new XMLHttpRequest();
					xhr.open('POST', 'index.php?option=com_edocman', true);
					xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					
					xhr.onload = function() {
						if (xhr.status === 200) {
							//do nothing
						}
					};
					
					xhr.onerror = function() {
						alert(xhr.statusText);
					};
					
					xhr.send(data);
				<?php
				}
				?>
				
				// Enable download links
				document.querySelectorAll(".edocmandownloadlink").forEach(function(link) {
					link.classList.remove("btn-disabled");
				});
			} else {
				agreeTerm.value = "0";
				<?php
				if($this->config->accept_license_one_time) {
				?>
					var data = 'task=document.disable_license_session';
					var xhr = new XMLHttpRequest();
					xhr.open('POST', 'index.php?option=com_edocman', true);
					xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					
					xhr.onload = function() {
						if (xhr.status === 200) {
							//do nothing
						}
					};
					
					xhr.onerror = function() {
						alert(xhr.statusText);
					};
					
					xhr.send(data);
				<?php
				}
				?>
				
				// Disable download links
				document.querySelectorAll(".edocmandownloadlink").forEach(function(link) {
					link.classList.add("btn-disabled");
				});
			}
		}


		function checkPassword(pwd) {
			const passwordField = document.getElementById("download_password");
			const downloadLinks = document.querySelectorAll(".edocmandownloadlink");
			
			if (passwordField.value == pwd) {
				// Remove disabled class from all download links
				downloadLinks.forEach(link => {
					link.classList.remove("btn-disabled");
				});
				
				alert("<?php echo Text::_('EDOCMAN_PASSWORD_IS_CORRECT');?>");
			} else {
				alert("<?php echo Text::_('EDOCMAN_PASSWORD_IS_NOT_CORRECT');?>");
				
				// Clear the password field
				passwordField.value = '';
				
				// Add disabled class to all download links
				downloadLinks.forEach(link => {
					link.classList.add("btn-disabled");
				});
				
				return false;
			}
		}


		function addBookmark(live_site, id) {
			const xhr = new XMLHttpRequest();
			xhr.open('POST', live_site + 'index.php?option=com_edocman', true);
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xhr.responseType = 'json';
			
			xhr.onload = function() {
				if (xhr.status === 200) {
					const response = xhr.response;
					alert(response.result);
				}
			};
			
			xhr.onerror = function() {
				console.error('Error in bookmark request');
			};
			
			xhr.send('task=document.bookmark&id=' + id + '&tmpl=component');
		}

		// DOM ready equivalent
		document.addEventListener('DOMContentLoaded', function() {
			const fileInput = document.getElementById('jform_filename');
			const titleInput = document.getElementById('jform_title');
			
			if (fileInput && titleInput) {
				fileInput.addEventListener('change', function(e) {
					if (e.target.files && e.target.files.length > 0) {
						const fileName = e.target.files[0].name;
						const fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
						
						if (titleInput.value === "") {
							titleInput.value = fileNameWithoutExtension;
						}
					}
				});
			}
		});

	</script>
</form>
<?php
if ($showDownloadForm && !EdocmanHelper::isJoomla4())
{
	echo EDocmanHelperHtml::loadCommonLayout('common/modal.php', array('bootstrapHelper' => $bootstrapHelper,'config' => $config));
}
if((!$canDownload && $hide_download_button != 1 && $this->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>
<?php
if($this->config->turn_on_sharing)
{
	echo EDocmanHelperHtml::loadCommonLayout('common/modalsharing.php', array());
	?>
	<script src="<?php echo Uri::base(); ?>components/com_edocman/assets/js/sharing.js" type="text/javascript"></script>
	<?php
}
?>
<script type="text/javascript">
	/*
    jQuery('#btnMassDownload').click(function($){
        jQuery('#btnMassDownload').attr('disabled','disabled');
        var documentId = "<?php echo $this->item->id; ?>";
        var data = {
            'task'	:	'document.store_mass_download',
            'document_id' : documentId
        };
        jQuery.ajax({
            type: 'POST',
            url: 'index.php?option=com_edocman',
            data: data,
            dataType: 'html',
            success: function(htmltext) {
                alert("<?php echo Text::_('EDOCMAN_DOCUMENT_HAS_BEEN_ADDED_INTO_MASS_DOWNLOAD_LIST');?>");
                jQuery('#massDownloadDiv').html(htmltext);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });
	
	jQuery('#btnMassDownload1').click(function($){
        jQuery('#btnMassDownload').attr('disabled','disabled');
        var documentId = "<?php echo $this->item->id; ?>";
        var data = {
            'task'	:	'document.store_mass_download',
            'document_id' : documentId
        };
        jQuery.ajax({
            type: 'POST',
            url: 'index.php?option=com_edocman',
            data: data,
            dataType: 'html',
            success: function(htmltext) {
                alert("<?php echo Text::_('EDOCMAN_DOCUMENT_HAS_BEEN_ADDED_INTO_MASS_DOWNLOAD_LIST');?>");
                jQuery('#massDownloadDiv').html(htmltext);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });
	*/

	// Function to close alert
	function closeAlert(element) {
		element.parentElement.style.display = 'none';
	}

	document.addEventListener('DOMContentLoaded', function() {
		const dropdownToggle = document.getElementById('mobileDropdownToggle');
		const dropdownMenu = document.getElementById('actionDropdown');
		
		if (dropdownToggle) {
			dropdownToggle.addEventListener('click', function(e) {
				e.preventDefault();
				e.stopPropagation();
				
				dropdownMenu.classList.toggle('show');
				
				if (dropdownMenu.classList.contains('show')) {
					const menuRect = dropdownMenu.getBoundingClientRect();
					
					
						dropdownMenu.style.top = 'auto';
						dropdownMenu.style.bottom = '100%';
						dropdownMenu.style.marginTop = '0';
						dropdownMenu.style.marginBottom = '5px';
					
				}
				
				//console.log('Edocman Dropdown toggle clicked');
				//console.log('Edocman Dropdown menu visible:', dropdownMenu.classList.contains('show'));
			});
		}
		

		const dropdownItems = document.querySelectorAll('.document-details-dropdown-item');
		dropdownItems.forEach(item => {
			item.addEventListener('click', function(e) {
				e.preventDefault();
				e.stopPropagation();
				
				const actionId = this.id;
				//console.log('Clicked on action:', actionId);
				
				dropdownMenu.classList.remove('show');
			});
		});
		
		document.addEventListener('click', function(e) {
			if (dropdownMenu.classList.contains('show') && 
				!dropdownToggle.contains(e.target) && 
				!dropdownMenu.contains(e.target)) {
				dropdownMenu.classList.remove('show');
			}
		});
		
		dropdownMenu.addEventListener('click', function(e) {
			e.stopPropagation();
		});
		
		if (dropdownToggle) {
			dropdownToggle.addEventListener('touchstart', function(e) {
				e.preventDefault();
				e.stopPropagation();
				
				dropdownMenu.classList.toggle('show');
				
				if (dropdownMenu.classList.contains('show')) {
					const menuRect = dropdownMenu.getBoundingClientRect();
					
					
						dropdownMenu.style.top = 'auto';
						dropdownMenu.style.bottom = '100%';
						dropdownMenu.style.marginTop = '0';
						dropdownMenu.style.marginBottom = '5px';
					
				}
				
				console.log('Dropdown touch triggered');
			});
		}
		
		// Thêm sự kiện touch cho document để đóng dropdown
		document.addEventListener('touchstart', function(e) {
			if (dropdownMenu.classList.contains('show') && 
				!dropdownToggle.contains(e.target) && 
				!dropdownMenu.contains(e.target)) {
				dropdownMenu.classList.remove('show');
			}
		});
	});
</script>
<?php
echo EDocmanHelperHtml::loadCommonLayout('common/massdownload.php');
?>
