ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjLanguageExtGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-20014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
7define("ILIAS_LANGUAGE_MODULE", "Services/Language");
8
9require_once("./Services/Object/classes/class.ilObjectGUI.php");
10require_once("Services/Language/classes/class.ilObjLanguageAccess.php");
11
12
28{
40 public function __construct($a_data, $a_id = 0, $a_call_by_reference = false)
41 {
42 global $DIC;
43 $ilClientIniFile = $DIC->clientIni();
44 $ilCtrl = $DIC->ctrl();
45 $lng = $DIC->language();
46
47 // language maintenance strings are defined in administration
48 $lng->loadLanguageModule("administration");
49 $lng->loadLanguageModule("meta");
50
51 // view mode ('translate' or empty) determins available table filters
52 $ilCtrl->saveParameter($this, "view_mode");
53
54 // type and id of get the bound object
55 $this->type = "lng";
56 if (!$this->id = $_GET['obj_id']) {
57 $this->id = ilObjLanguageAccess::_lookupId($lng->getUserLanguage());
58 }
59
60 // do all generic GUI initialisations
61 parent::__construct($a_data, $this->id, false, true);
62
63 // initialize the array to store session variables for extended language maintenance
64 if (!is_array($_SESSION['lang_ext_maintenance'])) {
65 $_SESSION['lang_ext_maintenance'] = array();
66 }
67 $this->session = &$_SESSION['lang_ext_maintenance'];
68
69
70 // read the lang mode
71 $this->langmode = $ilClientIniFile->readVariable("system", "LANGMODE");
72 }
73
74
81 public function assignObject()
82 {
83 require_once("Services/Language/classes/class.ilObjLanguageExt.php");
84 $this->object = new ilObjLanguageExt($this->id);
85 }
86
91 public function getId()
92 {
93 return $this->id;
94 }
95
99 public function executeCommand()
100 {
101 global $DIC;
102 $ilHelp = $DIC->help();
103
105 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
106 exit;
107 }
108
109 $cmd = $this->ctrl->getCmd("view") . "Object";
110 $this->$cmd();
111
112 $ilHelp->setScreenIdComponent("lng");
113 }
114
115
119 public function cancelObject()
120 {
121 $this->viewObject();
122 }
123
129 protected function getViewTable()
130 {
131 // create and configure the table object
132 include_once './Services/Language/classes/class.ilLanguageExtTableGUI.php';
133 $table_gui = new ilLanguageExtTableGUI($this, 'view', array(
134 'langmode' => $this->langmode,
135 'lang_key' => $this->object->key,
136 ));
137
138 return $table_gui;
139 }
140
144 public function viewObject($changesSuccessBool = 0)
145 {
146 global $DIC;
147 $tpl = $DIC['tpl'];
148
149 // get the view table
150 $table_gui = $this->getViewTable();
151
152 // get the remarks in database
153 $comments = $this->object->getAllRemarks();
154
155 // set the language to compare with
156 // get the default values if the compare language is the same
157 $compare = $table_gui->getFilterItemByPostVar('compare')->getValue();
158 if ($compare == $this->object->key) {
159 $compare_object = $this->object->getGlobalLanguageFile();
160 $compare_content = $compare_object->getAllValues();
161 $compare_comments = $compare_object->getAllComments();
162 }
163
164 // page translation mode:
165 // - the table is filtered by a list of modules and topics
167 // get the selection of modules and topics from request or session
170
171 // first call for translation
172 if ($_GET['reset_offset']) {
173 $table_gui->resetOffset();
174 }
175
176 if (!isset($compare_content)) {
177 $compare_content = ilObjLanguageExt::_getValues(
178 $compare,
179 $modules,
180 $topics
181 );
182
183 $compare_comments = ilObjLanguageExt::_getRemarks($compare);
184 }
185
186 $translations = ilObjLanguageExt::_getValues(
187 $this->object->key,
188 $modules,
189 $topics
190 );
191
192 // enable adding new entries
193 $db_found = array();
194 foreach ($translations as $name => $translation) {
195 $keys = explode($this->lng->separator, $name);
196 $db_found[] = $keys[1];
197 }
198 $missing_entries = array_diff($topics, $db_found);
199 }
200 // normal view mode:
201 // - the table is filtered manually by module, mode and pattern
202 else {
203 $filter_mode = $table_gui->getFilterItemByPostVar('mode')->getValue();
204 $filter_pattern = $table_gui->getFilterItemByPostVar('pattern')->getValue();
205 $filter_module = $table_gui->getFilterItemByPostVar('module')->getValue();
206 $filter_module = $filter_module == 'all' ? '' : $filter_module;
207 $filter_modules = $filter_module ? array($filter_module) : array();
208 $filter_identifier = $table_gui->getFilterItemByPostVar('identifier')->getValue();
209 $filter_topics = $filter_identifier ? array($filter_identifier) : array();
210
211 if (!isset($compare_content)) {
212 $compare_content = ilObjLanguageExt::_getValues(
213 $compare,
214 $filter_modules,
215 $filter_topics
216 );
217
218 $compare_comments = ilObjLanguageExt::_getRemarks($compare);
219 }
220
221 switch ($filter_mode) {
222 case "changed":
223 $translations = $this->object->getChangedValues(
224 $filter_modules,
225 $filter_pattern,
226 $filter_topics
227 );
228 break;
229
230 case "added": //langmode only
231 $translations = $this->object->getAddedValues(
232 $filter_modules,
233 $filter_pattern,
234 $filter_topics
235 );
236 break;
237
238 case "unchanged":
239 $translations = $this->object->getUnchangedValues(
240 $filter_modules,
241 $filter_pattern,
242 $filter_topics
243 );
244 break;
245
246 case "commented":
247 $translations = $this->object->getCommentedValues(
248 $filter_modules,
249 $filter_pattern,
250 $filter_topics
251 );
252 break;
253
254 case "dbremarks":
255 $translations = $this->object->getAllValues(
256 $filter_modules,
257 $filter_pattern,
258 $filter_topics
259 );
260
261 $translations = array_intersect_key($translations, $comments);
262 break;
263
264 case "equal":
265 $translations = $this->object->getAllValues(
266 $filter_modules,
267 $filter_pattern,
268 $filter_topics
269 );
270
271 $translations = array_intersect_assoc($translations, $compare_content);
272 break;
273
274 case "different":
275 $translations = $this->object->getAllValues(
276 $filter_modules,
277 $filter_pattern,
278 $filter_topics
279 );
280
281 $translations = array_diff_assoc($translations, $compare_content);
282 break;
283
284 case "conflicts":
285 $former_file = $this->object->getDataPath() . '/ilias_' . $this->object->key . '.lang';
286 if (!is_readable($former_file)) {
287 ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file)
288 . '<br />' . $this->lng->txt("language_former_file_description"), false);
289 $translations = array();
290 break;
291 }
292 $global_file_obj = $this->object->getGlobalLanguageFile();
293 $former_file_obj = new ilLanguageFile($former_file);
294 $former_file_obj->read();
295 $global_changes = array_diff_assoc(
296 $global_file_obj->getAllValues(),
297 $former_file_obj->getAllValues()
298 );
299 if (!count($global_changes)) {
300 ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file)
301 . '<br />' . $this->lng->txt("language_former_file_description"), false);
302 $translations = array();
303 break;
304 }
305 $translations = $this->object->getChangedValues(
306 $filter_modules,
307 $filter_pattern,
308 $filter_topics
309 );
310
311 $translations = array_intersect_key($translations, $global_changes);
312 break;
313
314 case "all":
315 default:
316 $translations = $this->object->getAllValues(
317 $filter_modules,
318 $filter_pattern,
319 $filter_topics
320 );
321 }
322 }
323
324 // prepare the the data for the table
325 $data = array();
326 foreach ($translations as $name => $translation) {
327 $keys = explode($this->lng->separator, $name);
328 $row = array();
329
330 $row["module"] = $keys[0];
331 $row["topic"] = $keys[1];
332 $row["name"] = $name;
333 $row["translation"] = $translation;
334 $row["comment"] = $comments[$name];
335 $row["default"] = $compare_content[$name];
336 $row["default_comment"] = $compare_comments[$name];
337
338 $data[] = $row;
339 }
340
341 if ($changesSuccessBool) {
342 $tpl->setVariable("MESSAGE", $this->getSuccessMessage());
343 }
344
345 // render and show the table
346 $table_gui->setData($data);
347 $tpl->setContent($table_gui->getHTML() .
348 $this->buildMissingEntries($missing_entries));
349 }
350
354 public function applyFilterObject()
355 {
356 $table_gui = $this->getViewTable();
357 $table_gui->writeFilterToSession(); // writes filter to session
358 $table_gui->resetOffset(); // sets record offest to 0 (first page)
359 $this->viewObject();
360 }
361
365 public function resetFilterObject()
366 {
367 $table_gui = $this->getViewTable();
368 $table_gui->resetOffset(); // sets record offest to 0 (first page)
369 $table_gui->resetFilter(); // clears filter
370 $this->viewObject();
371 }
372
376 public function saveObject()
377 {
378 // no changes have been made yet
379 $changesSuccessBool = 0;
380 // prepare the values to be saved
381 $save_array = array();
382 $remarks_array = array();
383 foreach ($_POST as $key => $value) {
384 // mantis #25237
385 // @see https://php.net/manual/en/language.variables.external.php
386 $key = str_replace('_POSTDOT_', '.', $key);
387 $key = str_replace('_POSTSPACE_', ' ', $key);
388
389 // example key of variable: 'common#:#access'
390 // example key of comment: 'common#:#access#:#comment'
391 $keys = explode($this->lng->separator, ilUtil::stripSlashes($key));
392
393 if (count($keys) == 2) {
394 // avoid line breaks
395 $value = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $value);
396 $value = str_replace("<<", "«",$value);
397 $value = ilUtil::stripSlashes($value, true, "<strong><em><u><strike><ol><li><ul><p><div><i><b><code><sup><pre><gap><a><img><bdo><br><span>");
398 $save_array[$key] = $value;
399
400 // the comment has the key of the language with the suffix
401 $remarks_array[$key] = $_POST[$key . $this->lng->separator . "comment"];
402 }
403 }
404
405 // save the translations
406 ilObjLanguageExt::_saveValues($this->object->key, $save_array, $remarks_array);
407
408 // set successful changes bool to true;
409 $changesSuccessBool = 1;
410
411 // view the list
412 $this->viewObject($changesSuccessBool);
413 }
414
415
419 public function importObject()
420 {
421 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
422 $form = new ilPropertyFormGUI();
423 $form->setFormAction($this->ctrl->getFormAction($this));
424 $form->setTitle($this->lng->txt("language_import_file"));
425 $form->addCommandButton('upload', $this->lng->txt("upload"));
426
427 $fu = new ilFileInputGUI($this->lng->txt("file"), "userfile");
428 $form->addItem($fu);
429
430 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_mode_existing"), "mode_existing");
431 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepall"), "keepall");
432 $ro->setInfo($this->lng->txt("language_mode_existing_keepall_info"));
433 $rg->addOption($ro);
434 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepnew"), "keepnew");
435 $ro->setInfo($this->lng->txt("language_mode_existing_keepnew_info"));
436 $rg->addOption($ro);
437 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_replace"), "replace");
438 $ro->setInfo($this->lng->txt("language_mode_existing_replace_info"));
439 $rg->addOption($ro);
440 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_delete"), "delete");
441 $ro->setInfo($this->lng->txt("language_mode_existing_delete_info"));
442 $rg->addOption($ro);
443 $rg->setValue($this->session["import"]["mode_existing"] ? $this->session["import"]["mode_existing"] : "keepall");
444 $form->addItem($rg);
445
446 $this->tpl->setContent($form->getHTML());
447 }
448
449
453 public function uploadObject()
454 {
455 global $DIC;
456
457 // save form inputs for next display
458 $this->session["import"]["mode_existing"] = ilUtil::stripSlashes($_POST['mode_existing']);
459
460 try {
461 $upload = $DIC->upload();
462 $upload->process();
463
464 if (!$upload->hasUploads()) {
465 throw new ilException($DIC->language()->txt("upload_error_file_not_found"));
466 }
467 $UploadResult = $upload->getResults()[$_FILES['userfile']['tmp_name']];
468
469 $ProcessingStatus = $UploadResult->getStatus();
470 if ($ProcessingStatus->getCode() === ProcessingStatus::REJECTED) {
471 throw new ilException($ProcessingStatus->getMessage());
472 }
473
474 // todo: refactor when importLanguageFile() is able to work with the new Filesystem service
475 $tempfile = ilUtil::ilTempnam() . '.sec';
476 $upload->moveOneFileTo($UploadResult, '', Location::TEMPORARY, basename($tempfile), true);
477 $this->object->importLanguageFile($tempfile, $_POST['mode_existing']);
478
479 $tempfs = $DIC->filesystem()->temp();
480 $tempfs->delete(basename($tempfile));
481 } catch (Exception $e) {
482 ilUtil::sendFailure($e->getMessage(), true);
483 $this->ctrl->redirect($this, 'import');
484 }
485
486 ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']), true);
487 $this->ctrl->redirect($this, 'import');
488 }
489
490
494 public function exportObject()
495 {
496 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
497 $form = new ilPropertyFormGUI();
498 $form->setFormAction($this->ctrl->getFormAction($this));
499 $form->setTitle($this->lng->txt("language_export_file"));
500 $form->setPreventDoubleSubmission(false);
501 $form->addCommandButton('download', $this->lng->txt("download"));
502
503 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_file_scope"), "scope");
504 $ro = new ilRadioOption($this->lng->txt("language_scope_global"), "global");
505 $ro->setInfo($this->lng->txt("language_scope_global_info"));
506 $rg->addOption($ro);
507 $ro = new ilRadioOption($this->lng->txt("language_scope_local"), "local");
508 $ro->setInfo($this->lng->txt("language_scope_local_info"));
509 $rg->addOption($ro);
510 if ($this->langmode) {
511 $ro = new ilRadioOption($this->lng->txt("language_scope_added"), "added");
512 $ro->setInfo($this->lng->txt("language_scope_added_info"));
513 $rg->addOption($ro);
514 }
515 $ro = new ilRadioOption($this->lng->txt("language_scope_unchanged"), "unchanged");
516 $ro->setInfo($this->lng->txt("language_scope_unchanged_info"));
517 $rg->addOption($ro);
518 if ($this->langmode) {
519 $ro = new ilRadioOption($this->lng->txt("language_scope_merged"), "merged");
520 $ro->setInfo($this->lng->txt("language_scope_merged_info"));
521 $rg->addOption($ro);
522 }
523
524 $rg->setValue($this->session["export"]["scope"] ? $this->session["export"]["scope"] : "global");
525 $form->addItem($rg);
526
527 $this->tpl->setContent($form->getHTML());
528 }
529
530
534 public function downloadObject()
535 {
536 // save the selected scope
537 $this->session["export"]["scope"] = ilUtil::stripSlashes($_POST["scope"]);
538
539 $filename = 'ilias_' . $this->object->key . '_'
540 . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
541 . "-" . date('Y-m-d')
542 . ".lang." . $this->session["export"]["scope"];
543
544 $global_file_obj = $this->object->getGlobalLanguageFile();
545 $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
546
547 if ($_POST["scope"] == 'global') {
548 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
549 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
550 $local_file_obj->setAllValues($this->object->getAllValues());
551 if ($this->langmode) {
552 $local_file_obj->setAllComments($this->object->getAllRemarks());
553 }
554 } elseif ($_POST["scope"] == 'local') {
555 $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
556 $local_file_obj->setAllValues($this->object->getChangedValues());
557 if ($this->langmode) {
558 $local_file_obj->setAllComments($this->object->getAllRemarks());
559 }
560 } elseif ($_POST["scope"] == 'added') { // langmode only
561 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
562 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
563 $local_file_obj->setAllValues($this->object->getAddedValues());
564 $local_file_obj->setAllComments($this->object->getAllRemarks());
565 } elseif ($_POST["scope"] == 'unchanged') {
566 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
567 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
568 $local_file_obj->setAllValues($this->object->getUnchangedValues());
569 if ($this->langmode) {
570 $local_file_obj->setAllComments($this->object->getAllRemarks());
571 }
572 } elseif ($_POST["scope"] == 'merged') { // langmode only
573 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
574 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
575 $local_file_obj->setAllValues($this->object->getMergedValues());
576 $local_file_obj->setAllComments($this->object->getMergedRemarks());
577 }
578
579 ilUtil::deliverData($local_file_obj->build(), $filename);
580 }
581
582
586 public function maintainObject()
587 {
588 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
589 $form = new ilPropertyFormGUI();
590 $form->setFormAction($this->ctrl->getFormAction($this));
591 $form->setTitle($this->lng->txt("language_maintenance"));
592 $form->setPreventDoubleSubmission(false);
593 $form->addCommandButton('maintainExecute', $this->lng->txt("language_process_maintenance"));
594
595 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_maintain_local_changes"), "maintain");
596 $ro = new ilRadioOption($this->lng->txt("language_load_local_changes"), "load");
597 $ro->setInfo(sprintf($this->lng->txt("language_load_local_changes_info"), $this->object->key));
598 $rg->addOption($ro);
599 $ro = new ilRadioOption($this->lng->txt("language_clear_local_changes"), "clear");
600 $ro->setInfo(sprintf($this->lng->txt("language_clear_local_changes_info"), $this->object->key));
601 $rg->addOption($ro);
602 if ($this->langmode) {
603 $ro = new ilRadioOption($this->lng->txt("language_delete_local_additions"), "delete_added");
604 $ro->setInfo(sprintf($this->lng->txt("language_delete_local_additions_info"), $this->object->key));
605 $rg->addOption($ro);
606 $ro = new ilRadioOption($this->lng->txt("language_remove_local_file"), "remove_local_file");
607 $ro->setInfo(sprintf($this->lng->txt("language_remove_local_file_info"), $this->object->key));
608 $rg->addOption($ro);
609 $ro = new ilRadioOption($this->lng->txt("language_merge_local_changes"), "merge");
610 $ro->setInfo(sprintf($this->lng->txt("language_merge_local_changes_info"), $this->object->key));
611 $rg->addOption($ro);
612 }
613 $ro = new ilRadioOption($this->lng->txt("language_save_dist"), "save_dist");
614 $ro->setInfo(sprintf($this->lng->txt("language_save_dist_info"), $this->object->key));
615 $rg->addOption($ro);
616 $rg->setValue($this->session["maintain"]);
617 $form->addItem($rg);
618
619 $this->tpl->setContent($form->getHTML());
620 }
621
622
623 public function maintainExecuteObject()
624 {
625 if (isset($_POST["maintain"])) {
626 $this->session["maintain"] = ilUtil::stripSlashes($_POST["maintain"]);
627 }
628
629 switch ($_POST["maintain"]) {
630 // save the global language file for merge after
631 case "save_dist":
632
633 // save a copy of the distributed language file
634 $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
635 $copy_file = $this->object->getDataPath() . '/ilias_' . $this->object->key . '.lang';
636 if (@copy($orig_file, $copy_file)) {
637 ilUtil::sendSuccess($this->lng->txt("language_saved_dist"), true);
638 } else {
639 ilUtil::sendFailure($this->lng->txt("language_save_dist_failed"), true);
640 }
641 break;
642
643 // load the content of the local language file
644 case "load":
645 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
646 if (is_file($lang_file) and is_readable($lang_file)) {
647 $this->object->importLanguageFile($lang_file, 'replace');
648 $this->object->setLocal(true);
649 ilUtil::sendSuccess($this->lng->txt("language_loaded_local"), true);
650 } else {
651 ilUtil::sendFailure($this->lng->txt("language_error_read_local"), true);
652 }
653 break;
654
655 // revert the database to the default language file
656 case "clear":
657 $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
658 if (is_file($lang_file) and is_readable($lang_file)) {
659 $this->object->importLanguageFile($lang_file, 'delete');
660 $this->object->setLocal(false);
661 ilUtil::sendSuccess($this->lng->txt("language_cleared_local"), true);
662 } else {
663 ilUtil::sendFailure($this->lng->txt("language_error_clear_local"), true);
664 }
665 break;
666
667 // delete local additions in the datavase (langmode only)
668 case "delete_added":
669 ilObjLanguageExt::_deleteValues($this->object->key, $this->object->getAddedValues());
670 break;
671
672 // merge local changes back to the global language file (langmode only)
673 case "merge":
674
675 $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
676 $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
677
678 if (is_file($orig_file) and is_writable($orig_file)) {
679 // save a copy of the global language file
680 @copy($orig_file, $copy_file);
681
682 // modify and write the new global file
683 $global_file_obj = $this->object->getGlobalLanguageFile();
684 $global_file_obj->setAllValues($this->object->getMergedValues());
685 $global_file_obj->setAllComments($this->object->getMergedRemarks());
686 $global_file_obj->write();
687 ilUtil::sendSuccess($this->lng->txt("language_merged_global"), true);
688 } else {
689 ilUtil::sendFailure($this->lng->txt("language_error_write_global"), true);
690 }
691 break;
692
693 // remove the local language file (langmode only)
694 case "remove_local_file":
695 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
696
697 if (!is_file($lang_file)) {
698 $this->object->setLocal(false);
699 ilUtil::sendFailure($this->lng->txt("language_error_local_missed"), true);
700 } elseif (@unlink($lang_file)) {
701 $this->object->setLocal(false);
702 ilUtil::sendSuccess($this->lng->txt("language_local_file_deleted"), true);
703 } else {
704 ilUtil::sendFailure($this->lng->txt("language_error_delete_local"), true);
705 }
706 break;
707 }
708
709 $this->ctrl->redirect($this, "maintain");
710 }
711
715 public function settingsObject()
716 {
717 global $DIC;
718 $ilSetting = $DIC->settings();
719
720 $translate_key = "lang_translate_" . $this->object->key;
721
722 // save and get the page translation setting
723 if (!empty($_POST)) {
724 $ilSetting->set($translate_key, (bool) $_POST["translation"]);
725 ilUtil::sendSuccess($this->lng->txt("settings_saved"));
726 }
727 $translate = $ilSetting->get($translate_key, false);
728
729 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
730 $form = new ilPropertyFormGUI();
731 $form->setFormAction($this->ctrl->getFormAction($this));
732 $form->setTitle($this->lng->txt("language_settings"));
733 $form->setPreventDoubleSubmission(false);
734 $form->addCommandButton('settings', $this->lng->txt("language_change_settings"));
735
736 $ci = new ilCheckboxInputGUI($this->lng->txt("language_translation_enabled"), "translation");
737 $ci->setChecked((bool) $translate);
738 $ci->setInfo($this->lng->txt("language_note_translation"));
739 $form->addItem($ci);
740
741 $this->tpl->setContent($form->getHTML());
742 }
743
747 public function statisticsObject()
748 {
749 $modules = ilObjLanguageExt::_getModules($this->object->key);
750
751 $data = array();
752 $total = array("module" => '',"all" => 0,"changed" => 0, "unchanged" => 0);
753 foreach ($modules as $module) {
754 $row = array();
755 $row['module'] = $module;
756 $row['all'] = count($this->object->getAllValues(array($module)));
757 $row['changed'] = count($this->object->getChangedValues(array($module)));
758 $row['unchanged'] = $row['all'] - $row['changed'];
759 $total['all'] += $row['all'];
760 $total['changed'] += $row['changed'];
761 $total['unchanged'] += $row['unchanged'];
762 $data[] = $row;
763 }
764 $total['module'] = "<b>" . $this->lng->txt("language_all_modules") . "</b>";
765 $total['all'] = "<b>" . $total['all'] . "</b>";
766 $total['changed'] = "<b>" . $total['changed'] . "</b>";
767 $total['unchanged'] = "<b>" . $total['unchanged'] . "</b>";
768 $data[] = $total;
769
770 // create and configure the table object
771 include_once 'Services/Table/classes/class.ilTable2GUI.php';
772 $table_gui = new ilTable2GUI($this, "statistics");
773 $table_gui->setRowTemplate("tpl.lang_statistics_row.html", "Services/Language");
774 $table_gui->setEnableTitle(false);
775 $table_gui->setEnableNumInfo(false);
776 $table_gui->setLimit(count($data));
777 $table_gui->setExportFormats(array(ilTable2GUI::EXPORT_EXCEL));
778
779 $table_gui->addColumn(ucfirst($this->lng->txt("module")), "", "25%");
780 $table_gui->addColumn($this->lng->txt("language_scope_global"), "", "25%");
781 $table_gui->addColumn($this->lng->txt("language_scope_local"), "", "25%");
782 $table_gui->addColumn($this->lng->txt("language_scope_unchanged"), "", "25%");
783
784 $table_gui->setData($data);
785
786 $this->tpl->setContent($table_gui->getHTML());
787 }
788
789
796 public function getAdminTabs()
797 {
798 global $DIC;
799 $ilCtrl = $DIC->ctrl();
800 $cmd = $ilCtrl->getCmd();
801
803 $this->tabs_gui->setBackTarget(
804 $this->lng->txt('back'),
805 $this->ctrl->getLinkTargetByClass('ilObjLanguageFolderGUI')
806 );
807
808 $this->tabs_gui->addTab(
809 "edit",
810 $this->lng->txt("edit"),
811 $this->ctrl->getLinkTarget($this, "view")
812 );
813
814 $this->tabs_gui->addTab(
815 "export",
816 $this->lng->txt('export'),
817 $this->ctrl->getLinkTarget($this, "export")
818 );
819
820 $this->tabs_gui->addTab(
821 "import",
822 $this->lng->txt('import'),
823 $this->ctrl->getLinkTarget($this, "import")
824 );
825
826 $this->tabs_gui->addTab(
827 "maintain",
828 $this->lng->txt('language_maintain'),
829 $this->ctrl->getLinkTarget($this, "maintain")
830 );
831
832 $this->tabs_gui->addTab(
833 "settings",
834 $this->lng->txt('settings'),
835 $this->ctrl->getLinkTarget($this, "settings")
836 );
837
838 $this->tabs_gui->addTab(
839 "statistics",
840 $this->lng->txt("language_statistics"),
841 $this->ctrl->getLinkTarget($this, "statistics")
842 );
843
844 switch ($cmd) {
845 case '':
846 case 'view':
847 case 'applyFilter':
848 case 'resetFilter':
849 case 'save':
850 $this->tabs_gui->activateTab('edit');
851 break;
852 default:
853 $this->tabs_gui->activateTab($cmd);
854 }
855 }
856 }
857
858
863 public function addAdminLocatorItems($a_do_not_add_object = false)
864 {
865 global $DIC;
866 $ilLocator = $DIC['ilLocator'];
867
869 parent::addAdminLocatorItems(true); // #13881
870
871 $ilLocator->addItem(
872 $this->lng->txt("languages"),
873 $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", "")
874 );
875
876 $ilLocator->addItem(
877 $this->lng->txt("meta_l_" . $this->object->getTitle()),
878 $this->ctrl->getLinkTarget($this, "view")
879 );
880 }
881 }
882
883
888 public function setTitleAndDescription()
889 {
891 $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
892 $this->tpl->setTitle($this->lng->txt("translation") . " " . $this->lng->txt("meta_l_" . $this->object->key));
893 } else {
894 $this->tpl->setTitle($this->lng->txt("meta_l_" . $this->object->key));
895 }
896 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lngf.svg"), $this->lng->txt("obj_" . $this->object->getType()));
897 }
898
899
900 //
901 // new entries
902 //
903
904 protected function buildMissingEntries(array $a_missing = null)
905 {
906 global $DIC;
907 $ilCtrl = $DIC->ctrl();
908
909 if (!is_array($a_missing) ||
910 !sizeof($a_missing)) {
911 return;
912 }
913
914 $res = array('<h3>' . $this->lng->txt("adm_missing_entries") . '</h3>', '<ul>');
915
916 foreach ($a_missing as $entry) {
917 $ilCtrl->setParameter($this, "eid", $entry);
918 $res[] = '<li>' . $entry .
919 ' <a href="' . $ilCtrl->getLinkTarget($this, "addNewEntry") .
920 '">' . $this->lng->txt("adm_missing_entry_add_action") . '</a></li>';
921 $ilCtrl->setParameter($this, "eid", "");
922 }
923
924 $res[] = '</ul>';
925
926 return implode("\n", $res);
927 }
928
929 public function addNewEntryObject(ilPropertyFormGUI $a_form = null)
930 {
931 global $DIC;
932 $tpl = $DIC['tpl'];
933
934 $id = trim($_GET["eid"]);
935
936 if (!$a_form) {
937 $a_form = $this->initAddNewEntryForm($id);
938 }
939
940 $tpl->setContent($a_form->getHTML());
941 }
942
943 protected function initAddNewEntryForm($a_id = null)
944 {
945 global $DIC;
946 $ilCtrl = $DIC->ctrl();
947
948 if (!$a_id) {
949 $a_id = $_POST["id"];
950 }
951
952 if (!$a_id ||
953 !in_array($a_id, ilObjLanguageAccess::_getSavedTopics())) {
954 $ilCtrl->redirect($this, "view");
955 }
956
957 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
958 $form = new ilPropertyFormGUI();
959 $form->setFormAction($ilCtrl->getFormAction($this, "saveNewEntry"));
960 $form->setTitle($this->lng->txt("adm_missing_entry_add"));
961
963 $options = array_combine($mods, $mods);
964
965 $mod = new ilSelectInputGUI(ucfirst($this->lng->txt("module")), "mod");
966 $mod->setOptions(array("" => $this->lng->txt("please_select")) + $options);
967 $mod->setRequired(true);
968 $form->addItem($mod);
969
970 $id = new ilTextInputGUI(ucfirst($this->lng->txt("identifier")), "id");
971 $id->setValue($a_id);
972 $id->setDisabled(true);
973 $form->addItem($id);
974
975 foreach ($this->lng->getInstalledLanguages() as $lang_key) {
976 $trans = new ilTextInputGUI($this->lng->txt("meta_l_" . $lang_key), "trans_" . $lang_key);
977 if (in_array($lang_key, array("de", "en"))) {
978 $trans->setRequired(true);
979 }
980 $form->addItem($trans);
981 }
982
983 $form->addCommandButton("saveNewEntry", $this->lng->txt("save"));
984 $form->addCommandButton("view", $this->lng->txt("cancel"));
985
986 return $form;
987 }
988
989 public function saveNewEntryObject()
990 {
991 global $DIC;
992 $ilDB = $DIC->database();
993 $ilCtrl = $DIC->ctrl();
994 $ilUser = $DIC->user();
995
996 $form = $this->initAddNewEntryForm();
997 if ($form->checkInput()) {
998 $mod = $form->getInput("mod");
999 $id = $form->getInput("id");
1000
1001 $lang = array();
1002 foreach ($this->lng->getInstalledLanguages() as $lang_key) {
1003 $trans = trim($form->getInput("trans_" . $lang_key));
1004 if ($trans) {
1005 // add single entry
1007 $mod,
1008 $id,
1009 $lang_key,
1010 $trans,
1011 date("Y-m-d H:i:s"),
1012 $ilUser->getLogin()
1013 );
1014
1015 // add to serialized module
1016 $set = $ilDB->query("SELECT lang_array FROM lng_modules" .
1017 " WHERE lang_key = " . $ilDB->quote($lang_key, "text") .
1018 " AND module = " . $ilDB->quote($mod, "text"));
1019 $row = $ilDB->fetchAssoc($set);
1020 $entries = unserialize($row["lang_array"]);
1021 if (is_array($entries)) {
1022 $entries[$id] = $trans;
1023 ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
1024 }
1025 }
1026 }
1027
1028 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
1029 $ilCtrl->redirect($this, "view");
1030 }
1031
1032 $form->setValuesByPost();
1033 $this->addNewEntryObject($form);
1034 }
1035
1040 protected function getSuccessMessage()
1041 {
1042 global $DIC;
1043 $f = $DIC->ui()->factory();
1044 $renderer = $DIC->ui()->renderer();
1045
1046 return $renderer->render($f->messageBox()->success($this->lng->txt("language_variables_saved")));
1047 }
1048} // END class.ilObjLanguageExtGUI
$total
Definition: Utf8Test.php:87
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
Class ilLanguageFile.
static _getSavedTopics()
Get the stored topics from the user session.
static _lookupId($a_key)
Lookup the object ID for a language key.
static _getSavedModules()
Get the stored modules from the user session.
static _checkMaintenance()
Permission check for language maintenance (import/export)
static _isPageTranslation()
Check if the current request is a page translation.
Class ilObjLanguageExtGUI.
setTitleAndDescription()
Set the Title and the description (Overwritten from ilObjectGUI, called by prepareOutput)
assignObject()
Assign the extended language object.
uploadObject()
Process an uploaded language file.
statisticsObject()
Print out statistics about the language.
viewObject($changesSuccessBool=0)
Show the edit screen.
getViewTable()
Get the table to view language entries.
__construct($a_data, $a_id=0, $a_call_by_reference=false)
Constructor.
buildMissingEntries(array $a_missing=null)
saveObject()
Save the changed translations.
cancelObject()
Cancel the current action.
maintainObject()
Process the language maintenance.
importObject()
Show the screen to import a language file.
exportObject()
Show the screen to export a language file.
addAdminLocatorItems($a_do_not_add_object=false)
Set the locator for admin mode (Overwritten from ilObjectGUI, called by prepareOutput)
downloadObject()
Download a language file.
getAdminTabs()
Get tabs for admin mode (Overwritten from ilObjectGUI, called by prepareOutput)
settingsObject()
Set the language settings.
getId()
get the language object id (needed for filter serialization)
getSuccessMessage()
Get success message after variables were saved.
addNewEntryObject(ilPropertyFormGUI $a_form=null)
Class ilObjLanguageExt.
static _deleteValues($a_lang_key, $a_values=array())
Delete a set of translation in the database.
static _getModules($a_lang_key)
Get all modules of a language.
static _getRemarks($a_lang_key, $a_all_changed=false)
Get all remarks of a language.
static _saveValues($a_lang_key, $a_values=array(), $a_remarks=array())
Save a set of translation in the database.
static _getValues( $a_lang_key, $a_modules=array(), $a_topics=array(), $a_pattern='', $a_state='')
Get the translations of specified topics.
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
Class ilObjectGUI Basic methods of all Output classes.
viewObject()
viewObject container presentation for "administration -> repository, trash, permissions"
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Class ilTable2GUI.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
const ILIAS_VERSION
Interface Location.
Definition: Location.php:17
exit
Definition: login.php:29
if($format !==null) $name
Definition: metadata.php:230
$keys
Definition: metadata.php:187
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res
global $ilDB
$lang
Definition: xapiexit.php:8