ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng, $ilCtrl, $ilClientIniFile;
43
44 // language maintenance strings are defined in administration
45 $lng->loadLanguageModule("administration");
46 $lng->loadLanguageModule("meta");
47
48 // view mode ('translate' or empty) determins available table filters
49 $ilCtrl->saveParameter($this, "view_mode");
50
51 // type and id of get the bound object
52 $this->type = "lng";
53 if (!$this->id = $_GET['obj_id']) {
54 $this->id = ilObjLanguageAccess::_lookupId($lng->getUserLanguage());
55 }
56
57 // do all generic GUI initialisations
58 parent::__construct($a_data, $this->id, false, true);
59
60 // initialize the array to store session variables for extended language maintenance
61 if (!is_array($_SESSION['lang_ext_maintenance'])) {
62 $_SESSION['lang_ext_maintenance'] = array();
63 }
64 $this->session =&$_SESSION['lang_ext_maintenance'];
65
66
67 // read the lang mode
68 $this->langmode = $ilClientIniFile->readVariable("system", "LANGMODE");
69 }
70
71
78 public function assignObject()
79 {
80 require_once("Services/Language/classes/class.ilObjLanguageExt.php");
81 $this->object = new ilObjLanguageExt($this->id);
82 }
83
88 public function getId()
89 {
90 return $this->id;
91 }
92
96 public function executeCommand()
97 {
98 global $ilHelp;
99
101 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
102 exit;
103 }
104
105 $cmd = $this->ctrl->getCmd("view") . "Object";
106 $this->$cmd();
107
108 $ilHelp->setScreenIdComponent("lng");
109 }
110
111
115 public function cancelObject()
116 {
117 $this->viewObject();
118 }
119
125 protected function getViewTable()
126 {
127 // create and configure the table object
128 include_once './Services/Language/classes/class.ilLanguageExtTableGUI.php';
129 $table_gui = new ilLanguageExtTableGUI($this, 'view', array(
130 'langmode' => $this->langmode,
131 'lang_key'=> $this->object->key,
132 ));
133
134 return $table_gui;
135 }
136
140 public function viewObject()
141 {
142 global $tpl;
143
144 // get the view table
145 $table_gui = $this->getViewTable();
146
147 // get the remarks in database
148 $comments = $this->object->getAllRemarks();
149
150 // set the language to compare with
151 // get the default values if the compare language is the same
152 $compare = $table_gui->getFilterItemByPostVar('compare')->getValue();
153 if ($compare == $this->object->key) {
154 $compare_object = $this->object->getGlobalLanguageFile();
155 $compare_content = $compare_object->getAllValues();
156 $compare_comments = $compare_object->getAllComments();
157 }
158
159 // page translation mode:
160 // - the table is filtered by a list of modules and topics
162 // get the selection of modules and topics from request or session
165
166 // first call for translation
167 if ($_GET['reset_offset']) {
168 $table_gui->resetOffset();
169 }
170
171 if (!isset($compare_content)) {
172 $compare_content = ilObjLanguageExt::_getValues(
173 $compare,
174 $modules,
175 $topics
176 );
177
178 $compare_comments = ilObjLanguageExt::_getRemarks($compare);
179 }
180
181 $translations = ilObjLanguageExt::_getValues(
182 $this->object->key,
183 $modules,
184 $topics
185 );
186
187 // enable adding new entries
188 $db_found = array();
189 foreach ($translations as $name => $translation) {
190 $keys = explode($this->lng->separator, $name);
191 $db_found[] = $keys[1];
192 }
193 $missing_entries = array_diff($topics, $db_found);
194 }
195 // normal view mode:
196 // - the table is filtered manually by module, mode and pattern
197 else {
198 $filter_mode = $table_gui->getFilterItemByPostVar('mode')->getValue();
199 $filter_pattern = $table_gui->getFilterItemByPostVar('pattern')->getValue();
200 $filter_module = $table_gui->getFilterItemByPostVar('module')->getValue();
201 $filter_module = $filter_module == 'all' ? '' : $filter_module;
202 $filter_modules = $filter_module ? array($filter_module) : array();
203 $filter_identifier = $table_gui->getFilterItemByPostVar('identifier')->getValue();
204 $filter_topics = $filter_identifier ? array($filter_identifier) : array();
205
206 if (!isset($compare_content)) {
207 $compare_content = ilObjLanguageExt::_getValues(
208 $compare,
209 $filter_modules,
210 $filter_topics
211 );
212
213 $compare_comments = ilObjLanguageExt::_getRemarks($compare);
214 }
215
216 switch ($filter_mode) {
217 case "changed":
218 $translations = $this->object->getChangedValues(
219 $filter_modules,
220 $filter_pattern,
221 $filter_topics
222 );
223 break;
224
225 case "added": //langmode only
226 $translations = $this->object->getAddedValues(
227 $filter_modules,
228 $filter_pattern,
229 $filter_topics
230 );
231 break;
232
233 case "unchanged":
234 $translations = $this->object->getUnchangedValues(
235 $filter_modules,
236 $filter_pattern,
237 $filter_topics
238 );
239 break;
240
241 case "commented":
242 $translations = $this->object->getCommentedValues(
243 $filter_modules,
244 $filter_pattern,
245 $filter_topics
246 );
247 break;
248
249 case "dbremarks":
250 $translations = $this->object->getAllValues(
251 $filter_modules,
252 $filter_pattern,
253 $filter_topics
254 );
255
256 $translations = array_intersect_key($translations, $remarks);
257 break;
258
259 case "equal":
260 $translations = $this->object->getAllValues(
261 $filter_modules,
262 $filter_pattern,
263 $filter_topics
264 );
265
266 $translations = array_intersect_assoc($translations, $compare_content);
267 break;
268
269 case "different":
270 $translations = $this->object->getAllValues(
271 $filter_modules,
272 $filter_pattern,
273 $filter_topics
274 );
275
276 $translations = array_diff_assoc($translations, $compare_content);
277 break;
278
279 case "conflicts":
280 $former_file = $this->object->getDataPath() . '/ilias_' . $this->object->key . '.lang';
281 if (!is_readable($former_file)) {
282 ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file)
283 . '<br />' . $this->lng->txt("language_former_file_description"), false);
284 $translations = array();
285 break;
286 }
287 $global_file_obj = $this->object->getGlobalLanguageFile();
288 $former_file_obj = new ilLanguageFile($former_file);
289 $former_file_obj->read();
290 $global_changes = array_diff_assoc(
291 $global_file_obj->getAllValues(),
292 $former_file_obj->getAllValues()
293 );
294 if (!count($global_changes)) {
295 ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file)
296 . '<br />' . $this->lng->txt("language_former_file_description"), false);
297 $translations = array();
298 break;
299 }
300 $translations = $this->object->getChangedValues(
301 $filter_modules,
302 $filter_pattern,
303 $filter_topics
304 );
305
306 $translations = array_intersect_key($translations, $global_changes);
307 break;
308
309 case "all":
310 default:
311 $translations = $this->object->getAllValues(
312 $filter_modules,
313 $filter_pattern,
314 $filter_topics
315 );
316 }
317 }
318
319 // prepare the the data for the table
320 $data = array();
321 foreach ($translations as $name => $translation) {
322 $keys = explode($this->lng->separator, $name);
323 $row = array();
324
325 $row["module"] = $keys[0];
326 $row["topic"] = $keys[1];
327 $row["name"] = $name;
328 $row["translation"] = $translation;
329 $row["comment"] = $comments[$name];
330 $row["default"] = $compare_content[$name];
331 $row["default_comment"] = $compare_comments[$name];
332
333 $data[] = $row;
334 }
335
336 // render and show the table
337 $table_gui->setData($data);
338 $tpl->setContent($table_gui->getHTML() .
339 $this->buildMissingEntries($missing_entries));
340 }
341
345 public function applyFilterObject()
346 {
347 $table_gui = $this->getViewTable();
348 $table_gui->writeFilterToSession(); // writes filter to session
349 $table_gui->resetOffset(); // sets record offest to 0 (first page)
350 $this->viewObject();
351 }
352
356 public function resetFilterObject()
357 {
358 $table_gui = $this->getViewTable();
359 $table_gui->resetOffset(); // sets record offest to 0 (first page)
360 $table_gui->resetFilter(); // clears filter
361 $this->viewObject();
362 }
363
367 public function saveObject()
368 {
369 // prepare the values to be saved
370 $save_array = array();
371 $remarks_array = array();
372 foreach ($_POST as $key => $value) {
373 // mantis #25237
374 // @see https://php.net/manual/en/language.variables.external.php
375 $key = str_replace('_POSTDOT_', '.', $key);
376 $key = str_replace('_POSTSPACE_', ' ', $key);
377
378 // example key of variable: 'common#:#access'
379 // example key of comment: 'common#:#access#:#comment'
380 $keys = explode($this->lng->separator, ilUtil::stripSlashes($key, false));
381
382 if (count($keys) == 2) {
383 // avoid line breaks
384 $value = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $value);
385 $value = ilUtil::stripSlashes($value, false);
386 $save_array[$key] = $value;
387
388 // the comment has the key of the language with the suffix
389 $remarks_array[$key] = $_POST[$key . $this->lng->separator . "comment"];
390 }
391 }
392
393 // save the translations
394 ilObjLanguageExt::_saveValues($this->object->key, $save_array, $remarks_array);
395
396 // view the list
397 $this->viewObject();
398 }
399
400
404 public function importObject()
405 {
406 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
407 $form = new ilPropertyFormGUI();
408 $form->setFormAction($this->ctrl->getFormAction($this));
409 $form->setTitle($this->lng->txt("language_import_file"));
410 $form->addCommandButton('upload', $this->lng->txt("upload"));
411
412 $fu = new ilFileInputGUI($this->lng->txt("file"), "userfile");
413 $form->addItem($fu);
414
415 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_mode_existing"), "mode_existing");
416 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepall"), "keepall");
417 $ro->setInfo($this->lng->txt("language_mode_existing_keepall_info"));
418 $rg->addOption($ro);
419 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepnew"), "keepnew");
420 $ro->setInfo($this->lng->txt("language_mode_existing_keepnew_info"));
421 $rg->addOption($ro);
422 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_replace"), "replace");
423 $ro->setInfo($this->lng->txt("language_mode_existing_replace_info"));
424 $rg->addOption($ro);
425 $ro = new ilRadioOption($this->lng->txt("language_mode_existing_delete"), "delete");
426 $ro->setInfo($this->lng->txt("language_mode_existing_delete_info"));
427 $rg->addOption($ro);
428 $rg->setValue($this->session["import"]["mode_existing"] ? $this->session["import"]["mode_existing"] : "keepall");
429 $form->addItem($rg);
430
431 $this->tpl->setContent($form->getHTML());
432 }
433
434
438 public function uploadObject()
439 {
440 global $DIC;
441
442 // save form inputs for next display
443 $this->session["import"]["mode_existing"] = ilUtil::stripSlashes($_POST['mode_existing']);
444
445 try {
446 $upload = $DIC->upload();
447 $upload->process();
448
449 if (!$upload->hasUploads()) {
450 throw new ilException($DIC->language()->txt("upload_error_file_not_found"));
451 }
452 $UploadResult = $upload->getResults()[$_FILES['userfile']['tmp_name']];
453
454 $ProcessingStatus = $UploadResult->getStatus();
455 if ($ProcessingStatus->getCode() === ProcessingStatus::REJECTED) {
456 throw new ilException($ProcessingStatus->getMessage());
457 }
458
459 // todo: refactor when importLanguageFile() is able to work with the new Filesystem service
460 $tempfile = ilUtil::ilTempnam() . '.sec';
461 $upload->moveOneFileTo($UploadResult, '', Location::TEMPORARY, basename($tempfile), true);
462 $this->object->importLanguageFile($tempfile, $_POST['mode_existing']);
463
464 $tempfs = $DIC->filesystem()->temp();
465 $tempfs->delete(basename($tempfile));
466 } catch (Exception $e) {
467 ilUtil::sendFailure($e->getMessage(), true);
468 $this->ctrl->redirect($this, 'import');
469 }
470
471 ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']), true);
472 $this->ctrl->redirect($this, 'import');
473 }
474
475
479 public function exportObject()
480 {
481 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
482 $form = new ilPropertyFormGUI();
483 $form->setFormAction($this->ctrl->getFormAction($this));
484 $form->setTitle($this->lng->txt("language_export_file"));
485 $form->setPreventDoubleSubmission(false);
486 $form->addCommandButton('download', $this->lng->txt("download"));
487
488 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_file_scope"), "scope");
489 $ro = new ilRadioOption($this->lng->txt("language_scope_global"), "global");
490 $ro->setInfo($this->lng->txt("language_scope_global_info"));
491 $rg->addOption($ro);
492 $ro = new ilRadioOption($this->lng->txt("language_scope_local"), "local");
493 $ro->setInfo($this->lng->txt("language_scope_local_info"));
494 $rg->addOption($ro);
495 if ($this->langmode) {
496 $ro = new ilRadioOption($this->lng->txt("language_scope_added"), "added");
497 $ro->setInfo($this->lng->txt("language_scope_added_info"));
498 $rg->addOption($ro);
499 }
500 $ro = new ilRadioOption($this->lng->txt("language_scope_unchanged"), "unchanged");
501 $ro->setInfo($this->lng->txt("language_scope_unchanged_info"));
502 $rg->addOption($ro);
503 if ($this->langmode) {
504 $ro = new ilRadioOption($this->lng->txt("language_scope_merged"), "merged");
505 $ro->setInfo($this->lng->txt("language_scope_merged_info"));
506 $rg->addOption($ro);
507 }
508
509 $rg->setValue($this->session["export"]["scope"] ? $this->session["export"]["scope"] : "global");
510 $form->addItem($rg);
511
512 $this->tpl->setContent($form->getHTML());
513 }
514
515
519 public function downloadObject()
520 {
521 // save the selected scope
522 $this->session["export"]["scope"] = ilUtil::stripSlashes($_POST["scope"]);
523
524 $filename = 'ilias_' . $this->object->key . '_'
525 . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
526 . "-" . date('Y-m-d')
527 . ".lang." . $this->session["export"]["scope"];
528
529 $global_file_obj = $this->object->getGlobalLanguageFile();
530 $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
531
532 if ($_POST["scope"] == 'global') {
533 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
534 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
535 $local_file_obj->setAllValues($this->object->getAllValues());
536 if ($this->langmode) {
537 $local_file_obj->setAllComments($this->object->getAllRemarks());
538 }
539 } elseif ($_POST["scope"] == 'local') {
540 $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
541 $local_file_obj->setAllValues($this->object->getChangedValues());
542 if ($this->langmode) {
543 $local_file_obj->setAllComments($this->object->getAllRemarks());
544 }
545 } elseif ($_POST["scope"] == 'added') { // langmode only
546 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
547 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
548 $local_file_obj->setAllValues($this->object->getAddedValues());
549 $local_file_obj->setAllComments($this->object->getAllRemarks());
550 } elseif ($_POST["scope"] == 'unchanged') {
551 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
552 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
553 $local_file_obj->setAllValues($this->object->getUnchangedValues());
554 if ($this->langmode) {
555 $local_file_obj->setAllComments($this->object->getAllRemarks());
556 }
557 } elseif ($_POST["scope"] == 'merged') { // langmode only
558 $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
559 $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
560 $local_file_obj->setAllValues($this->object->getMergedValues());
561 $local_file_obj->setAllComments($this->object->getMergedRemarks());
562 }
563
564 ilUtil::deliverData($local_file_obj->build(), $filename);
565 }
566
567
571 public function maintainObject()
572 {
573 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
574 $form = new ilPropertyFormGUI();
575 $form->setFormAction($this->ctrl->getFormAction($this));
576 $form->setTitle($this->lng->txt("language_maintenance"));
577 $form->setPreventDoubleSubmission(false);
578 $form->addCommandButton('maintainExecute', $this->lng->txt("language_process_maintenance"));
579
580 $rg = new ilRadioGroupInputGUI($this->lng->txt("language_maintain_local_changes"), "maintain");
581 $ro = new ilRadioOption($this->lng->txt("language_load_local_changes"), "load");
582 $ro->setInfo(sprintf($this->lng->txt("language_load_local_changes_info"), $this->object->key));
583 $rg->addOption($ro);
584 $ro = new ilRadioOption($this->lng->txt("language_clear_local_changes"), "clear");
585 $ro->setInfo(sprintf($this->lng->txt("language_clear_local_changes_info"), $this->object->key));
586 $rg->addOption($ro);
587 if ($this->langmode) {
588 $ro = new ilRadioOption($this->lng->txt("language_delete_local_additions"), "delete_added");
589 $ro->setInfo(sprintf($this->lng->txt("language_delete_local_additions_info"), $this->object->key));
590 $rg->addOption($ro);
591 $ro = new ilRadioOption($this->lng->txt("language_remove_local_file"), "remove_local_file");
592 $ro->setInfo(sprintf($this->lng->txt("language_remove_local_file_info"), $this->object->key));
593 $rg->addOption($ro);
594 $ro = new ilRadioOption($this->lng->txt("language_merge_local_changes"), "merge");
595 $ro->setInfo(sprintf($this->lng->txt("language_merge_local_changes_info"), $this->object->key));
596 $rg->addOption($ro);
597 }
598 $ro = new ilRadioOption($this->lng->txt("language_save_dist"), "save_dist");
599 $ro->setInfo(sprintf($this->lng->txt("language_save_dist_info"), $this->object->key));
600 $rg->addOption($ro);
601 $rg->setValue($this->session["maintain"]);
602 $form->addItem($rg);
603
604 $this->tpl->setContent($form->getHTML());
605 }
606
607
608 public function maintainExecuteObject()
609 {
610 if (isset($_POST["maintain"])) {
611 $this->session["maintain"] = ilUtil::stripSlashes($_POST["maintain"]);
612 }
613
614 switch ($_POST["maintain"]) {
615 // save the global language file for merge after
616 case "save_dist":
617
618 // save a copy of the distributed language file
619 $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
620 $copy_file = $this->object->getDataPath() . '/ilias_' . $this->object->key . '.lang';
621 if (@copy($orig_file, $copy_file)) {
622 ilUtil::sendSuccess($this->lng->txt("language_saved_dist"), true);
623 } else {
624 ilUtil::sendFailure($this->lng->txt("language_save_dist_failed"), true);
625 }
626 break;
627
628 // load the content of the local language file
629 case "load":
630 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
631 if (is_file($lang_file) and is_readable($lang_file)) {
632 $this->object->importLanguageFile($lang_file, 'replace');
633 $this->object->setLocal(true);
634 ilUtil::sendSuccess($this->lng->txt("language_loaded_local"), true);
635 } else {
636 ilUtil::sendFailure($this->lng->txt("language_error_read_local"), true);
637 }
638 break;
639
640 // revert the database to the default language file
641 case "clear":
642 $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
643 if (is_file($lang_file) and is_readable($lang_file)) {
644 $this->object->importLanguageFile($lang_file, 'delete');
645 $this->object->setLocal(false);
646 ilUtil::sendSuccess($this->lng->txt("language_cleared_local"), true);
647 } else {
648 ilUtil::sendFailure($this->lng->txt("language_error_clear_local"), true);
649 }
650 break;
651
652 // delete local additions in the datavase (langmode only)
653 case "delete_added":
654 ilObjLanguageExt::_deleteValues($this->object->key, $this->object->getAddedValues());
655 break;
656
657 // merge local changes back to the global language file (langmode only)
658 case "merge":
659
660 $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
661 $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
662
663 if (is_file($orig_file) and is_writable($orig_file)) {
664 // save a copy of the global language file
665 @copy($orig_file, $copy_file);
666
667 // modify and write the new global file
668 $global_file_obj = $this->object->getGlobalLanguageFile();
669 $global_file_obj->setAllValues($this->object->getMergedValues());
670 $global_file_obj->setAllComments($this->object->getMergedRemarks());
671 $global_file_obj->write();
672 ilUtil::sendSuccess($this->lng->txt("language_merged_global"), true);
673 } else {
674 ilUtil::sendFailure($this->lng->txt("language_error_write_global"), true);
675 }
676 break;
677
678 // remove the local language file (langmode only)
679 case "remove_local_file":
680 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
681
682 if (!is_file($lang_file)) {
683 $this->object->setLocal(false);
684 ilUtil::sendFailure($this->lng->txt("language_error_local_missed"), true);
685 } elseif (@unlink($lang_file)) {
686 $this->object->setLocal(false);
687 ilUtil::sendSuccess($this->lng->txt("language_local_file_deleted"), true);
688 } else {
689 ilUtil::sendFailure($this->lng->txt("language_error_delete_local"), true);
690 }
691 break;
692 }
693
694 $this->ctrl->redirect($this, "maintain");
695 }
696
700 public function settingsObject()
701 {
702 global $ilSetting;
703
704 $translate_key = "lang_translate_" . $this->object->key;
705
706 // save and get the page translation setting
707 if (!empty($_POST)) {
708 $ilSetting->set($translate_key, (bool) $_POST["translation"]);
709 ilUtil::sendSuccess($this->lng->txt("settings_saved"));
710 }
711 $translate = $ilSetting->get($translate_key, false);
712
713 require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
714 $form = new ilPropertyFormGUI();
715 $form->setFormAction($this->ctrl->getFormAction($this));
716 $form->setTitle($this->lng->txt("language_settings"));
717 $form->setPreventDoubleSubmission(false);
718 $form->addCommandButton('settings', $this->lng->txt("language_change_settings"));
719
720 $ci = new ilCheckboxInputGUI($this->lng->txt("language_translation_enabled"), "translation");
721 $ci->setChecked((bool) $translate);
722 $ci->setInfo($this->lng->txt("language_note_translation"));
723 $form->addItem($ci);
724
725 $this->tpl->setContent($form->getHTML());
726 }
727
731 public function statisticsObject()
732 {
733 $modules = ilObjLanguageExt::_getModules($this->object->key);
734
735 $data = array();
736 $total = array("module"=>'',"all"=>0,"changed"=>0, "unchanged"=>0);
737 foreach ($modules as $module) {
738 $row = array();
739 $row['module'] = $module;
740 $row['all'] = count($this->object->getAllValues(array($module)));
741 $row['changed'] = count($this->object->getChangedValues(array($module)));
742 $row['unchanged'] = $row['all']-$row['changed'];
743 $total['all'] += $row['all'];
744 $total['changed'] += $row['changed'];
745 $total['unchanged'] += $row['unchanged'];
746 $data[] = $row;
747 }
748 $total['module'] = "<b>" . $this->lng->txt("language_all_modules") . "</b>";
749 $total['all'] = "<b>" . $total['all'] . "</b>";
750 $total['changed'] = "<b>" . $total['changed'] . "</b>";
751 $total['unchanged'] = "<b>" . $total['unchanged'] . "</b>";
752 $data[] = $total;
753
754 // create and configure the table object
755 include_once 'Services/Table/classes/class.ilTable2GUI.php';
756 $table_gui = new ilTable2GUI($this, "statistics");
757 $table_gui->setRowTemplate("tpl.lang_statistics_row.html", "Services/Language");
758 $table_gui->setEnableTitle(false);
759 $table_gui->setEnableNumInfo(false);
760 $table_gui->setLimit(count($data));
761 $table_gui->setExportFormats(array(ilTable2GUI::EXPORT_EXCEL));
762
763 $table_gui->addColumn(ucfirst($this->lng->txt("module")), "", "25%");
764 $table_gui->addColumn($this->lng->txt("language_scope_global"), "", "25%");
765 $table_gui->addColumn($this->lng->txt("language_scope_local"), "", "25%");
766 $table_gui->addColumn($this->lng->txt("language_scope_unchanged"), "", "25%");
767
768 $table_gui->setData($data);
769
770 $this->tpl->setContent($table_gui->getHTML());
771 }
772
773
780 public function getAdminTabs()
781 {
783 $this->tabs_gui->addTarget(
784 "edit",
785 $this->ctrl->getLinkTarget($this, "view"),
786 array("","view","cancel","save")
787 );
788
789 $this->tabs_gui->addTarget(
790 "export",
791 $this->ctrl->getLinkTarget($this, "export"),
792 array("export","download")
793 );
794
795 $this->tabs_gui->addTarget(
796 "import",
797 $this->ctrl->getLinkTarget($this, "import"),
798 array("import","upload")
799 );
800
801 $this->tabs_gui->addTarget(
802 "language_maintain",
803 $this->ctrl->getLinkTarget($this, "maintain"),
804 array("maintain")
805 );
806
807 $this->tabs_gui->addTarget(
808 "settings",
809 $this->ctrl->getLinkTarget($this, "settings"),
810 array("settings")
811 );
812
813 $this->tabs_gui->addTarget(
814 "language_statistics",
815 $this->ctrl->getLinkTarget($this, "statistics"),
816 array("statistics")
817 );
818 }
819 }
820
821
826 public function addAdminLocatorItems($a_do_not_add_object = false)
827 {
828 global $ilLocator;
829
831 parent::addAdminLocatorItems(true); // #13881
832
833 $ilLocator->addItem(
834 $this->lng->txt("languages"),
835 $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", "")
836 );
837
838 $ilLocator->addItem(
839 $this->lng->txt("meta_l_" . $this->object->getTitle()),
840 $this->ctrl->getLinkTarget($this, "view")
841 );
842 }
843 }
844
845
850 public function setTitleAndDescription()
851 {
853 $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
854 $this->tpl->setTitle($this->lng->txt("translation") . " " . $this->lng->txt("meta_l_" . $this->object->key));
855 } else {
856 $this->tpl->setTitle($this->lng->txt("meta_l_" . $this->object->key));
857 }
858 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lngf.svg"), $this->lng->txt("obj_" . $this->object->getType()));
859 }
860
861
862 //
863 // new entries
864 //
865
866 protected function buildMissingEntries(array $a_missing = null)
867 {
868 global $ilCtrl;
869
870 if (!is_array($a_missing) ||
871 !sizeof($a_missing)) {
872 return;
873 }
874
875 $res = array('<h3>' . $this->lng->txt("adm_missing_entries") . '</h3>', '<ul>');
876
877 foreach ($a_missing as $entry) {
878 $ilCtrl->setParameter($this, "eid", $entry);
879 $res[] = '<li>' . $entry .
880 ' <a href="' . $ilCtrl->getLinkTarget($this, "addNewEntry") .
881 '">' . $this->lng->txt("adm_missing_entry_add_action") . '</a></li>';
882 $ilCtrl->setParameter($this, "eid", "");
883 }
884
885 $res[] = '</ul>';
886
887 return implode("\n", $res);
888 }
889
890 public function addNewEntryObject(ilPropertyFormGUI $a_form = null)
891 {
892 global $tpl;
893
894 $id = trim($_GET["eid"]);
895
896 if (!$a_form) {
897 $a_form = $this->initAddNewEntryForm($id);
898 }
899
900 $tpl->setContent($a_form->getHTML());
901 }
902
903 protected function initAddNewEntryForm($a_id = null)
904 {
905 global $ilCtrl;
906
907 if (!$a_id) {
908 $a_id = $_POST["id"];
909 }
910
911 if (!$a_id ||
912 !in_array($a_id, ilObjLanguageAccess::_getSavedTopics())) {
913 $ilCtrl->redirect($this, "view");
914 }
915
916 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
917 $form = new ilPropertyFormGUI();
918 $form->setFormAction($ilCtrl->getFormAction($this, "saveNewEntry"));
919 $form->setTitle($this->lng->txt("adm_missing_entry_add"));
920
922 $options = array_combine($mods, $mods);
923
924 $mod = new ilSelectInputGUI(ucfirst($this->lng->txt("module")), "mod");
925 $mod->setOptions(array(""=>$this->lng->txt("please_select"))+$options);
926 $mod->setRequired(true);
927 $form->addItem($mod);
928
929 $id = new ilTextInputGUI(ucfirst($this->lng->txt("identifier")), "id");
930 $id->setValue($a_id);
931 $id->setDisabled(true);
932 $form->addItem($id);
933
934 foreach ($this->lng->getInstalledLanguages() as $lang_key) {
935 $trans = new ilTextInputGUI($this->lng->txt("meta_l_" . $lang_key), "trans_" . $lang_key);
936 if (in_array($lang_key, array("de", "en"))) {
937 $trans->setRequired(true);
938 }
939 $form->addItem($trans);
940 }
941
942 $form->addCommandButton("saveNewEntry", $this->lng->txt("save"));
943 $form->addCommandButton("view", $this->lng->txt("cancel"));
944
945 return $form;
946 }
947
948 public function saveNewEntryObject()
949 {
950 global $ilCtrl, $ilUser, $ilDB;
951
952 $form = $this->initAddNewEntryForm();
953 if ($form->checkInput()) {
954 $mod = $form->getInput("mod");
955 $id = $form->getInput("id");
956
957 $lang = array();
958 foreach ($this->lng->getInstalledLanguages() as $lang_key) {
959 $trans = trim($form->getInput("trans_" . $lang_key));
960 if ($trans) {
961 // add single entry
963 $mod,
964 $id,
965 $lang_key,
966 $trans,
967 date("Y-m-d H:i:s"),
968 $ilUser->getLogin()
969 );
970
971 // add to serialized module
972 $set = $ilDB->query("SELECT lang_array FROM lng_modules" .
973 " WHERE lang_key = " . $ilDB->quote($lang_key, "text") .
974 " AND module = " . $ilDB->quote($mod, "text"));
975 $row = $ilDB->fetchAssoc($set);
976 $entries = unserialize($row["lang_array"]);
977 if (is_array($entries)) {
978 $entries[$id] = $trans;
979 ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
980 }
981 }
982 }
983
984 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
985 $ilCtrl->redirect($this, "view");
986 }
987
988 $form->setValuesByPost();
989 $this->addNewEntryObject($form);
990 }
991} // END class.ilObjLanguageExtGUI
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$total
Definition: Utf8Test.php:87
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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.
Base class for ILIAS Exception handling.
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.
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)
addNewEntryObject(ilPropertyFormGUI $a_form=null)
viewObject()
Show the edit screen.
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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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)
Create a temporary file in an ILIAS writable 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)
$lang
Definition: consent.php:3
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
const ILIAS_VERSION
Interface Location.
Definition: Location.php:17
if($format !==null) $name
Definition: metadata.php:146
$keys
if($modEnd===false) $module
Definition: module.php:59
global $ilSetting
Definition: privfeed.php:17
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18