ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjLanguageFolderGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
35 {
36  protected HTTPServices $http;
37  protected Refinery $refinery;
38  protected \ILIAS\DI\UIServices $ui;
39 
43  public function __construct(?array $a_data, int $a_id, bool $a_call_by_reference)
44  {
45  global $DIC;
46  $this->type = "lngf";
47  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
48  $this->lng->loadLanguageModule("lng");
49  $this->http = $DIC->http();
50  $this->refinery = $DIC->refinery();
51  $this->ui = $DIC->ui();
52  }
53 
57  public function viewObject(): void
58  {
59  global $DIC;
60 
61  if ($this->checkPermissionBool("write")) {
62  // refresh
63  $refresh = $this->ui->factory()->button()->standard(
64  $this->lng->txt("refresh_languages"),
65  $this->ctrl->getLinkTarget($this, "confirmRefresh")
66  );
67  $this->toolbar->addComponent($refresh);
68 
69  // check languages
70  $check = $this->ui->factory()->button()->standard(
71  $this->lng->txt("check_languages"),
72  $this->ctrl->getLinkTarget($this, "checkLanguage")
73  );
74  $this->toolbar->addComponent($check);
75  }
76 
77  $ilClientIniFile = $DIC["ilClientIniFile"];
78  if ($ilClientIniFile->variableExists("system", "LANGUAGE_LOG")) {
79  $download = $this->ui->factory()->button()->standard(
80  $this->lng->txt("lng_download_deprecated"),
81  $this->ctrl->getLinkTarget($this, "listDeprecated")
82  );
83  $this->toolbar->addComponent($download);
84  }
85 
86  if ($this->checkPermissionBool("write")) {
87  $modal_on = $this->ui->factory()->modal()->interruptive(
88  'ON',
89  $this->lng->txt("lng_enable_language_detection"),
90  $this->ctrl->getFormActionByClass(self::class, "enableLanguageDetection")
91  )
92  ->withActionButtonLabel($this->lng->txt('ok'));
93  $modal_off = $this->ui->factory()->modal()->interruptive(
94  'OFF',
95  $this->lng->txt("lng_disable_language_detection"),
96  $this->ctrl->getFormActionByClass(self::class, "disableLanguageDetection")
97  )
98  ->withActionButtonLabel($this->lng->txt('ok'));
99  $toggleButton = $this->ui->factory()->button()->toggle(
100  $this->lng->txt("language_detection"),
101  $modal_on->getShowSignal(),
102  $modal_off->getShowSignal(),
103  (bool) ($this->settings->get("lang_detection"))
104  )
105  ->withAriaLabel($this->lng->txt("lng_switch_language_detection"));
106  $this->toolbar->addComponent($modal_on);
107  $this->toolbar->addComponent($modal_off);
108  $this->toolbar->addComponent($toggleButton);
109  }
110 
111  $ltab = new ilLanguageTableGUI($this, "view", $this->object);
112  $this->tpl->setContent($ltab->getHTML());
113  }
114 
118  public function installObject(): void
119  {
120  $this->checkPermission("write");
121  $this->lng->loadLanguageModule("meta");
122 
123  foreach ($this->getPostId() as $obj_id) {
124  $langObj = new ilObjLanguage((int) $obj_id);
125  $key = $langObj->install();
126 
127  if ($key !== "") {
128  $lang_installed[] = $key;
129  }
130 
131  unset($langObj);
132  }
133 
134  if (isset($lang_installed)) {
135  if (count($lang_installed) === 1) {
136  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
137  } else {
138  $langnames = [];
139  foreach ($lang_installed as $lang_key) {
140  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
141  }
142  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
143  }
144  } else {
145  $this->data = $this->lng->txt("languages_already_installed");
146  }
147 
148  $this->out();
149  }
150 
151 
155  public function installLocalObject(): void
156  {
157  $this->checkPermission("write");
158  $this->lng->loadLanguageModule("meta");
159 
160  foreach ($this->getPostId() as $obj_id) {
161  $langObj = new ilObjLanguage($obj_id);
162  $key = $langObj->install();
163 
164  if ($key !== "") {
165  $lang_installed[] = $key;
166  }
167 
168  unset($langObj);
169 
170  $langObj = new ilObjLanguage($obj_id);
171  $key = $langObj->install("local");
172 
173  if ($key !== "") {
174  $local_installed[] = $key;
175  }
176 
177  unset($langObj);
178  }
179 
180  if (isset($lang_installed)) {
181  if (count($lang_installed) === 1) {
182  $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
183  } else {
184  $langnames = [];
185  foreach ($lang_installed as $lang_key) {
186  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
187  }
188  $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
189  }
190  }
191 
192  if (isset($local_installed)) {
193  if (count($local_installed) === 1) {
194  $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
195  } else {
196  $langnames = [];
197  foreach ($local_installed as $lang_key) {
198  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
199  }
200  $this->data .= " " . implode(", ", $langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
201  }
202  } else {
203  $this->data .= " " . $this->lng->txt("local_languages_already_installed");
204  }
205 
206  $this->out();
207  }
208 
209 
213  public function uninstallObject(): void
214  {
215  $this->checkPermission('write');
216  $this->lng->loadLanguageModule("meta");
217 
218  $sys_lang = false;
219  $usr_lang = false;
220 
221  // uninstall all selected languages
222  foreach ($this->getPostId() as $obj_id) {
223  $langObj = new ilObjLanguage($obj_id);
224  if (!($sys_lang = $langObj->isSystemLanguage()) && !($usr_lang = $langObj->isUserLanguage())) {
225  $key = $langObj->uninstall();
226  if ($key !== "") {
227  $lang_uninstalled[] = $key;
228  }
229  }
230  unset($langObj);
231  }
232 
233  // generate output message
234  if (isset($lang_uninstalled)) {
235  if (count($lang_uninstalled) === 1) {
236  $this->data = $this->lng->txt("meta_l_" . $lang_uninstalled[0]) . " " . $this->lng->txt("uninstalled");
237  } else {
238  $langnames = [];
239  foreach ($lang_uninstalled as $lang_key) {
240  $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
241  }
242 
243  $this->data = implode(", ", $langnames) . " " . $this->lng->txt("uninstalled");
244  }
245  } elseif ($sys_lang) {
246  $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
247  } elseif ($usr_lang) {
248  $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
249  } else {
250  $this->data = $this->lng->txt("languages_already_uninstalled");
251  }
252 
253  $this->out();
254  }
255 
256 
260  public function uninstallChangesObject(): void
261  {
262  $this->checkPermission("write");
263 
264  $this->data = $this->lng->txt("selected_languages_updated");
265  $this->lng->loadLanguageModule("meta");
266  $refreshed = [];
267 
268  foreach ($this->getPostId() as $id) {
269  $langObj = new ilObjLanguage((int) $id, false);
270 
271  if ($langObj->isInstalled()) {
272  if ($langObj->check()) {
273  $langObj->flush("all");
274  $langObj->insert();
275  $langObj->setTitle($langObj->getKey());
276  $langObj->setDescription("installed");
277  $langObj->update();
278  $refreshed[] = $langObj->getKey();
279  }
280  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
281  }
282 
283  unset($langObj);
284  }
285  ilObjLanguage::refreshPlugins($refreshed);
286  $this->out();
287  }
288 
292  public function refreshObject(): void
293  {
294  $this->checkPermission("write");
295 
297  $this->data = $this->lng->txt("languages_updated");
298  $this->out();
299  }
300 
301 
305  public function refreshSelectedObject(): void
306  {
307  $this->checkPermission("write");
308  $this->data = $this->lng->txt("selected_languages_updated");
309  $this->lng->loadLanguageModule("meta");
310 
311  $refreshed = array();
312  foreach ($this->getPostId() as $id) {
313  $langObj = new ilObjLanguage((int) $id, false);
314  if ($langObj->refresh()) {
315  $refreshed[] = $langObj->getKey();
316  $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
317  }
318  unset($langObj);
319  }
320 
321  ilObjLanguage::refreshPlugins($refreshed);
322  $this->out();
323  }
324 
328  public function setUserLanguageObject(): void
329  {
330  global $DIC;
331  $ilUser = $DIC->user();
332 
333  $this->checkPermission("write");
334  $this->lng->loadLanguageModule("meta");
335 
336  require_once "./Services/User/classes/class.ilObjUser.php";
337 
338  $post_id = $this->getPostId();
339 
340  if (count($post_id) !== 1) {
341  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
342  $this->ctrl->redirect($this, "view");
343  }
344 
345  $obj_id = $post_id[0];
346 
347  $newUserLangObj = new ilObjLanguage($obj_id);
348 
349  if ($newUserLangObj->isUserLanguage()) {
350  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . " " . $this->lng->txt("is_already_your") . " " . $this->lng->txt("user_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
351  $this->ctrl->redirect($this, "view");
352  }
353 
354  if (!$newUserLangObj->isInstalled()) {
355  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . " " . $this->lng->txt("language_not_installed") . "<br/>" . $this->lng->txt("action_aborted"), true);
356  $this->ctrl->redirect($this, "view");
357  }
358 
359  $curUser = new ilObjUser($ilUser->getId());
360  $curUser->setLanguage($newUserLangObj->getKey());
361  $curUser->update();
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 
372  public function setSystemLanguageObject(): void
373  {
374  $this->checkPermission("write");
375  $this->lng->loadLanguageModule("meta");
376 
377  $post_id = $this->getPostId();
378 
379  if (count($post_id) !== 1) {
380  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
381  $this->ctrl->redirect($this, "view");
382  }
383 
384  $obj_id = $post_id[0];
385 
386  $newSysLangObj = new ilObjLanguage($obj_id);
387 
388  if ($newSysLangObj->isSystemLanguage()) {
389  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " " . $this->lng->txt("is_already_your") . " " . $this->lng->txt("system_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
390  $this->ctrl->redirect($this, "view");
391  }
392 
393  if (!$newSysLangObj->isInstalled()) {
394  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " " . $this->lng->txt("language_not_installed") . "<br/>" . $this->lng->txt("action_aborted"), true);
395  $this->ctrl->redirect($this, "view");
396  }
397 
398  $this->ilias->setSetting("language", $newSysLangObj->getKey());
399 
400  // update ini-file
401  $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
402  $this->ilias->ini->write();
403 
404  $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
405 
406  $this->out();
407  }
408 
412  public function checkLanguageObject(): void
413  {
414  $this->checkPermission("write");
415  $this->data = $this->object->checkAllLanguages();
416  $this->out();
417  }
418 
419  public function out(): void
420  {
421  $this->tpl->setOnScreenMessage('info', $this->data, true);
422  $this->ctrl->redirect($this, "view");
423  }
424 
425  public function getAdminTabs(): void
426  {
427  $this->getTabs();
428  }
429 
434  protected function getTabs(): void
435  {
436  if ($this->checkPermissionBool("read")) {
437  $this->tabs_gui->addTab("settings", $this->lng->txt("settings"), $this->ctrl->getLinkTarget($this, "view"));
438  }
439 
440  if ($this->checkPermissionBool("edit_permission")) {
441  $this->tabs_gui->addTab("perm_settings", $this->lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass(array(self::class,"ilpermissiongui"), "perm"));
442  }
443  }
444 
445  public function executeCommand(): void
446  {
447  // always check read permission, needed write permissions are checked in the *Object functions
448  $this->checkPermission("read", "", $this->type, $this->ref_id);
449 
450  $next_class = $this->ctrl->getNextClass($this);
451  $cmd = $this->ctrl->getCmd();
452  $this->prepareOutput();
453 
454  switch ($next_class) {
455  case "ilpermissiongui":
456  include_once "Services/AccessControl/classes/class.ilPermissionGUI.php";
457  $perm_gui = new ilPermissionGUI($this);
458  $this->tabs_gui->activateTab("perm_settings");
459  $this->ctrl->forwardCommand($perm_gui);
460  break;
461 
462  default:
463  $this->tabs_gui->activateTab("settings");
464 
465  if (!$cmd) {
466  $cmd = "view";
467  }
468 
469  $cmd .= "Object";
470  $this->$cmd();
471 
472  break;
473  }
474  }
475 
476  public function confirmRefreshObject(): void
477  {
478  $this->checkPermission("write");
479 
480  $languages = ilObject::_getObjectsByType("lng");
481 
482  $ids = array();
483  foreach ($languages as $lang) {
484  $langObj = new ilObjLanguage((int) $lang["obj_id"], false);
485  if ($langObj->isInstalled()) {
486  $ids[] = $lang["obj_id"];
487  }
488  }
489  $this->confirmRefreshSelectedObject($ids);
490  }
491 
492  public function confirmRefreshSelectedObject(array $a_ids = array()): void
493  {
494  $this->checkPermission("write");
495  $this->lng->loadLanguageModule("meta");
496 
497  $header = '';
498  $ids = [];
499  if (!empty($a_ids)) {
500  $ids = $a_ids;
501  $header = $this->lng->txt("lang_refresh_confirm");
502  } elseif (!empty($post_id = $this->getPostId())) {
503  $ids = $post_id;
504  $header = $this->lng->txt("lang_refresh_confirm_selected");
505  } else {
506  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
507  $this->ctrl->redirect($this, "view");
508  }
509 
510  $conf_screen = new ilConfirmationGUI();
511  $some_changed = false;
512  foreach ($ids as $id) {
513  $lang_key = ilObject::_lookupTitle((int) $id);
514  $lang_title = $this->lng->txt("meta_l_" . $lang_key);
515  $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
516  if (!empty($last_change)) {
517  $some_changed = true;
518  $lang_title .= " (" . $this->lng->txt("last_change") . " "
519  . ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME)) . ")";
520  }
521  $conf_screen->addItem("id[]", (string) $id, $lang_title);
522  }
523 
524  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
525  if ($some_changed) {
526  $header .= "<br />" . $this->lng->txt("lang_refresh_confirm_info");
527  }
528  $conf_screen->setHeaderText($header);
529  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
530  $conf_screen->setConfirm($this->lng->txt("ok"), "refreshSelected");
531  $this->tpl->setContent($conf_screen->getHTML());
532  }
533 
534  public function confirmUninstallObject(): void
535  {
536  $this->checkPermission("write");
537 
538  $this->lng->loadLanguageModule("meta");
539  $conf_screen = new ilConfirmationGUI();
540  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
541  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_confirm"));
542  foreach ($this->getPostId() as $id) {
543  $lang_title = ilObject::_lookupTitle($id);
544  $conf_screen->addItem("id[]", (string) $id, $this->lng->txt("meta_l_" . $lang_title));
545  }
546  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
547  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstall");
548  $this->tpl->setContent($conf_screen->getHTML());
549  }
550 
551  public function confirmUninstallChangesObject(): void
552  {
553  $this->checkPermission('write');
554 
555  $this->lng->loadLanguageModule("meta");
556  $conf_screen = new ilConfirmationGUI();
557  $conf_screen->setFormAction($this->ctrl->getFormAction($this));
558  $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_changes_confirm"));
559  foreach ($this->getPostId() as $id) {
560  $lang_title = ilObject::_lookupTitle($id);
561  $conf_screen->addItem("id[]", (string) $id, $this->lng->txt("meta_l_" . $lang_title));
562  }
563  $conf_screen->setCancel($this->lng->txt("cancel"), "view");
564  $conf_screen->setConfirm($this->lng->txt("ok"), "uninstallChanges");
565  $this->tpl->setContent($conf_screen->getHTML());
566  }
567 
572  public function getActions(): array
573  {
574  // standard actions for container
575  return array(
576  "install" => array("name" => "install", "lng" => "install"),
577  "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
578  "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
579  "refresh" => array("name" => "confirmRefreshSelected", "lng" => "refresh"),
580  "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
581  "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
582  );
583  }
584 
588  protected function disableLanguageDetectionObject(): void
589  {
590  $this->settings->set("lang_detection", '0');
591  $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"));
592  $this->viewObject();
593  }
594 
598  protected function enableLanguageDetectionObject(): void
599  {
600  $this->settings->set("lang_detection", '1');
601  $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"));
602  $this->viewObject();
603  }
604 
608  public function listDeprecatedObject(): void
609  {
610  $button = $this->ui->factory()->button()->standard(
611  $this->lng->txt("download"),
612  $this->ctrl->getLinkTarget($this, "downloadDeprecated")
613  );
614  $this->toolbar->addComponent($button);
615 
616  include_once "./Services/Language/classes/class.ilLangDeprecated.php";
617 
618  $d = new ilLangDeprecated();
619  $res = "";
620  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
621  $res .= $mod . "," . $key . "\n";
622  }
623 
624  $this->tpl->setContent("<pre>" . $res . "</pre>");
625  }
626 
630  public function downloadDeprecatedObject(): void
631  {
632  include_once "./Services/Language/classes/class.ilLangDeprecated.php";
633  $d = new ilLangDeprecated();
634  $res = "";
635  foreach ($d->getDeprecatedLangVars() as $key => $mod) {
636  $res .= $mod . "," . $key . "\n";
637  }
638 
639  ilUtil::deliverData($res, "lang_deprecated.csv");
640  }
641 
645  private function getPostId()
646  {
647  $post_field = [];
648  if ($this->http->wrapper()->post()->has("id")) {
649  $post_field = $this->http->wrapper()->post()->retrieve(
650  "id",
651  $this->refinery->kindlyTo()->dictOf(
652  $this->refinery->kindlyTo()->int()
653  )
654  );
655  }
656  if ($post_field == null) {
657  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
658  $this->ctrl->redirect($this, "view");
659  }
660  return $post_field;
661  }
662 } // END class.ilObjLanguageFolderGUI
refreshSelectedObject()
update selected languages
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
static refreshPlugins(array $a_lang_keys=null)
Refresh languages of activated plugins $a_lang_keys keys of languages to be refreshed (not yet suppor...
prepareOutput(bool $show_sub_objects=true)
refreshObject()
update all installed languages
setSystemLanguageObject()
set the system language
Class ilObjLanguage.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
listDeprecatedObject()
Download deprecated lang entries.
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
static _getObjectsByType(string $obj_type="", int $owner=null)
confirmRefreshSelectedObject(array $a_ids=array())
installLocalObject()
Install local language modifications.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
uninstallChangesObject()
Uninstall local changes in the database.
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
Class ilObjectGUI Basic methods of all Output classes.
string $key
Consumer key/client ID value.
Definition: System.php:193
header include for all ilias files.
downloadDeprecatedObject()
Download deprecated lang entries.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
enableLanguageDetectionObject()
Enable language detection.
viewObject()
show installed languages
$lang
Definition: xapiexit.php:26
disableLanguageDetectionObject()
Disable language detection.
static refreshAll()
Refresh all installed languages.
$check
Definition: buildRTE.php:81
__construct(?array $a_data, int $a_id, bool $a_call_by_reference)
Constructor.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static _getLastLocalChange(string $a_key)
get the date of the last local change $a_key language key Return change_date "yyyy-mm-dd hh:mm:ss" ...
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
checkLanguageObject()
check all languages
Class ilObjLanguageFolderGUI.