ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjLanguageExtGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define("ILIAS_LANGUAGE_MODULE", "Services/Language");
25 
26 require_once("classes/class.ilObjectGUI.php");
27 require_once("Services/Language/classes/class.ilObjLanguageAccess.php");
28 
29 
45 {
50  private $inputsize = 40;
51 
63  function ilObjLanguageExtGUI($a_data, $a_id = 0, $a_call_by_reference = false)
64  {
65  global $lng, $ilCtrl;
66 
67  // language maintenance strings are defined in administration
68  $lng->loadLanguageModule("administration");
69  $lng->loadLanguageModule("meta");
70 
71  // view mode ('translate' or empty) needed for prepareOutput()
72  $ilCtrl->saveParameter($this, "view_mode");
73 
74  // type and id of get the bound object
75  $this->type = "lng";
76  if (! $this->id = $_GET['obj_id'])
77  {
78  $this->id = ilObjLanguageAccess::_lookupId($lng->getUserLanguage());
79  }
80 
81  // do all generic GUI initialisations
82  $this->ilObjectGUI($a_data, $this->id, false, true);
83 
84  // initialize the array to store GUI session variables
85  if (!is_array($_SESSION[get_class($this)]))
86  {
87  $_SESSION[get_class($this)] = array();
88  }
89  $this->session =& $_SESSION[get_class($this)];
90  }
91 
92 
99  function assignObject()
100  {
101  require_once("Services/Language/classes/class.ilObjLanguageExt.php");
102  $this->object =& new ilObjLanguageExt($this->id);
103  }
104 
105 
109  function &executeCommand()
110  {
112  {
113  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
114  exit;
115  }
116 
117  $cmd = $this->ctrl->getCmd("view")."Object";
118  $this->$cmd();
119  exit;
120  }
121 
122 
126  function cancelObject()
127  {
128  ilUtil::sendInfo($this->lng->txt("action_aborted"), false);
129  $this->viewObject();
130  }
131 
135  function viewObject()
136  {
137  global $ilUser;
138 
139  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_edit_items.html", "Services/Language");
140 
141  // set the language to compare with
142  $compare = $this->getPar('compare', $this->lng->getDefaultLanguage());
143 
144  // get the default values if the compare language is the same
145  if ($compare == $this->object->key)
146  {
147  $compare_object = $this->object->getGlobalLanguageFile();
148  $compare_content = $compare_object->getAllValues();
149  $compare_comments = $compare_object->getAllComments();
150  $compare_note = " ". $this->lng->txt("language_default_entries");
151  }
152 
153  // page translation mode:
154  // - the table is filtered by a list of modules and topics
155  // - all found entries are shown on the same page
156  if ($this->_isPageTranslation())
157  {
158  $offset = 0;
159  $limit = 0;
160 
161  $modules = $this->getPar("page_modules", array());
162  $topics = $this->getPar("page_topics", array());
163 
164  if (!isset($compare_content))
165  {
166  $compare_content = ilObjLanguageExt::_getValues(
167  $compare, $modules, $topics);
168  }
169 
170  $translations = ilObjLanguageExt::_getValues(
171  $this->object->key, $modules, $topics);
172  }
173  // normal view mode:
174  // - the table is filtered manually by module, mode and pattern
175  // - found entries are paged by maximum list length
176  // - the filter selection is shown
177  else
178  {
179  $offset = $this->getPar('offset','0');
180  $limit = $ilUser->getPref("hits_per_page");
181 
182  $filter_mode = $this->getPar('filter_mode','all');
183  $filter_pattern = $this->getPar('filter_pattern','');
184  $filter_module = $this->getPar('filter_module','administration');
185  $filter_modules = $filter_module ? array($filter_module) : array();
186 
187  if (!isset($compare_content))
188  {
189  $compare_content = ilObjLanguageExt::_getValues(
190  $compare, $filter_modules);
191  }
192 
193  switch ($filter_mode)
194  {
195  case "changed":
196  $translations = $this->object->getChangedValues(
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 "equal":
211  $translations = $this->object->getAllValues(
212  $filter_modules, $filter_pattern);
213 
214  $translations = array_intersect_assoc($translations, $compare_content);
215  break;
216 
217  case "different":
218  $translations = $this->object->getAllValues(
219  $filter_modules, $filter_pattern);
220 
221  $translations = array_diff_assoc($translations, $compare_content);
222  break;
223 
224  case "conflicts":
225  $former_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
226  if (!is_readable($former_file))
227  {
228  ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_missing"), $former_file)
229  .'<br />'. $this->lng->txt("language_former_file_description") , false);
230  $translations = array();
231  break;
232  }
233  $global_file_obj = $this->object->getGlobalLanguageFile();
234  $former_file_obj = new ilLanguageFile($former_file);
235  $former_file_obj->read();
236  $global_changes = array_diff_assoc(
237  $global_file_obj->getAllValues(),
238  $former_file_obj->getAllValues());
239  if (!count($global_changes))
240  {
241  ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file)
242  .'<br />'. $this->lng->txt("language_former_file_description") , false);
243  $translations = array();
244  break;
245  }
246  $translations = $this->object->getChangedValues(
247  $filter_modules, $filter_pattern);
248 
249  $translations = array_intersect_key($translations, $global_changes);
250  break;
251 
252  case "all":
253  default:
254  $translations = $this->object->getAllValues(
255  $filter_modules, $filter_pattern);
256  }
257 
258  // show the filter section
259  $this->tpl->setCurrentBlock("filter");
260 
261  // filter by language module
262  $options = array();
263  $options[""] = $this->lng->txt("language_all_modules");
264  $modules = ilObjLanguageExt::_getModules($this->object->key);
265  foreach ($modules as $mod)
266  {
267  $options[$mod] = $mod;
268  }
269  $this->tpl->setVariable("SELECT_MODULE",
270  ilUtil::formSelect($filter_module, "filter_module", $options, false, true));
271 
272  // filter by mode
273  $options = array();
274  $options["all"] = $this->lng->txt("language_scope_global");
275  $options["changed"] = $this->lng->txt("language_scope_local");
276  $options["unchanged"] = $this->lng->txt("language_scope_unchanged");
277  $options["equal"] = $this->lng->txt("language_scope_equal");
278  $options["different"] = $this->lng->txt("language_scope_different");
279  $options["commented"] = $this->lng->txt("language_scope_commented");
280  $options["conflicts"] = $this->lng->txt("language_scope_conflicts");
281  $this->tpl->setVariable("SELECT_MODE",
282  ilUtil::formSelect($filter_mode, "filter_mode", $options, false, true));
283 
284  // filter by pattern
285  $this->tpl->setVariable("PATTERN_NAME", "filter_pattern");
286  $this->tpl->setVariable("PATTERN_VALUE", ilUtil::prepareFormOutput($filter_pattern));
287 
288  // and general filter variables
289  $this->tpl->setVariable("FILTER_ACTION", $this->ctrl->getFormAction($this));
290  $this->tpl->setVariable("TXT_FILTER", $this->lng->txt("filter"));
291  $this->tpl->setVariable("OFFSET_NAME", "offset");
292  $this->tpl->setVariable("OFFSET_VALUE", "0");
293  $this->tpl->setVariable("TXT_APPLY_FILTER", $this->lng->txt("apply_filter"));
294  $this->tpl->setVariable("CMD_FILTER", "view");
295  $this->tpl->parseCurrentBlock();
296  }
297 
298  // show the compare section
299  $this->tpl->setCurrentBlock("compare");
300  $this->tpl->setVariable("COMPARE_ACTION", $this->ctrl->getFormAction($this));
301  $this->tpl->setVariable("TXT_COMPARE", $this->lng->txt("language_compare"));
302  $this->tpl->setVariable("TXT_CHANGE", $this->lng->txt("change"));
303  $options = array();
304  $langlist = $this->lng->getInstalledLanguages();
305  foreach ($langlist as $lang_key)
306  {
307  $options[$lang_key] = $this->lng->txt("meta_l_".$lang_key);
308  }
309  $this->tpl->setVariable("SELECT_COMPARE",
310  ilUtil::formSelect($compare, "compare", $options, false, true,1));
311  $this->tpl->setVariable("CMD_COMPARE", "view");
312  $this->tpl->parseCurrentBlock();
313 
314  // prepare the dataset for the output table
315  $sort_by = $this->getPar('sort_by','translation');
316  $sort_order = $this->getPar('sort_order','asc');
317 
318  $list = array();
319  foreach($translations as $name => $translation)
320  {
321  $keys = explode("#:#", $name);
322  $data = array();
323 
324  $data["module"] = $keys[0];
325  $data["topic"] = str_replace('_', ' ', $keys[1]);
326  $data["name"] = $name;
327  $data["translation"] = $translation;
328  $data["default"] = $compare_content[$name];
329  $data["comment"] = $compare_comments[$name];
330 
331  $list[] = $data;
332  }
333  $list = ilUtil::sortArray($list, $sort_by, $sort_order);
334  if ($limit > 0)
335  {
336  $list = array_slice($list, $offset, $limit);
337  }
338 
339  // create and configure the table object
340  include_once 'Services/Table/classes/class.ilTableGUI.php';
341  $tbl = new ilTableGUI();
342 
343  $tbl->disable('title');
344 
345  $tbl->setHeaderNames(array($this->lng->txt("module"),
346  $this->lng->txt("identifier"),
347  $this->lng->txt("meta_l_".$this->object->key),
348  $this->lng->txt("meta_l_".$compare).$compare_note));
349 
350  $tbl->setHeaderVars(array("module",
351  "topic",
352  "translation",
353  "default"),
354  $this->ctrl->getParameterArray($this));
355 
356 
357  $tbl->setColumnWidth(array( "10%",
358  "20%",
359  "40%",
360  "30%"));
361 
362  $tbl->setOrderColumn($sort_by);
363  $tbl->setOrderDirection($sort_order);
364  $tbl->setLimit($limit);
365  $tbl->setOffset($offset);
366  $tbl->setMaxCount(count($translations));
367 
368 
369  // prepare the table template
370  $tpl =& new ilTemplate("tpl.table.html", true, true);
371  $tpl->setCurrentBlock("tbl_form_header");
372  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
373  $tpl->parseCurrentBlock();
374 
375  $tpl->setCurrentBlock("tbl_action_btn");
376  $tpl->setVariable("BTN_NAME",'save');
377  $tpl->setVariable("BTN_VALUE",$this->lng->txt('save'));
378  $tpl->parseCurrentBlock();
379 
380  $tpl->setCurrentBlock("tbl_action_row");
381  $tpl->setVariable("COLUMN_COUNTS","4");
382  $tpl->parseCurrentBlock();
383 
384  // render the table rows
385  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.lang_items_row.html", "Services/Language");
386  foreach ($list as $data)
387  {
388  if (strlen($data["translation"]) <= $this->inputsize)
389  {
390  $tpl->setCurrentBlock("input");
391  $tpl->setVariable("I_NAME", ilUtil::prepareFormOutput($data["name"]));
392  $tpl->setVariable("I_SIZE", $this->inputsize);
393  $tpl->setVariable("I_USER_VALUE", ilUtil::prepareFormOutput($data["translation"]));
394  }
395  else
396  {
397  $tpl->setCurrentBlock("textarea");
398  $tpl->setVariable("T_ROWS", ceil(strlen($data["translation"]) / $this->inputsize));
399  $tpl->setVariable("T_SIZE", $this->inputsize);
400  $tpl->setVariable("T_NAME", ilUtil::prepareFormOutput($data["name"]));
401  $tpl->setVariable("T_USER_VALUE", ilUtil::prepareFormOutput($data["translation"]));
402  $tpl->parseCurrentBlock();
403  }
404 
405  $tpl->setCurrentBlock("row");
406  $tpl->setVariable("MODULE", ilUtil::prepareFormOutput($data["module"]));
407  $tpl->setVariable("TOPIC", ilUtil::prepareFormOutput($data["topic"]));
408  $tpl->setVariable("DEFAULT_VALUE", ilUtil::prepareFormOutput($data["default"]));
409  $tpl->setVariable("COMMENT", ilUtil::prepareFormOutput($data["comment"]));
410  $tpl->parseCurrentBlock();
411  }
412 
413  // render and show the table
414  $tbl->setTemplate($tpl);
415  $tbl->render();
416  $this->tpl->setVariable("TRANSLATION_TABLE", $tpl->get());
417  $this->tpl->show();
418  }
419 
420 
424  function saveObject()
425  {
426  // prepare the values to be saved
427  $save_array = array();
428  foreach ($_POST as $key => $value)
429  {
430  $keys = explode("#:#", ilUtil::stripSlashes($key, false));
431  if (count($keys) == 2)
432  {
433  // avoid line breaks
434  $value = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$value);
435  $value = ilUtil::stripSlashes($value, false);
436  $save_array[$key] = $value;
437  }
438  }
439 
440  // save the translations
441  ilObjLanguageExt::_saveValues($this->object->key, $save_array);
442 
443  // view the list
444  $this->viewObject();
445  }
446 
447 
451  function importObject()
452  {
453  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_import.html", "Services/Language");
454 
455  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
456  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_import_file"));
457  $this->tpl->setVariable("TXT_FILE",$this->lng->txt("file"));
458 
459  $this->tpl->setVariable("TXT_MODE",$this->lng->txt("language_mode_existing"));
460  $this->tpl->setVariable("TXT_MODE_KEEPALL",$this->lng->txt("language_mode_existing_keepall"));
461  $this->tpl->setVariable("TXT_MODE_KEEPNEW",$this->lng->txt("language_mode_existing_keepnew"));
462  $this->tpl->setVariable("TXT_MODE_REPLACE",$this->lng->txt("language_mode_existing_replace"));
463  $this->tpl->setVariable("TXT_MODE_DELETE",$this->lng->txt("language_mode_existing_delete"));
464 
465  $this->tpl->setVariable("TXT_UPLOAD",$this->lng->txt("upload"));
466  $this->tpl->setVariable("CMD_UPLOAD","upload");
467  $this->tpl->show();
468  }
469 
470 
474  function uploadObject()
475  {
476  if ($_POST['cmd']['upload'])
477  {
478  $file = $_FILES['userfile']['tmp_name'].'x';
479 
480  if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'],
481  $_FILES['userfile']['name'],
482  $file))
483  {
484  $this->object->importLanguageFile($file,$_POST['mode_existing']);
485  ilUtil::sendInfo(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']) , false);
486  $this->importObject();
487  }
488  else
489  {
490  $this->importObject();
491  }
492  }
493  else
494  {
495  $this->cancelObject();
496  }
497  }
498 
499 
503  function exportObject()
504  {
505  $scope = $_POST["scope"] ? $_POST["scope"] : "global";
506 
507  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_export.html", "Services/Language");
508 
509  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
510  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_export_file"));
511 
512  $this->tpl->setVariable("TXT_SCOPE",$this->lng->txt("language_file_scope"));
513  $this->tpl->setVariable("TXT_SCOPE_GLOBAL",$this->lng->txt("language_scope_global"));
514  $this->tpl->setVariable("TXT_SCOPE_LOCAL",$this->lng->txt("language_scope_local"));
515  $this->tpl->setVariable("TXT_SCOPE_UNCHANGED",$this->lng->txt("language_scope_unchanged"));
516 
517  $this->tpl->setVariable("CHECKED_GLOBAL",$scope == 'global' ? 'checked="checked"' : '');
518  $this->tpl->setVariable("CHECKED_LOCAL",$scope == 'local' ? 'checked="checked"' : '');
519  $this->tpl->setVariable("CHECKED_UNCHANGED",$scope == 'unchanged' ? 'checked="checked"' : '');
520 
521  $this->tpl->setVariable("TXT_DOWNLOAD",$this->lng->txt("download"));
522  $this->tpl->setVariable("CMD_DOWNLOAD","download");
523  $this->tpl->show();
524  }
525 
526 
530  function downloadObject()
531  {
532  $filename = 'ilias_' . $this->object->key . '_'
533  . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
534  . "-" . date('Y-m-d')
535  . ".lang.".$_POST["scope"];
536 
537  $global_file_obj = $this->object->getGlobalLanguageFile();
538  $local_file_obj = new ilLanguageFile($filename, $this->object->key, $_POST["scope"]);
539 
540  if ($_POST["scope"] == 'global')
541  {
542  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
543  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
544  $local_file_obj->setAllValues($this->object->getAllValues());
545  }
546  elseif ($_POST["scope"] == 'local')
547  {
548  $local_file_obj->setParam("based_on", $global_file_obj->getParam('version'));
549  $local_file_obj->setAllValues($this->object->getChangedValues());
550  }
551  elseif ($_POST["scope"] == 'unchanged')
552  {
553  $local_file_obj->setParam("author", $global_file_obj->getParam('author'));
554  $local_file_obj->setParam("version", $global_file_obj->getParam('version'));
555  $local_file_obj->setAllValues($this->object->getUnchangedValues());
556  }
557 
558  ilUtil::deliverData($local_file_obj->build(), $filename);
559  }
560 
561 
565  function maintainObject()
566  {
567  global $ilUser;
568 
569  switch ($_POST["maintain"])
570  {
571  // save the local changes to the local language file
572  case "save":
573  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
574 
575  if ((is_file($lang_file) and is_writable($lang_file))
576  or (!file_exists($lang_file) and is_writable($this->object->getCustLangPath())))
577  {
578  // save a copy of the distributed language file
579  $orig_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
580  $copy_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang';
581  @copy($orig_file, $copy_file);
582 
583  // save a backup of the old local language file
584  @rename($lang_file, $lang_file.".bak");
585 
586  // create and write the new local language file
587  $global_file_obj = $this->object->getGlobalLanguageFile();
588  $local_file_obj = new ilLanguageFile($lang_file, $this->object->key, 'local');
589  $local_file_obj->setParam('based_on', $global_file_obj->getParam('version'));
590  $local_file_obj->setAllValues($this->object->getChangedValues());
591  $local_file_obj->write();
592 
593  $this->object->setLocal(true);
594  ilUtil::sendInfo($this->lng->txt("language_saved_local") , false);
595  }
596  else
597  {
598  ilUtil::sendInfo($this->lng->txt("language_error_write_local") , false);
599  }
600  break;
601 
602  // load the content of the local language file
603  case "load":
604  $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
605  if (is_file($lang_file) and is_readable($lang_file))
606  {
607  $this->object->importLanguageFile($lang_file, 'replace');
608  $this->object->setLocal(true);
609  ilUtil::sendInfo($this->lng->txt("language_loaded_local") , false);
610  }
611  else
612  {
613  ilUtil::sendInfo($this->lng->txt("language_error_read_local") , false);
614  }
615  break;
616 
617  // revert the database to the default language file
618  case "clear":
619  $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
620  if (is_file($lang_file) and is_readable($lang_file))
621  {
622  $this->object->importLanguageFile($lang_file, 'delete');
623  $this->object->setLocal(false);
624  ilUtil::sendInfo($this->lng->txt("language_cleared_local") , false);
625  }
626  else
627  {
628  ilUtil::sendInfo($this->lng->txt("language_error_clear_local") , false);
629  }
630  break;
631  }
632 
633  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_maintenance.html", "Services/Language");
634  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
635  $this->tpl->setVariable("TXT_MAINTENANCE",$this->lng->txt("language_maintenance"));
636  $this->tpl->setVariable("TXT_MAINTAIN_LOCAL",$this->lng->txt("language_maintain_local_changes"));
637  $this->tpl->setVariable("TXT_SELECT",$this->lng->txt("please_select"));
638  $this->tpl->setVariable("TXT_SAVE",$this->lng->txt("language_save_local_changes"));
639  $this->tpl->setVariable("TXT_LOAD",$this->lng->txt("language_load_local_changes"));
640  $this->tpl->setVariable("TXT_CLEAR",$this->lng->txt("language_clear_local_changes"));
641  $this->tpl->setVariable("TXT_NOTE_SAVE",$this->lng->txt("language_note_save_local"));
642  $this->tpl->setVariable("TXT_MAINTAIN",$this->lng->txt("language_process_maintenance"));
643  $this->tpl->setVariable("VAR_MAINTAIN", "maintain");
644  $this->tpl->setVariable("CMD_MAINTAIN", "maintain");
645  $this->tpl->show();
646  }
647 
651  function settingsObject()
652  {
653  global $ilSetting;
654 
655  $translate_key = "lang_translate_". $this->object->key;
656 
657  // save and get the page translation setting
658  switch ($_POST["translation"])
659  {
660  case "enable":
661  $ilSetting->set($translate_key, true);
662  break;
663  case "disable":
664  $ilSetting->set($translate_key, false);
665  }
666  $translate = $ilSetting->get($translate_key, false);
667 
668  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_settings.html", "Services/Language");
669 
670  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
671  $this->tpl->setVariable("TXT_SETTINGS",$this->lng->txt("language_settings"));
672  $this->tpl->setVariable("TXT_TRANSLATION",$this->lng->txt("language_translation_mode"));
673  $this->tpl->setVariable("TXT_TRANSLATION_ENABLED",$this->lng->txt("language_translation_enabled"));
674  $this->tpl->setVariable("TXT_TRANSLATION_DISABLED",$this->lng->txt("language_translation_disabled"));
675  $this->tpl->setVariable("CHECKED_ENABLE", $translate ? 'checked="checked"': '');
676  $this->tpl->setVariable("CHECKED_DISABLE", $translate ? '' : 'checked="checked"');
677  $this->tpl->setVariable("TXT_NOTE_TRANSLATION",$this->lng->txt("language_note_translation"));
678  $this->tpl->setVariable("TXT_CHANGE_SETTINGS",$this->lng->txt("language_change_settings"));
679  $this->tpl->setVariable("CMD_SETTINGS", "settings");
680  $this->tpl->show();
681  }
682 
686  function statisticsObject()
687  {
688  $modules = ilObjLanguageExt::_getModules($this->object->key);
689 
690  $data = array();
691  $total = array("",0,0,0);
692  foreach($modules as $module)
693  {
694  $row = array();
695  $row[0] = $module;
696  $row[1] = count($this->object->getAllValues(array($module)));
697  $row[2] = count($this->object->getChangedValues(array($module)));
698  $row[3] = $row[1]-$row[2];
699  $total[1] += $row[1];
700  $total[2] += $row[2];
701  $total[3] += $row[3];
702  $data[] = $row;
703  }
704  $total[0] = "<b>".$this->lng->txt("language_all_modules")."</b>";
705  $total[1] = "<b>".$total[1]."</b>";
706  $total[2] = "<b>".$total[2]."</b>";
707  $total[3] = "<b>".$total[3]."</b>";
708  $data[] = $total;
709 
710  // prepare the templates for output
711  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_statistics.html", "Services/Language");
712  $this->tpl->addBlockFile("TABLE_STATISTICS", "table_statistics", "tpl.table.html");
713  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
714 
715  // create and configure the table object
716  include_once 'Services/Table/classes/class.ilTableGUI.php';
717  $tbl = new ilTableGUI();
718  $tbl->disable('title');
719  $tbl->disable('sort');
720  $tbl->disable('numinfo');
721 
722  $tbl->setHeaderNames(array($this->lng->txt("module"),
723  $this->lng->txt("language_scope_global"),
724  $this->lng->txt("language_scope_local"),
725  $this->lng->txt("language_scope_unchanged")));
726  $tbl->setColumnWidth(array( "25%", "25%", "25%", "25%"));
727  $tbl->setLimit(count($data));
728  $tbl->setData($data);
729 
730  // show the table
731  $tbl->render();
732  $this->tpl->show();
733  }
734 
735 
745  function getPar($a_request_name, $a_default_value)
746  {
747  // get the parameter value
748  if (isset($_GET[$a_request_name]))
749  {
750  $param = $_GET[$a_request_name];
751  $from_request = true;
752  }
753  elseif (isset($_POST[$a_request_name]))
754  {
755  $param = $_POST[$a_request_name];
756  $from_request = true;
757  }
758  elseif (isset($this->session[$a_request_name]))
759  {
760  $param = $this->session[$a_request_name];
761  $from_request = false;
762  }
763  else
764  {
765  $param = $a_default_value;
766  $from_request = false;
767  }
768 
769  // strip slashes from request parameters
770  if ($from_request)
771  {
772  if (is_array($param))
773  {
774  foreach ($param as $key => $value)
775  {
776  $param[$key] = ilUtil::stripSlashes($value);
777  }
778  }
779  else
780  {
781  $param = ilUtil::stripSlashes($param);
782  }
783  }
784 
785  // make the parameter available to further requests
786  $this->session[$a_request_name] = $param;
787 
788  return $param;
789  }
790 
795  function getAdminTabs(&$tabs_gui)
796  {
797  global $rbacsystem;
798 
799  $tabs_gui->addTarget("edit",
800  $this->ctrl->getLinkTarget($this, "view"),
801  array("","view","cancel","save"));
802 
803  $tabs_gui->addTarget("export",
804  $this->ctrl->getLinkTarget($this, "export"),
805  array("export","download"));
806 
807  $tabs_gui->addTarget("import",
808  $this->ctrl->getLinkTarget($this, "import"),
809  array("import","upload"));
810 
811  $tabs_gui->addTarget("language_maintain",
812  $this->ctrl->getLinkTarget($this, "maintain"),
813  array("maintain"));
814 
815  $tabs_gui->addTarget("settings",
816  $this->ctrl->getLinkTarget($this, "settings"),
817  array("settings"));
818 
819  $tabs_gui->addTarget("language_statistics",
820  $this->ctrl->getLinkTarget($this, "statistics"),
821  array("statistics"));
822  }
823 
824 
829  function prepareOutput()
830  {
831  if ($this->_isPageTranslation())
832  {
833  // show the pure translation page without menu, tabs etc.
834  $this->tpl->addBlockFile("CONTENT","content","tpl.adm_translate.html","Services/Language");
835  $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
836  $this->tpl->setTitle($this->lng->txt("translation"). " "
837  .$this->lng->txt("meta_l_".$this->object->key));
838  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lng_b.gif"),
839  $this->lng->txt("obj_" . $this->object->getType()));
840  }
841  else
842  {
843  // show the full page framework
845  }
846  }
847 
848 
854  {
855  global $ilLocator, $tpl;
856 
857  $ilLocator->addItem($this->lng->txt("administration"),
858  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
859  ilFrameTargetInfo::_getFrame("MainContent"));
860 
861  $ilLocator->addItem($this->lng->txt("languages"),
862  $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", ""));
863 
864  $ilLocator->addItem($this->lng->txt("meta_l_". $this->object->getTitle()),
865  $this->ctrl->getLinkTarget($this, "view"));
866  }
867 
868 
874  {
875  $this->tpl->setTitle($this->lng->txt("meta_l_".$this->object->getTitle()));
876  // $this->tpl->setDescription($this->object->getLongDescription());
877  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"), $this->lng->txt("obj_" . $this->object->getType()));
878  }
879 
880 
881  //
882  // STATIC FUNCTIONS
883  //
884 
897  public static function _isPageTranslation()
898  {
899  return ($_GET['view_mode'] == "translate");
900  }
901 
902 
911  public static function _getTranslationLink()
912  {
913  global $ilSetting, $lng;
914 
915  // prevent translation link on translation screen
916  // check setting of translation mode
917  if (self::_isPageTranslation()
918  or !$ilSetting->get("lang_translate_".$lng->getLangKey()))
919  {
920  return "";
921  }
922 
923  // set the target for translation
924  // ref id must be given to prevent params being deleted by ilAdministrtionGUI
925  $action = "ilias.php"
926  ."?ref_id=".ilobjLanguageAccess::_lookupLangFolderRefId()
927  ."&baseClass=ilAdministrationGUI"
928  ."&cmdClass=ilobjlanguageextgui"
929  ."&view_mode=translate";
930 
931  $tpl = new ilTemplate("tpl.translation_link.html",true,true, "Services/Language");
932 
933  foreach($lng->getUsedModules() as $module => $dummy)
934  {
935  $tpl->setCurrentBlock("hidden");
936  $tpl->setVariable("NAME", "page_modules[]");
937  $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($module));
938  $tpl->parseCurrentBlock();
939  }
940 
941  foreach($lng->getUsedTopics() as $topic => $dummy)
942  {
943  $tpl->setCurrentBlock("hidden");
944  $tpl->setVariable("NAME", "page_topics[]");
945  $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($topic));
946  $tpl->parseCurrentBlock();
947  }
948 
949  $tpl->setVariable("ACTION", $action);
950  $tpl->setVariable("TXT_TRANSLATE",$lng->txt("translation"));
951 
952  return $tpl->get();
953  }
954 
955 
956 } // END class.ilObjLanguageExtGUI
957 ?>