ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjLanguageFolderGUI.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 
17 require_once "./Services/Language/classes/class.ilObjLanguage.php";
18 require_once "./Services/Object/classes/class.ilObjectGUI.php";
19 
21 {
27  function __construct($a_data,$a_id,$a_call_by_reference)
28  {
29  $this->type = "lngf";
30  parent::__construct($a_data,$a_id,$a_call_by_reference, false);
31  $_GET["sort_by"] = "language";
32  $this->lng->loadLanguageModule('lng');
33  }
34 
40  function viewObject()
41  {
42  global $rbacsystem, $ilSetting, $tpl, $ilToolbar, $lng, $ilClientIniFile;
43 
44  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
45  {
46  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
47  }
48 
49  // refresh
50  $ilToolbar->addButton($lng->txt("refresh_languages"),
51  $this->ctrl->getLinkTarget($this, "confirmRefresh"));
52 
53  // check languages
54  $ilToolbar->addButton($lng->txt("check_languages"),
55  $this->ctrl->getLinkTarget($this, "checkLanguage"));
56 
57  // extended language maintenance
58  if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
59  {
60  if(!$ilSetting->get('lang_detection'))
61  {
62  $ilToolbar->addButton($lng->txt('lng_enable_language_detection'), $this->ctrl->getLinkTarget($this, 'enableLanguageDetection'));
63  }
64  else
65  {
66  $ilToolbar->addButton($lng->txt('lng_disable_language_detection'), $this->ctrl->getLinkTarget($this, 'disableLanguageDetection'));
67  }
68  }
69 
70  if($ilClientIniFile->variableExists('system', 'LANGUAGE_LOG'))
71  {
72  $ilToolbar->addButton($lng->txt('lng_download_deprecated'), $this->ctrl->getLinkTarget($this, 'listDeprecated'));
73  }
74 
75  include_once("./Services/Language/classes/class.ilLanguageTableGUI.php");
76  $ltab = new ilLanguageTableGUI($this, "view", $this->object);
77  $tpl->setContent($ltab->getHTML());
78  }
79 
83  function installObject()
84  {
85  $this->lng->loadLanguageModule("meta");
86 
87  if (!isset($_POST["id"]))
88  {
89  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
90  }
91 
92  foreach ($_POST["id"] as $obj_id)
93  {
94  $langObj = new ilObjLanguage($obj_id);
95  $key = $langObj->install();
96 
97  if ($key != "")
98  {
99  $lang_installed[] = $key;
100  }
101 
102  unset($langObj);
103  }
104 
105  if (isset($lang_installed))
106  {
107  if (count($lang_installed) == 1)
108  {
109  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
110  }
111  else
112  {
113  foreach ($lang_installed as $lang_key)
114  {
115  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
116  }
117  $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
118  }
119  }
120  else
121  {
122  $this->data = $this->lng->txt("languages_already_installed");
123  }
124 
125  $this->out();
126  }
127 
128 
133  {
134  $this->lng->loadLanguageModule("meta");
135 
136  if (!isset($_POST["id"]))
137  {
138  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
139  }
140 
141  foreach ($_POST["id"] as $obj_id)
142  {
143  $langObj = new ilObjLanguage($obj_id);
144  $key = $langObj->install();
145 
146  if ($key != "")
147  {
148  $lang_installed[] = $key;
149  }
150 
151  unset($langObj);
152 
153  $langObj = new ilObjLanguage($obj_id);
154  $key = $langObj->install('local');
155 
156  if ($key != "")
157  {
158  $local_installed[] = $key;
159  }
160 
161  unset($langObj);
162  }
163 
164  if (isset($lang_installed))
165  {
166  if (count($lang_installed) == 1)
167  {
168  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
169  }
170  else
171  {
172  foreach ($lang_installed as $lang_key)
173  {
174  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
175  }
176  $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
177  }
178  }
179 
180  if (isset($local_installed))
181  {
182  if (count($local_installed) == 1)
183  {
184  $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
185  }
186  else
187  {
188  foreach ($local_installed as $lang_key)
189  {
190  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
191  }
192  $this->data .= " " . implode(", ",$langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
193  }
194  }
195  else
196  {
197  $this->data .= " " . $this->lng->txt("local_languages_already_installed");
198  }
199 
200  $this->out();
201  }
202 
203 
207  function uninstallObject()
208  {
209  $this->lng->loadLanguageModule("meta");
210 
211  if (!isset($_POST["id"]))
212  {
213  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
214  }
215 
216  // uninstall all selected languages
217  foreach ($_POST["id"] as $obj_id)
218  {
219  $langObj = new ilObjLanguage($obj_id);
220  if (!($sys_lang = $langObj->isSystemLanguage()))
221  if (!($usr_lang = $langObj->isUserLanguage()))
222  {
223  $key = $langObj->uninstall();
224  if ($key != "")
225  $lang_uninstalled[] = $key;
226  }
227  unset($langObj);
228  }
229 
230  // generate output message
231  if (isset($lang_uninstalled))
232  {
233  if (count($lang_uninstalled) == 1)
234  {
235  $this->data = $this->lng->txt("meta_l_".$lang_uninstalled[0])." ".$this->lng->txt("uninstalled");
236  }
237  else
238  {
239  foreach ($lang_uninstalled as $lang_key)
240  {
241  $langnames[] = $this->lng->txt("meta_l_".$lang_key);
242  }
243 
244  $this->data = implode(", ",$langnames)." ".$this->lng->txt("uninstalled");
245  }
246  }
247  elseif ($sys_lang)
248  {
249  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
250  }
251  elseif ($usr_lang)
252  {
253  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
254  }
255  else
256  {
257  $this->data = $this->lng->txt("languages_already_uninstalled");
258  }
259 
260  $this->out();
261  }
262 
263 
268  {
269  global $lng;
270 
271  $this->data = $this->lng->txt("selected_languages_updated");
272  $lng->loadLanguageModule("meta");
273 
274  foreach ($_POST["id"] as $id)
275  {
276  $langObj = new ilObjLanguage($id, false);
277 
278  if ($langObj->isInstalled() == true)
279  {
280  if ($langObj->check())
281  {
282  $langObj->flush('all');
283  $langObj->insert();
284  $langObj->setTitle($langObj->getKey());
285  $langObj->setDescription('installed');
286  $langObj->update();
287  }
288  $this->data .= "<br />". $lng->txt("meta_l_".$langObj->getKey());
289  }
290 
291  unset($langObj);
292  }
293 
294  $this->out();
295  }
296 
297 
301  function refreshObject()
302  {
304  $this->data = $this->lng->txt("languages_updated");
305  $this->out();
306  }
307 
308 
313  {
314  global $lng;
315 
316  $this->data = $this->lng->txt("selected_languages_updated");
317  $lng->loadLanguageModule("meta");
318 
319  $refreshed = array();
320  foreach ($_POST["id"] as $id)
321  {
322  $langObj = new ilObjLanguage($id, false);
323  if ($langObj->refresh())
324  {
325  $refreshed[] = $langObj->getKey();
326  $this->data .= "<br />". $lng->txt("meta_l_".$langObj->getKey());
327  }
328  unset($langObj);
329  }
330 
331  ilObjLanguage::refreshPlugins($refreshed);
332  $this->out();
333  }
334 
335 
340  {
341  $this->lng->loadLanguageModule("meta");
342 
343  require_once './Services/User/classes/class.ilObjUser.php';
344 
345  if (!isset($_POST["id"]))
346  {
347  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
348  }
349 
350  if (count($_POST["id"]) != 1)
351  {
352  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
353  }
354 
355  $obj_id = $_POST["id"][0];
356 
357  $newUserLangObj = new ilObjLanguage($obj_id);
358 
359  if ($newUserLangObj->isUserLanguage())
360  {
361  $this->ilias->raiseError($this->lng->txt("meta_l_".$newUserLangObj->getKey())." ".$this->lng->txt("is_already_your")." ".$this->lng->txt("user_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
362  }
363 
364  if ($newUserLangObj->isInstalled() == false)
365  {
366  $this->ilias->raiseError($this->lng->txt("meta_l_".$newUserLangObj->getKey())." ".$this->lng->txt("language_not_installed")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
367  }
368 
369  $curUser = new ilObjUser($GLOBALS['DIC']['ilUser']->getId());
370  $curUser->setLanguage($newUserLangObj->getKey());
371  $curUser->update();
372  //$this->setUserLanguage($new_lang_key);
373 
374  $this->data = $this->lng->txt("user_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("meta_l_".$newUserLangObj->getKey()).".";
375 
376  $this->out();
377  }
378 
379 
384  {
385  $this->lng->loadLanguageModule("meta");
386 
387  if (!isset($_POST["id"]))
388  {
389  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
390  }
391 
392  if (count($_POST["id"]) != 1)
393  {
394  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
395  }
396 
397  $obj_id = $_POST["id"][0];
398 
399  $newSysLangObj = new ilObjLanguage($obj_id);
400 
401  if ($newSysLangObj->isSystemLanguage())
402  {
403  $this->ilias->raiseError($this->lng->txt("meta_l_".$newSysLangObj->getKey())." is already the system language!<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
404  }
405 
406  if ($newSysLangObj->isInstalled() == false)
407  {
408  $this->ilias->raiseError($this->lng->txt("meta_l_".$newSysLangObj->getKey())." is not installed. Please install that language first.<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
409  }
410 
411  $this->ilias->setSetting("language", $newSysLangObj->getKey());
412 
413  // update ini-file
414  $this->ilias->ini->setVariable("language","default",$newSysLangObj->getKey());
415  $this->ilias->ini->write();
416 
417  $this->data = $this->lng->txt("system_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("meta_l_".$newSysLangObj->getKey()).".";
418 
419  $this->out();
420  }
421 
422 
427  {
428  //$langFoldObj = new ilObjLanguageFolder($_GET["obj_id"]);
429  //$this->data = $langFoldObj->checkAllLanguages();
430  $this->data = $this->object->checkAllLanguages();
431  $this->out();
432  }
433 
434 
435  function out()
436  {
437  ilUtil::sendInfo($this->data,true);
438  $this->ctrl->redirect($this, "view");
439  }
440 
441  function getAdminTabs()
442  {
443  $this->getTabs();
444  }
445 
451  function getTabs()
452  {
453  global $rbacsystem;
454 
455  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
456  {
457  $this->tabs_gui->addTarget("settings",
458  $this->ctrl->getLinkTarget($this, "view"), array("view",""), "", "");
459  }
460 
461  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
462  {
463  $this->tabs_gui->addTarget("perm_settings",
464  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
465  }
466  }
467 
468  function executeCommand()
469  {
470  $next_class = $this->ctrl->getNextClass($this);
471  $cmd = $this->ctrl->getCmd();
472  $this->prepareOutput();
473 
474  switch($next_class)
475  {
476  case 'ilpermissiongui':
477  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
478  $perm_gui = new ilPermissionGUI($this);
479  $ret =& $this->ctrl->forwardCommand($perm_gui);
480  break;
481 
482  default:
483  if(!$cmd)
484  {
485  $cmd = "view";
486  }
487  $cmd .= "Object";
488  $this->$cmd();
489 
490  break;
491  }
492  return true;
493  }
494 
496  {
498 
499  $ids = array();
500  foreach ($languages as $lang)
501  {
502  $langObj = new ilObjLanguage($lang["obj_id"],false);
503  if ($langObj->isInstalled() == true)
504  {
505  $ids[] = $lang["obj_id"];
506  }
507  }
508  $this->confirmRefreshSelectedObject($ids);
509  }
510 
511  function confirmRefreshSelectedObject($a_ids = array())
512  {
513  global $ilCtrl, $lng;
514 
515  if (!empty($a_ids))
516  {
517  $ids = $a_ids;
518  $header = $lng->txt("lang_refresh_confirm");
519  }
520  elseif (!empty($_POST["id"]))
521  {
522  $ids = $_POST["id"];
523  $header = $lng->txt("lang_refresh_confirm_selected");
524  }
525  else
526  {
527  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
528  }
529 
530  $lng->loadLanguageModule("meta");
531  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
532 
533  $conf_screen = new ilConfirmationGUI();
534  $some_changed = false;
535  foreach ($ids as $id)
536  {
537  $lang_key = ilObject::_lookupTitle($id);
538  $lang_title = $lng->txt('meta_l_'.$lang_key);
539  $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
540  if (!empty($last_change))
541  {
542  $some_changed = true;
543  $lang_title .= ' ('. $this->lng->txt("last_change"). ' '
544  . ilDatePresentation::formatDate(new ilDateTime($last_change,IL_CAL_DATETIME)) . ')';
545  }
546  $conf_screen->addItem("id[]", $id, $lang_title);
547  }
548 
549  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
550  if ($some_changed)
551  {
552  $header .= '<br />' . $lng->txt("lang_refresh_confirm_info");
553  }
554  $conf_screen->setHeaderText($header);
555  $conf_screen->setCancel($lng->txt("cancel"), "view");
556  $conf_screen->setConfirm($lng->txt("ok"), "refreshSelected");
557  $this->tpl->setContent($conf_screen->getHTML());
558  }
559 
561  {
562  global $ilCtrl, $lng;
563 
564  if (!isset($_POST["id"]))
565  {
566  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
567  }
568 
569  $lng->loadLanguageModule("meta");
570  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
571  $conf_screen = new ilConfirmationGUI();
572  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
573  $conf_screen->setHeaderText($lng->txt("lang_uninstall_confirm"));
574  foreach ($_POST["id"] as $id)
575  {
576  $lang_title = ilObject::_lookupTitle($id);
577  $conf_screen->addItem("id[]", $id, $lng->txt("meta_l_".$lang_title));
578  }
579  $conf_screen->setCancel($lng->txt("cancel"), "view");
580  $conf_screen->setConfirm($lng->txt("ok"), "uninstall");
581  $this->tpl->setContent($conf_screen->getHTML());
582  }
583 
584 
586  {
587  global $ilCtrl, $lng;
588 
589  if (!isset($_POST["id"]))
590  {
591  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
592  }
593 
594  $lng->loadLanguageModule("meta");
595  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
596  $conf_screen = new ilConfirmationGUI();
597  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
598  $conf_screen->setHeaderText($lng->txt("lang_uninstall_changes_confirm"));
599  foreach ($_POST["id"] as $id)
600  {
601  $lang_title = ilObject::_lookupTitle($id);
602  $conf_screen->addItem("id[]", $id, $lng->txt("meta_l_".$lang_title));
603  }
604  $conf_screen->setCancel($lng->txt("cancel"), "view");
605  $conf_screen->setConfirm($lng->txt("ok"), "uninstallChanges");
606  $this->tpl->setContent($conf_screen->getHTML());
607  }
608 
612  function getActions()
613  {
614  global $ilSetting;
615 
616  // standard actions for container
617  return array(
618  "install" => array("name" => "install", "lng" => "install"),
619  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
620  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
621  "refresh" => array("name" => "confirmRefreshSelected", "lng" => "refresh"),
622  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
623  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
624  );
625  }
626 
630  protected function disableLanguageDetectionObject()
631  {
635  global $ilSetting;
636 
637  $ilSetting->set('lang_detection', 0);
638  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
639  $this->viewObject();
640  }
641 
645  protected function enableLanguageDetectionObject()
646  {
650  global $ilSetting;
651 
652  $ilSetting->set('lang_detection', 1);
653  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
654  $this->viewObject();
655  }
656 
661  {
662  global $DIC;
663 
664  $rbacsystem = $DIC->rbac()->system();
665  $tpl = $DIC["tpl"];
666  $ilToolbar = $DIC->toolbar();
667  $ctrl = $DIC->ctrl();
668  $lng = $DIC->language();
669 
670  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
671  {
672  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
673  }
674 
675  $ilToolbar->addButton($lng->txt("download"),
676  $ctrl->getLinkTarget($this, "downloadDeprecated"));
677 
678  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
679 
680  $d = new ilLangDeprecated();
681  $res = "";
682  foreach ($d->getDeprecatedLangVars() as $key => $mod)
683  {
684  $res.= $mod.",".$key."\n";
685  }
686 
687  $tpl->setContent("<pre>".$res."</pre>");
688  }
689 
694  {
695  global $DIC;
696 
697  $rbacsystem = $DIC->rbac()->system();
698 
699  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
700  {
701  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
702  }
703 
704  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
705  $d = new ilLangDeprecated();
706  $res = "";
707  foreach ($d->getDeprecatedLangVars() as $key => $mod)
708  {
709  $res.= $mod.",".$key."\n";
710  }
711 
712  ilUtil::deliverData($res, "lang_deprecated.csv");
713  }
714 
715 
716 } // END class.ilObjLanguageFolderGUI
717 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Add some data
refreshSelectedObject()
update selected languages
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
const IL_CAL_DATETIME
__construct($a_data, $a_id, $a_call_by_reference)
Constructor.
$_GET["client_id"]
refreshObject()
update all installed languages
setSystemLanguageObject()
set the system language
Class ilObjLanguage.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$cmd
Definition: sahs_server.php:35
listDeprecatedObject()
Download deprecated lang entries.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
for($col=0; $col< 50; $col++) $d
installLocalObject()
Install local language modifications.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Search for deprecated lang vars.
prepareOutput($a_show_subobjects=true)
prepare output
uninstallChangesObject()
Uninstall local changes in the database.
getId()
get object id public
$header
Class ilObjectGUI Basic methods of all Output classes.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
redirection script todo: (a better solution should control the processing via a xml file) ...
downloadDeprecatedObject()
Download deprecated lang entries.
Create styles array
The data for the language used.
viewObject()
show installed languages
global $ilSetting
Definition: privfeed.php:17
$ret
Definition: parser.php:6
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
static refreshAll()
Refresh all installed languages.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
global $DIC
$languages
Definition: cssgen2.php:34
static _getLastLocalChange($a_key)
get the date of the last local change
static refreshPlugins($a_lang_keys=null)
$_POST["username"]
checkLanguageObject()
check all languages
Class ilObjLanguageFolderGUI.
Confirmation screen class.