ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
59  $ilClientIniFile = $DIC['ilClientIniFile'];
60  if ($ilClientIniFile->variableExists('system', 'LANGUAGE_LOG')) {
61  $download = ilLinkButton::getInstance();
62  $download->setUrl($this->ctrl->getLinkTarget($this, "listDeprecated"));
63  $download->setCaption("lng_download_deprecated");
64  $this->toolbar->addButtonInstance($download);
65  }
66 
67  if ($this->checkPermissionBool('write')) {
68  if (!$this->settings->get('lang_detection')) {
69 
70  // Toggle Button for auto language detection (toggle off)
71  $toggleButton = $DIC->ui()->factory()->button()->toggle("", $DIC->ctrl()->getLinkTarget($this, "enableLanguageDetection"), $DIC->ctrl()->getLinkTarget($this, "disableLanguageDetection"), false)
72  ->withLabel($this->lng->txt("language_detection"))->withAriaLabel($this->lng->txt("lng_enable_language_detection"));
73  $this->toolbar->addComponent($toggleButton);
74  } else {
75 
76  // Toggle Button for auto language detection (toggle on)
77  $toggleButton = $DIC->ui()->factory()->button()->toggle("", $DIC->ctrl()->getLinkTarget($this, "enableLanguageDetection"), $DIC->ctrl()->getLinkTarget($this, "disableLanguageDetection"), true)
78  ->withLabel($this->lng->txt("language_detection"))->withAriaLabel($this->lng->txt("lng_disable_language_detection"));
79  $this->toolbar->addComponent($toggleButton);
80  }
81  }
82 
83  $ltab = new ilLanguageTableGUI($this, "view", $this->object);
84  $this->tpl->setContent($ltab->getHTML());
85  }
86 
90  public function installObject()
91  {
92  $this->checkPermission('write');
93  $this->lng->loadLanguageModule("meta");
94 
95  if (!isset($_POST["id"])) {
96  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
97  }
98 
99  foreach ($_POST["id"] as $obj_id) {
100  $langObj = new ilObjLanguage($obj_id);
101  $key = $langObj->install();
102 
103  if ($key != "") {
104  $lang_installed[] = $key;
105  }
106 
107  unset($langObj);
108  }
109 
110  if (isset($lang_installed)) {
111  if (count($lang_installed) == 1) {
112  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
113  } else {
114  foreach ($lang_installed as $lang_key) {
115  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
116  }
117  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
118  }
119  } else {
120  $this->data = $this->lng->txt("languages_already_installed");
121  }
122 
123  $this->out();
124  }
125 
126 
130  public function installLocalObject()
131  {
132  $this->checkPermission('write');
133  $this->lng->loadLanguageModule("meta");
134 
135  if (!isset($_POST["id"])) {
136  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
137  }
138 
139  foreach ($_POST["id"] as $obj_id) {
140  $langObj = new ilObjLanguage($obj_id);
141  $key = $langObj->install();
142 
143  if ($key != "") {
144  $lang_installed[] = $key;
145  }
146 
147  unset($langObj);
148 
149  $langObj = new ilObjLanguage($obj_id);
150  $key = $langObj->install('local');
151 
152  if ($key != "") {
153  $local_installed[] = $key;
154  }
155 
156  unset($langObj);
157  }
158 
159  if (isset($lang_installed)) {
160  if (count($lang_installed) == 1) {
161  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
162  } else {
163  foreach ($lang_installed as $lang_key) {
164  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
165  }
166  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
167  }
168  }
169 
170  if (isset($local_installed)) {
171  if (count($local_installed) == 1) {
172  $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
173  } else {
174  foreach ($local_installed as $lang_key) {
175  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
176  }
177  $this->data .= " " . implode(", ", $langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
178  }
179  } else {
180  $this->data .= " " . $this->lng->txt("local_languages_already_installed");
181  }
182 
183  $this->out();
184  }
185 
186 
190  public function uninstallObject()
191  {
192  $this->checkPermission('write');
193  $this->lng->loadLanguageModule("meta");
194 
195  if (!isset($_POST["id"])) {
196  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
197  }
198 
199  // uninstall all selected languages
200  foreach ($_POST["id"] as $obj_id) {
201  $langObj = new ilObjLanguage($obj_id);
202  if (!($sys_lang = $langObj->isSystemLanguage())) {
203  if (!($usr_lang = $langObj->isUserLanguage())) {
204  $key = $langObj->uninstall();
205  if ($key != "") {
206  $lang_uninstalled[] = $key;
207  }
208  }
209  }
210  unset($langObj);
211  }
212 
213  // generate output message
214  if (isset($lang_uninstalled)) {
215  if (count($lang_uninstalled) == 1) {
216  $this->data = $this->lng->txt("meta_l_" . $lang_uninstalled[0]) . " " . $this->lng->txt("uninstalled");
217  } else {
218  foreach ($lang_uninstalled as $lang_key) {
219  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
220  }
221 
222  $this->data = implode(", ", $langnames) . " " . $this->lng->txt("uninstalled");
223  }
224  } elseif ($sys_lang) {
225  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
226  } elseif ($usr_lang) {
227  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
228  } else {
229  $this->data = $this->lng->txt("languages_already_uninstalled");
230  }
231 
232  $this->out();
233  }
234 
235 
239  public function uninstallChangesObject()
240  {
241  $this->checkPermission('write');
242 
243  $this->data = $this->lng->txt("selected_languages_updated");
244  $this->lng->loadLanguageModule("meta");
245 
246  foreach ($_POST["id"] as $id) {
247  $langObj = new ilObjLanguage($id, false);
248 
249  if ($langObj->isInstalled() == true) {
250  if ($langObj->check()) {
251  $langObj->flush('all');
252  $langObj->insert();
253  $langObj->setTitle($langObj->getKey());
254  $langObj->setDescription('installed');
255  $langObj->update();
256  }
257  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
258  }
259 
260  unset($langObj);
261  }
262 
263  $this->out();
264  }
265 
266 
270  public function refreshObject()
271  {
272  $this->checkPermission('write');
273 
275  $this->data = $this->lng->txt("languages_updated");
276  $this->out();
277  }
278 
279 
283  public function refreshSelectedObject()
284  {
285  $this->checkPermission('write');
286  $this->data = $this->lng->txt("selected_languages_updated");
287  $this->lng->loadLanguageModule("meta");
288 
289  $refreshed = array();
290  foreach ($_POST["id"] as $id) {
291  $langObj = new ilObjLanguage($id, false);
292  if ($langObj->refresh()) {
293  $refreshed[] = $langObj->getKey();
294  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
295  }
296  unset($langObj);
297  }
298 
299  ilObjLanguage::refreshPlugins($refreshed);
300  $this->out();
301  }
302 
303 
307  public function setUserLanguageObject()
308  {
309  global $DIC;
310  $ilUser = $DIC->user();
311 
312  $this->checkPermission('write');
313  $this->lng->loadLanguageModule("meta");
314 
315  require_once './Services/User/classes/class.ilObjUser.php';
316 
317  if (!isset($_POST["id"])) {
318  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
319  }
320 
321  if (count($_POST["id"]) != 1) {
322  $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
323  }
324 
325  $obj_id = $_POST["id"][0];
326 
327  $newUserLangObj = new ilObjLanguage($obj_id);
328 
329  if ($newUserLangObj->isUserLanguage()) {
330  $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);
331  }
332 
333  if ($newUserLangObj->isInstalled() == false) {
334  $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);
335  }
336 
337 
338  $curUser = new ilObjUser($ilUser->getId());
339  $curUser->setLanguage($newUserLangObj->getKey());
340  $curUser->update();
341 
342  $this->data = $this->lng->txt("user_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . ".";
343 
344  $this->out();
345  }
346 
347 
351  public function setSystemLanguageObject()
352  {
353  $this->checkPermission('write');
354  $this->lng->loadLanguageModule("meta");
355 
356  if (!isset($_POST["id"])) {
357  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
358  }
359 
360  if (count($_POST["id"]) != 1) {
361  $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
362  }
363 
364  $obj_id = $_POST["id"][0];
365 
366  $newSysLangObj = new ilObjLanguage($obj_id);
367 
368  if ($newSysLangObj->isSystemLanguage()) {
369  $this->ilias->raiseError($this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " is already the system language!<br>Action aborted!", $this->ilias->error_obj->MESSAGE);
370  }
371 
372  if ($newSysLangObj->isInstalled() == false) {
373  $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);
374  }
375 
376  $this->ilias->setSetting("language", $newSysLangObj->getKey());
377 
378  // update ini-file
379  $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
380  $this->ilias->ini->write();
381 
382  $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
383 
384  $this->out();
385  }
386 
387 
391  public function checkLanguageObject()
392  {
393  $this->checkPermission('write');
394  $this->data = $this->object->checkAllLanguages();
395  $this->out();
396  }
397 
398 
399  public function out()
400  {
401  ilUtil::sendInfo($this->data, true);
402  $this->ctrl->redirect($this, "view");
403  }
404 
405  public function getAdminTabs()
406  {
407  $this->getTabs();
408  }
409 
415  public function getTabs()
416  {
417  if ($this->checkPermissionBool("read")) {
418  $this->tabs_gui->addTab('settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, "view"));
419  }
420 
421  if ($this->checkPermissionBool('edit_permission')) {
422  $this->tabs_gui->addTab('perm_settings', $this->lng->txt('perm_settings'), $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
423  }
424  }
425 
426  public function executeCommand()
427  {
428  // always check read permission, needed write permissions are checked in the *Object functions
429  $this->checkPermission('read', '', $this->type, $this->ref_id);
430 
431  $next_class = $this->ctrl->getNextClass($this);
432  $cmd = $this->ctrl->getCmd();
433  $this->prepareOutput();
434 
435  switch ($next_class) {
436  case 'ilpermissiongui':
437  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
438  $perm_gui = new ilPermissionGUI($this);
439  $this->tabs_gui->activateTab('perm_settings');
440  $this->ctrl->forwardCommand($perm_gui);
441  break;
442 
443  default:
444  $this->tabs_gui->activateTab('settings');
445 
446  if (!$cmd) {
447  $cmd = "view";
448  }
449 
450  $cmd .= "Object";
451  $this->$cmd();
452 
453  break;
454  }
455  return true;
456  }
457 
458  public function confirmRefreshObject()
459  {
460  $this->checkPermission('write');
461 
462  $languages = ilObject::_getObjectsByType("lng");
463 
464  $ids = array();
465  foreach ($languages as $lang) {
466  $langObj = new ilObjLanguage($lang["obj_id"], false);
467  if ($langObj->isInstalled() == true) {
468  $ids[] = $lang["obj_id"];
469  }
470  }
471  $this->confirmRefreshSelectedObject($ids);
472  }
473 
474  public function confirmRefreshSelectedObject($a_ids = array())
475  {
476  $this->checkPermission('write');
477  $this->lng->loadLanguageModule("meta");
478 
479  if (!empty($a_ids)) {
480  $ids = $a_ids;
481  $header = $this->lng->txt("lang_refresh_confirm");
482  } elseif (!empty($_POST["id"])) {
483  $ids = $_POST["id"];
484  $header = $this->lng->txt("lang_refresh_confirm_selected");
485  } else {
486  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
487  }
488 
489 
490  $conf_screen = new ilConfirmationGUI();
491  $some_changed = false;
492  foreach ($ids as $id) {
493  $lang_key = ilObject::_lookupTitle($id);
494  $lang_title = $this->lng->txt('meta_l_' . $lang_key);
495  $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
496  if (!empty($last_change)) {
497  $some_changed = true;
498  $lang_title .= ' (' . $this->lng->txt("last_change") . ' '
499  . ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME)) . ')';
500  }
501  $conf_screen->addItem("id[]", $id, $lang_title);
502  }
503 
504  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
505  if ($some_changed) {
506  $header .= '<br />' . $this->lng->txt("lang_refresh_confirm_info");
507  }
508  $conf_screen->setHeaderText($header);
509  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
510  $conf_screen->setConfirm($this->lng->txt("ok"), "refreshSelected");
511  $this->tpl->setContent($conf_screen->getHTML());
512  }
513 
514  public function confirmUninstallObject()
515  {
516  $this->checkPermission('write');
517 
518  if (!isset($_POST["id"])) {
519  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
520  }
521 
522  $this->lng->loadLanguageModule("meta");
523  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
524  $conf_screen = new ilConfirmationGUI();
525  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
526  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_confirm"));
527  foreach ($_POST["id"] as $id) {
528  $lang_title = ilObject::_lookupTitle($id);
529  $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
530  }
531  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
532  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstall");
533  $this->tpl->setContent($conf_screen->getHTML());
534  }
535 
536 
538  {
539  $this->checkPermission('write');
540 
541  if (!isset($_POST["id"])) {
542  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
543  }
544 
545  $this->lng->loadLanguageModule("meta");
546  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
547  $conf_screen = new ilConfirmationGUI();
548  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
549  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_changes_confirm"));
550  foreach ($_POST["id"] as $id) {
551  $lang_title = ilObject::_lookupTitle($id);
552  $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
553  }
554  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
555  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstallChanges");
556  $this->tpl->setContent($conf_screen->getHTML());
557  }
558 
563  public function getActions()
564  {
565  // standard actions for container
566  return array(
567  "install" => array("name" => "install", "lng" => "install"),
568  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
569  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
570  "refresh" => array("name" => "confirmRefreshSelected", "lng" => "refresh"),
571  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
572  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
573  );
574  }
575 
579  protected function disableLanguageDetectionObject()
580  {
581  $this->settings->set('lang_detection', 0);
582  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
583  $this->viewObject();
584  }
585 
589  protected function enableLanguageDetectionObject()
590  {
591  $this->settings->set('lang_detection', 1);
592  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
593  $this->viewObject();
594  }
595 
599  public function listDeprecatedObject()
600  {
601  $button = ilLinkButton::getInstance();
602  $button->setCaption("download");
603  $button->setUrl($this->ctrl->getLinkTarget($this, "downloadDeprecated"));
604  $this->toolbar->addButtonInstance($button);
605 
606  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
607 
608  $d = new ilLangDeprecated();
609  $res = "";
610  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
611  $res .= $mod . "," . $key . "\n";
612  }
613 
614  $this->tpl->setContent("<pre>" . $res . "</pre>");
615  }
616 
620  public function downloadDeprecatedObject()
621  {
622  include_once("./Services/Language/classes/class.ilLangDeprecated.php");
623  $d = new ilLangDeprecated();
624  $res = "";
625  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
626  $res .= $mod . "," . $key . "\n";
627  }
628 
629  ilUtil::deliverData($res, "lang_deprecated.csv");
630  }
631 } // END class.ilObjLanguageFolderGUI
refreshSelectedObject()
update selected languages
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
settings()
Definition: settings.php:2
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.
listDeprecatedObject()
Download deprecated lang entries.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
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
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file) ...
downloadDeprecatedObject()
Download deprecated lang entries.
enableLanguageDetectionObject()
Enable language detection.
viewObject()
show installed languages
$lang
Definition: xapiexit.php:8
__construct(Container $dic, ilPlugin $plugin)
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.
$ilUser
Definition: imgupload.php:18
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.
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.