ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
17require_once "./Services/Language/classes/class.ilObjLanguage.php";
18require_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
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
296 $this->out();
297 }
298
299
303 public function setUserLanguageObject()
304 {
305 global $DIC;
306 $ilUser = $DIC->user();
307
308 $this->checkPermission('write');
309 $this->lng->loadLanguageModule("meta");
310
311 require_once './Services/User/classes/class.ilObjUser.php';
312
313 if (!isset($_POST["id"])) {
314 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
315 }
316
317 if (count($_POST["id"]) != 1) {
318 $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
319 }
320
321 $obj_id = $_POST["id"][0];
322
323 $newUserLangObj = new ilObjLanguage($obj_id);
324
325 if ($newUserLangObj->isUserLanguage()) {
326 $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);
327 }
328
329 if ($newUserLangObj->isInstalled() == false) {
330 $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);
331 }
332
333
334 $curUser = new ilObjUser($ilUser->getId());
335 $curUser->setLanguage($newUserLangObj->getKey());
336 $curUser->update();
337
338 $this->data = $this->lng->txt("user_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newUserLangObj->getKey()) . ".";
339
340 $this->out();
341 }
342
343
347 public function setSystemLanguageObject()
348 {
349 $this->checkPermission('write');
350 $this->lng->loadLanguageModule("meta");
351
352 if (!isset($_POST["id"])) {
353 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
354 }
355
356 if (count($_POST["id"]) != 1) {
357 $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
358 }
359
360 $obj_id = $_POST["id"][0];
361
362 $newSysLangObj = new ilObjLanguage($obj_id);
363
364 if ($newSysLangObj->isSystemLanguage()) {
365 $this->ilias->raiseError($this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " is already the system language!<br>Action aborted!", $this->ilias->error_obj->MESSAGE);
366 }
367
368 if ($newSysLangObj->isInstalled() == false) {
369 $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);
370 }
371
372 $this->ilias->setSetting("language", $newSysLangObj->getKey());
373
374 // update ini-file
375 $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
376 $this->ilias->ini->write();
377
378 $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
379
380 $this->out();
381 }
382
383
387 public function checkLanguageObject()
388 {
389 $this->checkPermission('write');
390 $this->data = $this->object->checkAllLanguages();
391 $this->out();
392 }
393
394
395 public function out()
396 {
397 ilUtil::sendInfo($this->data, true);
398 $this->ctrl->redirect($this, "view");
399 }
400
401 public function getAdminTabs()
402 {
403 $this->getTabs();
404 }
405
411 public function getTabs()
412 {
413 if ($this->checkPermissionBool("read")) {
414 $this->tabs_gui->addTab('settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, "view"));
415 }
416
417 if ($this->checkPermissionBool('edit_permission')) {
418 $this->tabs_gui->addTab('perm_settings', $this->lng->txt('perm_settings'), $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
419 }
420 }
421
422 public function executeCommand()
423 {
424 // always check read permission, needed write permissions are checked in the *Object functions
425 $this->checkPermission('read', '', $this->type, $this->ref_id);
426
427 $next_class = $this->ctrl->getNextClass($this);
428 $cmd = $this->ctrl->getCmd();
429 $this->prepareOutput();
430
431 switch ($next_class) {
432 case 'ilpermissiongui':
433 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
434 $perm_gui = new ilPermissionGUI($this);
435 $this->tabs_gui->activateTab('perm_settings');
436 $this->ctrl->forwardCommand($perm_gui);
437 break;
438
439 default:
440 $this->tabs_gui->activateTab('settings');
441
442 if (!$cmd) {
443 $cmd = "view";
444 }
445
446 $cmd .= "Object";
447 $this->$cmd();
448
449 break;
450 }
451 return true;
452 }
453
454 public function confirmRefreshObject()
455 {
456 $this->checkPermission('write');
457
459
460 $ids = array();
461 foreach ($languages as $lang) {
462 $langObj = new ilObjLanguage($lang["obj_id"], false);
463 if ($langObj->isInstalled() == true) {
464 $ids[] = $lang["obj_id"];
465 }
466 }
467 $this->confirmRefreshSelectedObject($ids);
468 }
469
470 public function confirmRefreshSelectedObject($a_ids = array())
471 {
472 $this->checkPermission('write');
473 $this->lng->loadLanguageModule("meta");
474
475 if (!empty($a_ids)) {
476 $ids = $a_ids;
477 $header = $this->lng->txt("lang_refresh_confirm");
478 } elseif (!empty($_POST["id"])) {
479 $ids = $_POST["id"];
480 $header = $this->lng->txt("lang_refresh_confirm_selected");
481 } else {
482 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
483 }
484
485
486 $conf_screen = new ilConfirmationGUI();
487 $some_changed = false;
488 foreach ($ids as $id) {
489 $lang_key = ilObject::_lookupTitle($id);
490 $lang_title = $this->lng->txt('meta_l_' . $lang_key);
491 $last_change = ilObjLanguage::_getLastLocalChange($lang_key);
492 if (!empty($last_change)) {
493 $some_changed = true;
494 $lang_title .= ' (' . $this->lng->txt("last_change") . ' '
496 }
497 $conf_screen->addItem("id[]", $id, $lang_title);
498 }
499
500 $conf_screen->setFormAction($this->ctrl->getFormAction($this));
501 if ($some_changed) {
502 $header .= '<br />' . $this->lng->txt("lang_refresh_confirm_info");
503 }
504 $conf_screen->setHeaderText($header);
505 $conf_screen->setCancel($this->lng->txt("cancel"), "view");
506 $conf_screen->setConfirm($this->lng->txt("ok"), "refreshSelected");
507 $this->tpl->setContent($conf_screen->getHTML());
508 }
509
510 public function confirmUninstallObject()
511 {
512 $this->checkPermission('write');
513
514 if (!isset($_POST["id"])) {
515 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
516 }
517
518 $this->lng->loadLanguageModule("meta");
519 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
520 $conf_screen = new ilConfirmationGUI();
521 $conf_screen->setFormAction($this->ctrl->getFormAction($this));
522 $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_confirm"));
523 foreach ($_POST["id"] as $id) {
524 $lang_title = ilObject::_lookupTitle($id);
525 $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
526 }
527 $conf_screen->setCancel($this->lng->txt("cancel"), "view");
528 $conf_screen->setConfirm($this->lng->txt("ok"), "uninstall");
529 $this->tpl->setContent($conf_screen->getHTML());
530 }
531
532
534 {
535 $this->checkPermission('write');
536
537 if (!isset($_POST["id"])) {
538 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
539 }
540
541 $this->lng->loadLanguageModule("meta");
542 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
543 $conf_screen = new ilConfirmationGUI();
544 $conf_screen->setFormAction($this->ctrl->getFormAction($this));
545 $conf_screen->setHeaderText($this->lng->txt("lang_uninstall_changes_confirm"));
546 foreach ($_POST["id"] as $id) {
547 $lang_title = ilObject::_lookupTitle($id);
548 $conf_screen->addItem("id[]", $id, $this->lng->txt("meta_l_" . $lang_title));
549 }
550 $conf_screen->setCancel($this->lng->txt("cancel"), "view");
551 $conf_screen->setConfirm($this->lng->txt("ok"), "uninstallChanges");
552 $this->tpl->setContent($conf_screen->getHTML());
553 }
554
559 public function getActions()
560 {
561 // standard actions for container
562 return array(
563 "install" => array("name" => "install", "lng" => "install"),
564 "installLocal" => array("name" => "installLocal", "lng" => "install_local"),
565 "uninstall" => array("name" => "uninstall", "lng" => "uninstall"),
566 "refresh" => array("name" => "confirmRefreshSelected", "lng" => "refresh"),
567 "setSystemLanguage" => array("name" => "setSystemLanguage", "lng" => "setSystemLanguage"),
568 "setUserLanguage" => array("name" => "setUserLanguage", "lng" => "setUserLanguage")
569 );
570 }
571
576 {
577 $this->settings->set('lang_detection', 0);
578 ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
579 $this->viewObject();
580 }
581
585 protected function enableLanguageDetectionObject()
586 {
587 $this->settings->set('lang_detection', 1);
588 ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
589 $this->viewObject();
590 }
591
595 public function listDeprecatedObject()
596 {
597 $button = ilLinkButton::getInstance();
598 $button->setCaption("download");
599 $button->setUrl($this->ctrl->getLinkTarget($this, "downloadDeprecated"));
600 $this->toolbar->addButtonInstance($button);
601
602 include_once("./Services/Language/classes/class.ilLangDeprecated.php");
603
604 $d = new ilLangDeprecated();
605 $res = "";
606 foreach ($d->getDeprecatedLangVars() as $key => $mod) {
607 $res .= $mod . "," . $key . "\n";
608 }
609
610 $this->tpl->setContent("<pre>" . $res . "</pre>");
611 }
612
616 public function downloadDeprecatedObject()
617 {
618 include_once("./Services/Language/classes/class.ilLangDeprecated.php");
619 $d = new ilLangDeprecated();
620 $res = "";
621 foreach ($d->getDeprecatedLangVars() as $key => $mod) {
622 $res .= $mod . "," . $key . "\n";
623 }
624
625 ilUtil::deliverData($res, "lang_deprecated.csv");
626 }
627} // END class.ilObjLanguageFolderGUI
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Search for deprecated lang vars.
static getInstance()
Factory.
Class ilObjLanguageFolderGUI.
__construct($a_data, $a_id, $a_call_by_reference)
Constructor.
checkLanguageObject()
check all languages
getTabs()
get tabs @access public
disableLanguageDetectionObject()
Disable language detection.
setSystemLanguageObject()
set the system language
installLocalObject()
Install local language modifications.
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.
getAdminTabs()
administration tabs show only permissions and trash folder
Class ilObjLanguage.
static refreshPlugins($a_lang_keys=null)
static refreshAll()
Refresh all installed languages.
static _getLastLocalChange($a_key)
get the date of the last local change
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$key
Definition: croninfo.php:18
$languages
Definition: cssgen2.php:34
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
redirection script todo: (a better solution should control the processing via a xml file)
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
$this data['403_header']
$ilUser
Definition: imgupload.php:18