ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
7 define("ILIAS_LANGUAGE_MODULE", "Services/Language");
8 
9 require_once("./Services/Object/classes/class.ilObjectGUI.php");
10 require_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()
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  // render and show the table
342  $table_gui->setData($data);
343  $tpl->setContent($table_gui->getHTML() .
344  $this->buildMissingEntries($missing_entries));
345  }
346 
350  public function applyFilterObject()
351  {
352  $table_gui = $this->getViewTable();
353  $table_gui->writeFilterToSession(); // writes filter to session
354  $table_gui->resetOffset(); // sets record offest to 0 (first page)
355  $this->viewObject();
356  }
357 
361  public function resetFilterObject()
362  {
363  $table_gui = $this->getViewTable();
364  $table_gui->resetOffset(); // sets record offest to 0 (first page)
365  $table_gui->resetFilter(); // clears filter
366  $this->viewObject();
367  }
368 
372  public function saveObject()
373  {
374  // prepare the values to be saved
375  $save_array = array();
376  $remarks_array = array();
377  foreach ($_POST as $key => $value) {
378  // mantis #25237
379  // @see https://php.net/manual/en/language.variables.external.php
380  $key = str_replace('_POSTDOT_', '.', $key);
381  $key = str_replace('_POSTSPACE_', ' ', $key);
382 
383  // example key of variable: 'common#:#access'
384  // example key of comment: 'common#:#access#:#comment'
385  $keys = explode($this->lng->separator, ilUtil::stripSlashes($key, false));
386 
387  if (count($keys) == 2) {
388  // avoid line breaks
389  $value = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $value);
390  $value = ilUtil::stripSlashes($value, false);
391  $save_array[$key] = $value;
392 
393  // the comment has the key of the language with the suffix
394  $remarks_array[$key] = $_POST[$key . $this->lng->separator . "comment"];
395  }
396  }
397 
398  // save the translations
399  ilObjLanguageExt::_saveValues($this->object->key, $save_array, $remarks_array);
400 
401  // view the list
402  $this->viewObject();
403  }
404 
405 
409  public function importObject()
410  {
411  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
412  $form = new ilPropertyFormGUI();
413  $form->setFormAction($this->ctrl->getFormAction($this));
414  $form->setTitle($this->lng->txt("language_import_file"));
415  $form->addCommandButton('upload', $this->lng->txt("upload"));
416 
417  $fu = new ilFileInputGUI($this->lng->txt("file"), "userfile");
418  $form->addItem($fu);
419 
420  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_mode_existing"), "mode_existing");
421  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepall"), "keepall");
422  $ro->setInfo($this->lng->txt("language_mode_existing_keepall_info"));
423  $rg->addOption($ro);
424  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepnew"), "keepnew");
425  $ro->setInfo($this->lng->txt("language_mode_existing_keepnew_info"));
426  $rg->addOption($ro);
427  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_replace"), "replace");
428  $ro->setInfo($this->lng->txt("language_mode_existing_replace_info"));
429  $rg->addOption($ro);
430  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_delete"), "delete");
431  $ro->setInfo($this->lng->txt("language_mode_existing_delete_info"));
432  $rg->addOption($ro);
433  $rg->setValue($this->session["import"]["mode_existing"] ? $this->session["import"]["mode_existing"] : "keepall");
434  $form->addItem($rg);
435 
436  $this->tpl->setContent($form->getHTML());
437  }
438 
439 
443  public function uploadObject()
444  {
445  global $DIC;
446 
447  // save form inputs for next display
448  $this->session["import"]["mode_existing"] = ilUtil::stripSlashes($_POST['mode_existing']);
449 
450  try {
451  $upload = $DIC->upload();
452  $upload->process();
453 
454  if (!$upload->hasUploads()) {
455  throw new ilException($DIC->language()->txt("upload_error_file_not_found"));
456  }
457  $UploadResult = $upload->getResults()[$_FILES['userfile']['tmp_name']];
458 
459  $ProcessingStatus = $UploadResult->getStatus();
460  if ($ProcessingStatus->getCode() === ProcessingStatus::REJECTED) {
461  throw new ilException($ProcessingStatus->getMessage());
462  }
463 
464  // todo: refactor when importLanguageFile() is able to work with the new Filesystem service
465  $tempfile = ilUtil::ilTempnam() . '.sec';
466  $upload->moveOneFileTo($UploadResult, '', Location::TEMPORARY, basename($tempfile), true);
467  $this->object->importLanguageFile($tempfile, $_POST['mode_existing']);
468 
469  $tempfs = $DIC->filesystem()->temp();
470  $tempfs->delete(basename($tempfile));
471  } catch (Exception $e) {
472  ilUtil::sendFailure($e->getMessage(), true);
473  $this->ctrl->redirect($this, 'import');
474  }
475 
476  ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']), true);
477  $this->ctrl->redirect($this, 'import');
478  }
479 
480 
484  public function exportObject()
485  {
486  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
487  $form = new ilPropertyFormGUI();
488  $form->setFormAction($this->ctrl->getFormAction($this));
489  $form->setTitle($this->lng->txt("language_export_file"));
490  $form->setPreventDoubleSubmission(false);
491  $form->addCommandButton('download', $this->lng->txt("download"));
492 
493  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_file_scope"), "scope");
494  $ro = new ilRadioOption($this->lng->txt("language_scope_global"), "global");
495  $ro->setInfo($this->lng->txt("language_scope_global_info"));
496  $rg->addOption($ro);
497  $ro = new ilRadioOption($this->lng->txt("language_scope_local"), "local");
498  $ro->setInfo($this->lng->txt("language_scope_local_info"));
499  $rg->addOption($ro);
500  if ($this->langmode) {
501  $ro = new ilRadioOption($this->lng->txt("language_scope_added"), "added");
502  $ro->setInfo($this->lng->txt("language_scope_added_info"));
503  $rg->addOption($ro);
504  }
505  $ro = new ilRadioOption($this->lng->txt("language_scope_unchanged"), "unchanged");
506  $ro->setInfo($this->lng->txt("language_scope_unchanged_info"));
507  $rg->addOption($ro);
508  if ($this->langmode) {
509  $ro = new ilRadioOption($this->lng->txt("language_scope_merged"), "merged");
510  $ro->setInfo($this->lng->txt("language_scope_merged_info"));
511  $rg->addOption($ro);
512  }
513 
514  $rg->setValue($this->session["export"]["scope"] ? $this->session["export"]["scope"] : "global");
515  $form->addItem($rg);
516 
517  $this->tpl->setContent($form->getHTML());
518  }
519 
520 
524  public function downloadObject()
525  {
526  // save the selected scope
527  $this->session["export"]["scope"] = ilUtil::stripSlashes($_POST["scope"]);
528 
529  $filename = 'ilias_' . $this->object->key . '_'
530  . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
531  . "-" . date('Y-m-d')
532  . ".lang." . $this->session["export"]["scope"];
533 
534  $global_file_obj = $this->object->getGlobalLanguageFile();
535  $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
536 
537  if ($_POST["scope"] == 'global') {
538  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
539  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
540  $local_file_obj->setAllValues($this->object->getAllValues());
541  if ($this->langmode) {
542  $local_file_obj->setAllComments($this->object->getAllRemarks());
543  }
544  } elseif ($_POST["scope"] == 'local') {
545  $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
546  $local_file_obj->setAllValues($this->object->getChangedValues());
547  if ($this->langmode) {
548  $local_file_obj->setAllComments($this->object->getAllRemarks());
549  }
550  } elseif ($_POST["scope"] == 'added') { // langmode only
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->getAddedValues());
554  $local_file_obj->setAllComments($this->object->getAllRemarks());
555  } elseif ($_POST["scope"] == 'unchanged') {
556  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
557  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
558  $local_file_obj->setAllValues($this->object->getUnchangedValues());
559  if ($this->langmode) {
560  $local_file_obj->setAllComments($this->object->getAllRemarks());
561  }
562  } elseif ($_POST["scope"] == 'merged') { // langmode only
563  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
564  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
565  $local_file_obj->setAllValues($this->object->getMergedValues());
566  $local_file_obj->setAllComments($this->object->getMergedRemarks());
567  }
568 
569  ilUtil::deliverData($local_file_obj->build(), $filename);
570  }
571 
572 
576  public function maintainObject()
577  {
578  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
579  $form = new ilPropertyFormGUI();
580  $form->setFormAction($this->ctrl->getFormAction($this));
581  $form->setTitle($this->lng->txt("language_maintenance"));
582  $form->setPreventDoubleSubmission(false);
583  $form->addCommandButton('maintainExecute', $this->lng->txt("language_process_maintenance"));
584 
585  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_maintain_local_changes"), "maintain");
586  $ro = new ilRadioOption($this->lng->txt("language_load_local_changes"), "load");
587  $ro->setInfo(sprintf($this->lng->txt("language_load_local_changes_info"), $this->object->key));
588  $rg->addOption($ro);
589  $ro = new ilRadioOption($this->lng->txt("language_clear_local_changes"), "clear");
590  $ro->setInfo(sprintf($this->lng->txt("language_clear_local_changes_info"), $this->object->key));
591  $rg->addOption($ro);
592  if ($this->langmode) {
593  $ro = new ilRadioOption($this->lng->txt("language_delete_local_additions"), "delete_added");
594  $ro->setInfo(sprintf($this->lng->txt("language_delete_local_additions_info"), $this->object->key));
595  $rg->addOption($ro);
596  $ro = new ilRadioOption($this->lng->txt("language_remove_local_file"), "remove_local_file");
597  $ro->setInfo(sprintf($this->lng->txt("language_remove_local_file_info"), $this->object->key));
598  $rg->addOption($ro);
599  $ro = new ilRadioOption($this->lng->txt("language_merge_local_changes"), "merge");
600  $ro->setInfo(sprintf($this->lng->txt("language_merge_local_changes_info"), $this->object->key));
601  $rg->addOption($ro);
602  }
603  $ro = new ilRadioOption($this->lng->txt("language_save_dist"), "save_dist");
604  $ro->setInfo(sprintf($this->lng->txt("language_save_dist_info"), $this->object->key));
605  $rg->addOption($ro);
606  $rg->setValue($this->session["maintain"]);
607  $form->addItem($rg);
608 
609  $this->tpl->setContent($form->getHTML());
610  }
611 
612 
613  public function maintainExecuteObject()
614  {
615  if (isset($_POST["maintain"])) {
616  $this->session["maintain"] = ilUtil::stripSlashes($_POST["maintain"]);
617  }
618 
619  switch ($_POST["maintain"]) {
620  // save the global language file for merge after
621  case "save_dist":
622 
623  // save a copy of the distributed language file
624  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
625  $copy_file = $this->object->getDataPath() . '/ilias_' . $this->object->key . '.lang';
626  if (@copy($orig_file, $copy_file)) {
627  ilUtil::sendSuccess($this->lng->txt("language_saved_dist"), true);
628  } else {
629  ilUtil::sendFailure($this->lng->txt("language_save_dist_failed"), true);
630  }
631  break;
632 
633  // load the content of the local language file
634  case "load":
635  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
636  if (is_file($lang_file) and is_readable($lang_file)) {
637  $this->object->importLanguageFile($lang_file, 'replace');
638  $this->object->setLocal(true);
639  ilUtil::sendSuccess($this->lng->txt("language_loaded_local"), true);
640  } else {
641  ilUtil::sendFailure($this->lng->txt("language_error_read_local"), true);
642  }
643  break;
644 
645  // revert the database to the default language file
646  case "clear":
647  $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
648  if (is_file($lang_file) and is_readable($lang_file)) {
649  $this->object->importLanguageFile($lang_file, 'delete');
650  $this->object->setLocal(false);
651  ilUtil::sendSuccess($this->lng->txt("language_cleared_local"), true);
652  } else {
653  ilUtil::sendFailure($this->lng->txt("language_error_clear_local"), true);
654  }
655  break;
656 
657  // delete local additions in the datavase (langmode only)
658  case "delete_added":
659  ilObjLanguageExt::_deleteValues($this->object->key, $this->object->getAddedValues());
660  break;
661 
662  // merge local changes back to the global language file (langmode only)
663  case "merge":
664 
665  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
666  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
667 
668  if (is_file($orig_file) and is_writable($orig_file)) {
669  // save a copy of the global language file
670  @copy($orig_file, $copy_file);
671 
672  // modify and write the new global file
673  $global_file_obj = $this->object->getGlobalLanguageFile();
674  $global_file_obj->setAllValues($this->object->getMergedValues());
675  $global_file_obj->setAllComments($this->object->getMergedRemarks());
676  $global_file_obj->write();
677  ilUtil::sendSuccess($this->lng->txt("language_merged_global"), true);
678  } else {
679  ilUtil::sendFailure($this->lng->txt("language_error_write_global"), true);
680  }
681  break;
682 
683  // remove the local language file (langmode only)
684  case "remove_local_file":
685  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
686 
687  if (!is_file($lang_file)) {
688  $this->object->setLocal(false);
689  ilUtil::sendFailure($this->lng->txt("language_error_local_missed"), true);
690  } elseif (@unlink($lang_file)) {
691  $this->object->setLocal(false);
692  ilUtil::sendSuccess($this->lng->txt("language_local_file_deleted"), true);
693  } else {
694  ilUtil::sendFailure($this->lng->txt("language_error_delete_local"), true);
695  }
696  break;
697  }
698 
699  $this->ctrl->redirect($this, "maintain");
700  }
701 
705  public function settingsObject()
706  {
707  global $DIC;
708  $ilSetting = $DIC->settings();
709 
710  $translate_key = "lang_translate_" . $this->object->key;
711 
712  // save and get the page translation setting
713  if (!empty($_POST)) {
714  $ilSetting->set($translate_key, (bool) $_POST["translation"]);
715  ilUtil::sendSuccess($this->lng->txt("settings_saved"));
716  }
717  $translate = $ilSetting->get($translate_key, false);
718 
719  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
720  $form = new ilPropertyFormGUI();
721  $form->setFormAction($this->ctrl->getFormAction($this));
722  $form->setTitle($this->lng->txt("language_settings"));
723  $form->setPreventDoubleSubmission(false);
724  $form->addCommandButton('settings', $this->lng->txt("language_change_settings"));
725 
726  $ci = new ilCheckboxInputGUI($this->lng->txt("language_translation_enabled"), "translation");
727  $ci->setChecked((bool) $translate);
728  $ci->setInfo($this->lng->txt("language_note_translation"));
729  $form->addItem($ci);
730 
731  $this->tpl->setContent($form->getHTML());
732  }
733 
737  public function statisticsObject()
738  {
739  $modules = ilObjLanguageExt::_getModules($this->object->key);
740 
741  $data = array();
742  $total = array("module" => '',"all" => 0,"changed" => 0, "unchanged" => 0);
743  foreach ($modules as $module) {
744  $row = array();
745  $row['module'] = $module;
746  $row['all'] = count($this->object->getAllValues(array($module)));
747  $row['changed'] = count($this->object->getChangedValues(array($module)));
748  $row['unchanged'] = $row['all'] - $row['changed'];
749  $total['all'] += $row['all'];
750  $total['changed'] += $row['changed'];
751  $total['unchanged'] += $row['unchanged'];
752  $data[] = $row;
753  }
754  $total['module'] = "<b>" . $this->lng->txt("language_all_modules") . "</b>";
755  $total['all'] = "<b>" . $total['all'] . "</b>";
756  $total['changed'] = "<b>" . $total['changed'] . "</b>";
757  $total['unchanged'] = "<b>" . $total['unchanged'] . "</b>";
758  $data[] = $total;
759 
760  // create and configure the table object
761  include_once 'Services/Table/classes/class.ilTable2GUI.php';
762  $table_gui = new ilTable2GUI($this, "statistics");
763  $table_gui->setRowTemplate("tpl.lang_statistics_row.html", "Services/Language");
764  $table_gui->setEnableTitle(false);
765  $table_gui->setEnableNumInfo(false);
766  $table_gui->setLimit(count($data));
767  $table_gui->setExportFormats(array(ilTable2GUI::EXPORT_EXCEL));
768 
769  $table_gui->addColumn(ucfirst($this->lng->txt("module")), "", "25%");
770  $table_gui->addColumn($this->lng->txt("language_scope_global"), "", "25%");
771  $table_gui->addColumn($this->lng->txt("language_scope_local"), "", "25%");
772  $table_gui->addColumn($this->lng->txt("language_scope_unchanged"), "", "25%");
773 
774  $table_gui->setData($data);
775 
776  $this->tpl->setContent($table_gui->getHTML());
777  }
778 
779 
786  public function getAdminTabs()
787  {
788  global $DIC;
789  $ilCtrl = $DIC->ctrl();
790  $cmd = $ilCtrl->getCmd();
791 
793  $this->tabs_gui->setBackTarget(
794  $this->lng->txt('back'),
795  $this->ctrl->getLinkTargetByClass('ilObjLanguageFolderGUI')
796  );
797 
798  $this->tabs_gui->addTab(
799  "edit",
800  $this->lng->txt("edit"),
801  $this->ctrl->getLinkTarget($this, "view")
802  );
803 
804  $this->tabs_gui->addTab(
805  "export",
806  $this->lng->txt('export'),
807  $this->ctrl->getLinkTarget($this, "export")
808  );
809 
810  $this->tabs_gui->addTab(
811  "import",
812  $this->lng->txt('import'),
813  $this->ctrl->getLinkTarget($this, "import")
814  );
815 
816  $this->tabs_gui->addTab(
817  "maintain",
818  $this->lng->txt('language_maintain'),
819  $this->ctrl->getLinkTarget($this, "maintain")
820  );
821 
822  $this->tabs_gui->addTab(
823  "settings",
824  $this->lng->txt('settings'),
825  $this->ctrl->getLinkTarget($this, "settings")
826  );
827 
828  $this->tabs_gui->addTab(
829  "statistics",
830  $this->lng->txt("language_statistics"),
831  $this->ctrl->getLinkTarget($this, "statistics")
832  );
833 
834  switch ($cmd) {
835  case '':
836  case 'view':
837  case 'applyFilter':
838  case 'resetFilter':
839  case 'save':
840  $this->tabs_gui->activateTab('edit');
841  break;
842  default:
843  $this->tabs_gui->activateTab($cmd);
844  }
845  }
846  }
847 
848 
853  public function addAdminLocatorItems($a_do_not_add_object = false)
854  {
855  global $DIC;
856  $ilLocator = $DIC['ilLocator'];
857 
859  parent::addAdminLocatorItems(true); // #13881
860 
861  $ilLocator->addItem(
862  $this->lng->txt("languages"),
863  $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", "")
864  );
865 
866  $ilLocator->addItem(
867  $this->lng->txt("meta_l_" . $this->object->getTitle()),
868  $this->ctrl->getLinkTarget($this, "view")
869  );
870  }
871  }
872 
873 
878  public function setTitleAndDescription()
879  {
881  $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
882  $this->tpl->setTitle($this->lng->txt("translation") . " " . $this->lng->txt("meta_l_" . $this->object->key));
883  } else {
884  $this->tpl->setTitle($this->lng->txt("meta_l_" . $this->object->key));
885  }
886  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lngf.svg"), $this->lng->txt("obj_" . $this->object->getType()));
887  }
888 
889 
890  //
891  // new entries
892  //
893 
894  protected function buildMissingEntries(array $a_missing = null)
895  {
896  global $DIC;
897  $ilCtrl = $DIC->ctrl();
898 
899  if (!is_array($a_missing) ||
900  !sizeof($a_missing)) {
901  return;
902  }
903 
904  $res = array('<h3>' . $this->lng->txt("adm_missing_entries") . '</h3>', '<ul>');
905 
906  foreach ($a_missing as $entry) {
907  $ilCtrl->setParameter($this, "eid", $entry);
908  $res[] = '<li>' . $entry .
909  ' <a href="' . $ilCtrl->getLinkTarget($this, "addNewEntry") .
910  '">' . $this->lng->txt("adm_missing_entry_add_action") . '</a></li>';
911  $ilCtrl->setParameter($this, "eid", "");
912  }
913 
914  $res[] = '</ul>';
915 
916  return implode("\n", $res);
917  }
918 
919  public function addNewEntryObject(ilPropertyFormGUI $a_form = null)
920  {
921  global $DIC;
922  $tpl = $DIC['tpl'];
923 
924  $id = trim($_GET["eid"]);
925 
926  if (!$a_form) {
927  $a_form = $this->initAddNewEntryForm($id);
928  }
929 
930  $tpl->setContent($a_form->getHTML());
931  }
932 
933  protected function initAddNewEntryForm($a_id = null)
934  {
935  global $DIC;
936  $ilCtrl = $DIC->ctrl();
937 
938  if (!$a_id) {
939  $a_id = $_POST["id"];
940  }
941 
942  if (!$a_id ||
943  !in_array($a_id, ilObjLanguageAccess::_getSavedTopics())) {
944  $ilCtrl->redirect($this, "view");
945  }
946 
947  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
948  $form = new ilPropertyFormGUI();
949  $form->setFormAction($ilCtrl->getFormAction($this, "saveNewEntry"));
950  $form->setTitle($this->lng->txt("adm_missing_entry_add"));
951 
953  $options = array_combine($mods, $mods);
954 
955  $mod = new ilSelectInputGUI(ucfirst($this->lng->txt("module")), "mod");
956  $mod->setOptions(array("" => $this->lng->txt("please_select")) + $options);
957  $mod->setRequired(true);
958  $form->addItem($mod);
959 
960  $id = new ilTextInputGUI(ucfirst($this->lng->txt("identifier")), "id");
961  $id->setValue($a_id);
962  $id->setDisabled(true);
963  $form->addItem($id);
964 
965  foreach ($this->lng->getInstalledLanguages() as $lang_key) {
966  $trans = new ilTextInputGUI($this->lng->txt("meta_l_" . $lang_key), "trans_" . $lang_key);
967  if (in_array($lang_key, array("de", "en"))) {
968  $trans->setRequired(true);
969  }
970  $form->addItem($trans);
971  }
972 
973  $form->addCommandButton("saveNewEntry", $this->lng->txt("save"));
974  $form->addCommandButton("view", $this->lng->txt("cancel"));
975 
976  return $form;
977  }
978 
979  public function saveNewEntryObject()
980  {
981  global $DIC;
982  $ilDB = $DIC->database();
983  $ilCtrl = $DIC->ctrl();
984  $ilUser = $DIC->user();
985 
986  $form = $this->initAddNewEntryForm();
987  if ($form->checkInput()) {
988  $mod = $form->getInput("mod");
989  $id = $form->getInput("id");
990 
991  $lang = array();
992  foreach ($this->lng->getInstalledLanguages() as $lang_key) {
993  $trans = trim($form->getInput("trans_" . $lang_key));
994  if ($trans) {
995  // add single entry
997  $mod,
998  $id,
999  $lang_key,
1000  $trans,
1001  date("Y-m-d H:i:s"),
1002  $ilUser->getLogin()
1003  );
1004 
1005  // add to serialized module
1006  $set = $ilDB->query("SELECT lang_array FROM lng_modules" .
1007  " WHERE lang_key = " . $ilDB->quote($lang_key, "text") .
1008  " AND module = " . $ilDB->quote($mod, "text"));
1009  $row = $ilDB->fetchAssoc($set);
1010  $entries = unserialize($row["lang_array"]);
1011  if (is_array($entries)) {
1012  $entries[$id] = $trans;
1013  ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
1014  }
1015  }
1016  }
1017 
1018  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
1019  $ilCtrl->redirect($this, "view");
1020  }
1021 
1022  $form->setValuesByPost();
1023  $this->addNewEntryObject($form);
1024  }
1025 } // END class.ilObjLanguageExtGUI
downloadObject()
Download a language file.
This class represents an option in a radio group.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
executeCommand()
execute command
assignObject()
Assign the extended language object.
const ILIAS_VERSION
viewObject()
Show the edit screen.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
uploadObject()
Process an uploaded language file.
static _getRemarks($a_lang_key, $a_all_changed=false)
Get all remarks of a language.
global $DIC
Definition: saml.php:7
static _isPageTranslation()
Check if the current request is a page translation.
$_GET["client_id"]
static _getSavedModules()
Get the stored modules from the user session.
This class represents a file property in a property form.
getViewTable()
Get the table to view language entries.
addAdminLocatorItems($a_do_not_add_object=false)
Set the locator for admin mode (Overwritten from ilObjectGUI, called by prepareOutput) ...
static _deleteValues($a_lang_key, $a_values=array())
Delete a set of translation in the database.
if(!array_key_exists('StateId', $_REQUEST)) $id
cancelObject()
Cancel the current action.
This class represents a checkbox property in a property form.
Class ilObjLanguageExtGUI.
__construct($a_data, $a_id=0, $a_call_by_reference=false)
Constructor.
exportObject()
Show the screen to export a language file.
static _checkMaintenance()
Permission check for language maintenance (import/export)
$keys
static _lookupId($a_key)
Lookup the object ID for a language key.
$total
Definition: Utf8Test.php:87
if($modEnd===false) $module
Definition: module.php:59
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setChecked($a_checked)
Set Checked.
importObject()
Show the screen to import a language file.
This class represents a property in a property form.
Class ilTable2GUI.
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
Class ilObjLanguageExt.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Class ilObjectGUI Basic methods of all Output classes.
static _getValues( $a_lang_key, $a_modules=array(), $a_topics=array(), $a_pattern='', $a_state='')
Get the translations of specified topics.
getAdminTabs()
Get tabs for admin mode (Overwritten from ilObjectGUI, called by prepareOutput)
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
buildMissingEntries(array $a_missing=null)
statisticsObject()
Print out statistics about the language.
settingsObject()
Set the language settings.
setTitleAndDescription()
Set the Title and the description (Overwritten from ilObjectGUI, called by prepareOutput) ...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _getSavedTopics()
Get the stored topics from the user session.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$filename
Definition: buildRTE.php:89
saveObject()
Save the changed translations.
$row
static _saveValues($a_lang_key, $a_values=array(), $a_remarks=array())
Save a set of translation in the database.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
exit
Definition: backend.php:16
Class ilLanguageFile.
global $ilSetting
Definition: privfeed.php:17
global $ilDB
addNewEntryObject(ilPropertyFormGUI $a_form=null)
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
static _getModules($a_lang_key)
Get all modules of a language.
maintainObject()
Process the language maintenance.
getId()
get the language object id (needed for filter serialization)
$key
Definition: croninfo.php:18
$_POST["username"]
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
setRequired($a_required)
Set Required.