ILIAS  Release_5_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 "./Services/Object/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  $this->lng->loadLanguageModule("meta");
90 
91  if (!isset($_POST["id"]))
92  {
93  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
94  }
95 
96  foreach ($_POST["id"] as $obj_id)
97  {
98  $langObj = new ilObjLanguage($obj_id);
99  $key = $langObj->install();
100 
101  if ($key != "")
102  {
103  $lang_installed[] = $key;
104  }
105 
106  unset($langObj);
107  }
108 
109  if (isset($lang_installed))
110  {
111  if (count($lang_installed) == 1)
112  {
113  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
114  }
115  else
116  {
117  foreach ($lang_installed as $lang_key)
118  {
119  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
120  }
121  $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
122  }
123  }
124  else
125  {
126  $this->data = $this->lng->txt("languages_already_installed");
127  }
128 
129  $this->out();
130  }
131 
132 
137  {
138  $this->lng->loadLanguageModule("meta");
139 
140  if (!isset($_POST["id"]))
141  {
142  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
143  }
144 
145  foreach ($_POST["id"] as $obj_id)
146  {
147  $langObj = new ilObjLanguage($obj_id);
148  $key = $langObj->install();
149 
150  if ($key != "")
151  {
152  $lang_installed[] = $key;
153  }
154 
155  unset($langObj);
156 
157  $langObj = new ilObjLanguage($obj_id);
158  $key = $langObj->install('local');
159 
160  if ($key != "")
161  {
162  $local_installed[] = $key;
163  }
164 
165  unset($langObj);
166  }
167 
168  if (isset($lang_installed))
169  {
170  if (count($lang_installed) == 1)
171  {
172  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
173  }
174  else
175  {
176  foreach ($lang_installed as $lang_key)
177  {
178  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
179  }
180  $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
181  }
182  }
183 
184  if (isset($local_installed))
185  {
186  if (count($local_installed) == 1)
187  {
188  $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
189  }
190  else
191  {
192  foreach ($local_installed as $lang_key)
193  {
194  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
195  }
196  $this->data .= " " . implode(", ",$langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
197  }
198  }
199  else
200  {
201  $this->data .= " " . $this->lng->txt("local_languages_already_installed");
202  }
203 
204  $this->out();
205  }
206 
207 
211  function uninstallObject()
212  {
213  $this->lng->loadLanguageModule("meta");
214 
215  if (!isset($_POST["id"]))
216  {
217  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
218  }
219 
220  // uninstall all selected languages
221  foreach ($_POST["id"] as $obj_id)
222  {
223  $langObj = new ilObjLanguage($obj_id);
224  if (!($sys_lang = $langObj->isSystemLanguage()))
225  if (!($usr_lang = $langObj->isUserLanguage()))
226  {
227  $key = $langObj->uninstall();
228  if ($key != "")
229  $lang_uninstalled[] = $key;
230  }
231  unset($langObj);
232  }
233 
234  // generate output message
235  if (isset($lang_uninstalled))
236  {
237  if (count($lang_uninstalled) == 1)
238  {
239  $this->data = $this->lng->txt("meta_l_".$lang_uninstalled[0])." ".$this->lng->txt("uninstalled");
240  }
241  else
242  {
243  foreach ($lang_uninstalled as $lang_key)
244  {
245  $langnames[] = $this->lng->txt("meta_l_".$lang_key);
246  }
247 
248  $this->data = implode(", ",$langnames)." ".$this->lng->txt("uninstalled");
249  }
250  }
251  elseif ($sys_lang)
252  {
253  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
254  }
255  elseif ($usr_lang)
256  {
257  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
258  }
259  else
260  {
261  $this->data = $this->lng->txt("languages_already_uninstalled");
262  }
263 
264  $this->out();
265  }
266 
270  function refreshObject()
271  {
273  $this->data = $this->lng->txt("languages_updated");
274  $this->out();
275  }
276 
277 
282  {
283  global $lng;
284 
285  $this->data = $this->lng->txt("selected_languages_updated");
286  $lng->loadLanguageModule("meta");
287 
288  foreach ($_POST["id"] as $id)
289  {
290  $langObj = new ilObjLanguage($id, false);
291 
292  if ($langObj->isInstalled() == true)
293  {
294  if ($langObj->check())
295  {
296  $langObj->flush('keep_local');
297  $langObj->insert();
298  $langObj->setTitle($langObj->getKey());
299  $langObj->setDescription($langObj->getStatus());
300  $langObj->update();
301  $langObj->optimizeData();
302 
303  if ($langObj->isLocal() == true)
304  {
305  if ($langObj->check('local'))
306  {
307  $langObj->insert('local');
308  $langObj->setTitle($langObj->getKey());
309  $langObj->setDescription($langObj->getStatus());
310  $langObj->update();
311  $langObj->optimizeData();
312  }
313  }
314  }
315  $this->data .= "<br />". $lng->txt("meta_l_".$langObj->getKey());
316  }
317 
318  unset($langObj);
319  }
320 
321  $this->out();
322  }
323 
324 
329  {
330  $this->lng->loadLanguageModule("meta");
331 
332  require_once './Services/User/classes/class.ilObjUser.php';
333 
334  if (!isset($_POST["id"]))
335  {
336  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
337  }
338 
339  if (count($_POST["id"]) != 1)
340  {
341  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
342  }
343 
344  $obj_id = $_POST["id"][0];
345 
346  $newUserLangObj = new ilObjLanguage($obj_id);
347 
348  if ($newUserLangObj->isUserLanguage())
349  {
350  $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);
351  }
352 
353  if ($newUserLangObj->isInstalled() == false)
354  {
355  $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);
356  }
357 
358  $curUser = new ilObjUser($_SESSION["AccountId"]);
359  $curUser->setLanguage($newUserLangObj->getKey());
360  $curUser->update();
361  //$this->setUserLanguage($new_lang_key);
362 
363  $this->data = $this->lng->txt("user_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("meta_l_".$newUserLangObj->getKey()).".";
364 
365  $this->out();
366  }
367 
368 
373  {
374  $this->lng->loadLanguageModule("meta");
375 
376  if (!isset($_POST["id"]))
377  {
378  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
379  }
380 
381  if (count($_POST["id"]) != 1)
382  {
383  $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
384  }
385 
386  $obj_id = $_POST["id"][0];
387 
388  $newSysLangObj = new ilObjLanguage($obj_id);
389 
390  if ($newSysLangObj->isSystemLanguage())
391  {
392  $this->ilias->raiseError($this->lng->txt("meta_l_".$newSysLangObj->getKey())." is already the system language!<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
393  }
394 
395  if ($newSysLangObj->isInstalled() == false)
396  {
397  $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);
398  }
399 
400  $this->ilias->setSetting("language", $newSysLangObj->getKey());
401 
402  // update ini-file
403  $this->ilias->ini->setVariable("language","default",$newSysLangObj->getKey());
404  $this->ilias->ini->write();
405 
406  $this->data = $this->lng->txt("system_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("meta_l_".$newSysLangObj->getKey()).".";
407 
408  $this->out();
409  }
410 
411 
416  {
417  //$langFoldObj = new ilObjLanguageFolder($_GET["obj_id"]);
418  //$this->data = $langFoldObj->checkAllLanguages();
419  $this->data = $this->object->checkAllLanguages();
420  $this->out();
421  }
422 
423 
424  function out()
425  {
426  ilUtil::sendInfo($this->data,true);
427  $this->ctrl->redirect($this, "view");
428  }
429 
430  function getAdminTabs(&$tabs_gui)
431  {
432  $this->getTabs($tabs_gui);
433  }
434 
440  function getTabs(&$tabs_gui)
441  {
442  global $rbacsystem;
443 
444  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
445  {
446  $tabs_gui->addTarget("settings",
447  $this->ctrl->getLinkTarget($this, "view"), array("view",""), "", "");
448  }
449 
450  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
451  {
452  $tabs_gui->addTarget("perm_settings",
453  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
454  }
455  }
456 
457  function &executeCommand()
458  {
459  $next_class = $this->ctrl->getNextClass($this);
460  $cmd = $this->ctrl->getCmd();
461  $this->prepareOutput();
462 
463  switch($next_class)
464  {
465  case 'ilpermissiongui':
466  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
467  $perm_gui =& new ilPermissionGUI($this);
468  $ret =& $this->ctrl->forwardCommand($perm_gui);
469  break;
470 
471  default:
472  if(!$cmd)
473  {
474  $cmd = "view";
475  }
476  $cmd .= "Object";
477  $this->$cmd();
478 
479  break;
480  }
481  return true;
482  }
483 
488  {
489  global $ilSetting, $ilCtrl;
490 
491  $ilSetting->set("lang_ext_maintenance", 1);
492  $ilCtrl->redirect($this, "view");
493  }
494 
499  {
500  global $ilSetting, $ilCtrl;
501 
502  $ilSetting->set("lang_ext_maintenance", 0);
503  $ilCtrl->redirect($this, "view");
504  }
505 
507  {
508  global $ilCtrl, $lng;
509 
510  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
511  $conf_screen = new ilConfirmationGUI();
512  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
513  $conf_screen->setHeaderText($lng->txt("lang_refresh_confirm"));
514  $conf_screen->addItem("d", "d", $lng->txt("lang_refresh_confirm_info"));
515  $conf_screen->setCancel($lng->txt("cancel"), "view");
516  $conf_screen->setConfirm($lng->txt("ok"), "refresh");
517 
518  $this->tpl->setContent($conf_screen->getHTML());
519  }
520 
522  {
523  global $ilCtrl, $lng;
524 
525  if (!isset($_POST["id"]))
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  $conf_screen = new ilConfirmationGUI();
533  $conf_screen->setFormAction($ilCtrl->getFormAction($this));
534  $conf_screen->setHeaderText($lng->txt("lang_refresh_confirm_selected"));
535  foreach ($_POST["id"] as $id)
536  {
537  $lang_title = ilObject::_lookupTitle($id);
538  $conf_screen->addItem("id[]", $id, $lng->txt("meta_l_".$lang_title));
539  }
540  $conf_screen->addItem("d", "d", $lng->txt("lang_refresh_confirm_info"));
541  $conf_screen->setCancel($lng->txt("cancel"), "view");
542  $conf_screen->setConfirm($lng->txt("ok"), "refreshSelected");
543  $this->tpl->setContent($conf_screen->getHTML());
544  }
545 
549  function getActions()
550  {
551  global $ilSetting;
552 
553  // standard actions for container
554  return array(
555  "install" => array("name" => "install", "lng" => "install"),
556  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
557  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
558  "refresh" => $ilSetting->get("lang_ext_maintenance") == "1" ?
559  array("name" => "confirmRefreshSelected", "lng" => "refresh") :
560  array("name" => "RefreshSelected", "lng" => "refresh"),
561  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
562  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
563  );
564  }
565 
566 
567 } // END class.ilObjLanguageFolderGUI
568 ?>