ILIAS  release_8 Revision v8.24
class.ilObjLanguageFolderGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\HTTP\Services as HTTPServices;
22use ILIAS\Refinery\Factory as Refinery;
23
35{
36 protected HTTPServices $http;
37 protected Refinery $refinery;
38
42 public function __construct(?array $a_data, int $a_id, bool $a_call_by_reference)
43 {
44 global $DIC;
45 $this->type = "lngf";
46 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
47 //$_GET["sort_by"] = "language";
48 $this->lng->loadLanguageModule("lng");
49 $this->http = $DIC->http();
50 $this->refinery = $DIC->refinery();
51 }
52
56 public function viewObject(): void
57 {
58 global $DIC;
59
60 if ($this->checkPermissionBool("write")) {
61 // refresh
62 $refresh = ilLinkButton::getInstance();
63 $refresh->setUrl($this->ctrl->getLinkTarget($this, "confirmRefresh"));
64 $refresh->setCaption("refresh_languages");
65 $this->toolbar->addButtonInstance($refresh);
66
67 // check languages
69 $check->setUrl($this->ctrl->getLinkTarget($this, "checkLanguage"));
70 $check->setCaption("check_languages");
71 $this->toolbar->addButtonInstance($check);
72 }
73
74 $ilClientIniFile = $DIC["ilClientIniFile"];
75 if ($ilClientIniFile->variableExists("system", "LANGUAGE_LOG")) {
76 $download = ilLinkButton::getInstance();
77 $download->setUrl($this->ctrl->getLinkTarget($this, "listDeprecated"));
78 $download->setCaption("lng_download_deprecated");
79 $this->toolbar->addButtonInstance($download);
80 }
81
82 if ($this->checkPermissionBool("write")) {
83 if (!$this->settings->get("lang_detection")) {
84 // Toggle Button for auto language detection (toggle off)
85 $toggleButton = $DIC->ui()->factory()->button()->toggle("", $DIC->ctrl()->getLinkTarget($this, "enableLanguageDetection"), $DIC->ctrl()->getLinkTarget($this, "disableLanguageDetection"), false)
86 ->withLabel($this->lng->txt("language_detection"))->withAriaLabel($this->lng->txt("lng_enable_language_detection"));
87 } else {
88 // Toggle Button for auto language detection (toggle on)
89 $toggleButton = $DIC->ui()->factory()->button()->toggle("", $DIC->ctrl()->getLinkTarget($this, "enableLanguageDetection"), $DIC->ctrl()->getLinkTarget($this, "disableLanguageDetection"), true)
90 ->withLabel($this->lng->txt("language_detection"))->withAriaLabel($this->lng->txt("lng_disable_language_detection"));
91 }
92 $this->toolbar->addComponent($toggleButton);
93 }
94
95 $ltab = new ilLanguageTableGUI($this, "view", $this->object);
96 $this->tpl->setContent($ltab->getHTML());
97 }
98
102 public function installObject(): void
103 {
104 $this->checkPermission("write");
105 $this->lng->loadLanguageModule("meta");
106
107 foreach ($this->getPostId() as $obj_id) {
108 $langObj = new ilObjLanguage((int) $obj_id);
109 $key = $langObj->install();
110
111 if ($key !== "") {
112 $lang_installed[] = $key;
113 }
114
115 unset($langObj);
116 }
117
118 if (isset($lang_installed)) {
119 if (count($lang_installed) === 1) {
120 $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
121 } else {
122 $langnames = [];
123 foreach ($lang_installed as $lang_key) {
124 $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
125 }
126 $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
127 }
128 } else {
129 $this->data = $this->lng->txt("languages_already_installed");
130 }
131
132 $this->out();
133 }
134
135
139 public function installLocalObject(): void
140 {
141 $this->checkPermission("write");
142 $this->lng->loadLanguageModule("meta");
143
144 foreach ($this->getPostId() as $obj_id) {
145 $langObj = new ilObjLanguage($obj_id);
146 $key = $langObj->install();
147
148 if ($key !== "") {
149 $lang_installed[] = $key;
150 }
151
152 unset($langObj);
153
154 $langObj = new ilObjLanguage($obj_id);
155 $key = $langObj->install("local");
156
157 if ($key !== "") {
158 $local_installed[] = $key;
159 }
160
161 unset($langObj);
162 }
163
164 if (isset($lang_installed)) {
165 if (count($lang_installed) === 1) {
166 $this->data = $this->lng->txt("meta_l_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
167 } else {
168 $langnames = [];
169 foreach ($lang_installed as $lang_key) {
170 $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
171 }
172 $this->data = implode(", ", $langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
173 }
174 }
175
176 if (isset($local_installed)) {
177 if (count($local_installed) === 1) {
178 $this->data .= " " . $this->lng->txt("meta_l_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
179 } else {
180 $langnames = [];
181 foreach ($local_installed as $lang_key) {
182 $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
183 }
184 $this->data .= " " . implode(", ", $langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
185 }
186 } else {
187 $this->data .= " " . $this->lng->txt("local_languages_already_installed");
188 }
189
190 $this->out();
191 }
192
193
197 public function uninstallObject(): void
198 {
199 $this->checkPermission('write');
200 $this->lng->loadLanguageModule("meta");
201
202 $sys_lang = false;
203 $usr_lang = false;
204
205 // uninstall all selected languages
206 foreach ($this->getPostId() as $obj_id) {
207 $langObj = new ilObjLanguage($obj_id);
208 if (!($sys_lang = $langObj->isSystemLanguage()) && !($usr_lang = $langObj->isUserLanguage())) {
209 $key = $langObj->uninstall();
210 if ($key !== "") {
211 $lang_uninstalled[] = $key;
212 }
213 }
214 unset($langObj);
215 }
216
217 // generate output message
218 if (isset($lang_uninstalled)) {
219 if (count($lang_uninstalled) === 1) {
220 $this->data = $this->lng->txt("meta_l_" . $lang_uninstalled[0]) . " " . $this->lng->txt("uninstalled");
221 } else {
222 $langnames = [];
223 foreach ($lang_uninstalled as $lang_key) {
224 $langnames[] = $this->lng->txt("meta_l_" . $lang_key);
225 }
226
227 $this->data = implode(", ", $langnames) . " " . $this->lng->txt("uninstalled");
228 }
229 } elseif ($sys_lang) {
230 $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
231 } elseif ($usr_lang) {
232 $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
233 } else {
234 $this->data = $this->lng->txt("languages_already_uninstalled");
235 }
236
237 $this->out();
238 }
239
240
244 public function uninstallChangesObject(): void
245 {
246 $this->checkPermission("write");
247
248 $this->data = $this->lng->txt("selected_languages_updated");
249 $this->lng->loadLanguageModule("meta");
250 $refreshed = [];
251
252 foreach ($this->getPostId() as $id) {
253 $langObj = new ilObjLanguage((int) $id, false);
254
255 if ($langObj->isInstalled()) {
256 if ($langObj->check()) {
257 $langObj->flush("all");
258 $langObj->insert();
259 $langObj->setTitle($langObj->getKey());
260 $langObj->setDescription("installed");
261 $langObj->update();
262 $refreshed[] = $langObj->getKey();
263 }
264 $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
265 }
266
267 unset($langObj);
268 }
270 $this->out();
271 }
272
276 public function refreshObject(): void
277 {
278 $this->checkPermission("write");
279
281 $this->data = $this->lng->txt("languages_updated");
282 $this->out();
283 }
284
285
289 public function refreshSelectedObject(): void
290 {
291 $this->checkPermission("write");
292 $this->data = $this->lng->txt("selected_languages_updated");
293 $this->lng->loadLanguageModule("meta");
294
295 $refreshed = array();
296 foreach ($this->getPostId() as $id) {
297 $langObj = new ilObjLanguage((int) $id, false);
298 if ($langObj->refresh()) {
299 $refreshed[] = $langObj->getKey();
300 $this->data .= "<br />" . $this->lng->txt("meta_l_" . $langObj->getKey());
301 }
302 unset($langObj);
303 }
304
306 $this->out();
307 }
308
312 public function setUserLanguageObject(): void
313 {
314 global $DIC;
315 $ilUser = $DIC->user();
316
317 $this->checkPermission("write");
318 $this->lng->loadLanguageModule("meta");
319
320 require_once "./Services/User/classes/class.ilObjUser.php";
321
322 $post_id = $this->getPostId();
323
324 if (count($post_id) !== 1) {
325 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
326 $this->ctrl->redirect($this, "view");
327 }
328
329 $obj_id = $post_id[0];
330
331 $newUserLangObj = new ilObjLanguage($obj_id);
332
333 if ($newUserLangObj->isUserLanguage()) {
334 $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);
335 $this->ctrl->redirect($this, "view");
336 }
337
338 if (!$newUserLangObj->isInstalled()) {
339 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . " " . $this->lng->txt("language_not_installed") . "<br/>" . $this->lng->txt("action_aborted"), true);
340 $this->ctrl->redirect($this, "view");
341 }
342
343 $curUser = new ilObjUser($ilUser->getId());
344 $curUser->setLanguage($newUserLangObj->getKey());
345 $curUser->update();
346
347 $this->data = $this->lng->txt("user_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . ".";
348
349 $this->out();
350 }
351
352
356 public function setSystemLanguageObject(): void
357 {
358 $this->checkPermission("write");
359 $this->lng->loadLanguageModule("meta");
360
361 $post_id = $this->getPostId();
362
363 if (count($post_id) !== 1) {
364 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), true);
365 $this->ctrl->redirect($this, "view");
366 }
367
368 $obj_id = $post_id[0];
369
370 $newSysLangObj = new ilObjLanguage($obj_id);
371
372 if ($newSysLangObj->isSystemLanguage()) {
373 $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);
374 $this->ctrl->redirect($this, "view");
375 }
376
377 if (!$newSysLangObj->isInstalled()) {
378 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " " . $this->lng->txt("language_not_installed") . "<br/>" . $this->lng->txt("action_aborted"), true);
379 $this->ctrl->redirect($this, "view");
380 }
381
382 $this->ilias->setSetting("language", $newSysLangObj->getKey());
383
384 // update ini-file
385 $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
386 $this->ilias->ini->write();
387
388 $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
389
390 $this->out();
391 }
392
396 public function checkLanguageObject(): void
397 {
398 $this->checkPermission("write");
399 $this->data = $this->object->checkAllLanguages();
400 $this->out();
401 }
402
403 public function out(): void
404 {
405 $this->tpl->setOnScreenMessage('info', $this->data, true);
406 $this->ctrl->redirect($this, "view");
407 }
408
409 public function getAdminTabs(): void
410 {
411 $this->getTabs();
412 }
413
418 protected function getTabs(): void
419 {
420 if ($this->checkPermissionBool("read")) {
421 $this->tabs_gui->addTab("settings", $this->lng->txt("settings"), $this->ctrl->getLinkTarget($this, "view"));
422 }
423
424 if ($this->checkPermissionBool("edit_permission")) {
425 $this->tabs_gui->addTab("perm_settings", $this->lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass(array(self::class,"ilpermissiongui"), "perm"));
426 }
427 }
428
429 public function executeCommand(): void
430 {
431 // always check read permission, needed write permissions are checked in the *Object functions
432 $this->checkPermission("read", "", $this->type, $this->ref_id);
433
434 $next_class = $this->ctrl->getNextClass($this);
435 $cmd = $this->ctrl->getCmd();
436 $this->prepareOutput();
437
438 switch ($next_class) {
439 case "ilpermissiongui":
440 include_once "Services/AccessControl/classes/class.ilPermissionGUI.php";
441 $perm_gui = new ilPermissionGUI($this);
442 $this->tabs_gui->activateTab("perm_settings");
443 $this->ctrl->forwardCommand($perm_gui);
444 break;
445
446 default:
447 $this->tabs_gui->activateTab("settings");
448
449 if (!$cmd) {
450 $cmd = "view";
451 }
452
453 $cmd .= "Object";
454 $this->$cmd();
455
456 break;
457 }
458 }
459
460 public function confirmRefreshObject(): void
461 {
462 $this->checkPermission("write");
463
464 $languages = ilObject::_getObjectsByType("lng");
465
466 $ids = array();
467 foreach ($languages as $lang) {
468 $langObj = new ilObjLanguage((int) $lang["obj_id"], false);
469 if ($langObj->isInstalled()) {
470 $ids[] = $lang["obj_id"];
471 }
472 }
473 $this->confirmRefreshSelectedObject($ids);
474 }
475
476 public function confirmRefreshSelectedObject(array $a_ids = array()): void
477 {
478 $this->checkPermission("write");
479 $this->lng->loadLanguageModule("meta");
480
481 $header = '';
482 $ids = [];
483 if (!empty($a_ids)) {
484 $ids = $a_ids;
485 $header = $this->lng->txt("lang_refresh_confirm");
486 } elseif (!empty($post_id = $this->getPostId())) {
487 $ids = $post_id;
488 $header = $this->lng->txt("lang_refresh_confirm_selected");
489 } else {
490 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
491 $this->ctrl->redirect($this, "view");
492 }
493
494 $conf_screen = new ilConfirmationGUI();
495 $some_changed = false;
496 foreach ($ids as $id) {
497 $lang_key = ilObject::_lookupTitle((int) $id);
498 $lang_title = $this->lng->txt("meta_l_" . $lang_key);
499 $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
500 if (!empty($last_change)) {
501 $some_changed = true;
502 $lang_title .= " (" . $this->lng->txt("last_change") . " "
504 }
505 $conf_screen->addItem("id[]", (string) $id, $lang_title);
506 }
507
508 $conf_screen->setFormAction($this->ctrl->getFormAction($this));
509 if ($some_changed) {
510 $header .= "<br />" . $this->lng->txt("lang_refresh_confirm_info");
511 }
512 $conf_screen->setHeaderText($header);
513 $conf_screen->setCancel($this->lng->txt("cancel"), "view");
514 $conf_screen->setConfirm($this->lng->txt("ok"), "refreshSelected");
515 $this->tpl->setContent($conf_screen->getHTML());
516 }
517
518 public function confirmUninstallObject(): void
519 {
520 $this->checkPermission("write");
521
522 $this->lng->loadLanguageModule("meta");
523 $conf_screen = new ilConfirmationGUI();
524 $conf_screen->setFormAction($this->ctrl->getFormAction($this));
525 $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_confirm"));
526 foreach ($this->getPostId() as $id) {
527 $lang_title = ilObject::_lookupTitle($id);
528 $conf_screen->addItem("id[]", (string) $id, $this->lng->txt("meta_l_" . $lang_title));
529 }
530 $conf_screen->setCancel($this->lng->txt("cancel"), "view");
531 $conf_screen->setConfirm($this->lng->txt("ok"), "uninstall");
532 $this->tpl->setContent($conf_screen->getHTML());
533 }
534
535 public function confirmUninstallChangesObject(): void
536 {
537 $this->checkPermission('write');
538
539 $this->lng->loadLanguageModule("meta");
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 ($this->getPostId() as $id) {
544 $lang_title = ilObject::_lookupTitle($id);
545 $conf_screen->addItem("id[]", (string) $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(): array
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(): void
573 {
574 $this->settings->set("lang_detection", '0');
575 $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"));
576 $this->viewObject();
577 }
578
582 protected function enableLanguageDetectionObject(): void
583 {
584 $this->settings->set("lang_detection", '1');
585 $this->tpl->setOnScreenMessage('success', $this->lng->txt("saved_successfully"));
586 $this->viewObject();
587 }
588
592 public function listDeprecatedObject(): void
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(): void
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
628 private function getPostId()
629 {
630 $post_field = [];
631 if ($this->http->wrapper()->post()->has("id")) {
632 $post_field = $this->http->wrapper()->post()->retrieve(
633 "id",
634 $this->refinery->kindlyTo()->dictOf(
635 $this->refinery->kindlyTo()->int()
636 )
637 );
638 }
639 if ($post_field == null) {
640 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
641 $this->ctrl->redirect($this, "view");
642 }
643 return $post_field;
644 }
645} // END class.ilObjLanguageFolderGUI
$check
Definition: buildRTE.php:81
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjLanguageFolderGUI.
checkLanguageObject()
check all languages
disableLanguageDetectionObject()
Disable language detection.
setSystemLanguageObject()
set the system language
installLocalObject()
Install local language modifications.
__construct(?array $a_data, int $a_id, bool $a_call_by_reference)
Constructor.
enableLanguageDetectionObject()
Enable language detection.
refreshSelectedObject()
update selected languages
uninstallChangesObject()
Uninstall local changes in the database.
viewObject()
show installed languages
refreshObject()
update all installed languages
downloadDeprecatedObject()
Download deprecated lang entries.
listDeprecatedObject()
Download deprecated lang entries.
confirmRefreshSelectedObject(array $a_ids=array())
getAdminTabs()
administration tabs show only permissions and trash folder
Class ilObjLanguage.
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"
static refreshAll()
Refresh all installed languages.
static refreshPlugins(array $a_lang_keys=null)
Refresh languages of activated plugins $a_lang_keys keys of languages to be refreshed (not yet suppor...
User class.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
prepareOutput(bool $show_sub_objects=true)
static _getObjectsByType(string $obj_type="", int $owner=null)
static _lookupTitle(int $obj_id)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
header include for all ilias files.
$lang
Definition: xapiexit.php:26