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