<?php

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

// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Editor\Editor;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Route;

HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', ['placement' => 'left']);
////HTMLHelper::_('formbehavior.chosen', '#jformextra_category_ids');
//HTMLHelper::_('formbehavior.chosen', '#groups');

$document				= Factory::getApplication()->getDocument();
$user					= Factory::getApplication()->getIdentity();
$editor					= Editor::getInstance(Factory::getApplication()->get('editor'));
$fields					= $this->form->getGroup('params');
$bootstrapHelper		= $this->bootstrapHelper;
$rowFluidClass			= $bootstrapHelper->getClassMapping('row-fluid');
$span8Class				= $bootstrapHelper->getClassMapping('span8');
$span4Class				= $bootstrapHelper->getClassMapping('span4');
$span7Class				= $bootstrapHelper->getClassMapping('span7');
$span5Class				= $bootstrapHelper->getClassMapping('span5');
$span12Class			= $bootstrapHelper->getClassMapping('span12');
$controlGroupClass		= $bootstrapHelper->getClassMapping('control-group');
$controlLabelClass		= $bootstrapHelper->getClassMapping('control-label');
$controlsClass			= $bootstrapHelper->getClassMapping('controls');
if (!EdocmanHelper::isJoomla4())
{
	?>
	<script type="text/javascript">
		Joomla.submitbutton = function(task)
		{
			if (task == 'cancel' || document.formvalidator.isValid(document.getElementById('adminForm'))) {
				Joomla.submitform(task, document.getElementById('adminForm'));
			} else {
				alert('<?php echo $this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
			}
		}
	</script>
<?php
	$span1	   = $span7Class;
	$span2	   = $span5Class;
}
else
{
	$span1	   = $span7Class;
	$span2	   = $span5Class;	
}


$keys = ['EDOCMAN_ENTER_DOCUMENT_TITLE','EDOCMAN_SELECT_CATEGORY'];
EdocmanHelper::addJSStrings($keys);

HTMLHelper::_('behavior.core');


EdocmanHelper::addScript(Uri::root().'components/com_edocman/assets/js/noconflict.js');
EdocmanHelper::addScript(Uri::root().'components/com_edocman/assets/js/admin-document-default.js');
?>
<form action="<?php echo Route::_('index.php?option=com_edocman&view=document&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate" enctype="multipart/form-data">
<div id="j-main-container">
		<?php
		echo HTMLHelper::_('bootstrap.startTabSet', 'document', array('active' => 'general-page'));
			echo HTMLHelper::_('bootstrap.addTab', 'document', 'general-page', Text::_('EDOCMAN_GENERAL', true));
			?>
			<div class="<?php echo $rowFluidClass;?>">
				<div class="<?php echo $span1;?>">
					<fieldset class="form-horizontal options-form">
						<legend><?php echo Text::_('EDOCMAN_FIELDSET_DETAILS');?></legend>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('title'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('title'); ?>
							</div>
						</div>				
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('alias'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('alias'); ?>
							</div>
						</div>	
						<?php
							if ((int)$this->config->file_upload_method == 0 || (int)$this->config->file_upload_method == 2) {
							?>
								<div class="<?php echo $controlGroupClass; ?>">
									<label class="<?php echo $controlLabelClass; ?>">
										<?php echo $this->form->getLabel('filename'); ?>
									</label>
									<div class="<?php echo $controlsClass; ?>">
										<?php echo $this->form->getInput('filename'); ?>        						
										<?php
											if ($this->item->id) {
												?>
													<span style="padding-top: 3px; display: block;">
												<?php
												if ($this->item->original_filename) {
													echo Text::_('Current File : ');                                    
												?>
													<a href="<?php echo 'index.php?option=com_edocman&task=document.download&id='.$this->item->id; ?>&Itemid=<?php echo EdocmanHelper::getItemid(); ?>"><?php echo $this->item->original_filename ; ?></a>
												<?php        
												}      
												?>
													</span>
												<?php
											}
										?>																							
									</div>
								</div>
							<?php        
							}
							if ((int)$this->config->file_upload_method == 1 || (int)$this->config->file_upload_method == 2) 
							{
							?>
								<div class="<?php echo $controlGroupClass; ?>">
									<label class="<?php echo $controlLabelClass; ?>">	
										<?php echo $this->form->getLabel('select_filename'); ?>
									</label>
									<div class="<?php echo $controlsClass; ?>">
										<div id="selectedFilesDiv">
											<?php echo EdocmanHelper::getChoicesJsSelect($this->form->getInput('select_filename')); ?>		
										</div>
									</div>
								</div>
							<?php    
							}
						?>											
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('document_url'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('document_url'); ?>
							</div>
						</div>
						<?php
						if(EDocmanHelper::isAmazonS3TurnedOn() && (int)$this->item->id == 0)
						{
							?>
							<div class="<?php echo $controlGroupClass; ?>">
								<label class="<?php echo $controlLabelClass; ?>">
									<?php echo $this->form->getLabel('document_name'); ?>
								</label>
								<div class="<?php echo $controlsClass; ?>">
									<?php echo $this->form->getInput('document_name'); ?>
									<?php
									echo $this->lists['storage'];
									?>
								</div>
							</div>
							<?php
						}
						?>
						<?php
						if($this->config->view_url){
						?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('view_url'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('view_url'); ?>
							</div>
						</div>
						<?php } ?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('category_id'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<div style="display:none;">
									<?php
									echo $this->form->getInput('category_id');
									?>
								</div>
								<div class="categories-dropdown">
									<div class="selected-display"><?php echo Text::_("EDOCMAN_SELECT_CATEGORY");?></div>
									<div class="categories-dropdown-content">
										<div class="categories-dropdown-header-section">
											<input type="text" class="search-input" placeholder="<?php echo Text::_("EDOCMAN_SEARCH_CATEGORIES");?>...">
											<button class="categories-dropdown-clear-btn" style="display: none;"><?php echo Text::_('JCLEAR');?></button>
											<div class="loading-indicator"><?php echo Text::_("EDOCMAN_SEARCH_CATEGORIES");?>...</div>
										</div>
										<div class="categories-list"></div>
									</div>
								</div>
								
								<script>
									<?php
									if($this->item->category_id > 0 && $this->item->id > 0)
									{
										$mainCat = EdocmanHelper::getCategory($this->item->category_id);
										?>
										localStorage.setItem('selectedCategoryId', <?php echo $this->item->category_id;?>);
										localStorage.setItem('selectedCategoryName', '<?php echo $mainCat->title;?>');
										<?php
									}
									elseif($this->item->id == 0)
									{
										?>
										localStorage.setItem('selectedCategoryId', 0);
										localStorage.setItem('selectedCategoryName', '');
										<?php
									}
									?>
									localStorage.setItem('holdertext', '<?php echo Text::_("EDOCMAN_SELECT_CATEGORY");?>');
								</script>
								<script src="<?php echo Uri::root(); ?>administrator/components/com_edocman/assets/js/category.js" type="text/javascript"></script>
							</div>
						</div>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('extra_category_ids'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo EDocmanHelper::getChoicesJsSelect($this->form->getInput('extra_category_ids')); ?>		
							</div>
						</div>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">							
								<?php echo $this->form->getLabel('tags'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<div class="tagFields">
									
									<ul class="tags">
										<?php if(isset($this->tags) && count($this->tags)): ?>
										<?php foreach($this->tags as $tag): ?>
										<li class="tagAdded">
											<?php echo $tag->tag; ?>
											<span title="<?php echo Text::_('EDOCMAN_CLICK_TO_REMOVE_TAG'); ?>" class="tagRemove">&times;</span>
											<input type="hidden" name="tags[]" value="<?php echo $tag->tag; ?>" />
										</li>
										<?php endforeach; ?>
										<?php endif; ?>
										<li class="tagAdd">
											<input type="text" id="search-field" style="border:0px !important;"/>
										</li>
										<li class="clr"></li>
									</ul>
								</div>
							</div>
						</div>

						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('short_description'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('short_description'); ?>		
							</div>
						</div>

						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('description'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('description'); ?>		
							</div>
						</div>

						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('document_history'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->form->getInput('document_history'); ?>		
							</div>
						</div>
					</fieldset>
				</div>
			<?php
			
			?>
				<div class="<?php echo $span2;?>">
					<fieldset class="access form-horizontal options-form">
						<legend><?php echo Text::_( 'EDOCMAN_ACCESS' ); ?></legend>
						<?php
							if (!isset($this->config->access_level_inheritance) || $this->config->access_level_inheritance !== '1')
							{
							?>
								<div class="<?php echo $controlGroupClass; ?>">
									<label class="<?php echo $controlLabelClass; ?>">
                                        <?php echo $this->form->getLabel('accesspicker'); ?>
									</label>
									<div class="<?php echo $controlsClass; ?>">
                                        <?php
                                        EDocmanHelper::showCheckboxfield('accesspicker', $this->item->accesspicker, Text::_('EDOCMAN_PRESETS'), Text::_('EDOCMAN_GROUPS'));
                                        ?>
                                        <div class="clr"></div>
                                        <?php
                                        if($this->item->accesspicker == 0){
                                            $style1 = "display:block";
                                            $style2 = "display:none";
                                        }else{
                                            $style2 = "display:block";
                                            $style1 = "display:none";
                                        }
                                        ?>
                                        <div class="control-group" id="presetsdiv" style="<?php echo $style1;?>" data-showon='<?php echo EDocmanHelper::renderShowon(array('jform[accesspicker]' => '0')); ?>'>
                                            <?php echo $this->form->getInput('access'); ?>
                                        </div>
                                        <div class="control-group" id="groupsdiv" style="<?php echo $style2;?>" data-showon='<?php echo EDocmanHelper::renderShowon(array('jform[accesspicker]' => '1')); ?>'>
                                            <?php 
											echo $this->form->getLabel('groups');
											if(EdocmanHelper::isJoomla4())
											{
												echo HTMLHelper::_('access.usergroup', 'groups[]', $this->item->groups, 'multiple class="form-select"');
											}
											else
											{
												echo $this->form->getInput('groups'); 
											}
											?>
                                        </div>
									</div>
								</div>
							<?php
							}
						?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('user_ids'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?> extra_information">
                                <?php
                                if($this->config->owner_inheritance)
                                {
                                    if($this->item->id == 0)
                                    {
                                        echo Text::_('EDOCMAN_INHERIT_FROM_MAIN_CATEGORIES');
                                    }
                                    else
                                    {
                                        if($this->item->user_ids != "")
                                        {
                                            echo $this->item->user_ids;
                                            echo " (".Text::_('EDOCMAN_INHERIT_FROM_MAIN_CATEGORIES').")";
                                        }
                                        else
                                        {
                                            echo Text::_('EDOCMAN_INHERIT_FROM_MAIN_CATEGORIES');
                                        }
                                    }
                                    ?>

                                    <?php
                                }
                                else
                                {
                                    ?>
                                    <?php echo EdocmanHelper::getUserInputBackend($this->item->user_ids, true); ?>
                                    <?php
                                }
                                ?>
							</div>
						</div>
						<?php
						if($this->config->user_group_ids)
						{
						?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('group_ids'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">						
								<?php
								if(EdocmanHelper::isJoomla4())
								{
									echo EdocmanHelper::getChoicesJsSelect(HTMLHelper::_('access.usergroup', 'jform[group_ids][]', $this->item->group_ids, 'multiple class="form-select"'));
								}
								else
								{
									echo $this->form->getInput('group_ids'); 
								}
								?>
							</div>
						</div>
						<?php 
						} 
						if($user->authorise('core.edit.state', 'com_edocman'))
						{
						?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('published'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php //echo $this->form->getInput('published'); 
								EDocmanHelperHtml::showStateField($this->item->published);
								?>
							</div>
						</div>
						<?php
						}
						if($this->config->lock_function){
						?>
							<div class="<?php echo $controlGroupClass; ?>">
								<label class="<?php echo $controlLabelClass; ?>">
									<?php echo $this->form->getLabel('is_locked'); ?>
								</label>
								<div class="<?php echo $controlsClass; ?>">
									<?php echo $this->form->getInput('is_locked'); ?>
								</div>
							</div>
							<input type="hidden" name="old_locked_status" value="<?php echo $this->item->is_locked; ?>" />
						<?php
						}
						?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo Text::_('EDOCMAN_HIDE_FROM_SEARCH_ENGINES'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php echo $this->lists['hide_search_engines']; ?>
							</div>
						</div>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo Text::_('EDOCMAN_DISABLE_DOWNLOAD_WHEN_REACH'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<input type="text" name="disable_download" id="jform_disable_download" class="input-large form-control ilarge" value="<?php echo $this->item->disable_download;?>" />
								<?php echo Text::_('EDOCMAN_DOWNLOAD_TIMES'); ?>
							</div>
						</div>
					</fieldset>
					<fieldset class="other form-horizontal options-form">
						<legend><?php echo Text::_( 'EDOCMAN_OTHER_INFORMATION' ); ?></legend>
						
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo Text::_('EDOCMAN_PASSWORD_DOWNLOAD');?>
							</label>
							<div class="<?php echo $controlsClass; ?>">	
								<input	type="text"
								name="download_password"
								id="jform_download_password"
								value="<?php echo $this->item->download_password; ?>"
								class="form-control input-small" size="20" />
							</div>
						</div>
                        <?php
                        if(!$this->config->increase_document_version){
                        ?>
							<div class="<?php echo $controlGroupClass; ?>">
								<label class="<?php echo $controlLabelClass; ?>">
									<?php echo $this->form->getLabel('document_version'); ?>	
								</label>
								<div class="<?php echo $controlsClass; ?>">	
									<?php echo $this->form->getInput('document_version'); ?>
								</div>
							</div>
                        <?php } ?>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('license_id'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">	
								<?php echo $this->form->getInput('license_id'); ?>
							</div>
						</div>
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('indicators'); ?>	
							</label>
							<div class="<?php echo $controlsClass; ?>">	
								<?php echo $this->form->getInput('indicators'); ?>		
							</div>
						</div>
						<?php
							if ($this->config->activate_multilingual_feature) 
							{
							?>
							<div class="<?php echo $controlGroupClass; ?>">
								<label class="<?php echo $controlLabelClass; ?>">
									<?php echo $this->form->getLabel('language'); ?>
								</label>
								<div class="<?php echo $controlsClass; ?>">	
									<?php echo $this->form->getInput('language'); ?>
								</div>
							</div>     	
							<?php    
							}        
						?>
					</fieldset>
					<fieldset class="image form-horizontal options-form">
						<legend><?php echo Text::_( 'EDOCMAN_IMAGE' ); ?></legend>	
					
						<div class="<?php echo $controlGroupClass; ?>">
							<label class="<?php echo $controlLabelClass; ?>">
								<?php echo $this->form->getLabel('image'); ?>
							</label>
							<div class="<?php echo $controlsClass; ?>">
								<?php
									if ($this->item->image && file_exists(JPATH_ROOT.'/media/com_edocman/document/thumbs/'.$this->item->image)) {								
									?>	
										<img src="<?php echo Uri::root()?>/media/com_edocman/document/thumbs/<?php echo $this->item->image;?>"  class="img-polaroid" />
										<div class="clearfix"></div>
										<input type="checkbox" name="del_image" value="1" title="<?php echo Text::_('EDOCMAN_DEL_IMAGE_DESC'); ?>" />
										<?php echo Text::_('EDOCMAN_DELETE_THUMBNAIL');?>?
										<div class="clearfix"></div>
									<?php	
									}
								?>
								<?php echo $this->form->getInput('image'); ?>
							</div>
						</div>
					</fieldset>
					<?php
					if(count($fields))
					{
					?>
						<fieldset class="fields form-horizontal options-form">
							<legend><?php echo Text::_( 'EDOCMAN_CUSTOM_FIELDS' ); ?></legend>
							<?php foreach($fields as $field): ?>
								<?php if ($field->hidden): ?>
									<div class="<?php echo $controlGroupClass; ?>">
										<div class="<?php echo $controlsClass; ?>">
											<?php echo $field->input; ?>
										</div>
									</div>
								<?php else: ?>
									<div class="<?php echo $controlGroupClass; ?>">
										<label class="<?php echo $controlLabelClass; ?>">
											<?php echo $field->label; ?>
										</label>
										<div class="<?php echo $controlsClass; ?>">
											<?php echo $field->input; ?>
										</div>
									</div>
								<?php endif; ?>
							<?php endforeach; ?>
						</fieldset>
					<?php
					}
					?>
				</div>
			</div>
			<?php
			echo HTMLHelper::_('bootstrap.endTab');
			echo HTMLHelper::_('bootstrap.addTab', 'document', 'permission-page', Text::_('Permissions', true));
			?>
			<div class="tab-pane" id="permission-page">		
				<?php
					if ($this->canDo->get('core.admin'))
					{
						echo $this->form->getInput('rules');
					}						
				?>
			</div>
			<?php
			echo HTMLHelper::_('bootstrap.endTab');
			echo HTMLHelper::_('bootstrap.addTab', 'document', 'publishing-details', Text::_('JGLOBAL_FIELDSET_PUBLISHING', true));
			?>
			<div class="tab-pane" id="publishing-details">			
				<?php echo $this->loadTemplate('options'); ?>			
			</div>
			<?php
			echo HTMLHelper::_('bootstrap.endTab');
			echo HTMLHelper::_('bootstrap.addTab', 'document', 'meta-options', Text::_('JGLOBAL_FIELDSET_METADATA_OPTIONS', true));
			?>
			<div class="tab-pane" id="meta-options">
				<?php echo $this->loadTemplate('metadata'); ?>	
			</div>
			<?php
			echo HTMLHelper::_('bootstrap.endTab');
			if($this->indexer == 1)
			{
				echo HTMLHelper::_('bootstrap.addTab', 'document', 'indexed-content', Text::_('EDOCMAN_INDEXED_CONTENT', true));
				?>
				<fieldset class="indexed form-horizontal options-form">
					<legend><?php echo Text::_( 'EDOCMAN_INDEXED_CONTENT' ); ?></legend>
					<?php 
					if($this->item->exclude_indexing == 1)
					{
						echo '<div class="alert alert-no-items">'.Text::_('EDOCMAN_THIS_DOCUMENT_IS_IN_EXCLUDE_INDEXING_LIST').'</div>';
					}
					else
					{
						if($this->item->indexed_content != "")
						{
							?>
							<div class="<?php echo $rowFluidClass;?>">
								<div class="<?php echo $span12Class;?>" style="border:1px solid #CCC;padding:10px;">
									<?php
									echo $this->item->indexed_content;
									?>
								</div>
							</div>
							<?php
						}
						else
						{
							echo '<div class="alert alert-no-items">'.Text::_('EDOCMAN_HASNOT_INDEX_CONTENT_OF_THIS_DOCUMENT_WILL_DO_IT_AFTER_SAVING').'</div>';
						}
					}
					?>	
				</fieldset>
				<?php
				echo HTMLHelper::_('bootstrap.endTab');
			}

            if($this->config->activate_multilingual_feature)
            {
                echo HTMLHelper::_('bootstrap.addTab', 'document', 'associations', Text::_('EDOCMAN_ASSOCIATIONS', true));
                ?>
                <div class="tab-pane" id="associations">
                    <?php
                    if($this->item->id == 0)
                    {
                        echo "<div class='alert alert-info'>".Text::_('EDOCMAN_YOU_WILL_ABLE_TO_SELECT_ASSOCIATION_DOCUMENTS_AFTER_SAVING_DATA')."</div>";
                    }
                    elseif($this->item->language == '' || $this->item->language == '*')
                    {
                        echo "<div class='alert alert-info'>".Text::_('EDOCMAN_PLEASE_SELECT_SPECIFIC_LANGUAGE_FOR_THIS_DOCUMENT_BEFORE_SELECTING_ASSOCIATION')."</div>";
                    }
                    elseif(count($this->langs))
                    {
                        ?>
                        <table class="table" width="100%">
                            <tr>
                                <td colspan="2">
                                    <?php
                                    echo Text::_('EDOCMAN_ASSOCIATION_EXPLANATION');
                                    ?>
                                </td>
                            </tr>
                            <?php
                            foreach($this->langs as $lang)
                            {
                                ?>
                                <tr>
                                    <td class="key" width="15%">
                                        <?php
                                        echo $lang->title
                                        ?>
                                    </td>
                                    <td>
                                        <input type="text" name="assoc[<?php echo $lang->lang_code;?>]" class="input-small form-control ishort" value="<?php echo $lang->assoc_id;?>" />
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                        </table>
                        <?php
                    }
                    ?>
                </div>
                <?php
                echo HTMLHelper::_('bootstrap.endTab');
            }

            if (count($this->plugins))
            {
                $count = 0;

                foreach ($this->plugins as $plugin)
                {
                    $count++;
                    echo HTMLHelper::_('bootstrap.addTab', 'document', 'tab_' . $count, Text::_($plugin['title'], true));
                    echo $plugin['form'];
                    echo HTMLHelper::_('bootstrap.endTab');
                }
            }
			if (!empty($this->document_versions) && $this->config->keep_previous_versions) :
			echo HTMLHelper::_('bootstrap.addTab', 'document', 'document_history', Text::_('EDOCMAN_DOCUMENT_HISTORY_LABEL'));
			?>
			<div class="<?php echo $$rowFluidClass; ?>">
				<div class="<?php echo $span12Class; ?>">
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th style="text-align:center;"><?php echo Text::_('EDOCMAN_VERSION');?></th>
								<th><?php echo Text::_('EDOCMAN_FILE_NAME');?></th>
								<th><?php echo Text::_('EDOCMAN_FILESIZE');?></th>
								<th><?php echo Text::_('EDOCMAN_CREATED_DATE');?></th>
								<th><?php echo Text::_('EDOCMAN_NOTE');?></th>
								<th style="text-align:center;"><?php echo Text::_('EDOCMAN_ACTION');?></th>
							</tr>
						</thead>
						<tbody>
						<?php foreach ($this->document_versions as $version): ?>
							<tr>
								<td style="text-align:center;"><?php echo (int)$version->version_number; ?></td>
								<td><?php echo htmlspecialchars($version->file_name); ?></td>
								<td><?php echo number_format($version->file_size/1024, 2); ?> KB</td>
								<td><?php echo $version->created_at; ?></td>
								<td><?php echo htmlspecialchars($version->note); ?></td>
								<td style="text-align:center;">
									<?php
									if ($version->cloud_provider == 'local'): ?>
										<?php
										$file_name = $version->file_url;
										$file_name_ended_code = base64_encode($file_name);
										?>
										<a href="index.php?option=com_edocman&task=downloadFileHistory&file_path=<?php echo $file_name_ended_code; ?>" class="icon-action" title="<?php echo Text::_('EDOCMAN_DOWNLOAD')?>">
											<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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>
										</a>
									<?php else: 
										
									$cloud_id = (string)$version->cloud_file_id;
									if($cloud_id != "")
									{
										$cloud_id = "&clould_id=".$cloud_id;
									}	
									?>
										<a href="index.php?option=com_edocman&task=downloadFileHistory&file_path=<?php echo base64_encode($version->file_name); ?><?php echo $cloud_id?>" class="icon-action" title="<?php echo Text::_('EDOCMAN_DOWNLOAD')?>">
											<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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>
										</a>
									<?php endif; ?>
									
									<a title="<?php echo Text::_('EDOCMAN_RESTORE_VERSION');?>" href="index.php?option=com_edocman&task=document.restoreVersion&id=<?php echo $this->item->id; ?>&version=<?php echo $version->id; ?>" class="icon-action">
										<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
  <path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z"/>
  <path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466"/>
</svg>
									</a>
									
								</td>
							</tr>
						<?php endforeach; ?>
						</tbody>
					</table>
				</div>
			</div>
			<?php
			echo HTMLHelper::_('bootstrap.endTab');
			endif;
            echo HTMLHelper::_('bootstrap.endTabSet');
            ?>
            <input type="hidden" name="task" value="" />
            <?php echo HTMLHelper::_('form.token'); ?>
	</div>
</form>
<script type="text/javascript">
    /**
    jQuery("[name='accesspicker']").click(function(){
        if(jQuery("[name='accesspicker']").val() == '0'){
            jQuery('#presetsdiv').slideDown();
            jQuery('#groupsdiv').slideUp();
        }else{
            jQuery('#presetsdiv').slideUp();
            jQuery('#groupsdiv').slideDown();
        }
    })
     **/

    function updateRadioButton(select_item)
	{
        if(select_item == '0')
		{
            jQuery('#presetsdiv').slideDown();
            jQuery('#groupsdiv').slideUp();
        }
		else
		{
            jQuery('#presetsdiv').slideUp();
            jQuery('#groupsdiv').slideDown();
        }
    }
</script>

	<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery('#jform_filename').change(function(e){
			var fileName = e.target.files[0].name;
			fileName = fileName.substring(0,fileName.lastIndexOf('.'));
			if(jQuery('#jform_title').val() == '')
			{
				jQuery('#jform_title').val(fileName);
			}
		});
	});

	jQuery('.tagRemove').click(function(event) {
		event.preventDefault();
		jQuery(this).parent().remove();
	});
	jQuery('ul.tags').click(function() {
		jQuery('#search-field').focus();
	});
	jQuery('#search-field').keypress(function(event) {
		if (event.which == '13') {
			if (jQuery(this).val() != '') {
				jQuery('<li class=\'tagAdded\'>' + jQuery(this).val() + '<span class=\'tagRemove\' onclick=\'jQuery(this).parent().remove();\'>&times;</span><input type=\'hidden\' value=\'' + jQuery(this).val() + '\' name=\'tags[]\'></li>').insertBefore('.tags .tagAdd');
				jQuery(this).val('');
				event.preventDefault();
			}
		}
	});
	var tagsUrl = '<?php echo Uri::root(); ?>administrator/';
	tagsUrl += 'index.php?option=com_edocman&task=tags';
	jQuery('#search-field').autocomplete({
		source: function(request, response) {
			jQuery.ajax({
				type: 'post',
				url: tagsUrl,
				data: 'q=' + request.term,
				dataType: 'json',
				success: function(data) {
					jQuery('#search-field').removeClass('tagsLoading');
					response(jQuery.map(data, function(item) {
						return item;
					}));
				}
			});
		},
		minLength: 3,
		select: function(event, ui) {
			jQuery('<li class=\'tagAdded\'>' + ui.item.label + '<span class=\'tagRemove\' onclick=\'jQuery(this).parent().remove();\'>&times;</span><input type=\'hidden\' value=\'' + ui.item.value + '\' name=\'tags[]\'></li>').insertBefore('.tags .tagAdd');
			this.value = '';
			return false;
		},
		search: function(event, ui) {
			jQuery('#search-field').addClass('tagsLoading');
		}
	});

	<?php
	if (((int)$this->config->file_upload_method == 1 || (int)$this->config->file_upload_method == 2)  && $this->config->activate_herachical_folder_structure)
	{
		?>
		var url = '<?php echo Uri::root(); ?>administrator/';
		url		+= 'index.php?option=com_edocman&task=showfilesbasedonselectcategory&tmpl=component&current_file=<?php echo $this->item->filename; ?>';
		jQuery('#jformcategory_id').change(function() 
		{
			jQuery.ajax({
				type: 'post',
				url: url,
				data: 'category_id=' + jQuery("#jformcategory_id").val(),
				dataType: 'html',
				success: function(htmltext) {
					jQuery('#selectedFilesDiv').html(htmltext);
				}
			});
		});
		<?php
	}
	?>
	</script>
