ILIAS  Release_4_4_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-2009 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 {
30  private $inputsize = 50;
31  private $commentsize = 30;
32 
44  function ilObjLanguageExtGUI($a_data, $a_id = 0, $a_call_by_reference = false)
45  {
46  global $lng, $ilCtrl, $ilClientIniFile;
47 
48  // language maintenance strings are defined in administration
49  $lng->loadLanguageModule("administration");
50  $lng->loadLanguageModule("meta");
51 
52  // view mode ('translate' or empty) needed for prepareOutput()
53  $ilCtrl->saveParameter($this, "view_mode");
54 
55  // type and id of get the bound object
56  $this->type = "lng";
57  if (! $this->id = $_GET['obj_id'])
58  {
59  $this->id = ilObjLanguageAccess::_lookupId($lng->getUserLanguage());
60  }
61 
62  // do all generic GUI initialisations
63  $this->ilObjectGUI($a_data, $this->id, false, true);
64 
65  // initialize the array to store GUI session variables
66  if (!is_array($_SESSION[get_class($this)]))
67  {
68  $_SESSION[get_class($this)] = array();
69  }
70  $this->session =& $_SESSION[get_class($this)];
71 
72 
73  // read the lang mode
74  $this->langmode = $ilClientIniFile->readVariable("system","LANGMODE");
75  }
76 
77 
84  function assignObject()
85  {
86  require_once("Services/Language/classes/class.ilObjLanguageExt.php");
87  $this->object =& new ilObjLanguageExt($this->id);
88  }
89 
90 
94  function &executeCommand()
95  {
96  global $ilHelp;
97 
99  {
100  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
101  exit;
102  }
103 
104  $cmd = $this->ctrl->getCmd("view")."Object";
105  $this->$cmd();
106 
107  $ilHelp->setScreenIdComponent("lng");
108 // exit;
109  }
110 
111 
115  function cancelObject()
116  {
117  $this->viewObject();
118  }
119 
123  function viewObject()
124  {
125  global $ilUser;
126 
127  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_edit_items.html", "Services/Language");
128 
129  // set the language to compare with
130  $compare = $this->getPar('compare', $this->lng->getDefaultLanguage());
131 
132  // get the default values if the compare language is the same
133  if ($compare == $this->object->key)
134  {
135  $compare_object = $this->object->getGlobalLanguageFile();
136  $compare_content = $compare_object->getAllValues();
137  $compare_comments = $compare_object->getAllComments();
138  $compare_note = " ". $this->lng->txt("language_default_entries");
139  }
140 
141  // get the remarks in database
142  $remarks = $this->object->getAllRemarks();
143 
144  // page translation mode:
145  // - the table is filtered by a list of modules and topics
146  // - all found entries are shown on the same page
147  if ($this->_isPageTranslation())
148  {
149  $offset = 0;
150  $limit = 0;
151 
152  $modules = $this->getPar("page_modules", array());
153  $topics = $this->getPar("page_topics", array());
154 
155  if (!isset($compare_content))
156  {
157  $compare_content = ilObjLanguageExt::_getValues(
158  $compare, $modules, $topics);
159 
160  $compare_comments = ilObjLanguageExt::_getRemarks($compare);
161  }
162 
163  $translations = ilObjLanguageExt::_getValues(
164  $this->object->key, $modules, $topics);
165  }
166  // normal view mode:
167  // - the table is filtered manually by module, mode and pattern
168  // - found entries are paged by maximum list length
169  // - the filter selection is shown
170  else
171  {
172  $offset = $this->getPar('offset','0');
173  $limit = $ilUser->getPref("hits_per_page");
174 
175  $filter_mode = $this->getPar('filter_mode','all');
176  $filter_pattern = $this->getPar('filter_pattern','');
177  $filter_module = $this->getPar('filter_module','administration');
178  $filter_modules = $filter_module ? array($filter_module) : array();
179 
180  if (!isset($compare_content))
181  {
182  $compare_content = ilObjLanguageExt::_getValues(
183  $compare, $filter_modules);
184 
185  $compare_comments = ilObjLanguageExt::_getRemarks($compare);
186  }
187 
188  switch ($filter_mode)
189  {
190  case "changed":
191  $translations = $this->object->getChangedValues(
192  $filter_modules, $filter_pattern);
193  break;
194 
195  case "added": //langmode only
196  $translations = $this->object->getAddedValues(
197  $filter_modules, $filter_pattern);
198  break;
199 
200  case "unchanged":
201  $translations = $this->object->getUnchangedValues(
202  $filter_modules, $filter_pattern);
203  break;
204 
205  case "commented":
206  $translations = $this->object->getCommentedValues(
207  $filter_modules, $filter_pattern);
208  break;
209 
210  case "dbremarks":
211  $translations = $this->object->getAllValues(
212  $filter_modules, $filter_pattern);
213 
214  $translations = array_intersect_key($translations, $remarks);
215  break;
216 
217  case "equal":
218  $translations = $this->object->getAllValues(
219  $filter_modules, $filter_pattern);
220 
221  $translations = array_intersect_assoc($translations, $compare_content);
222  break;
223 
224  case "different":
225  $translations = $this->object->getAllValues(
226  $filter_modules, $filter_pattern);
227 
228  $translations = array_diff_assoc($translations, $compare_content);
229  break;
230 
231  case "conflicts":
232  $former_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
233  if (!is_readable($former_file))
234  {
235  ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file)
236  .'<br />'. $this->lng->txt("language_former_file_description") , false);
237  $translations = array();
238  break;
239  }
240  $global_file_obj = $this->object->getGlobalLanguageFile();
241  $former_file_obj = new ilLanguageFile($former_file);
242  $former_file_obj->read();
243  $global_changes = array_diff_assoc(
244  $global_file_obj->getAllValues(),
245  $former_file_obj->getAllValues());
246  if (!count($global_changes))
247  {
248  ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file)
249  .'<br />'. $this->lng->txt("language_former_file_description") , false);
250  $translations = array();
251  break;
252  }
253  $translations = $this->object->getChangedValues(
254  $filter_modules, $filter_pattern);
255 
256  $translations = array_intersect_key($translations, $global_changes);
257  break;
258 
259  case "all":
260  default:
261  $translations = $this->object->getAllValues(
262  $filter_modules, $filter_pattern);
263  }
264 
265  // show the filter section
266  $this->tpl->setCurrentBlock("filter");
267 
268  // filter by language module
269  $options = array();
270  $options[""] = $this->lng->txt("language_all_modules");
271  $modules = ilObjLanguageExt::_getModules($this->object->key);
272  foreach ($modules as $mod)
273  {
274  $options[$mod] = $mod;
275  }
276  $this->tpl->setVariable("SELECT_MODULE",
277  ilUtil::formSelect($filter_module, "filter_module", $options, false, true));
278 
279  // filter by mode
280  $options = array();
281  $options["all"] = $this->lng->txt("language_scope_global");
282  $options["changed"] = $this->lng->txt("language_scope_local");
283  if ($this->langmode)
284  {
285  $options["added"] = $this->lng->txt("language_scope_added");
286  }
287  $options["unchanged"] = $this->lng->txt("language_scope_unchanged");
288  $options["equal"] = $this->lng->txt("language_scope_equal");
289  $options["different"] = $this->lng->txt("language_scope_different");
290  $options["commented"] = $this->lng->txt("language_scope_commented");
291  if ($this->langmode)
292  {
293  $options["dbremarks"] = $this->lng->txt("language_scope_dbremarks");
294  }
295  $options["conflicts"] = $this->lng->txt("language_scope_conflicts");
296  $this->tpl->setVariable("SELECT_MODE",
297  ilUtil::formSelect($filter_mode, "filter_mode", $options, false, true));
298 
299  // filter by pattern
300  $this->tpl->setVariable("PATTERN_NAME", "filter_pattern");
301  $this->tpl->setVariable("PATTERN_VALUE", ilUtil::prepareFormOutput($filter_pattern));
302 
303  // and general filter variables
304  $this->tpl->setVariable("FILTER_ACTION", $this->ctrl->getFormAction($this));
305  $this->tpl->setVariable("TXT_FILTER", $this->lng->txt("filter"));
306  $this->tpl->setVariable("OFFSET_NAME", "offset");
307  $this->tpl->setVariable("OFFSET_VALUE", "0");
308  $this->tpl->setVariable("TXT_APPLY_FILTER", $this->lng->txt("apply_filter"));
309  $this->tpl->setVariable("CMD_FILTER", "view");
310  $this->tpl->parseCurrentBlock();
311  }
312 
313  // show the compare section
314  $this->tpl->setCurrentBlock("compare");
315  $this->tpl->setVariable("COMPARE_ACTION", $this->ctrl->getFormAction($this));
316  $this->tpl->setVariable("TXT_COMPARE", $this->lng->txt("language_compare"));
317  $this->tpl->setVariable("TXT_CHANGE", $this->lng->txt("change"));
318  $options = array();
319  $langlist = $this->lng->getInstalledLanguages();
320  foreach ($langlist as $lang_key)
321  {
322  $options[$lang_key] = $this->lng->txt("meta_l_".$lang_key);
323  }
324  $this->tpl->setVariable("SELECT_COMPARE",
325  ilUtil::formSelect($compare, "compare", $options, false, true,1));
326  $this->tpl->setVariable("CMD_COMPARE", "view");
327  $this->tpl->parseCurrentBlock();
328 
329  // prepare the dataset for the output table
330  $sort_by = $this->getPar('sort_by','translation');
331  $sort_order = $this->getPar('sort_order','asc');
332 
333  $list = array();
334  foreach($translations as $name => $translation)
335  {
336  $keys = explode($this->lng->separator, $name);
337  $data = array();
338 
339  $data["module"] = $keys[0];
340  $data["topic"] = $keys[1];
341  $data["name"] = $name;
342  $data["translation"] = $translation;
343  $data["default"] = $compare_content[$name];
344  $data["default_comment"] = $compare_comments[$name];
345 
346  $list[] = $data;
347  }
348  $list = ilUtil::sortArray($list, $sort_by, $sort_order);
349  if ($limit > 0)
350  {
351  $list = array_slice($list, $offset, $limit);
352  }
353 
354  // create and configure the table object
355  include_once 'Services/Table/classes/class.ilTableGUI.php';
356  $tbl = new ilTableGUI();
357 
358  $tbl->disable('title');
359 
360  $tbl->setHeaderNames(array($this->lng->txt("module"),
361  $this->lng->txt("identifier"),
362  $this->lng->txt("meta_l_".$this->object->key),
363  $this->lng->txt("meta_l_".$compare).$compare_note));
364 
365  $tbl->setHeaderVars(array("module",
366  "topic",
367  "translation",
368  "default"),
369  $this->ctrl->getParameterArray($this));
370 
371 
372  $tbl->setColumnWidth(array( "10%",
373  "20%",
374  "40%",
375  "30%"));
376 
377  $tbl->setOrderColumn($sort_by);
378  $tbl->setOrderDirection($sort_order);
379  $tbl->setLimit($limit);
380  $tbl->setOffset($offset);
381  $tbl->setMaxCount(count($translations));
382 
383 
384  // prepare the table template
385  $tpl =& new ilTemplate("tpl.table.html", true, true);
386  $tpl->setCurrentBlock("tbl_form_header");
387  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
388  $tpl->parseCurrentBlock();
389 
390  $tpl->setCurrentBlock("tbl_action_btn");
391  $tpl->setVariable("BTN_NAME",'save');
392  $tpl->setVariable("BTN_VALUE",$this->lng->txt('save'));
393  $tpl->parseCurrentBlock();
394 
395  $tpl->setCurrentBlock("tbl_action_row");
396  $tpl->setVariable("COLUMN_COUNTS","4");
397  $tpl->parseCurrentBlock();
398 
399  // render the table rows
400  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.lang_items_row.html", "Services/Language");
401  foreach ($list as $data)
402  {
403  if ($this->langmode)
404  {
405  $tpl->setCurrentBlock('comment');
406  $tpl->setVariable("COM_ID", ilUtil::prepareFormOutput($data["name"].$this->lng->separator."comment"));
407  $tpl->setVariable("COM_NAME", ilUtil::prepareFormOutput($data["name"].$this->lng->separator."comment"));
408  $tpl->setVariable("COM_VALUE", ilUtil::prepareFormOutput($remarks[$data["name"]]));
409  $tpl->setVariable("COM_SIZE", $this->commentsize);
410  $tpl->setVariable("COM_MAX", 250);
411  $tpl->setVariable("TXT_COMMENT", $this->lng->txt('comment'));
412  $tpl->parseCurrentBlock();
413  }
414  else
415  {
416  $tpl->setCurrentBlock('hidden_comment');
417  $tpl->setVariable("COM_NAME", ilUtil::prepareFormOutput($data["name"].$this->lng->separator."comment"));
418  $tpl->setVariable("COM_VALUE", ilUtil::prepareFormOutput($remarks[$data["name"]]));
419  $tpl->parseCurrentBlock();
420  }
421 
422  $tpl->setCurrentBlock("row");
423  $tpl->setVariable("T_ROWS", ceil(strlen($data["translation"]) / $this->inputsize));
424  $tpl->setVariable("T_SIZE", $this->inputsize);
425  $tpl->setVariable("T_NAME", ilUtil::prepareFormOutput($data["name"]));
426  $tpl->setVariable("T_USER_VALUE", ilUtil::prepareFormOutput($data["translation"]));
427 
428  $tpl->setVariable("MODULE", ilUtil::prepareFormOutput($data["module"]));
429  $tpl->setVariable("TOPIC", ilUtil::prepareFormOutput($data["topic"]));
430  $tpl->setVariable("DEFAULT_VALUE", ilUtil::prepareFormOutput($data["default"]));
431  $tpl->setVariable("COMMENT", ilUtil::prepareFormOutput($data["default_comment"]));
432  $tpl->parseCurrentBlock();
433  }
434 
435  // render and show the table
436  $tbl->setTemplate($tpl);
437  $tbl->render();
438  $this->tpl->setVariable("TRANSLATION_TABLE", $tpl->get());
439 // $this->tpl->show();
440  }
441 
442 
446  function saveObject()
447  {
448  // prepare the values to be saved
449  $save_array = array();
450  $remarks_array = array();
451  foreach ($_POST as $key => $value)
452  {
453  $keys = explode($this->lng->separator, ilUtil::stripSlashes($key, false));
454 
455  if (count($keys) == 2)
456  {
457  // avoid line breaks
458  $value = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$value);
459  $value = ilUtil::stripSlashes($value, false);
460  $save_array[$key] = $value;
461 
462  $remarks_array[$key] = $_POST[$key.$this->lng->separator."comment"];
463  }
464  }
465 
466  // save the translations
467  ilObjLanguageExt::_saveValues($this->object->key, $save_array, $remarks_array);
468 
469  // view the list
470  $this->viewObject();
471  }
472 
473 
477  function importObject()
478  {
479  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_import.html", "Services/Language");
480 
481  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
482  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_import_file"));
483  $this->tpl->setVariable("TXT_FILE",$this->lng->txt("file"));
484 
485  $this->tpl->setVariable("TXT_MODE",$this->lng->txt("language_mode_existing"));
486  $this->tpl->setVariable("TXT_MODE_KEEPALL",$this->lng->txt("language_mode_existing_keepall"));
487  $this->tpl->setVariable("TXT_MODE_KEEPNEW",$this->lng->txt("language_mode_existing_keepnew"));
488  $this->tpl->setVariable("TXT_MODE_REPLACE",$this->lng->txt("language_mode_existing_replace"));
489  $this->tpl->setVariable("TXT_MODE_DELETE",$this->lng->txt("language_mode_existing_delete"));
490 
491  $this->tpl->setVariable("TXT_UPLOAD",$this->lng->txt("upload"));
492  $this->tpl->setVariable("CMD_UPLOAD","upload");
493 // $this->tpl->show();
494  }
495 
496 
500  function uploadObject()
501  {
502  if ($_POST['cmd']['upload'])
503  {
504  $file = $_FILES['userfile']['tmp_name'].'x';
505 
506  if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'],
507  $_FILES['userfile']['name'],
508  $file))
509  {
510  $this->object->importLanguageFile($file,$_POST['mode_existing']);
511  ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']) , false);
512  $this->importObject();
513  }
514  else
515  {
516  $this->importObject();
517  }
518  }
519  else
520  {
521  $this->cancelObject();
522  }
523  }
524 
525 
529  function exportObject()
530  {
531  $scope = $_POST["scope"] ? $_POST["scope"] : "global";
532 
533  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_export.html", "Services/Language");
534 
535  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
536  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_export_file"));
537 
538  $this->tpl->setVariable("TXT_SCOPE",$this->lng->txt("language_file_scope"));
539  $this->tpl->setVariable("TXT_SCOPE_GLOBAL",$this->lng->txt("language_scope_global"));
540  $this->tpl->setVariable("TXT_SCOPE_LOCAL",$this->lng->txt("language_scope_local"));
541  $this->tpl->setVariable("TXT_SCOPE_UNCHANGED",$this->lng->txt("language_scope_unchanged"));
542 
543  $this->tpl->setVariable("CHECKED_GLOBAL",$scope == 'global' ? 'checked="checked"' : '');
544  $this->tpl->setVariable("CHECKED_LOCAL",$scope == 'local' ? 'checked="checked"' : '');
545  $this->tpl->setVariable("CHECKED_UNCHANGED",$scope == 'unchanged' ? 'checked="checked"' : '');
546 
547  if ($this->langmode)
548  {
549  $this->tpl->setVariable("TXT_SCOPE_ADDED",$this->lng->txt("language_scope_added"));
550  $this->tpl->setVariable("CHECKED_ADDED",$scope == 'added' ? 'checked="checked"' : '');
551 
552  $this->tpl->setVariable("TXT_SCOPE_MERGED",$this->lng->txt("language_scope_merged"));
553  $this->tpl->setVariable("CHECKED_MERGED",$scope == 'merged' ? 'checked="checked"' : '');
554  }
555 
556  $this->tpl->setVariable("TXT_DOWNLOAD",$this->lng->txt("download"));
557  $this->tpl->setVariable("CMD_DOWNLOAD","download");
558 // $this->tpl->show();
559  }
560 
561 
565  function downloadObject()
566  {
567  $filename = 'ilias_' . $this->object->key . '_'
568  . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
569  . "-" . date('Y-m-d')
570  . ".lang.".$_POST["scope"];
571 
572  $global_file_obj = $this->object->getGlobalLanguageFile();
573  $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
574 
575  if ($_POST["scope"] == 'global')
576  {
577  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
578  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
579  $local_file_obj->setAllValues($this->object->getAllValues());
580  if ($this->langmode)
581  {
582  $local_file_obj->setAllComments($this->object->getAllRemarks());
583  }
584  }
585  elseif ($_POST["scope"] == 'local')
586  {
587  $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
588  $local_file_obj->setAllValues($this->object->getChangedValues());
589  if ($this->langmode)
590  {
591  $local_file_obj->setAllComments($this->object->getAllRemarks());
592  }
593  }
594  elseif ($_POST["scope"] == 'added') // langmode only
595  {
596  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
597  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
598  $local_file_obj->setAllValues($this->object->getAddedValues());
599  $local_file_obj->setAllComments($this->object->getAllRemarks());
600  }
601  elseif ($_POST["scope"] == 'unchanged')
602  {
603  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
604  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
605  $local_file_obj->setAllValues($this->object->getUnchangedValues());
606  if ($this->langmode)
607  {
608  $local_file_obj->setAllComments($this->object->getAllRemarks());
609  }
610  }
611  elseif ($_POST["scope"] == 'merged') // langmode only
612  {
613  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
614  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
615  $local_file_obj->setAllValues($this->object->getMergedValues());
616  $local_file_obj->setAllComments($this->object->getMergedRemarks());
617  }
618 
619  ilUtil::deliverData($local_file_obj->build(), $filename);
620  }
621 
622 
626  function maintainObject()
627  {
628  global $ilUser;
629 
630  switch ($_POST["maintain"])
631  {
632  // save the local changes to the local language file
633  case "save":
634  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
635 
636  if ((is_file($lang_file) and is_writable($lang_file))
637  or (!file_exists($lang_file) and is_writable($this->object->getCustLangPath())))
638  {
639  // save a copy of the distributed language file
640  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
641  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
642  @copy($orig_file, $copy_file);
643 
644  // save a backup of the old local language file
645  @rename($lang_file, $lang_file.".bak");
646 
647  // create and write the new local language file
648  $global_file_obj = $this->object->getGlobalLanguageFile();
649  $local_file_obj = new ilLanguageFile($lang_file, $this->object->key, 'local');
650  $local_file_obj->setParam('based_on', $global_file_obj->getParam('version'));
651  $local_file_obj->setAllValues($this->object->getChangedValues());
652  if ($this->langmode)
653  {
654  $local_file_obj->setAllComments($this->object->getAllRemarks());
655  }
656  $local_file_obj->write();
657 
658  $this->object->setLocal(true);
659  ilUtil::sendSuccess($this->lng->txt("language_saved_local") , false);
660  }
661  else
662  {
663  ilUtil::sendFailure($this->lng->txt("language_error_write_local") , false);
664  }
665  break;
666 
667  // load the content of the local language file
668  case "load":
669  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
670  if (is_file($lang_file) and is_readable($lang_file))
671  {
672  $this->object->importLanguageFile($lang_file, 'replace');
673  $this->object->setLocal(true);
674  ilUtil::sendSuccess($this->lng->txt("language_loaded_local") , false);
675  }
676  else
677  {
678  ilUtil::sendFailure($this->lng->txt("language_error_read_local") , false);
679  }
680  break;
681 
682  // revert the database to the default language file
683  case "clear":
684  $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
685  if (is_file($lang_file) and is_readable($lang_file))
686  {
687  $this->object->importLanguageFile($lang_file, 'delete');
688  $this->object->setLocal(false);
689  ilUtil::sendSuccess($this->lng->txt("language_cleared_local") , false);
690  }
691  else
692  {
693  ilUtil::sendFailure($this->lng->txt("language_error_clear_local") , false);
694  }
695  break;
696 
697  // delete local additions in the datavase (langmode only)
698  case "delete_added":
699  ilObjLanguageExt::_deleteValues($this->object->key, $this->object->getAddedValues());
700  break;
701 
702  // merge local changes back to the global language file (langmode only)
703  case "merge":
704 
705  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
706  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
707 
708  if (is_file($orig_file) and is_writable($orig_file))
709  {
710  // save a copy of the global language file
711  @copy($orig_file, $copy_file);
712 
713  // modify and write the new global file
714  $global_file_obj = $this->object->getGlobalLanguageFile();
715  $global_file_obj->setAllValues($this->object->getMergedValues());
716  $global_file_obj->setAllComments($this->object->getMergedRemarks());
717  $global_file_obj->write();
718  ilUtil::sendSuccess($this->lng->txt("language_merged_global") , false);
719  }
720  else
721  {
722  ilUtil::sendFailure($this->lng->txt("language_error_write_global") , false);
723  }
724  break;
725 
726  // remove the local language file (langmode only)
727  case "remove_local_file":
728  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
729 
730  if (!is_file($lang_file))
731  {
732  $this->object->setLocal(false);
733  ilUtil::sendFailure($this->lng->txt("language_error_local_missed") , false);
734  }
735  elseif (@unlink($lang_file))
736  {
737  $this->object->setLocal(false);
738  ilUtil::sendSuccess($this->lng->txt("language_local_file_deleted") , false);
739  }
740  else
741  {
742  ilUtil::sendFailure($this->lng->txt("language_error_delete_local") , false);
743  }
744  break;
745 
746  }
747 
748  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_maintenance.html", "Services/Language");
749  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
750  $this->tpl->setVariable("TXT_MAINTENANCE",$this->lng->txt("language_maintenance"));
751  $this->tpl->setVariable("TXT_MAINTAIN_LOCAL",$this->lng->txt("language_maintain_local_changes"));
752  $this->tpl->setVariable("TXT_SELECT",$this->lng->txt("please_select"));
753  $this->tpl->setVariable("TXT_SAVE",$this->lng->txt("language_save_local_changes"));
754  $this->tpl->setVariable("TXT_LOAD",$this->lng->txt("language_load_local_changes"));
755  $this->tpl->setVariable("TXT_CLEAR",$this->lng->txt("language_clear_local_changes"));
756  if ($this->langmode)
757  {
758  $this->tpl->setVariable("TXT_DELETE_ADDED",$this->lng->txt("language_delete_local_additions"));
759  $this->tpl->setVariable("TXT_MERGE",$this->lng->txt("language_merge_local_changes"));
760  $this->tpl->setVariable("TXT_REMOVE_LOCAL_FILE",$this->lng->txt("language_remove_local_file"));
761  }
762  $this->tpl->setVariable("TXT_NOTE_SAVE",$this->lng->txt("language_note_save_local"));
763  $this->tpl->setVariable("TXT_MAINTAIN",$this->lng->txt("language_process_maintenance"));
764  $this->tpl->setVariable("VAR_MAINTAIN", "maintain");
765  $this->tpl->setVariable("CMD_MAINTAIN", "maintain");
766 // $this->tpl->show();
767  }
768 
772  function settingsObject()
773  {
774  global $ilSetting;
775 
776  $translate_key = "lang_translate_". $this->object->key;
777 
778  // save and get the page translation setting
779  switch ($_POST["translation"])
780  {
781  case "enable":
782  $ilSetting->set($translate_key, true);
783  break;
784  case "disable":
785  $ilSetting->set($translate_key, false);
786  }
787  $translate = $ilSetting->get($translate_key, false);
788 
789  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_settings.html", "Services/Language");
790 
791  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
792  $this->tpl->setVariable("TXT_SETTINGS",$this->lng->txt("language_settings"));
793  $this->tpl->setVariable("TXT_TRANSLATION",$this->lng->txt("language_translation_mode"));
794  $this->tpl->setVariable("TXT_TRANSLATION_ENABLED",$this->lng->txt("language_translation_enabled"));
795  $this->tpl->setVariable("TXT_TRANSLATION_DISABLED",$this->lng->txt("language_translation_disabled"));
796  $this->tpl->setVariable("CHECKED_ENABLE", $translate ? 'checked="checked"': '');
797  $this->tpl->setVariable("CHECKED_DISABLE", $translate ? '' : 'checked="checked"');
798  $this->tpl->setVariable("TXT_NOTE_TRANSLATION",$this->lng->txt("language_note_translation"));
799  $this->tpl->setVariable("TXT_CHANGE_SETTINGS",$this->lng->txt("language_change_settings"));
800  $this->tpl->setVariable("CMD_SETTINGS", "settings");
801 // $this->tpl->show();
802  }
803 
807  function statisticsObject()
808  {
809  $modules = ilObjLanguageExt::_getModules($this->object->key);
810 
811  $data = array();
812  $total = array("",0,0,0);
813  foreach($modules as $module)
814  {
815  $row = array();
816  $row[0] = $module;
817  $row[1] = count($this->object->getAllValues(array($module)));
818  $row[2] = count($this->object->getChangedValues(array($module)));
819  $row[3] = $row[1]-$row[2];
820  $total[1] += $row[1];
821  $total[2] += $row[2];
822  $total[3] += $row[3];
823  $data[] = $row;
824  }
825  $total[0] = "<b>".$this->lng->txt("language_all_modules")."</b>";
826  $total[1] = "<b>".$total[1]."</b>";
827  $total[2] = "<b>".$total[2]."</b>";
828  $total[3] = "<b>".$total[3]."</b>";
829  $data[] = $total;
830 
831  // prepare the templates for output
832  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_statistics.html", "Services/Language");
833  $this->tpl->addBlockFile("TABLE_STATISTICS", "table_statistics", "tpl.table.html");
834  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
835 
836  // create and configure the table object
837  include_once 'Services/Table/classes/class.ilTableGUI.php';
838  $tbl = new ilTableGUI();
839  $tbl->disable('title');
840  $tbl->disable('sort');
841  $tbl->disable('numinfo');
842 
843  $tbl->setHeaderNames(array($this->lng->txt("module"),
844  $this->lng->txt("language_scope_global"),
845  $this->lng->txt("language_scope_local"),
846  $this->lng->txt("language_scope_unchanged")));
847  $tbl->setColumnWidth(array( "25%", "25%", "25%", "25%"));
848  $tbl->setLimit(count($data));
849  $tbl->setData($data);
850 
851  // show the table
852  $tbl->render();
853 // $this->tpl->show();
854  }
855 
856 
866  function getPar($a_request_name, $a_default_value)
867  {
868  // get the parameter value
869  if (isset($_GET[$a_request_name]))
870  {
871  $param = $_GET[$a_request_name];
872  $from_request = true;
873  }
874  elseif (isset($_POST[$a_request_name]))
875  {
876  $param = $_POST[$a_request_name];
877  $from_request = true;
878  }
879  elseif (isset($this->session[$a_request_name]))
880  {
881  $param = $this->session[$a_request_name];
882  $from_request = false;
883  }
884  else
885  {
886  $param = $a_default_value;
887  $from_request = false;
888  }
889 
890  // strip slashes from request parameters
891  if ($from_request)
892  {
893  if (is_array($param))
894  {
895  foreach ($param as $key => $value)
896  {
897  $param[$key] = ilUtil::stripSlashes($value);
898  }
899  }
900  else
901  {
902  $param = ilUtil::stripSlashes($param);
903  }
904  }
905 
906  // make the parameter available to further requests
907  $this->session[$a_request_name] = $param;
908 
909  return $param;
910  }
911 
916  function getAdminTabs(&$tabs_gui)
917  {
918  global $rbacsystem;
919 
920  $tabs_gui->addTarget("edit",
921  $this->ctrl->getLinkTarget($this, "view"),
922  array("","view","cancel","save"));
923 
924  $tabs_gui->addTarget("export",
925  $this->ctrl->getLinkTarget($this, "export"),
926  array("export","download"));
927 
928  $tabs_gui->addTarget("import",
929  $this->ctrl->getLinkTarget($this, "import"),
930  array("import","upload"));
931 
932  $tabs_gui->addTarget("language_maintain",
933  $this->ctrl->getLinkTarget($this, "maintain"),
934  array("maintain"));
935 
936  $tabs_gui->addTarget("settings",
937  $this->ctrl->getLinkTarget($this, "settings"),
938  array("settings"));
939 
940  $tabs_gui->addTarget("language_statistics",
941  $this->ctrl->getLinkTarget($this, "statistics"),
942  array("statistics"));
943  }
944 
945 
950  function prepareOutput()
951  {
952  if ($this->_isPageTranslation())
953  {
954  // show the pure translation page without menu, tabs etc.
955  $this->tpl->addBlockFile("CONTENT","content","tpl.adm_translate.html","Services/Language");
956  $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
957  $this->tpl->setTitle($this->lng->txt("translation"). " "
958  .$this->lng->txt("meta_l_".$this->object->key));
959  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lng_b.png"),
960  $this->lng->txt("obj_" . $this->object->getType()));
961  }
962  else
963  {
964  // show the full page framework
966  }
967  }
968 
969 
975  {
976  global $ilLocator, $tpl;
977 
978  $ilLocator->addItem($this->lng->txt("administration"),
979  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
980  ilFrameTargetInfo::_getFrame("MainContent"));
981 
982  $ilLocator->addItem($this->lng->txt("languages"),
983  $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", ""));
984 
985  $ilLocator->addItem($this->lng->txt("meta_l_". $this->object->getTitle()),
986  $this->ctrl->getLinkTarget($this, "view"));
987  }
988 
989 
995  {
996  $this->tpl->setTitle($this->lng->txt("meta_l_".$this->object->getTitle()));
997  // $this->tpl->setDescription($this->object->getLongDescription());
998  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.png"), $this->lng->txt("obj_" . $this->object->getType()));
999  }
1000 
1001 
1002  //
1003  // STATIC FUNCTIONS
1004  //
1005 
1018  public static function _isPageTranslation()
1019  {
1020  return ($_GET['view_mode'] == "translate");
1021  }
1022 
1023 
1032  public static function _getTranslationLink()
1033  {
1034  global $ilSetting, $lng;
1035 
1036  // prevent translation link on translation screen
1037  // check setting of translation mode
1038  if (self::_isPageTranslation()
1039  or !$ilSetting->get("lang_translate_".$lng->getLangKey()))
1040  {
1041  return "";
1042  }
1043 
1044  // set the target for translation
1045  // ref id must be given to prevent params being deleted by ilAdministrtionGUI
1046  $action = "ilias.php"
1047  ."?ref_id=".ilobjLanguageAccess::_lookupLangFolderRefId()
1048  ."&baseClass=ilAdministrationGUI"
1049  ."&cmdClass=ilobjlanguageextgui"
1050  ."&view_mode=translate";
1051 
1052  $tpl = new ilTemplate("tpl.translation_link.html",true,true, "Services/Language");
1053 
1054  foreach($lng->getUsedModules() as $module => $dummy)
1055  {
1056  $tpl->setCurrentBlock("hidden");
1057  $tpl->setVariable("NAME", "page_modules[]");
1058  $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($module));
1059  $tpl->parseCurrentBlock();
1060  }
1061 
1062  foreach($lng->getUsedTopics() as $topic => $dummy)
1063  {
1064  $tpl->setCurrentBlock("hidden");
1065  $tpl->setVariable("NAME", "page_topics[]");
1066  $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($topic));
1067  $tpl->parseCurrentBlock();
1068  }
1069 
1070  $tpl->setVariable("ACTION", $action);
1071  $tpl->setVariable("TXT_TRANSLATE",$lng->txt("translation"));
1072 
1073  return $tpl->get();
1074  }
1075 
1076 
1077 } // END class.ilObjLanguageExtGUI
1078 ?>