ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 ilObjLanguageExtGUI($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  $this->ilObjectGUI($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 
204  if (!isset($compare_content))
205  {
206  $compare_content = ilObjLanguageExt::_getValues(
207  $compare, $filter_modules);
208 
209  $compare_comments = ilObjLanguageExt::_getRemarks($compare);
210  }
211 
212  switch ($filter_mode)
213  {
214  case "changed":
215  $translations = $this->object->getChangedValues(
216  $filter_modules, $filter_pattern);
217  break;
218 
219  case "added": //langmode only
220  $translations = $this->object->getAddedValues(
221  $filter_modules, $filter_pattern);
222  break;
223 
224  case "unchanged":
225  $translations = $this->object->getUnchangedValues(
226  $filter_modules, $filter_pattern);
227  break;
228 
229  case "commented":
230  $translations = $this->object->getCommentedValues(
231  $filter_modules, $filter_pattern);
232  break;
233 
234  case "dbremarks":
235  $translations = $this->object->getAllValues(
236  $filter_modules, $filter_pattern);
237 
238  $translations = array_intersect_key($translations, $remarks);
239  break;
240 
241  case "equal":
242  $translations = $this->object->getAllValues(
243  $filter_modules, $filter_pattern);
244 
245  $translations = array_intersect_assoc($translations, $compare_content);
246  break;
247 
248  case "different":
249  $translations = $this->object->getAllValues(
250  $filter_modules, $filter_pattern);
251 
252  $translations = array_diff_assoc($translations, $compare_content);
253  break;
254 
255  case "conflicts":
256  $former_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
257  if (!is_readable($former_file))
258  {
259  ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file)
260  .'<br />'. $this->lng->txt("language_former_file_description") , false);
261  $translations = array();
262  break;
263  }
264  $global_file_obj = $this->object->getGlobalLanguageFile();
265  $former_file_obj = new ilLanguageFile($former_file);
266  $former_file_obj->read();
267  $global_changes = array_diff_assoc(
268  $global_file_obj->getAllValues(),
269  $former_file_obj->getAllValues());
270  if (!count($global_changes))
271  {
272  ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file)
273  .'<br />'. $this->lng->txt("language_former_file_description") , false);
274  $translations = array();
275  break;
276  }
277  $translations = $this->object->getChangedValues(
278  $filter_modules, $filter_pattern);
279 
280  $translations = array_intersect_key($translations, $global_changes);
281  break;
282 
283  case "all":
284  default:
285  $translations = $this->object->getAllValues(
286  $filter_modules, $filter_pattern);
287  }
288  }
289 
290  // prepare the the data for the table
291  $data = array();
292  foreach($translations as $name => $translation)
293  {
294  $keys = explode($this->lng->separator, $name);
295  $row = array();
296 
297  $row["module"] = $keys[0];
298  $row["topic"] = $keys[1];
299  $row["name"] = $name;
300  $row["translation"] = $translation;
301  $row["comment"] = $comments[$name];
302  $row["default"] = $compare_content[$name];
303  $row["default_comment"] = $compare_comments[$name];
304 
305  $data[] = $row;
306  }
307 
308  // render and show the table
309  $table_gui->setData($data);
310  $tpl->setContent($table_gui->getHTML().
311  $this->buildMissingEntries($missing_entries));
312  }
313 
317  function applyFilterObject()
318  {
319  $table_gui = $this->getViewTable();
320  $table_gui->writeFilterToSession(); // writes filter to session
321  $table_gui->resetOffset(); // sets record offest to 0 (first page)
322  $this->viewObject();
323  }
324 
328  function resetFilterObject()
329  {
330  $table_gui = $this->getViewTable();
331  $table_gui->resetOffset(); // sets record offest to 0 (first page)
332  $table_gui->resetFilter(); // clears filter
333  $this->viewObject();
334  }
335 
339  function saveObject()
340  {
341  // prepare the values to be saved
342  $save_array = array();
343  $remarks_array = array();
344  foreach ($_POST as $key => $value)
345  {
346  $keys = explode($this->lng->separator, ilUtil::stripSlashes($key, false));
347 
348  if (count($keys) == 2)
349  {
350  // avoid line breaks
351  $value = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$value);
352  $value = ilUtil::stripSlashes($value, false);
353  $save_array[$key] = $value;
354 
355  $remarks_array[$key] = $_POST[$key.$this->lng->separator."comment"];
356  }
357  }
358 
359  // save the translations
360  ilObjLanguageExt::_saveValues($this->object->key, $save_array, $remarks_array);
361 
362  // view the list
363  $this->viewObject();
364  }
365 
366 
370  function importObject()
371  {
372  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
373  $form = new ilPropertyFormGUI();
374  $form->setFormAction($this->ctrl->getFormAction($this));
375  $form->setTitle($this->lng->txt("language_import_file"));
376  $form->addCommandButton('upload',$this->lng->txt("upload"));
377 
378  $fu = new ilFileInputGUI($this->lng->txt("file"), "userfile");
379  $form->addItem($fu);
380 
381  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_mode_existing"), "mode_existing");
382  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepall"), "keepall");
383  $ro->setInfo($this->lng->txt("language_mode_existing_keepall_info"));
384  $rg->addOption($ro);
385  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_keepnew"), "keepnew");
386  $ro->setInfo($this->lng->txt("language_mode_existing_keepnew_info"));
387  $rg->addOption($ro);
388  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_replace"), "replace");
389  $ro->setInfo($this->lng->txt("language_mode_existing_replace_info"));
390  $rg->addOption($ro);
391  $ro = new ilRadioOption($this->lng->txt("language_mode_existing_delete"), "delete");
392  $ro->setInfo($this->lng->txt("language_mode_existing_delete_info"));
393  $rg->addOption($ro);
394  $rg->setValue($this->session["import"]["mode_existing"] ? $this->session["import"]["mode_existing"] : "keepall");
395  $form->addItem($rg);
396 
397  $this->tpl->setContent($form->getHTML());
398  }
399 
400 
404  function uploadObject()
405  {
406  // save form inputs for next display
407  $this->session["import"]["mode_existing"] = ilUtil::stripSlashes($_POST['mode_existing']);
408 
409  if ($_POST['cmd']['upload'])
410  {
411  $file = $_FILES['userfile']['tmp_name'].'x';
412 
413  if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'],
414  $_FILES['userfile']['name'],
415  $file))
416  {
417  $this->object->importLanguageFile($file,$_POST['mode_existing']);
418  ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']) , true);
419  }
420  }
421 
422  $this->ctrl->redirect($this, 'import');
423  }
424 
425 
429  function exportObject()
430  {
431  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
432  $form = new ilPropertyFormGUI();
433  $form->setFormAction($this->ctrl->getFormAction($this));
434  $form->setTitle($this->lng->txt("language_export_file"));
435  $form->setPreventDoubleSubmission(false);
436  $form->addCommandButton('download',$this->lng->txt("download"));
437 
438  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_file_scope"), "scope");
439  $ro = new ilRadioOption($this->lng->txt("language_scope_global"), "global");
440  $ro->setInfo($this->lng->txt("language_scope_global_info"));
441  $rg->addOption($ro);
442  $ro = new ilRadioOption($this->lng->txt("language_scope_local"), "local");
443  $ro->setInfo($this->lng->txt("language_scope_local_info"));
444  $rg->addOption($ro);
445  if ($this->langmode)
446  {
447  $ro = new ilRadioOption($this->lng->txt("language_scope_added"), "added");
448  $ro->setInfo($this->lng->txt("language_scope_added_info"));
449  $rg->addOption($ro);
450  }
451  $ro = new ilRadioOption($this->lng->txt("language_scope_unchanged"), "unchanged");
452  $ro->setInfo($this->lng->txt("language_scope_unchanged_info"));
453  $rg->addOption($ro);
454  if ($this->langmode)
455  {
456  $ro = new ilRadioOption($this->lng->txt("language_scope_merged"), "merged");
457  $ro->setInfo($this->lng->txt("language_scope_merged_info"));
458  $rg->addOption($ro);
459  }
460 
461  $rg->setValue($this->session["export"]["scope"] ? $this->session["export"]["scope"] : "global");
462  $form->addItem($rg);
463 
464  $this->tpl->setContent($form->getHTML());
465  }
466 
467 
471  function downloadObject()
472  {
473  // save the selected scope
474  $this->session["export"]["scope"] = ilUtil::stripSlashes($_POST["scope"]);
475 
476  $filename = 'ilias_' . $this->object->key . '_'
477  . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
478  . "-" . date('Y-m-d')
479  . ".lang.".$this->session["export"]["scope"];
480 
481  $global_file_obj = $this->object->getGlobalLanguageFile();
482  $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
483 
484  if ($_POST["scope"] == 'global')
485  {
486  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
487  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
488  $local_file_obj->setAllValues($this->object->getAllValues());
489  if ($this->langmode)
490  {
491  $local_file_obj->setAllComments($this->object->getAllRemarks());
492  }
493  }
494  elseif ($_POST["scope"] == 'local')
495  {
496  $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
497  $local_file_obj->setAllValues($this->object->getChangedValues());
498  if ($this->langmode)
499  {
500  $local_file_obj->setAllComments($this->object->getAllRemarks());
501  }
502  }
503  elseif ($_POST["scope"] == 'added') // langmode only
504  {
505  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
506  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
507  $local_file_obj->setAllValues($this->object->getAddedValues());
508  $local_file_obj->setAllComments($this->object->getAllRemarks());
509  }
510  elseif ($_POST["scope"] == 'unchanged')
511  {
512  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
513  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
514  $local_file_obj->setAllValues($this->object->getUnchangedValues());
515  if ($this->langmode)
516  {
517  $local_file_obj->setAllComments($this->object->getAllRemarks());
518  }
519  }
520  elseif ($_POST["scope"] == 'merged') // langmode only
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->getMergedValues());
525  $local_file_obj->setAllComments($this->object->getMergedRemarks());
526  }
527 
528  ilUtil::deliverData($local_file_obj->build(), $filename);
529  }
530 
531 
535  function maintainObject()
536  {
537  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
538  $form = new ilPropertyFormGUI();
539  $form->setFormAction($this->ctrl->getFormAction($this));
540  $form->setTitle($this->lng->txt("language_maintenance"));
541  $form->setPreventDoubleSubmission(false);
542  $form->addCommandButton('maintainExecute',$this->lng->txt("language_process_maintenance"));
543 
544  $rg = new ilRadioGroupInputGUI($this->lng->txt("language_maintain_local_changes"), "maintain");
545  $ro = new ilRadioOption($this->lng->txt("language_save_local_changes"), "save");
546  $ro->setInfo(sprintf($this->lng->txt("language_save_local_changes_info"),$this->object->key));
547  $rg->addOption($ro);
548  $ro = new ilRadioOption($this->lng->txt("language_load_local_changes"), "load");
549  $ro->setInfo(sprintf($this->lng->txt("language_load_local_changes_info"),$this->object->key));
550  $rg->addOption($ro);
551  $ro = new ilRadioOption($this->lng->txt("language_clear_local_changes"), "clear");
552  $ro->setInfo(sprintf($this->lng->txt("language_clear_local_changes_info"),$this->object->key));
553  $rg->addOption($ro);
554  if ($this->langmode)
555  {
556  $ro = new ilRadioOption($this->lng->txt("language_delete_local_additions"), "delete_added");
557  $ro->setInfo(sprintf($this->lng->txt("language_delete_local_additions_info"), $this->object->key));
558  $rg->addOption($ro);
559  $ro = new ilRadioOption($this->lng->txt("language_merge_local_changes"), "merge");
560  $ro->setInfo(sprintf($this->lng->txt("language_merge_local_changes_info"), $this->object->key));
561  $rg->addOption($ro);
562  $ro = new ilRadioOption($this->lng->txt("language_remove_local_file"), "remove_local_file");
563  $ro->setInfo(sprintf($this->lng->txt("language_remove_local_file_info"), $this->object->key));
564  $rg->addOption($ro);
565  }
566  $rg->setValue($this->session["maintain"]);
567  $form->addItem($rg);
568 
569  $this->tpl->setContent($form->getHTML());
570  }
571 
572 
574  {
575  if (isset($_POST["maintain"]))
576  {
577  $this->session["maintain"] = ilUtil::stripSlashes($_POST["maintain"]);
578  }
579 
580  switch ($_POST["maintain"])
581  {
582  // save the local changes to the local language file
583  case "save":
584  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
585 
586  if ((is_file($lang_file) and is_writable($lang_file))
587  or (!file_exists($lang_file) and is_writable($this->object->getCustLangPath())))
588  {
589  // save a copy of the distributed language file
590  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
591  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
592  @copy($orig_file, $copy_file);
593 
594  // save a backup of the old local language file
595  @rename($lang_file, $lang_file.".bak");
596 
597  // create and write the new local language file
598  $global_file_obj = $this->object->getGlobalLanguageFile();
599  $local_file_obj = new ilLanguageFile($lang_file, $this->object->key, 'local');
600  $local_file_obj->setParam('based_on', $global_file_obj->getParam('version'));
601  $local_file_obj->setAllValues($this->object->getChangedValues());
602  if ($this->langmode)
603  {
604  $local_file_obj->setAllComments($this->object->getAllRemarks());
605  }
606  $local_file_obj->write();
607 
608  $this->object->setLocal(true);
609  ilUtil::sendSuccess($this->lng->txt("language_saved_local") , true);
610  }
611  else
612  {
613  ilUtil::sendFailure($this->lng->txt("language_error_write_local") , true);
614  }
615  break;
616 
617  // load the content of the local language file
618  case "load":
619  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
620  if (is_file($lang_file) and is_readable($lang_file))
621  {
622  $this->object->importLanguageFile($lang_file, 'replace');
623  $this->object->setLocal(true);
624  ilUtil::sendSuccess($this->lng->txt("language_loaded_local") , true);
625  }
626  else
627  {
628  ilUtil::sendFailure($this->lng->txt("language_error_read_local") , true);
629  }
630  break;
631 
632  // revert the database to the default language file
633  case "clear":
634  $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
635  if (is_file($lang_file) and is_readable($lang_file))
636  {
637  $this->object->importLanguageFile($lang_file, 'delete');
638  $this->object->setLocal(false);
639  ilUtil::sendSuccess($this->lng->txt("language_cleared_local") , true);
640  }
641  else
642  {
643  ilUtil::sendFailure($this->lng->txt("language_error_clear_local") , true);
644  }
645  break;
646 
647  // delete local additions in the datavase (langmode only)
648  case "delete_added":
649  ilObjLanguageExt::_deleteValues($this->object->key, $this->object->getAddedValues());
650  break;
651 
652  // merge local changes back to the global language file (langmode only)
653  case "merge":
654 
655  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
656  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
657 
658  if (is_file($orig_file) and is_writable($orig_file))
659  {
660  // save a copy of the global language file
661  @copy($orig_file, $copy_file);
662 
663  // modify and write the new global file
664  $global_file_obj = $this->object->getGlobalLanguageFile();
665  $global_file_obj->setAllValues($this->object->getMergedValues());
666  $global_file_obj->setAllComments($this->object->getMergedRemarks());
667  $global_file_obj->write();
668  ilUtil::sendSuccess($this->lng->txt("language_merged_global") , true);
669  }
670  else
671  {
672  ilUtil::sendFailure($this->lng->txt("language_error_write_global") , true);
673  }
674  break;
675 
676  // remove the local language file (langmode only)
677  case "remove_local_file":
678  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
679 
680  if (!is_file($lang_file))
681  {
682  $this->object->setLocal(false);
683  ilUtil::sendFailure($this->lng->txt("language_error_local_missed") , true);
684  }
685  elseif (@unlink($lang_file))
686  {
687  $this->object->setLocal(false);
688  ilUtil::sendSuccess($this->lng->txt("language_local_file_deleted") , true);
689  }
690  else
691  {
692  ilUtil::sendFailure($this->lng->txt("language_error_delete_local") , true);
693  }
694  break;
695  }
696 
697  $this->ctrl->redirect($this,"maintain");
698  }
699 
703  function settingsObject()
704  {
705  global $ilSetting;
706 
707  $translate_key = "lang_translate_". $this->object->key;
708 
709  // save and get the page translation setting
710  if (!empty($_POST))
711  {
712  $ilSetting->set($translate_key, (bool) $_POST["translation"]);
713  ilUtil::sendSuccess($this->lng->txt("settings_saved"));
714  }
715  $translate = $ilSetting->get($translate_key, false);
716 
717  require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
718  $form = new ilPropertyFormGUI();
719  $form->setFormAction($this->ctrl->getFormAction($this));
720  $form->setTitle($this->lng->txt("language_settings"));
721  $form->setPreventDoubleSubmission(false);
722  $form->addCommandButton('settings',$this->lng->txt("language_change_settings"));
723 
724  $ci = new ilCheckboxInputGUI($this->lng->txt("language_translation_enabled"), "translation");
725  $ci->setChecked((bool) $translate);
726  $ci->setInfo($this->lng->txt("language_note_translation"));
727  $form->addItem($ci);
728 
729  $this->tpl->setContent($form->getHTML());
730  }
731 
735  function statisticsObject()
736  {
737  $modules = ilObjLanguageExt::_getModules($this->object->key);
738 
739  $data = array();
740  $total = array("module"=>'',"all"=>0,"changed"=>0, "unchanged"=>0);
741  foreach($modules as $module)
742  {
743  $row = array();
744  $row['module'] = $module;
745  $row['all'] = count($this->object->getAllValues(array($module)));
746  $row['changed'] = count($this->object->getChangedValues(array($module)));
747  $row['unchanged'] = $row['all']-$row['changed'];
748  $total['all'] += $row['all'];
749  $total['changed'] += $row['changed'];
750  $total['unchanged'] += $row['unchanged'];
751  $data[] = $row;
752  }
753  $total['module'] = "<b>".$this->lng->txt("language_all_modules")."</b>";
754  $total['all'] = "<b>".$total['all']."</b>";
755  $total['changed'] = "<b>".$total['changed']."</b>";
756  $total['unchanged'] = "<b>".$total['unchanged']."</b>";
757  $data[] = $total;
758 
759  // create and configure the table object
760  include_once 'Services/Table/classes/class.ilTable2GUI.php';
761  $table_gui = new ilTable2GUI($this, "statistics");
762  $table_gui->setRowTemplate("tpl.lang_statistics_row.html","Services/Language");
763  $table_gui->setEnableTitle(false);
764  $table_gui->setEnableNumInfo(false);
765  $table_gui->setLimit(count($data));
766  $table_gui->setExportFormats(array(ilTable2GUI::EXPORT_EXCEL));
767 
768  $table_gui->addColumn(ucfirst($this->lng->txt("module")), "", "25%");
769  $table_gui->addColumn($this->lng->txt("language_scope_global"), "", "25%");
770  $table_gui->addColumn($this->lng->txt("language_scope_local"), "", "25%");
771  $table_gui->addColumn($this->lng->txt("language_scope_unchanged"), "", "25%");
772 
773  $table_gui->setData($data);
774 
775  $this->tpl->setContent($table_gui->getHTML());
776  }
777 
778 
785  function getAdminTabs(&$tabs_gui)
786  {
788  {
789  $tabs_gui->addTarget("edit",
790  $this->ctrl->getLinkTarget($this, "view"),
791  array("","view","cancel","save"));
792 
793  $tabs_gui->addTarget("export",
794  $this->ctrl->getLinkTarget($this, "export"),
795  array("export","download"));
796 
797  $tabs_gui->addTarget("import",
798  $this->ctrl->getLinkTarget($this, "import"),
799  array("import","upload"));
800 
801  $tabs_gui->addTarget("language_maintain",
802  $this->ctrl->getLinkTarget($this, "maintain"),
803  array("maintain"));
804 
805  $tabs_gui->addTarget("settings",
806  $this->ctrl->getLinkTarget($this, "settings"),
807  array("settings"));
808 
809  $tabs_gui->addTarget("language_statistics",
810  $this->ctrl->getLinkTarget($this, "statistics"),
811  array("statistics"));
812  }
813  }
814 
815 
821  {
822  global $ilLocator;
823 
825  {
826  parent::addAdminLocatorItems(true); // #13881
827 
828  $ilLocator->addItem($this->lng->txt("languages"),
829  $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", ""));
830 
831  $ilLocator->addItem($this->lng->txt("meta_l_". $this->object->getTitle()),
832  $this->ctrl->getLinkTarget($this, "view"));
833  }
834  }
835 
836 
842  {
844  {
845  $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
846  $this->tpl->setTitle($this->lng->txt("translation"). " ".$this->lng->txt("meta_l_".$this->object->key));
847  }
848  else
849  {
850  $this->tpl->setTitle($this->lng->txt("meta_l_".$this->object->key));
851  }
852  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lngf.svg"), $this->lng->txt("obj_" . $this->object->getType()));
853  }
854 
855 
856  //
857  // new entries
858  //
859 
860  protected function buildMissingEntries(array $a_missing = null)
861  {
862  global $ilCtrl;
863 
864  if(!is_array($a_missing) ||
865  !sizeof($a_missing))
866  {
867  return;
868  }
869 
870  $res = array('<h3>'.$this->lng->txt("adm_missing_entries").'</h3>', '<ul>');
871 
872  foreach($a_missing as $entry)
873  {
874  $ilCtrl->setParameter($this, "eid", $entry);
875  $res[] = '<li>'.$entry.
876  ' <a href="'.$ilCtrl->getLinkTarget($this, "addNewEntry").
877  '">'.$this->lng->txt("adm_missing_entry_add_action").'</a></li>';
878  $ilCtrl->setParameter($this, "eid", "");
879  }
880 
881  $res[] = '</ul>';
882 
883  return implode("\n", $res);
884  }
885 
886  function addNewEntryObject(ilPropertyFormGUI $a_form = null)
887  {
888  global $tpl;
889 
890  $id = trim($_GET["eid"]);
891 
892  if(!$a_form)
893  {
894  $a_form = $this->initAddNewEntryForm($id);
895  }
896 
897  $tpl->setContent($a_form->getHTML());
898  }
899 
900  protected function initAddNewEntryForm($a_id = null)
901  {
902  global $ilCtrl;
903 
904  if(!$a_id)
905  {
906  $a_id = $_POST["id"];
907  }
908 
909  if(!$a_id ||
910  !in_array($a_id, ilObjLanguageAccess::_getSavedTopics()))
911  {
912  $ilCtrl->redirect($this, "view");
913  }
914 
915  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
916  $form = new ilPropertyFormGUI();
917  $form->setFormAction($ilCtrl->getFormAction($this, "saveNewEntry"));
918  $form->setTitle($this->lng->txt("adm_missing_entry_add"));
919 
921  $options = array_combine($mods, $mods);
922 
923  $mod = new ilSelectInputGUI(ucfirst($this->lng->txt("module")), "mod");
924  $mod->setOptions(array(""=>$this->lng->txt("please_select"))+$options);
925  $mod->setRequired(true);
926  $form->addItem($mod);
927 
928  $id = new ilTextInputGUI(ucfirst($this->lng->txt("identifier")), "id");
929  $id->setValue($a_id);
930  $id->setDisabled(true);
931  $form->addItem($id);
932 
933  foreach ($this->lng->getInstalledLanguages() as $lang_key)
934  {
935  $trans = new ilTextInputGUI($this->lng->txt("meta_l_".$lang_key), "trans_".$lang_key);
936  if(in_array($lang_key, array("de", "en")))
937  {
938  $trans->setRequired(true);
939  }
940  $form->addItem($trans);
941  }
942 
943  $form->addCommandButton("saveNewEntry", $this->lng->txt("save"));
944  $form->addCommandButton("view", $this->lng->txt("cancel"));
945 
946  return $form;
947  }
948 
950  {
951  global $ilCtrl, $ilUser, $ilDB;
952 
953  $form = $this->initAddNewEntryForm();
954  if($form->checkInput())
955  {
956  $mod = $form->getInput("mod");
957  $id = $form->getInput("id");
958 
959  $lang = array();
960  foreach ($this->lng->getInstalledLanguages() as $lang_key)
961  {
962  $trans = trim($form->getInput("trans_".$lang_key));
963  if($trans)
964  {
965  // add single entry
967  $mod,
968  $id,
969  $lang_key,
970  $trans,
971  date("Y-m-d H:i:s"),
972  $ilUser->getLogin()
973  );
974 
975  // add to serialized module
976  $set = $ilDB->query("SELECT lang_array FROM lng_modules".
977  " WHERE lang_key = ".$ilDB->quote($lang_key, "text").
978  " AND module = ".$ilDB->quote($mod, "text"));
979  $row = $ilDB->fetchAssoc($set);
980  $entries = unserialize($row["lang_array"]);
981  if(is_array($entries))
982  {
983  $entries[$id] = $trans;
984  ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
985  }
986  }
987  }
988 
989  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
990  $ilCtrl->redirect($this, "view");
991  }
992 
993  $form->setValuesByPost();
994  $this->addNewEntryObject($form);
995  }
996 
997 
998 } // END class.ilObjLanguageExtGUI
999 ?>