<?php

/**
 * @version        1.9.7
 * @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\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;

ToolbarHelper::title(   Text::_( 'EDOCMAN_MANAGEMENT'), 'generic.png' );
ToolbarHelper::save('save');
ToolbarHelper::cancel();		
?>
<form action="index.php?option=com_edocman&view=language" method="post" name="adminForm" id="adminForm">
	<table width="100%">
        <tr>
            <td width="30%" style="text-align: left;">
				<div class="btn-group">
					<input placeholder="<?php echo Text::_('JSEARCH_FILTER');?>" type="text" name="search" id="search" value="<?php echo $this->search;?>" class="text_area search-query form-control" onchange="document.adminForm.submit();" />
					<button onclick="this.form.submit();" class="btn" title="<?php echo Text::_('JSEARCH_FILTER_SUBMIT');?>"><i class="icon icon-search"></i></button>
					<button onclick="document.getElementById('search').value='';this.form.submit();" class="btn btn-secondary" title="<?php echo Text::_('JSEARCH_FILTER_CLEAR');?>"><i class="icon icon-delete"></i></button>
				</div>
            </td>
            <td width="70%" style="text-align:right;">
                &nbsp;<?php echo Text::_("EDOCMAN_SELECT_LANGUAGE")?>: &nbsp;
                <?php echo $this->lists['langs'];?>
                <?php echo Text::_("EDOCMAN_SELECT_SIDE")?>: &nbsp;
                <?php echo $this->lists['site'];?>
            </td>
        </tr>
	</table>			
	<table class="adminlist table table-bordered" id="languagesTable">
		<thead>		
			<tr>
                <th class="key" style="width:5%;"><?php echo Text::_('#'); ?></td>
				<th class="key" style="width:20%;">Key</th>
				<th class="key" style="width:40%; ">Original</th>
				<th class="key" style="width:40%; ">Translation</th>
			</tr>	
		</thead>
        <tfoot>
        <tr>
            <td colspan="4" style="text-align:center;">
                <?php
                echo $this->pagNav->getListFooter();
                ?>
            </td>
        </tr>
        </tfoot>
		<tbody>	
		<?php
            $j = 0;
			$original = $this->trans['en-GB'][$this->item] ;
			$trans = $this->trans[$this->lang][$this->item] ;

            $search = @strtolower($this->search);
			foreach ($original as  $key=>$value) {
                $j++;
                $i = $j - 1;
                $str[] = $key;
                $show = true ;
                if (isset($tran[$key])) {
                    $translatedValue = $tran[$key];
                    $missing = false ;
                } else {
                    $translatedValue = $value;
                    $missing = true ;
                }
                if ($search != "") {
                    if (strpos(strtolower($key), $search) === false && strpos(strtolower($value), $search) === false) {
                        $show = false ;
                    }
                }
                if ($show) {
                                        ?>
                    <tr>
                        <td class="key" style="text-align:center;">
                            <?php echo $j + $this->pagNav->limitstart;?>.
                        </td>
                        <td class="key" style="text-align: left;"><?php echo $key; ?></td>
                        <td style="text-align: left;"><?php echo $value; ?></td>
                        <td style="text-align: left;">
                            <?php
                                if (isset($trans[$key]))
                                {
                                    $translatedValue = $trans[$key];
                                    $missing = false ;
                                }
                                else
                                {
                                    $translatedValue = $value;
                                    $missing = true ;
                                }
                            ?>
							<input type="hidden" name="keys[]" value="<?php echo $key; ?>" />
							<input type="hidden" name="items[]" value="<?php echo $i;?>" />
							<input type="text" id="item_<?php echo $i?>" name="item_<?php echo $i?>" value="<?php echo $translatedValue; ; ?>" class="input-xlarge form-control" />
                            <?php
                                if ($missing) {
                                ?>
                                    <span style="color:red;">*</span>
                                <?php
                                }
                            ?>
                        </td>
                    </tr>
                    <?php }else{ ?>
                    <tr style="display: none;">
                        <td colspan="4">
                            <input type="hidden" name="keys[]" value="<?php echo $key; ?>" />
                            <input type="hidden" name="<?php echo $key; ?>"  value="<?php echo $translatedValue; ; ?>" />
                        </td>
                    </tr>
                    <?php } ?>
			<?php
			}
		?>
		</tbody>
	</table>
	<input type="hidden" name="option" value="com_edocman" />	
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="item" value="com_edocman" />			
	<?php echo HTMLHelper::_( 'form.token' ); ?>
</form>
