PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.11
VikBooking Hotel Booking Engine & PMS v1.8.11
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / views / translations / tmpl / default.php

default.php in VikBooking Hotel Booking Engine & PMS 1.8.11, at admin/views/translations/tmpl/default.php

669 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 $vbo_tn = $this->vbo_tn;
14
15 $vbo_app = VikBooking::getVboApplication();
16 $vbo_app->loadVisualEditorAssets();
17
18 $editor = JEditor::getInstance(JFactory::getApplication()->get('editor'));
19
20 $langs = $vbo_tn->getLanguagesList();
21 $xml_tables = $vbo_tn->getTranslationTables();
22 $active_table = '';
23 $active_table_key = '';
24
25 // JS lang vars
26 JText::script('VBO_COPY_ORIGINAL_TN');
27 JText::script('VCM_TRANSLATE');
28
29 if (!(count($langs) > 1)) {
30 //Error: only one language is published. Translations are useless
31 ?>
32 <p class="err"><?php echo JText::translate('VBTRANSLATIONERRONELANG'); ?></p>
33 <form name="adminForm" id="adminForm" action="index.php" method="post">
34 <input type="hidden" name="task" value="">
35 <input type="hidden" name="option" value="com_vikbooking">
36 </form>
37 <?php
38 } elseif (!$xml_tables || strlen($vbo_tn->getError())) {
39 //Error: XML file not readable or errors occurred
40 ?>
41 <p class="err"><?php echo $vbo_tn->getError(); ?></p>
42 <form name="adminForm" id="adminForm" action="index.php" method="post">
43 <input type="hidden" name="task" value="">
44 <input type="hidden" name="option" value="com_vikbooking">
45 </form>
46 <?php
47 } else {
48 $cur_langtab = VikRequest::getString('vbo_lang', '', 'request');
49 $table = VikRequest::getString('vbo_table', '', 'request');
50 if (!empty($table)) {
51 $table = $vbo_tn->replacePrefix($table);
52 }
53
54 /**
55 * Allows to filter/search translations by a key-search value.
56 *
57 * @since 1.16.6 (J) - 1.6.6 (WP)
58 */
59 $keysearch = VikRequest::getString('keysearch', '', 'request');
60 $vbo_tn->setKeySearch($keysearch);
61 ?>
62
63 <form action="index.php?option=com_vikbooking&amp;task=translations" method="post" onsubmit="return vboCheckChanges();">
64 <div style="width: 100%; display: inline-block;" class="btn-toolbar vbo-btn-toolbar" id="filter-bar">
65 <div class="btn-group pull-right">
66 <button class="btn" type="submit"><?php echo JText::translate('VBOGETTRANSLATIONS'); ?></button>
67 </div>
68 <div class="btn-group pull-right">
69 <select name="vbo_table">
70 <option value="">-----------</option>
71 <?php
72 foreach ($xml_tables as $key => $value) {
73 $active_table = $vbo_tn->replacePrefix($key) == $table ? $value : $active_table;
74 $active_table_key = $vbo_tn->replacePrefix($key) == $table ? $key : $active_table_key;
75 ?>
76 <option value="<?php echo $key; ?>"<?php echo $vbo_tn->replacePrefix($key) == $table ? ' selected="selected"' : ''; ?>><?php echo $value; ?></option>
77 <?php
78 }
79 ?>
80 </select>
81 </div>
82 <?php
83 if (!empty($active_table_key)) {
84 ?>
85 <div class="btn-group pull-left">
86 <input type="text" name="keysearch" value="<?php echo JHtml::fetch('esc_attr', $keysearch); ?>" placeholder="<?php echo JHtml::fetch('esc_attr', JText::translate('VBODASHSEARCHKEYS')); ?>..." />
87 </div>
88 <?php
89 }
90 ?>
91 </div>
92 <input type="hidden" name="vbo_lang" class="vbo_lang" value="<?php echo $vbo_tn->default_lang; ?>">
93 <input type="hidden" name="option" value="com_vikbooking" />
94 <input type="hidden" name="task" value="translations" />
95 </form>
96 <form name="adminForm" id="adminForm" action="index.php" method="post">
97 <div class="vbo-translation-langtabs">
98 <?php
99 foreach ($langs as $ltag => $lang) {
100 $is_def = ($ltag == $vbo_tn->default_lang);
101 $lcountry = substr($ltag, 0, 2);
102 $flag = '';
103 if (VBOPlatformDetection::isJoomla() && is_file(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'mod_languages' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $lcountry . '.gif')) {
104 $flag = '<img src="' . JUri::root() . 'media/mod_languages/images/' . $lcountry . '.gif"/>';
105 }
106 ?><div class="vbo-translation-tab<?php echo $is_def ? ' vbo-translation-tab-default' : ''; ?>" data-vbolang="<?php echo $ltag; ?>">
107 <?php
108 if (!empty($flag)) {
109 ?>
110 <span class="vbo-translation-flag"><?php echo $flag; ?></span>
111 <?php
112 }
113 ?>
114 <span class="vbo-translation-langname"><?php echo $lang['name']; ?></span>
115 </div><?php
116 }
117
118 if (VBOPlatformDetection::isJoomla()) {
119 ?>
120 <div class="vbo-translation-tab vbo-translation-tab-ini" data-vbolang="">
121 <span class="vbo-translation-iniflag">.INI</span>
122 <span class="vbo-translation-langname"><?php echo JText::translate('VBTRANSLATIONINISTATUS'); ?></span>
123 </div>
124 <?php
125 }
126 ?>
127 </div>
128 <div class="vbo-translation-tabscontents">
129 <?php
130 $table_cols = !empty($active_table_key) ? $vbo_tn->getTableColumns($active_table_key) : [];
131 $table_def_dbvals = !empty($active_table_key) ? $vbo_tn->getTableDefaultDbValues($active_table_key, array_keys($table_cols)) : [];
132 if (!empty($active_table_key)) {
133 echo '<input type="hidden" name="vbo_table" value="'.$active_table_key.'"/>'."\n";
134 if (!empty($keysearch)) {
135 echo '<input type="hidden" name="keysearch" value="' . JHtml::fetch('esc_attr', $keysearch) . '"/>'."\n";
136 }
137 }
138 foreach ($langs as $ltag => $lang) {
139 $is_def = ($ltag == $vbo_tn->default_lang);
140 ?>
141 <div class="vbo-translation-langcontent" style="display: <?php echo $is_def ? 'block' : 'none'; ?>;" id="vbo_langcontent_<?php echo $ltag; ?>">
142 <?php
143 if (empty($active_table_key)) {
144 ?>
145 <p class="warn"><?php echo JText::translate('VBTRANSLATIONSELTABLEMESS'); ?></p>
146 <?php
147 } elseif (strlen($vbo_tn->getError()) > 0) {
148 ?>
149 <p class="err"><?php echo $vbo_tn->getError(); ?></p>
150 <?php
151 } else {
152 ?>
153 <fieldset class="adminform">
154 <legend class="adminlegend"><?php echo $active_table; ?> - <?php echo $lang['name'].($is_def ? ' - '.JText::translate('VBTRANSLATIONDEFLANG') : ''); ?></legend>
155 <div class="vbo-translations-tab-container">
156 <?php
157 if ($is_def) {
158 // values of Default Language to be translated
159 foreach ($table_def_dbvals as $reference_id => $values) {
160 ?>
161 <div class="vbo-translations-default-element">
162 <div class="vbo-translations-element-title" data-reference="<?php echo $ltag.'-'.$reference_id; ?>">
163 <div class="vbo-translate-element-cell"><?php echo $vbo_tn->getRecordReferenceName($table_cols, $values); ?></div>
164 </div>
165 <div class="vbo-translations-element-contents">
166 <?php
167 foreach ($values as $field => $def_value) {
168 $title = $table_cols[$field]['jlang'];
169 $type = $table_cols[$field]['type'];
170 if ($type == 'html') {
171 $def_value = VBOPlatformDetection::isWordPress() ? wpautop($def_value) : $def_value;
172 }
173 ?>
174 <div class="vbo-translations-element-row" data-reference="<?php echo $ltag.'-'.$reference_id; ?>">
175 <div class="vbo-translations-element-lbl"><?php echo $title; ?></div>
176 <div class="vbo-translations-element-val" data-origvalue="<?php echo $reference_id . '-' . $field; ?>"><?php echo $type != 'json' ? $def_value : ''; ?></div>
177 </div>
178 <?php
179 if ($type == 'json') {
180 $tn_keys = $table_cols[$field]['keys'];
181 $keys = !empty($tn_keys) ? explode(',', $tn_keys) : [];
182 $json_def_values = json_decode($def_value, true);
183 if ($json_def_values) {
184 foreach ($json_def_values as $jkey => $jval) {
185 if ((!in_array($jkey, $keys) && count($keys) > 0) || empty($jval)) {
186 continue;
187 }
188 $json_lbl = '&nbsp;';
189 if (!is_numeric($jkey)) {
190 $guess_lbl = JText::translate('VBO_' . strtoupper($jkey));
191 $json_lbl = $guess_lbl != 'VBO_' . strtoupper($jkey) ? $guess_lbl : ucwords($jkey);
192 }
193 ?>
194 <div class="vbo-translations-element-row vbo-translations-element-row-nested" data-reference="<?php echo $ltag.'-'.$reference_id; ?>">
195 <div class="vbo-translations-element-lbl"><?php echo $json_lbl; ?></div>
196 <div class="vbo-translations-element-val" data-origvalue="<?php echo $reference_id . '-' . $field . '-' . $jkey; ?>"><?php echo $jval; ?></div>
197 </div>
198 <?php
199 }
200 }
201 }
202 ?>
203 <?php
204 }
205 ?>
206 </div>
207 </div>
208 <?php
209 }
210 } else {
211 // translation fields for this language
212 $lang_record_tn = $vbo_tn->getTranslatedTable($active_table_key, $ltag);
213 foreach ($table_def_dbvals as $reference_id => $values) {
214 ?>
215 <div class="vbo-translations-language-element">
216 <div class="vbo-translations-element-title" data-reference="<?php echo $ltag.'-'.$reference_id; ?>">
217 <div class="vbo-translate-element-cell"><?php echo $vbo_tn->getRecordReferenceName($table_cols, $values); ?></div>
218 </div>
219 <div class="vbo-translations-element-contents">
220 <?php
221 foreach ($values as $field => $def_value) {
222 $title = $table_cols[$field]['jlang'];
223 $type = $table_cols[$field]['type'];
224 if ($type == 'skip') {
225 continue;
226 }
227 $tn_value = '';
228 $tn_class = ' vbo-missing-translation';
229 if (array_key_exists($reference_id, ($lang_record_tn ?? [])) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? [])) && strlen($lang_record_tn[$reference_id]['content'][$field])) {
230 if (in_array($type, array('text', 'textarea', 'html'))) {
231 $tn_class = ' vbo-field-translated';
232 } else {
233 $tn_class = '';
234 }
235 }
236 ?>
237 <div class="vbo-translations-element-row<?php echo $tn_class; ?>" data-reference="<?php echo $ltag.'-'.$reference_id; ?>" data-copyoriginal="<?php echo $reference_id . '-' . $field; ?>">
238 <div class="vbo-translations-element-lbl"><?php echo $title; ?></div>
239 <div class="vbo-translations-element-val">
240 <?php
241 if ($type == 'text') {
242 if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, $lang_record_tn[$reference_id]['content'])) {
243 $tn_value = $lang_record_tn[$reference_id]['content'][$field];
244 }
245 ?>
246 <input type="text" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>]" value="<?php echo htmlspecialchars($tn_value); ?>" size="40" placeholder="<?php echo htmlspecialchars($def_value); ?>"/>
247 <?php
248 } elseif ($type == 'textarea') {
249 if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, $lang_record_tn[$reference_id]['content'])) {
250 $tn_value = $lang_record_tn[$reference_id]['content'][$field];
251 }
252 ?>
253 <textarea name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>]" rows="7" cols="170" placeholder="<?php echo htmlspecialchars($def_value); ?>"><?php echo $tn_value; ?></textarea>
254 <?php
255 } elseif ($type == 'html') {
256 if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, $lang_record_tn[$reference_id]['content'])) {
257 $tn_value = $lang_record_tn[$reference_id]['content'][$field];
258 }
259 if (VBOPlatformDetection::isWordPress() && interface_exists('Throwable')) {
260 /**
261 * With PHP >= 7 supporting throwable exceptions for Fatal Errors
262 * we try to avoid issues with third party plugins that make use
263 * of the WP native function get_current_screen().
264 *
265 * @wponly
266 */
267 try {
268 echo $editor->display( "tn[".$ltag."][".$reference_id."][".$field."]", $tn_value, '100%', 350, 70, 20, true, "tn_".$ltag."_".$reference_id."_".$field );
269 } catch (Throwable $t) {
270 echo $t->getMessage() . ' in ' . $t->getFile() . ':' . $t->getLine() . '<br/>';
271 }
272 } else {
273 // we cannot catch Fatal Errors in PHP 5.x
274 echo $editor->display( "tn[".$ltag."][".$reference_id."][".$field."]", $tn_value, '100%', 350, 70, 20, true, "tn_".$ltag."_".$reference_id."_".$field );
275 }
276 }
277 ?>
278 </div>
279 </div>
280 <?php
281 if ($type == 'json') {
282 $tn_keys = $table_cols[$field]['keys'];
283 $keys = !empty($tn_keys) ? explode(',', $tn_keys) : [];
284 $json_def_values = json_decode($def_value, true);
285 if ($json_def_values) {
286 $tn_json_value = [];
287 if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, $lang_record_tn[$reference_id]['content'])) {
288 $tn_json_value = json_decode($lang_record_tn[$reference_id]['content'][$field], true);
289 }
290 foreach ($json_def_values as $jkey => $jval) {
291 if ((!in_array($jkey, $keys) && count($keys) > 0) || empty($jval)) {
292 continue;
293 }
294 $json_lbl = '&nbsp;';
295 if (!is_numeric($jkey)) {
296 $guess_lbl = JText::translate('VBO_' . strtoupper($jkey));
297 $json_lbl = $guess_lbl != 'VBO_' . strtoupper($jkey) ? $guess_lbl : ucwords($jkey);
298 }
299 ?>
300 <div class="vbo-translations-element-row vbo-translations-element-row-nested" data-reference="<?php echo $ltag.'-'.$reference_id; ?>" data-copyoriginal="<?php echo $reference_id . '-' . $field . '-' . $jkey; ?>">
301 <div class="vbo-translations-element-lbl"><?php echo $json_lbl; ?></div>
302 <div class="vbo-translations-element-val">
303 <?php
304 if (strlen($jval) > 40) {
305 // check if this translation field requires the rich text visual editor
306 if ($jkey == 'tpl_text' && strpos($jval, '<') !== false) {
307 // the original field contains HTML code built through the visual editor
308 $veditor_name = 'tn[' . $ltag . '][' . $reference_id . '][' . $field . '][' . $jkey . ']';
309 $veditor_id = 'tn_' . $ltag . '_' . $reference_id . '_' . $field . '_' . $jkey;
310 $tarea_attr = array(
311 'id' => $veditor_id,
312 'rows' => '7',
313 'cols' => '170',
314 'style' => 'min-width: 60%;',
315 );
316 $editor_opts = array(
317 'modes' => array(
318 'visual',
319 'text',
320 ),
321 );
322 echo $vbo_app->renderVisualEditor($veditor_name, (isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''), $tarea_attr, $editor_opts);
323 } else {
324 ?>
325 <textarea rows="7" cols="170" style="min-width: 60%;" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>][<?php echo $jkey; ?>]"><?php echo isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''; ?></textarea>
326 <?php
327 }
328 } else {
329 ?>
330 <input type="text" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>][<?php echo $jkey; ?>]" value="<?php echo isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''; ?>" size="40" placeholder="<?php echo htmlspecialchars($jval); ?>"/>
331 <?php
332 }
333 ?>
334 </div>
335 </div>
336 <?php
337 }
338 }
339 }
340 }
341 ?>
342 </div>
343 </div>
344 <?php
345 }
346 }
347 ?>
348 </div>
349 </fieldset>
350 <?php
351 }
352 ?>
353 </div>
354 <?php
355 }
356
357 // ini files status
358 if (VBOPlatformDetection::isJoomla()) {
359 $all_inis = $vbo_tn->getIniFiles();
360 ?>
361 <div class="vbo-translation-langcontent" style="display: none;" id="vbo_langcontent_ini">
362 <fieldset class="adminform">
363 <legend class="adminlegend">.INI <?php echo JText::translate('VBTRANSLATIONINISTATUS'); ?></legend>
364 <div class="vbo-translations-tab-container">
365 <?php
366 foreach ($all_inis as $initype => $inidet) {
367 $inipath = $inidet['path'];
368 ?>
369 <div class="vbo-translations-ini-element">
370 <div class="vbo-translations-element-title">
371 <div class="vbo-translate-element-cell"><?php echo JText::translate('VBINIEXPL'.strtoupper($initype)); ?></div>
372 </div>
373 <div class="vbo-translations-element-contents">
374 <?php
375 foreach ($langs as $ltag => $lang) {
376 $t_file_exists = file_exists(str_replace('en-GB', $ltag, $inipath));
377 $t_parsed_ini = $t_file_exists ? parse_ini_file(str_replace('en-GB', $ltag, $inipath)) : false;
378 ?>
379 <div class="vbo-translations-element-row <?php echo $t_file_exists ? 'vbo-field-translated' : 'vbo-missing-translation'; ?>">
380 <div class="vbo-translations-element-lbl"><?php echo ($ltag == 'en-GB' ? 'Native ' : '').$lang['name']; ?></div>
381 <div class="vbo-translations-element-val">
382 <span class="vbo-inifile-totrows <?php echo $t_file_exists ? 'vbo-inifile-exists' : 'vbo-inifile-notfound'; ?>"><?php echo $t_file_exists && $t_parsed_ini !== false ? JText::translate('VBOINIDEFINITIONS').': '.count($t_parsed_ini) : JText::translate('VBOINIMISSINGFILE'); ?></span>
383 <span class="vbo-inifile-path <?php echo $t_file_exists ? 'vbo-inifile-exists' : 'vbo-inifile-notfound'; ?>"><?php echo JText::translate('VBOINIPATH').': '.str_replace('en-GB', $ltag, $inipath); ?></span>
384 </div>
385 </div>
386 <?php
387 }
388 ?>
389 </div>
390 </div>
391 <?php
392 }
393 ?>
394 </div>
395 </fieldset>
396 </div>
397 <?php
398 // end ini files status
399 }
400 ?>
401 </div>
402 <input type="hidden" name="vbo_lang" class="vbo_lang" value="<?php echo $vbo_tn->default_lang; ?>">
403 <input type="hidden" name="task" value="translations">
404 <input type="hidden" name="option" value="com_vikbooking">
405 <?php echo JHtml::fetch('form.token'); ?>
406
407 <div class="vbo-translations-lim-wrap">
408 <table align="center">
409 <tr>
410 <td align="center"><?php echo $vbo_tn->getPagination(); ?></td>
411 </tr>
412 <tr>
413 <td align="center">
414 <select name="limit" onchange="vboHandleCustomLimit(this.value);">
415 <option value="2"<?php echo $vbo_tn->lim == 2 ? ' selected="selected"' : ''; ?>>2</option>
416 <option value="5"<?php echo $vbo_tn->lim == 5 ? ' selected="selected"' : ''; ?>>5</option>
417 <option value="10"<?php echo $vbo_tn->lim == 10 ? ' selected="selected"' : ''; ?>>10</option>
418 <option value="20"<?php echo $vbo_tn->lim == 20 ? ' selected="selected"' : ''; ?>>20</option>
419 </select>
420 </td>
421 </tr>
422 </table>
423 </div>
424 </form>
425
426 <script type="text/Javascript">
427 var vbo_tn_changes = false;
428 var vbo_copy_delay = 500;
429 var vbo_copy_timeout = null;
430
431 function vboHandleCustomLimit(lim) {
432 var cur_limstart = document.adminForm.limitstart;
433 if (typeof cur_limstart === 'undefined') {
434 // append hidden input field to form
435 var limstart_node = document.createElement('INPUT');
436 limstart_node.setAttribute('type', 'hidden');
437 limstart_node.setAttribute('name', 'limitstart');
438 limstart_node.setAttribute('value', '0');
439 document.adminForm.appendChild(limstart_node);
440 } else {
441 // update existing value
442 document.adminForm.limitstart.value = '0';
443 }
444 // submit form
445 document.adminForm.submit();
446 }
447
448 function vboCheckChanges() {
449 if (!vbo_tn_changes) {
450 return true;
451 }
452 return confirm("<?php echo addslashes(JText::translate('VBTANSLATIONSCHANGESCONF')); ?>");
453 }
454
455 function vboHoverCopyTranslation(elem) {
456 if (!elem) {
457 return false;
458 }
459 var copy_reference = elem.attr('data-copyoriginal');
460 if (!copy_reference) {
461 return false;
462 }
463 var orig_elem = jQuery('.vbo-translations-element-val[data-origvalue="' + copy_reference + '"]');
464 if (!orig_elem || !orig_elem.length || !orig_elem.html().length) {
465 return false;
466 }
467
468 const label = elem.find('.vbo-translations-element-lbl');
469
470 // translation actions wrapper
471 const txActions = jQuery('<div class="vbo-tn-actions"></div>');
472
473 let tn_field_val;
474
475 try {
476 let lang_reference_arr = elem.closest('.vbo-translations-element-row[data-copyoriginal]').attr('data-reference').split('-');
477 lang_reference_arr.splice(lang_reference_arr.length - 1, 1);
478 let wysiwyg_hipo_id = 'tn_' + (lang_reference_arr.join('-') + '-' + copy_reference).replace(/-/g, '_');
479
480 tn_field_val = Joomla.editors.instances[wysiwyg_hipo_id].getValue();
481 } catch (err) {
482 // fallback to default input/textarea
483 tn_field_val = elem.find('.vbo-translations-element-val').find('input[type="text"],textarea').val();
484 }
485
486 // check if translation field has got a value
487 if (!(tn_field_val || '').trim()) {
488 // add button to copy the original translation
489 txActions.append(
490 jQuery('<span class="tn-copy-original vbo-tooltip vbo-tooltip-bottom" onclick="vboApplyCopyTranslation(this)"></span>')
491 .attr('data-tooltiptext', Joomla.JText._('VBO_COPY_ORIGINAL_TN'))
492 .html('<?php VikBookingIcons::e('copy'); ?>')
493 );
494
495 // check whether the channel manager is installed
496 if (<?php echo (int) class_exists('VikChannelManager'); ?>) {
497 // add button to translate the original text
498 txActions.append(
499 jQuery('<span class="tn-translate-original vbo-tooltip vbo-tooltip-bottom" onclick="vboTranslateOriginal(this)"></span>')
500 .attr('data-tooltiptext', Joomla.JText._('VCM_TRANSLATE'))
501 .html('<?php VikBookingIcons::e('language'); ?>')
502 );
503 }
504
505 // append the actions below the label
506 label.append(txActions);
507 }
508 }
509
510 async function vboApplyCopyTranslation(elem) {
511 let orig_elem = null;
512
513 try {
514 orig_elem = await vboGetOriginalTranslationElement(elem);
515 } catch (error) {
516 return false;
517 }
518
519 vboSetTranslation(jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]'), orig_elem.html());
520
521 // make sure to remove any copy-from-original button
522 // jQuery('.vbo-tn-actions').remove();
523 }
524
525 function vboGetOriginalTranslationElement(elem) {
526 return new Promise((resolve, reject) => {
527 elem = jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]');
528
529 if (!elem || !elem.length) {
530 reject(new Error('Copiable record not found'));
531 return false;
532 }
533
534 const copy_reference = elem.attr('data-copyoriginal');
535 if (!copy_reference) {
536 reject(new Error('Reference dara attribute not found'));
537 return false;
538 }
539
540 const orig_elem = jQuery('.vbo-translations-element-val[data-origvalue="' + copy_reference + '"]');
541 if (!orig_elem || !orig_elem.length) {
542 reject(new Error('Missing original value'));
543 return false;
544 }
545
546 resolve(orig_elem);
547 });
548 }
549
550 function vboSetTranslation(elem, translation) {
551 const copy_reference = elem.attr('data-copyoriginal');
552
553 try {
554 // grab lang tag, which could be part of the ID of a WYSIWYG editor
555 let lang_reference_arr = elem.attr('data-reference').split('-');
556 lang_reference_arr.splice((lang_reference_arr.length - 1), 1);
557 let wysiwyg_hipo_id = 'tn_' + (lang_reference_arr.join('-') + '-' + copy_reference).replace(/-/g, '_');
558
559 // attempt to inject value inside wysiwyg editor
560 Joomla.editors.instances[wysiwyg_hipo_id].setValue(translation);
561 } catch(e) {
562 // fallback to standard input/textarea
563 const input = elem.find('.vbo-translations-element-val').find('input[type="text"]');
564 if (input && input.length) {
565 input.val(translation).trigger('change');
566 }
567
568 const textarea = elem.find('.vbo-translations-element-val').find('textarea');
569 if (textarea && textarea.length) {
570 textarea.val(translation).trigger('change');
571 }
572 }
573 }
574
575 async function vboTranslateOriginal(elem) {
576 if (jQuery(elem).prop('aria-disabled') == true) {
577 return false;
578 }
579
580 let orig_elem = null;
581
582 try {
583 orig_elem = await vboGetOriginalTranslationElement(elem);
584 } catch (error) {
585 return false;
586 }
587
588 const originalRow = jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]');
589
590 const locale = originalRow.attr('data-reference').split('-').slice(0, -1).join('-');
591
592 jQuery(elem).prop('aria-disabled', true);
593 jQuery(elem).find('i').attr('class', '<?php echo VikBookingIcons::i('spinner', 'fa-spin'); ?>');
594
595 VBOCore.doAjax(
596 '<?php echo VikBooking::ajaxUrl('index.php?option=com_vikchannelmanager&task=ai.translate'); ?>',
597 {
598 text: orig_elem.html(),
599 locale: locale,
600 },
601 (response) => {
602 vboSetTranslation(originalRow, response.translated);
603 jQuery(elem).hide();
604 },
605 (error) => {
606 alert(error.responseText || error.statusText || 'An error has occurred.');
607 jQuery(elem).find('i').attr('class', '<?php echo VikBookingIcons::i('language'); ?>');
608 jQuery(elem).prop('aria-disabled', false);
609 }
610 );
611 }
612
613 jQuery(function() {
614
615 jQuery('.vbo-translation-tab').click(function() {
616 var langtag = jQuery(this).attr('data-vbolang');
617 if (jQuery('#vbo_langcontent_'+langtag).length) {
618 jQuery('.vbo_lang').val(langtag);
619 jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default');
620 jQuery(this).addClass('vbo-translation-tab-default');
621 jQuery('.vbo-translation-langcontent').hide();
622 jQuery('#vbo_langcontent_'+langtag).fadeIn();
623 } else {
624 jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default');
625 jQuery(this).addClass('vbo-translation-tab-default');
626 jQuery('.vbo-translation-langcontent').hide();
627 jQuery('#vbo_langcontent_ini').fadeIn();
628 }
629 });
630
631 jQuery('#adminForm input[type=text], #adminForm textarea').change(function() {
632 vbo_tn_changes = true;
633 });
634
635 jQuery('.vbo-translations-element-row[data-copyoriginal]').hover(function() {
636 var elem = jQuery(this);
637 vbo_copy_timeout = setTimeout(function() {
638 vboHoverCopyTranslation(elem);
639 }, vbo_copy_delay);
640 }, function() {
641 // cancel scheduled hovering function
642 clearTimeout(vbo_copy_timeout);
643 // make sure to remove any copy-from-original button
644 jQuery('.vbo-tn-actions').remove();
645 });
646 <?php
647 if (!empty($cur_langtab)) {
648 ?>
649 jQuery('.vbo-translation-tab').each(function() {
650 var langtag = jQuery(this).attr('data-vbolang');
651 if (langtag != '<?php echo $cur_langtab; ?>') {
652 return true;
653 }
654 if (jQuery('#vbo_langcontent_'+langtag).length) {
655 jQuery('.vbo_lang').val(langtag);
656 jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default');
657 jQuery(this).addClass('vbo-translation-tab-default');
658 jQuery('.vbo-translation-langcontent').hide();
659 jQuery('#vbo_langcontent_'+langtag).fadeIn();
660 }
661 });
662 <?php
663 }
664 ?>
665 });
666 </script>
667 <?php
668 }
669