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