ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public 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  public function viewObject()
41  {
42  global $DIC;
43 
44  if ($this->checkPermissionBool('write')) {
45  // refresh
46  $refresh = ilLinkButton::getInstance();
47  $refresh->setUrl($this->ctrl->getLinkTarget($this, "confirmRefresh"));
48  $refresh->setCaption("refresh_languages");
49  $this->toolbar->addButtonInstance($refresh);
50 
51  // check languages
52  $check = ilLinkButton::getInstance();
53  $check->setUrl($this->ctrl->getLinkTarget($this, "checkLanguage"));
54  $check->setCaption("check_languages");
55  $this->toolbar->addButtonInstance($check);
56 
57 
58  if (!$this->settings->get('lang_detection')) {
59  $detect = ilLinkButton::getInstance();
60  $detect->setUrl($this->ctrl->getLinkTarget($this, "enableLanguageDetection"));
61  $detect->setCaption("lng_enable_language_detection");
62  $this->toolbar->addButtonInstance($detect);
63  } else {
64  $detect = ilLinkButton::getInstance();
65  $detect->setUrl($this->ctrl->getLinkTarget($this, "disableLanguageDetection"));
66  $detect->setCaption("lng_disable_language_detection");
67  $this->toolbar->addButtonInstance($detect);
68  }
69  }
70 
71  $ilClientIniFile = $DIC['ilClientIniFile'];
72  if ($ilClientIniFile->variableExists('system', 'LANGUAGE_LOG')) {
73  $download = ilLinkButton::getInstance();
74  $download->setUrl($this->ctrl->getLinkTarget($this, "listDeprecated"));
75  $download->setCaption("lng_download_deprecated");
76  $this->toolbar->addButtonInstance($download);
77  }
78 
79  $ltab = new ilLanguageTableGUI($this, "view", $this->object);
80  $this->tpl->setContent($ltab->getHTML());
81  }
82 
86  public function installObject()
87  {
88  $this->checkPermission('write');
89  $this->lng->loadLanguageModule("meta");
90 
91  if (!isset($_POST["id"])) {
92  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
93  }
94 
95  foreach ($_POST["id"] as $obj_id) {
96  $langObj = new ilObjLanguage($obj_id);
97  $key = $langObj->install();
98 
99  if ($key != "") {
100  $lang_installed[] = $key;
101  }
102 
103  unset($langObj);
104  }
105 
106  if (isset($lang_installed)) {
107  if (count($lang_installed) == 1) {
108  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
109  } else {
110  foreach ($lang_installed as $lang_key) {
111  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
112  }
113  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
114  }
115  } else {
116  $this->data = $this->lng->txt("languages_already_installed");
117  }
118 
119  $this->out();
120  }
121 
122 
126  public function installLocalObject()
127  {
128  $this->checkPermission('write');
129  $this->lng->loadLanguageModule("meta");
130 
131  if (!isset($_POST["id"])) {
132  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
133  }
134 
135  foreach ($_POST["id"] as $obj_id) {
136  $langObj = new ilObjLanguage($obj_id);
137  $key = $langObj->install();
138 
139  if ($key != "") {
140  $lang_installed[] = $key;
141  }
142 
143  unset($langObj);
144 
145  $langObj = new ilObjLanguage($obj_id);
146  $key = $langObj->install('local');
147 
148  if ($key != "") {
149  $local_installed[] = $key;
150  }
151 
152  unset($langObj);
153  }
154 
155  if (isset($lang_installed)) {
156  if (count($lang_installed) == 1) {
157  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
158  } else {
159  foreach ($lang_installed as $lang_key) {
160  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
161  }
162  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
163  }
164  }
165 
166  if (isset($local_installed)) {
167  if (count($local_installed) == 1) {
168  $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
169  } else {
170  foreach ($local_installed as $lang_key) {
171  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
172  }
173  $this->data .= " " . implode(", ", $langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
174  }
175  } else {
176  $this->data .= " " . $this->lng->txt("local_languages_already_installed");
177  }
178 
179  $this->out();
180  }
181 
182 
186  public function uninstallObject()
187  {
188  $this->checkPermission('write');
189  $this->lng->loadLanguageModule("meta");
190 
191  if (!isset($_POST["id"])) {
192  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
193  }
194 
195  // uninstall all selected languages
196  foreach ($_POST["id"] as $obj_id) {
197  $langObj = new ilObjLanguage($obj_id);
198  if (!($sys_lang = $langObj->isSystemLanguage())) {
199  if (!($usr_lang = $langObj->isUserLanguage())) {
200  $key = $langObj->uninstall();
201  if ($key != "") {
202  $lang_uninstalled[] = $key;
203  }
204  }
205  }
206  unset($langObj);
207  }
208 
209  // generate output message
210  if (isset($lang_uninstalled)) {
211  if (count($lang_uninstalled) == 1) {
212  $this->data = $this->lng->txt("meta_l_" . $lang_uninstalled[0]) . " " . $this->lng->txt("uninstalled");
213  } else {
214  foreach ($lang_uninstalled as $lang_key) {
215  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
216  }
217 
218  $this->data = implode(", ", $langnames) . " " . $this->lng->txt("uninstalled");
219  }
220  } elseif ($sys_lang) {
221  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
222  } elseif ($usr_lang) {
223  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
224  } else {
225  $this->data = $this->lng->txt("languages_already_uninstalled");
226  }
227 
228  $this->out();
229  }
230 
231 
235  public function uninstallChangesObject()
236  {
237  $this->checkPermission('write');
238 
239  $this->data = $this->lng->txt("selected_languages_updated");
240  $this->lng->loadLanguageModule("meta");
241 
242  foreach ($_POST["id"] as $id) {
243  $langObj = new ilObjLanguage($id, false);
244 
245  if ($langObj->isInstalled() == true) {
246  if ($langObj->check()) {
247  $langObj->flush('all');
248  $langObj->insert();
249  $langObj->setTitle($langObj->getKey());
250  $langObj->setDescription('installed');
251  $langObj->update();
252  }
253  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
254  }
255 
256  unset($langObj);
257  }
258 
259  $this->out();
260  }
261 
262 
266  public function refreshObject()
267  {
268  $this->checkPermission('write');
269 
271  $this->data = $this->lng->txt("languages_updated");
272  $this->out();
273  }
274 
275 
279  public function refreshSelectedObject()
280  {
281  $this->checkPermission('write');
282  $this->data = $this->lng->txt("selected_languages_updated");
283  $this->lng->loadLanguageModule("meta");
284 
285  $refreshed = array();
286  foreach ($_POST["id"] as $id) {
287  $langObj = new ilObjLanguage($id, false);
288  if ($langObj->refresh()) {
289  $refreshed[] = $langObj->getKey();
290  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
291  }
292  unset($langObj);
293  }
294 
295  ilObjLanguage::refreshPlugins($refreshed);
296  $this->out();
297  }
298 
299 
303  public function setUserLanguageObject()
304  {
305  $this->checkPermission('write');
306  $this->lng->loadLanguageModule("meta");
307 
308  require_once './Services/User/classes/class.ilObjUser.php';
309 
310  if (!isset($_POST["id"])) {
311  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
312  }
313 
314  if (count($_POST["id"]) != 1) {
315  $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
316  }
317 
318  $obj_id = $_POST["id"][0];
319 
320  $newUserLangObj = new ilObjLanguage($obj_id);
321 
322  if ($newUserLangObj->isUserLanguage()) {
323  $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);
324  }
325 
326  if ($newUserLangObj->isInstalled() == false) {
327  $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);
328  }
329 
330  $curUser = new ilObjUser($GLOBALS['DIC']['ilUser']->getId());
331  $curUser->setLanguage($newUserLangObj->getKey());
332  $curUser->update();
333  //$this->setUserLanguage($new_lang_key);
334 
335  $this->data = $this->lng->txt("user_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . ".";
336 
337  $this->out();
338  }
339 
340 
344  public function setSystemLanguageObject()
345  {
346  $this->checkPermission('write');
347  $this->lng->loadLanguageModule("meta");
348 
349  if (!isset($_POST["id"])) {
350  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
351  }
352 
353  if (count($_POST["id"]) != 1) {
354  $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
355  }
356 
357  $obj_id = $_POST["id"][0];
358 
359  $newSysLangObj = new ilObjLanguage($obj_id);
360 
361  if ($newSysLangObj->isSystemLanguage()) {
362  $this->ilias->raiseError($this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " is already the system language!<br>Action aborted!", $this->ilias->error_obj->MESSAGE);
363  }
364 
365  if ($newSysLangObj->isInstalled() == false) {
366  $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);
367  }
368 
369  $this->ilias->setSetting("language", $newSysLangObj->getKey());
370 
371  // update ini-file
372  $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
373  $this->ilias->ini->write();
374 
375  $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
376 
377  $this->out();
378  }
379 
380 
384  public function checkLanguageObject()
385  {
386  $this->checkPermission('write');
387  $this->data = $this->object->checkAllLanguages();
388  $this->out();
389  }
390 
391 
392  public function out()
393  {
394  ilUtil::sendInfo($this->data, true);
395  $this->ctrl->redirect($this, "view");
396  }
397 
398  public function getAdminTabs()
399  {
400  $this->getTabs();
401  }
402 
408  public function getTabs()
409  {
410  if ($this->checkPermissionBool("read")) {
411  $this->tabs_gui->addTab('settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, "view"));
412  }
413 
414  if ($this->checkPermissionBool('edit_permission')) {
415  $this->tabs_gui->addTab('perm_settings', $this->lng->txt('perm_settings'), $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
416  }
417  }
418 
419  public function executeCommand()
420  {
421  // always check read permission, needed write permissions are checked in the *Object functions
422  $this->checkPermission('read', '', $this->type, $this->ref_id);
423 
424  $next_class = $this->ctrl->getNextClass($this);
425  $cmd = $this->ctrl->getCmd();
426  $this->prepareOutput();
427 
428  switch ($next_class) {
429  case 'ilpermissiongui':
430  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
431  $perm_gui = new ilPermissionGUI($this);
432  $this->tabs_gui->activateTab('perm_settings');
433  $this->ctrl->forwardCommand($perm_gui);
434  break;
435 
436  default:
437  $this->tabs_gui->activateTab('settings');
438 
439  if (!$cmd) {
440  $cmd = "view";
441  }
442 
443  $cmd .= "Object";
444  $this->$cmd();
445 
446  break;
447  }
448  return true;
449  }
450 
451  public function confirmRefreshObject()
452  {
453  $this->checkPermission('write');
454 
455  $languages = ilObject::_getObjectsByType("lng");
456 
457  $ids = array();
458  foreach ($languages as $lang) {
459  $langObj = new ilObjLanguage($lang["obj_id"], false);
460  if ($langObj->isInstalled() == true) {
461  $ids[] = $lang["obj_id"];
462  }
463  }
464  $this->confirmRefreshSelectedObject($ids);
465  }
466 
467  public function confirmRefreshSelectedObject($a_ids = array())
468  {
469  $this->checkPermission('write');
470  $this->lng->loadLanguageModule("meta");
471 
472  if (!empty($a_ids)) {
473  $ids = $a_ids;
474  $header = $this->lng->txt("lang_refresh_confirm");
475  } elseif (!empty($_POST["id"])) {
476  $ids = $_POST["id"];
477  $header = $this->lng->txt("lang_refresh_confirm_selected");
478  } else {
479  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
480  }
481 
482 
483  $conf_screen = new ilConfirmationGUI();
484  $some_changed = false;
485  foreach ($ids as $id) {
486  $lang_key = ilObject::_lookupTitle($id);
487  $lang_title = $this->lng->txt('meta_l_' . $lang_key);
488  $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
489  if (!empty($last_change)) {
490  $some_changed = true;
491  $lang_title .= ' (' . $this->lng->txt("last_change") . ' '
492  . ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME)) . ')';
493  }
494  $conf_screen->addItem("id[]", $id, $lang_title);
495  }
496 
497  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
498  if ($some_changed) {
499  $header .= '<br />' . $this->lng->txt("lang_refresh_confirm_info");
500  }
501  $conf_screen->setHeaderText($header);
502  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
503  $conf_screen->setConfirm($this->lng->txt("ok"), "refreshSelected");
504  $this->tpl->setContent($conf_screen->getHTML());
505  }
506 
507  public function confirmUninstallObject()
508  {
509  $this->checkPermission('write');
510 
511  if (!isset($_POST["id"])) {
512  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
513  }
514 
515  $this->lng->loadLanguageModule("meta");
516  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
517  $conf_screen = new ilConfirmationGUI();
518  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
519  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_confirm"));
520  foreach ($_POST["id"] as $id) {
521  $lang_title = ilObject::_lookupTitle($id);
522  $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
523  }
524  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
525  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstall");
526  $this->tpl->setContent($conf_screen->getHTML());
527  }
528 
529 
531  {
532  $this->checkPermission('write');
533 
534  if (!isset($_POST["id"])) {
535  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
536  }
537 
538  $this->lng->loadLanguageModule("meta");
539  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
540  $conf_screen = new ilConfirmationGUI();
541  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
542  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_changes_confirm"));
543  foreach ($_POST["id"] as $id) {
544  $lang_title = ilObject::_lookupTitle($id);
545  $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
546  }
547  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
548  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstallChanges");
549  $this->tpl->setContent($conf_screen->getHTML());
550  }
551 
556  public function getActions()
557  {
558  // standard actions for container
559  return array(
560  "install" => array("name" => "install", "lng" => "install"),
561  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
562  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
563  "refresh" => array("name" => "confirmRefreshSelected", "lng" => "refresh"),
564  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
565  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
566  );
567  }
568 
572  protected function disableLanguageDetectionObject()
573  {
574  $this->settings->set('lang_detection', 0);
575  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
576  $this->viewObject();
577  }
578 
582  protected function enableLanguageDetectionObject()
583  {
584  $this->settings->set('lang_detection', 1);
585  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
586  $this->viewObject();
587  }
588 
592  public function listDeprecatedObject()
593  {
594  $button = ilLinkButton::getInstance();
595  $button->setCaption("download");
596  $button->setUrl($this->ctrl->getLinkTarget($this, "downloadDeprecated"));
597  $this->toolbar->addButtonInstance($button);
598 
599  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
600 
601  $d = new ilLangDeprecated();
602  $res = "";
603  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
604  $res.= $mod . "," . $key . "\n";
605  }
606 
607  $this->tpl->setContent("<pre>" . $res . "</pre>");
608  }
609 
613  public function downloadDeprecatedObject()
614  {
615  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
616  $d = new ilLangDeprecated();
617  $res = "";
618  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
619  $res.= $mod . "," . $key . "\n";
620  }
621 
622  ilUtil::deliverData($res, "lang_deprecated.csv");
623  }
624 } // END class.ilObjLanguageFolderGUI
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.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
refreshObject()
update all installed languages
setSystemLanguageObject()
set the system language
Class ilObjLanguage.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
listDeprecatedObject()
Download deprecated lang entries.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
installLocalObject()
Install local language modifications.
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.
foreach($_POST as $key=> $value) $res
getId()
get object id public
Class ilObjectGUI Basic methods of all Output classes.
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.
enableLanguageDetectionObject()
Enable language detection.
viewObject()
show installed languages
settings()
Definition: settings.php:2
disableLanguageDetectionObject()
Disable language detection.
static refreshAll()
Refresh all installed languages.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static _getLastLocalChange($a_key)
get the date of the last local change
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
$key
Definition: croninfo.php:18
static refreshPlugins($a_lang_keys=null)
$_POST["username"]
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
checkLanguageObject()
check all languages
Class ilObjLanguageFolderGUI.
Confirmation screen class.