<?php 
/**
* @version		$Id: single.html.php 2706 2025-08-04 17:33:39Z IOS $
* @package		Elxis
* @subpackage	Component Translator
* @copyright	Copyright (c) 2006-2025 Elxis CMS (https://www.elxis.org). All rights reserved.
* @license		Elxis Public License ( https://www.elxis.org/elxis-public-license.html )
* @author		Elxis Team ( https://www.elxis.org )
* @description 	Elxis CMS is free software. Read the license for copyright notices and details
*/

defined('_ELXIS_') or die ('Direct access to this location is not allowed');


class singleEtranslatorView extends etranslatorView {

	/*********************/
	/* MAGIC CONSTRUCTOR */
	/*********************/
	public function __construct() {
		parent::__construct();
	}


	/**************************/
	/* SHOW TRANSLATIONS LIST */
	/**************************/
	public function listTrans($rows, $options, $trcats, $trelements, $elxis, $eLang) {
		$link = $elxis->makeAURL('etranslator:/');
		$inlink = $elxis->makeAURL('etranslator:/', 'inner.php');

		$htmlHelper = $elxis->obj('html');

		elxisLoader::loadFile('includes/libraries/elxis/form5.class.php');

		$parts = array();
		if ($options['category'] != '') { $parts[] = 'category='.$options['category']; }
		if ($options['element'] != '') { $parts[] = 'element='.$options['element']; }
		if ($options['language'] != '') { $parts[] = 'language='.$options['language']; }
		if ($options['elid'] > 0) { $parts[] = 'elid='.$options['elid']; }
		$ordlink = ($parts) ? $link.'?'.implode('&amp;', $parts).'&amp;' : $link.'?';
		$is_filtered = $parts ? true : false;
		unset($parts);

		echo '<h2>'.$eLang->get('TRANS_MANAGEMENT')."</h2>\n";
		if ($elxis->getConfig('MULTILINGUISM') == 0) {
			echo '<div class="elx5_warning">'.$eLang->get('MLCONTENT_DISABLED')."</div>\n";
		}

		echo '<div class="elx5_box elx5_border_blue">'."\n";
		echo '<div class="elx5_box_body">'."\n";
		echo '<div class="elx5_sticky">'."\n";

		echo '<div class="elx5_dataactions">'."\n";
		echo '<a href="#" data-etransid="0" data-isadd="1" class="elx5_dataaction" data-selector="1" data-activeclass="elx5_datahighlight" title="'.$eLang->get('ADD').'"><i class="fas fa-plus"></i><span class="elx5_lmobhide"> '.$eLang->get('ADD')."</span></a>\n";
		echo '<a href="#" data-etransid="0" data-isadd="0" class="elx5_dataaction" data-selector="1" title="'.$eLang->get('EDIT').'"><i class="fas fa-edit"></i><span class="elx5_lmobhide"> '.$eLang->get('EDIT')."</span></a>\n";
		echo '<a href="#" id="etransdelrowslink" class="elx5_dataaction" title="'.$eLang->get('DELETE').'" data-selector="1" data-activeclass="elx5_datawarn"><i class="fas fa-trash"></i><span class="elx5_lmobhide"> '.$eLang->get('DELETE')."</span></a>\n";
		if ($is_filtered) {
			echo '<a href="#" id="etranstogopt" class="elx5_dataaction elx5_dataorange" data-elx5tooltip="'.$eLang->get('FILTERS_HAVE_APPLIED').'"><i class="fas fa-filter"></i><span class="elx5_lmobhide"> '.$eLang->get('SEARCH_OPTIONS')."</span></a>\n";
		} else {
			echo '<a href="#" id="etranstogopt" class="elx5_dataaction elx5_dataactive" title="'.$eLang->get('SEARCH_OPTIONS').'"><i class="fas fa-filter"></i><span class="elx5_lmobhide"> '.$eLang->get('SEARCH_OPTIONS')."</span></a>\n";
		}
		echo "</div>\n";

		echo '<div class="elx5_invisible" id="etranssearchoptions">'."\n";
		echo '<div class="elx5_actionsbox elx5_dspace">';

		$form = new elxis5Form(array('idprefix' => 'trs', 'labelclass' => 'elx5_label', 'sideclass' => 'elx5_labelside'));
		$form->openForm(array('name' => 'fmsrtrans', 'method' =>'get', 'action' => $link, 'id' => 'fmsrtrans'));

		$form->addHTML('<div class="elx5_2colwrap"><div class="elx5_2colbox elx5_spad">');
		$foptions = array();
		$foptions[] = $form->makeOption('', '- '.$eLang->get('ANY').' -');
		if ($trcats) {
			foreach ($trcats as $trcat) { $foptions[] = $form->makeOption($trcat, $trcat); }
		}
		$form->addSelect('category', $eLang->get('CATEGORY'), $options['category'], $foptions);

		$foptions = array();
		$foptions[] = $form->makeOption('', '- '.$eLang->get('ANY').' -');
		if ($trelements) {
			foreach ($trelements as $trelement => $txt) { $foptions[] = $form->makeOption($trelement, $txt); }
		}
		$form->addSelect('element', $eLang->get('ELEMENT'), $options['element'], $foptions);

		$form->addHTML('</div><div class="elx5_2colbox elx5_spad">');

		$form->addLanguage('language', $eLang->get('LANGUAGE'), $options['language'], array(), 1, 5, true, '- '.$eLang->get('SELECT').' -');
		$form->addText('elid', $options['elid'], $eLang->get('ID'), array('dir' => 'ltr'));

		$form->addHTML('</div></div>');

		$form->addHidden('sn', $options['sn']);
		$form->addHidden('so', $options['so']);

		$form->addHTML('<div class="elx5_vpad">');
		$form->addButton('srcbtn', $eLang->get('SEARCH'), 'submit');
		$form->addHTML('</div>');

		$form->closeForm();
		echo "</div>\n";//elx5_actionsbox
		echo "</div>\n";//#etranssearchoptions
		echo "</div>\n";//elx5_sticky

		echo '<table id="translationstbl" class="elx5_datatable" data-deletelng="'.addslashes($eLang->get('AREYOUSURE')).'" data-deletepage="'.$inlink.'single/delete">'."\n";
		echo "<thead>\n";
		echo "<tr>\n";
		echo $htmlHelper->tableHead('&#160;', 'elx5_nosorting elx5_center');
		echo $htmlHelper->sortableTableHead($ordlink, $eLang->get('CATEGORY'), 'category', $options['sn'], $options['so'], 'elx5_lmobhide');
		echo $htmlHelper->sortableTableHead($ordlink, $eLang->get('ELEMENT'), 'element', $options['sn'], $options['so'], 'elx5_lmobhide');
		echo $htmlHelper->sortableTableHead($ordlink, $eLang->get('ID'), 'elid', $options['sn'], $options['so'], 'elx5_center elx5_lmobhide');
		$txt = $eLang->get('ORIGINAL_TEXT').' <img src="'.$elxis->secureBase().'/includes/libraries/elxis/language/flags/'.$elxis->getConfig('LANG').'.png" ';
		$txt .= 'alt="'.$elxis->getConfig('LANG').'" title="'.$elxis->getConfig('LANG').'">';
		echo $htmlHelper->tableHead($txt, 'elx5_nosorting elx5_lmobhide');
		echo $htmlHelper->sortableTableHead($ordlink, $eLang->get('LANGUAGE'), 'language', $options['sn'], $options['so'], 'elx5_center');
		echo $htmlHelper->sortableTableHead($ordlink, $eLang->get('TRANSLATION'), 'translation', $options['sn'], $options['so']);
		echo "</tr>\n";
		echo "</thead>\n";

		echo "<tbody>\n";
		if ($rows) {
			$flags_dir = $elxis->secureBase().'/includes/libraries/elxis/language/flags/';
			$otextdir = (in_array($elxis->getConfig('LANG'), array('fa', 'he', 'ar'))) ? 'rtl' : 'ltr';
			foreach ($rows as $row) {
				if (in_array($row['element'], array('introtext', 'maintext', 'category_description', 'content', 'locdescription', 'roomdesc', 'hotterms', 'hotdesc', 'rtextradesc', 'rtpaydesc', 'rentterms', 'rtprincdesc'))) {
					$trans_txt = '<em>'.$eLang->get('LONG_TEXT').'</em>';
					$orig_txt = '<em>'.$eLang->get('LONG_TEXT').'</em>';
				} else if ((strpos($row['element'], 'description') === true) || (strpos($row['element'], 'text') === true)) {
					$trans_txt = '<em>'.$eLang->get('LONG_TEXT').'</em>';
					$orig_txt = '<em>'.$eLang->get('LONG_TEXT').'</em>';
				} else {
					$textdir = (in_array($row['translation'], array('fa', 'he', 'ar'))) ? 'rtl' : 'ltr';
					$trans_txt = (eUTF::strlen($row['translation']) > 30) ? eUTF::substr(strip_tags($row['translation']), 0, 27).'...' : $row['translation'];
					$trans_txt = '<span dir="'.$textdir.'">'.$trans_txt.'</span>';
					if ($row['original_text'] == '') {
						$orig_txt = '<em>'.$eLang->get('NOT_AVAILABLE').'</em>';
					} else {
						$orig_txt = (eUTF::strlen($row['original_text']) > 30) ? eUTF::substr(strip_tags($row['original_text']), 0, 27).'...' : $row['original_text'];
						$orig_txt = '<span dir="'.$otextdir.'">'.$orig_txt.'</span>';
					}
				}

				$element_txt = $eLang->silentGet($row['element'], true);

				echo '<tr id="datarow'.$row['trid'].'">'."\n";
				echo '<td class="elx5_center">';
				echo '<input type="checkbox" name="dataprimary" id="dataprimary'.$row['trid'].'" class="elx5_datacheck" value="'.$row['trid'].'">';
				echo '<label for="dataprimary'.$row['trid'].'"></label></td>'."\n";
				echo '<td class="elx5_lmobhide">'.$row['category'].'</td>'."\n";
				echo '<td class="elx5_lmobhide"><a href="#" title="'.$eLang->get('EDIT').'" data-etransid="'.$row['trid'].'" data-isadd="0">'.$element_txt.'</a></td>'."\n";
				echo '<td class="elx5_center elx5_lmobhide">'.$row['elid'].'</td>'."\n";
				echo '<td class="elx5_lmobhide">'.$orig_txt.'</td>'."\n";
				echo '<td class="elx5_center"><img src="'.$flags_dir.$row['language'].'.png" alt="'.$row['language'].'" title="'.$row['language'].'"></td>'."\n";
				echo '<td><a href="#" title="'.$eLang->get('EDIT').'" data-etransid="'.$row['trid'].'" data-isadd="0">'.$trans_txt.'</a></td>'."\n";
				echo "</tr>\n";
			}
		} else {
			echo '<tr id="datarow0" class="elx5_rowwarn"><td class="elx5_center" colspan="7">'.$eLang->get('NO_RESULTS')."</td></tr>\n";
		}
		echo "</tbody>\n";
		echo "</table>\n";

		echo "</div>\n";//elx5_box_body

		if ($rows) {
			$linkbase = $ordlink.'sn='.$options['sn'].'&amp;so='.$options['so'];
			echo $htmlHelper->tableSummary($linkbase, $options['page'], $options['maxpage'], $options['total']);
		}

		echo "</div>\n";//elx5_box

		$attrs = array('data-addlng' => $eLang->get('ADD_TRANSLATION'), 'data-editlng' => $eLang->get('EDIT_TRANSLATION'));
		echo $htmlHelper->startModalWindow($eLang->get('ADD_TRANSLATION'), '1', '', true, '', '', $attrs);

		$form = new elxis5Form(array('idprefix' => 'etrans_', 'labelclass' => 'elx5_labelblock', 'sideclass' => 'elx5_zero'));

		$form->openForm(array('name' => 'fmedtrans', 'method' =>'post', 'action' => $inlink.'single/gettransdata', 'id' => 'fmedtrans'));
		$form->openFieldset();
		$label = '<img src="'.$elxis->secureBase().'/includes/libraries/elxis/language/flags/'.$elxis->getConfig('LANG').'.png" alt="'.$elxis->getConfig('LANG').'" title="'.$elxis->getConfig('LANG').'">'."\n";
		$label .= ' '.$eLang->get('ORIGINAL_TEXT');
		$orig_txt = '<div class="elx5_zero" id="etrans_original" dir="'.$eLang->getinfo('DIR').'">-</div>';
		$form->addInfo($label, $orig_txt);

		$form->setOption('labelclass', 'elx5_label');
		$form->setOption('sideclass', 'elx5_labelside');
		$form->addLanguage('language', $eLang->get('LANGUAGE'), '', array(), 2, 5, true);

		$form->setOption('labelclass', 'elx5_labelblock');
		$form->setOption('sideclass', 'elx5_zero');

		$form->addHTML('<div class="elx5_invisible" id="etrans_transwrap">');
		$form->addText('translation', '', $eLang->get('TRANSLATION'), array('maxlength' => 255, 'dir' => 'ltr'));
		$form->addHTML('</div>');

		$form->addHTML('<div class="elx5_invisible" id="etrans_texttranswrap">');
		$form->addTextarea('translationtext', '', $eLang->get('TRANSLATION'));
		$form->addHTML('</div>');

		$form->addHTML('<div class="elx5_spad elx5_center"><a href="#" id="etransswdirlink" title="'.$eLang->get('SWITCH_WRITE_DIR').'">LTR/RTL</a></div>');

		$form->addHidden('trid', '0');
		$form->addHidden('category', '');
		$form->addHidden('element', '');
		$form->addHidden('elid', '0');
		$form->addHidden('longtext', '0');
		$form->addHidden('saveurl', $inlink.'api/savetrans');

		$form->addHTML('<div class="elx5_vpad">');
		$form->addButton('save', $eLang->get('SAVE'), 'button', array('class' => 'elx5_btn elx5_sucbtn', 'data-waitlng' => $eLang->get('PLEASE_WAIT'), 'data-savelng' => $eLang->get('SAVE')));
		$form->addHTML('</div>');

		$form->closeFieldset();
		$form->closeForm();
		echo $htmlHelper->endModalWindow(true);
	}


	/*****************************************/
	/* ADD/EDIT ALL ITEM'S TRANSLATIONS HTML */
	/*****************************************/
	public function editAllTranslations($options, $original, $translations) {
		$eLang = eFactory::getLang();
		$elxis = eFactory::getElxis();

		$inlink = $elxis->makeAURL('etranslator:/', 'inner.php');

		elxisLoader::loadFile('includes/libraries/elxis/form5.class.php');

		$form = new elxis5Form(array('idprefix' => 'tra_', 'labelclass' => 'elx5_label', 'sideclass' => 'elx5_labelside'));
		$form->addHTML('<div class="elx5_pad">');
		$form->openForm(array('name' => 'fmalltrans', 'method' =>'post', 'action' => $inlink.'api/saveall', 'id' => 'fmalltrans'));
		$form->openFieldset($eLang->get('TRANS_MANAGEMENT'));
		$trdata = array('category' => $options['category'], 'element' => $options['element'], 'elid' => $options['id']);
		$form->addMLText('translation', $trdata, $original, $eLang->get('TRANSLATION'), array('required' => 'required', 'maxlength' => 255));

		$form->addHidden('category', $options['category']);
		$form->addHidden('element', $options['element']);
		$form->addHidden('elid', $options['id']);

		$form->addHTML('<div class="elx5_vpad">');
		$form->addButton('save', $eLang->get('SAVE'), 'submit', array('class' => 'elx5_btn elx5_sucbtn'));
		$form->addHTML('</div>');
		$form->closeFieldset();
		$form->closeForm();
		$form->addHTML('</div>');
	}

}

?>