ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 "./classes/class.ilObjectGUI.php";
19 
21 {
27  function ilObjLanguageFolderGUI($a_data,$a_id,$a_call_by_reference)
28  {
29  $this->type = "lngf";
30  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
31  $_GET["sort_by"] = "language";
32  }
33 
39  function viewObject()
40  {
41  global $rbacsystem, $ilSetting, $tpl, $ilToolbar, $lng;
42 
43  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
44  {
45  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
46  }
47 
48  // refresh
49  if ($ilSetting->get("lang_ext_maintenance") == "1")
50  {
51  $ilToolbar->addButton($lng->txt("refresh_languages"),
52  $this->ctrl->getLinkTarget($this, "confirmRefresh"));
53  }
54  else
55  {
56  $ilToolbar->addButton($lng->txt("refresh_languages"),
57  $this->ctrl->getLinkTarget($this, "refresh"));
58  }
59 
60  // check languages
61  $ilToolbar->addButton($lng->txt("check_languages"),
62  $this->ctrl->getLinkTarget($this, "checkLanguage"));
63 
64  // extended language maintenance
65  if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
66  {
67  if ($ilSetting->get("lang_ext_maintenance") == "1")
68  {
69  $ilToolbar->addButton($lng->txt("disable_ext_lang_maint"),
70  $this->ctrl->getLinkTarget($this, "disableExtendedLanguageMaintenance"));
71  }
72  else
73  {
74  $ilToolbar->addButton($lng->txt("enable_ext_lang_maint"),
75  $this->ctrl->getLinkTarget($this, "enableExtendedLanguageMaintenance"));
76  }
77  }
78 
79  include_once("./Services/Language/classes/class.ilLanguageTableGUI.php");
80  $ltab = new ilLanguageTableGUI($this, "view", $this->object);
81  $tpl->setContent($ltab->getHTML());
82  }
83 
87  function installObject()
88  {
89  if (!isset($_POST["id"]))
90  {
91  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
92  }
93 
94  foreach ($_POST["id"] as $obj_id)
95  {
96  $langObj = new ilObjLanguage($obj_id);
97  $key = $langObj->install();
98 
99  if ($key != "")
100  {
101  $lang_installed[] = $key;
102  }
103 
104  unset($langObj);
105  }
106 
107  if (isset($lang_installed))
108  {
109  if (count($lang_installed) == 1)
110  {
111  $this->data = $this->lng->txt("lang_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
112  }
113  else
114  {
115  foreach ($lang_installed as $lang_key)
116  {
117  $langnames[] = $this->lng->txt("lang_" . $lang_key);
118  }
119  $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
120  }
121  }
122  else
123  {
124  $this->data = $this->lng->txt("languages_already_installed");
125  }
126 
127  $this->out();
128  }
129 
130 
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("lang_" . $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("lang_" . $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("lang_" . $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("lang_" . $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  if (!isset($_POST["id"]))
210  {
211  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
212  }
213 
214  // uninstall all selected languages
215  foreach ($_POST["id"] as $obj_id)
216  {
217  $langObj = new ilObjLanguage($obj_id);
218  if (!($sys_lang = $langObj->isSystemLanguage()))
219  if (!($usr_lang = $langObj->isUserLanguage()))
220  {
221  $key = $langObj->uninstall();
222  if ($key != "")
223  $lang_uninstalled[] = $key;
224  }
225  unset($langObj);
226  }
227 
228  // generate output message
229  if (isset($lang_uninstalled))
230  {
231  if (count($lang_uninstalled) == 1)
232  {
233  $this->data = $this->lng->txt("lang_".$lang_uninstalled[0])." ".$this->lng->txt("uninstalled");
234  }
235  else
236  {
237  foreach ($lang_uninstalled as $lang_key)
238  {
239  $langnames[] = $this->lng->txt("lang_".$lang_key);
240  }
241 
242  $this->data = implode(", ",$langnames)." ".$this->lng->txt("uninstalled");
243  }
244  }
245  elseif ($sys_lang)
246  {
247  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
248  }
249  elseif ($usr_lang)
250  {
251  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
252  }
253  else
254  {
255  $this->data = $this->lng->txt("languages_already_uninstalled");
256  }
257 
258  $this->out();
259  }
260 
264  function refreshObject()
265  {
267  $this->data = $this->lng->txt("languages_updated");
268  $this->out();
269  }
270 
271 
276  {
277  global $lng;
278 
279  $this->data = $this->lng->txt("selected_languages_updated");
280  $lng->loadLanguageModule("meta");
281 
282  foreach ($_POST["id"] as $id)
283  {
284  $langObj = new ilObjLanguage($id, false);
285 
286  if ($langObj->isInstalled() == true)
287  {
288  if ($langObj->check())
289  {
290  $langObj->flush('keep_local');
291  $langObj->insert();
292  $langObj->setTitle($langObj->getKey());
293  $langObj->setDescription($langObj->getStatus());
294  $langObj->update();
295  $langObj->optimizeData();
296 
297  if ($langObj->isLocal() == true)
298  {
299  if ($langObj->check('local'))
300  {
301  $langObj->insert('local');
302  $langObj->setTitle($langObj->getKey());
303  $langObj->setDescription($langObj->getStatus());
304  $langObj->update();
305  $langObj->optimizeData();
306  }
307  }
308  }
309  $this->data .= "<br />". $lng->txt("meta_l_".$langObj->getKey());
310  }
311 
312  unset($langObj);
313  }
314 
315  $this->out();
316  }
317 
318 
323  {
324  require_once './Services/User/classes/class.ilObjUser.php';
325 
326  if (!isset($_POST["id"]))
327  {
328  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
329  }
330 
331  if (count($_POST["id"]) != 1)
332  {
333  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
334  }
335 
336  $obj_id = $_POST["id"][0];
337 
338  $newUserLangObj = new ilObjLanguage($obj_id);
339 
340  if ($newUserLangObj->isUserLanguage())
341  {
342  $this->ilias->raiseError($this->lng->txt("lang_".$newUserLangObj->getKey())." ".$this->lng->txt("is_already_your")." ".$this->lng->txt("user_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
343  }
344 
345  if ($newUserLangObj->isInstalled() == false)
346  {
347  $this->ilias->raiseError($this->lng->txt("lang_".$newUserLangObj->getKey())." ".$this->lng->txt("language_not_installed")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
348  }
349 
350  $curUser = new ilObjUser($_SESSION["AccountId"]);
351  $curUser->setLanguage($newUserLangObj->getKey());
352  $curUser->update();
353  //$this->setUserLanguage($new_lang_key);
354 
355  $this->data = $this->lng->txt("user_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("lang_".$newUserLangObj->getKey()).".";
356 
357  $this->out();
358  }
359 
360 
365  {
366  if (!isset($_POST["id"]))
367  {
368  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
369  }
370 
371  if (count($_POST["id"]) != 1)
372  {
373  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
374  }
375 
376  $obj_id = $_POST["id"][0];
377 
378  $newSysLangObj = new ilObjLanguage($obj_id);
379 
380  if ($newSysLangObj->isSystemLanguage())
381  {
382  $this->ilias->raiseError($this->lng->txt("lang_".$newSysLangObj->getKey())." is already the system language!<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
383  }
384 
385  if ($newSysLangObj->isInstalled() == false)
386  {
387  $this->ilias->raiseError($this->lng->txt("lang_".$newSysLangObj->getKey())." is not installed. Please install that language first.<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
388  }
389 
390  $this->ilias->setSetting("language", $newSysLangObj->getKey());
391 
392  // update ini-file
393  $this->ilias->ini->setVariable("language","default",$newSysLangObj->getKey());
394  $this->ilias->ini->write();
395 
396  $this->data = $this->lng->txt("system_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("lang_".$newSysLangObj->getKey()).".";
397 
398  $this->out();
399  }
400 
401 
406  {
407  //$langFoldObj = new ilObjLanguageFolder($_GET["obj_id"]);
408  //$this->data = $langFoldObj->checkAllLanguages();
409  $this->data = $this->object->checkAllLanguages();
410  $this->out();
411  }
412 
413 
414  function out()
415  {
416  ilUtil::sendInfo($this->data,true);
417  $this->ctrl->redirect($this, "view");
418  }
419 
420  function getAdminTabs(&$tabs_gui)
421  {
422  $this->getTabs($tabs_gui);
423  }
424 
430  function getTabs(&$tabs_gui)
431  {
432  global $rbacsystem;
433 
434  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
435  {
436  $tabs_gui->addTarget("settings",
437  $this->ctrl->getLinkTarget($this, "view"), array("view",""), "", "");
438  }
439 
440  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
441  {
442  $tabs_gui->addTarget("perm_settings",
443  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
444  }
445  }
446 
447  function &executeCommand()
448  {
449  $next_class = $this->ctrl->getNextClass($this);
450  $cmd = $this->ctrl->getCmd();
451  $this->prepareOutput();
452 
453  switch($next_class)
454  {
455  case 'ilpermissiongui':
456  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
457  $perm_gui =& new ilPermissionGUI($this);
458  $ret =& $this->ctrl->forwardCommand($perm_gui);
459  break;
460 
461  default:
462  if(!$cmd)
463  {
464  $cmd = "view";
465  }
466  $cmd .= "Object";
467  $this->$cmd();
468 
469  break;
470  }
471  return true;
472  }
473 
478  {
479  global $ilSetting, $ilCtrl;
480 
481  $ilSetting->set("lang_ext_maintenance", 1);
482  $ilCtrl->redirect($this, "view");
483  }
484 
489  {
490  global $ilSetting, $ilCtrl;
491 
492  $ilSetting->set("lang_ext_maintenance", 0);
493  $ilCtrl->redirect($this, "view");
494  }
495 
497  {
498  global $ilCtrl, $lng;
499 
500  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
501  $conf_screen = new ilConfirmationGUI();
502  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
503  $conf_screen->setHeaderText($lng->txt("lang_refresh_confirm"));
504  $conf_screen->addItem("d", "d", $lng->txt("lang_refresh_confirm_info"));
505  $conf_screen->setCancel($lng->txt("cancel"), "view");
506  $conf_screen->setConfirm($lng->txt("ok"), "refresh");
507 
508  $this->tpl->setContent($conf_screen->getHTML());
509  }
510 
512  {
513  global $ilCtrl, $lng;
514 
515  if (!isset($_POST["id"]))
516  {
517  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
518  }
519 
520  $lng->loadLanguageModule("meta");
521  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
522  $conf_screen = new ilConfirmationGUI();
523  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
524  $conf_screen->setHeaderText($lng->txt("lang_refresh_confirm_selected"));
525  foreach ($_POST["id"] as $id)
526  {
527  $lang_title = ilObject::_lookupTitle($id);
528  $conf_screen->addItem("id[]", $id, $lng->txt("meta_l_".$lang_title));
529  }
530  $conf_screen->addItem("d", "d", $lng->txt("lang_refresh_confirm_info"));
531  $conf_screen->setCancel($lng->txt("cancel"), "view");
532  $conf_screen->setConfirm($lng->txt("ok"), "refreshSelected");
533  $this->tpl->setContent($conf_screen->getHTML());
534  }
535 
539  function getActions()
540  {
541  global $ilSetting;
542 
543  // standard actions for container
544  return array(
545  "install" => array("name" => "install", "lng" => "install"),
546  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
547  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
548  "refresh" => $ilSetting->get("lang_ext_maintenance") == "1" ?
549  array("name" => "confirmRefreshSelected", "lng" => "refresh") :
550  array("name" => "RefreshSelected", "lng" => "refresh"),
551  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
552  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
553  );
554  }
555 
556 
557 } // END class.ilObjLanguageFolderGUI
558 ?>