ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAuthLoginPageEditorGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
31 {
32  private ilCtrl $ctrl;
33  private ilLanguage $lng;
35  private ilTabsGUI $tabs;
41 
42  private int $ref_id;
44  private ?ilSetting $loginSettings = null;
45  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
46 
47  //variables from requests
48  private ?string $redirect_source = null;
49  private ?int $key = null;
50  private array $visible_languages = [];
51  private array $languages = [];
52 
53  public function __construct(int $a_ref_id)
54  {
55  global $DIC;
56 
57  $this->ctrl = $DIC->ctrl();
58  $this->tpl = $DIC->ui()->mainTemplate();
59  $this->tabs = $DIC->tabs();
60  $this->toolbar = $DIC->toolbar();
61  $this->rbacsystem = $DIC->rbac()->system();
62  $this->setting = $DIC->settings();
63  $this->ilErr = $DIC['ilErr'];
64 
65  $this->lng = $DIC['lng'];
66 
67  $this->lng->loadLanguageModule('auth');
68  $this->ref_id = $a_ref_id;
69 
71  $this->content_style_domain = $DIC->contentStyle()
72  ->domain()
73  ->styleForRefId($a_ref_id);
74 
75  $query_wrapper = $DIC->http()->wrapper()->query();
76  $post_wrapper = $DIC->http()->wrapper()->post();
77  $is_post_request = $DIC->http()->request()->getMethod() === "POST";
78  $refinery = $DIC->refinery();
79 
80  if ($query_wrapper->has("redirectSource")) {
81  $this->redirect_source = $query_wrapper->retrieve("redirectSource", $refinery->kindlyTo()->string());
82  }
83  if ($post_wrapper->has("key")) {
84  $this->key = $post_wrapper->retrieve("key", $refinery->kindlyTo()->int());
85  } elseif ($query_wrapper->has("key")) {
86  $this->key = $query_wrapper->retrieve("key", $refinery->kindlyTo()->int());
87  }
88  if ($is_post_request) {
89  if ($post_wrapper->has("visible_languages")) {
90  $this->visible_languages = $post_wrapper->retrieve("visible_languages", $refinery->kindlyTo()->listOf($refinery->kindlyTo()->string()));
91  }
92  if ($post_wrapper->has("languages")) {
93  $this->languages = $post_wrapper->retrieve("languages", $refinery->kindlyTo()->listOf($refinery->kindlyTo()->string()));
94  }
95  }
96  }
97 
99  {
100  return $this->settings;
101  }
102 
103  public function getRefId(): int
104  {
105  return $this->ref_id;
106  }
107 
111  public function executeCommand(): void
112  {
113  switch ($this->ctrl->getNextClass($this)) {
114  case 'illoginpagegui':
115  $this->tabs->clearTargets();
116  $this->tabs->setBackTarget(
117  $this->lng->txt('back'),
118  $this->ctrl->getLinkTarget($this, 'show'),
119  '_top'
120  );
121 
122  if ($this->redirect_source !== "ilinternallinkgui") {
123  $this->forwardToPageObject();
124  }
125  break;
126 
127  default:
128  if (!$cmd = $this->ctrl->getCmd()) {
129  $cmd = 'show';
130  }
131  $this->$cmd();
132  break;
133  }
134  }
135 
136 
140  protected function forwardToPageObject(): void
141  {
142  $this->ctrl->saveParameter($this, 'key');
143 
144  $this->lng->loadLanguageModule("content");
145 
146  if (!ilLoginPage::_exists('auth', $this->key)) {
147  // doesn't exist -> create new one
148  $new_page_object = new ilLoginPage();
149  $new_page_object->setParentId($this->key);
150  $new_page_object->setId($this->key);
151  $new_page_object->createFromXML();
152  }
153 
154  $this->tpl->addCss(ilObjStyleSheet::getContentStylePath(0));
155  $this->tpl->addCss(ilObjStyleSheet::getSyntaxStylePath());
156 
157 
158  $this->ctrl->setReturnByClass('illoginpagegui', "edit");
159  $page_gui = new ilLoginPageGUI($this->key);
160 
161  $page_gui->setTemplateTargetVar("ADM_CONTENT");
162  //TODO check what should go here $link_xml is undefined
163  //$page_gui->setLinkXML($link_xml);
164  //$page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
165  //$page_gui->setFileDownloadLink($this->ctrl->getLinkTarget($this, "downloadFile"));
166  //$page_gui->setFullscreenLink($this->ctrl->getLinkTarget($this, "showMediaFullscreen"));
167  //$page_gui->setLinkParams($this->ctrl->getUrlParameterString()); // todo
168  // $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTarget($this, ""));
169  $page_gui->setStyleId($this->content_style_domain->getEffectiveStyleId());
170  $page_gui->setTemplateOutput(false);
171  //$page_gui->setLocator($contObjLocator);
172 
173  // style tab
174  //$page_gui->setTabHook($this, "addPageTabs");
175 
176  if ($this->ctrl->getCmd() === 'editPage') {
177  $this->ctrl->setCmd('edit');
178  }
179  $html = $this->ctrl->forwardCommand($page_gui);
180 
181  if ($html !== "") {
182  $this->tpl->setContent($html);
183  }
184  }
185 
189  protected function show(): void
190  {
191  $this->addEditorSwitch();
192 
193  switch ($this->getSettings()->getMode()) {
195  $this->showRichtextEditor();
196  break;
198  $this->showIliasEditor();
199  break;
200  }
201  }
202 
206  protected function addEditorSwitch(): void
207  {
208  $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
209  switch ($this->getSettings()->getMode()) {
211 
212  $this->toolbar->addButton(
213  $this->lng->txt('login_page_switch_ipe'),
214  $this->ctrl->getLinkTarget($this, 'switchIPE')
215  );
216  break;
217 
219 
220  $this->toolbar->addButton(
221  $this->lng->txt('login_page_switch_rte'),
222  $this->ctrl->getLinkTarget($this, 'switchRTE')
223  );
224  break;
225  }
226  }
227 
231  protected function switchIPE(): void
232  {
234  $this->getSettings()->update();
235 
236  $this->tpl->setOnScreenMessage('success', $this->lng->txt('login_page_editor_switched'), true);
237  $this->ctrl->redirect($this, 'show');
238  }
239 
243  protected function switchRTE(): void
244  {
246  $this->getSettings()->update();
247 
248  $this->tpl->setOnScreenMessage('success', $this->lng->txt('login_page_editor_switched'), true);
249  $this->ctrl->redirect($this, 'show');
250  }
251 
255  protected function activate(): void
256  {
258  foreach ($this->visible_languages as $lang_key) {
259  $settings->enableIliasEditor($lang_key, in_array($lang_key, $this->languages, true));
260  }
261  $settings->update();
262 
263  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
264  $this->ctrl->redirect($this, 'show');
265  }
266 
270  protected function showIliasEditor(): void
271  {
272  $tbl = new ilAuthLoginPageEditorTableGUI($this, 'show');
273  $tbl->parse();
274 
275  $this->tpl->setContent($tbl->getHTML());
276  }
277 
285  protected function showRichtextEditor(): void
286  {
287  if (!$this->rbacsystem->checkAccess("visible,read", $this->getRefId())) {
288  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
289  }
290  $this->lng->loadLanguageModule("meta");
291 
292  $this->tpl->addBlockFile(
293  "ADM_CONTENT",
294  "adm_content",
295  "tpl.auth_login_messages.html",
296  "Services/Authentication"
297  );
298  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
299  $this->tpl->setVariable("TXT_HEADLINE", $this->lng->txt("login_information"));
300  $this->tpl->setVariable("TXT_DESCRIPTION", $this->lng->txt("login_information_desc"));
301  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
302  $this->initLoginForm();
303  $this->tpl->setVariable('LOGIN_INFO', $this->form->getHTML());
304  }
305 
311  protected function saveLoginInfo(): void
312  {
313  if (!$this->rbacsystem->checkAccess("write", $this->getRefId())) {
314  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
315  }
316 
317  $this->initLoginForm();
318  if ($this->form->checkInput()) {
319  // @todo: Move settings ilAuthLoginPageSettings
320  $this->loginSettings = new ilSetting("login_settings");
321  foreach ($this->lng->getInstalledLanguages() as $lang_key) {
322  $settingKey = "login_message_" . $lang_key;
323  if ($this->form->getItemByPostVar($settingKey)) {
324  $this->loginSettings->set($settingKey, $this->form->getInput($settingKey));
325  }
326  }
327  if ($this->form->getInput('default_auth_mode')) {
328  $this->setting->set('default_auth_mode', $this->form->getInput('default_auth_mode'));
329  }
330 
331  $this->tpl->setOnScreenMessage('success', $this->lng->txt("login_information_settings_saved"), true);
332  }
333 
334  $this->ctrl->redirect($this, 'show');
335  }
336 
340  protected function initLoginForm(): void
341  {
342  $this->form = new ilPropertyFormGUI();
343  $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveLoginInfo'));
344  $this->form->setTableWidth('80%');
345  $this->form->setTitle($this->lng->txt('login_information'));
346 
347  $this->form->addCommandButton('saveLoginInfo', $this->lng->txt('save'));
348 
349  if ($ldap_id = ilLDAPServer::_getFirstActiveServer()) {
350  $select = new ilSelectInputGUI($this->lng->txt('default_auth_mode'), 'default_auth_mode');
351  $select->setValue($this->setting->get('default_auth_mode', (string) ilAuthUtils::AUTH_LOCAL));
352  $select->setInfo($this->lng->txt('default_auth_mode_info'));
353  $options[ilAuthUtils::AUTH_LOCAL] = $this->lng->txt('auth_local');
354  if ($ldap_id) {
355  $options[ilAuthUtils::AUTH_LDAP] = $this->lng->txt('auth_ldap');
356  }
357  $select->setOptions($options);
358  $this->form->addItem($select);
359  }
360 
361  if (!is_object($this->loginSettings)) {
362  $this->loginSettings = new ilSetting("login_settings");
363  }
364 
365  $login_settings = $this->loginSettings->getAll();
366  $languages = $this->lng->getInstalledLanguages();
367  $def_language = $this->lng->getDefaultLanguage();
368 
369  foreach ($this->setDefLangFirst($def_language, $languages) as $lang_key) {
370  $add = "";
371  if ($lang_key === $def_language) {
372  $add = " (" . $this->lng->txt("default") . ")";
373  }
374 
375  $textarea = new ilTextAreaInputGUI(
376  $this->lng->txt("meta_l_" . $lang_key) . $add,
377  'login_message_' . $lang_key
378  );
379  $textarea->setRows(10);
380  $msg_login_lang = "login_message_" . $lang_key;
381  if (isset($login_settings[$msg_login_lang])) {
382  $textarea->setValue($login_settings[$msg_login_lang]);
383  }
384  $textarea->setUseRte(true);
385  $textarea->setRteTagSet("extended");
386  $this->form->addItem($textarea);
387 
388  unset($login_settings["login_message_" . $lang_key]);
389  }
390 
391  foreach ($login_settings as $key => $message) {
392  $lang_key = substr($key, strrpos($key, "_") + 1, strlen($key) - strrpos($key, "_"));
393 
394  $textarea = new ilTextAreaInputGUI(
395  $this->lng->txt("meta_l_" . $lang_key),
396  'login_message_' . $lang_key
397  );
398  $textarea->setRows(10);
399  $textarea->setValue($message);
400  $textarea->setUseRte(true);
401  $textarea->setRteTagSet("extended");
402  if (!in_array($lang_key, $languages, true)) {
403  $textarea->setAlert($this->lng->txt("not_installed"));
404  }
405  $this->form->addItem($textarea);
406  }
407  }
408 
417  private function setDefLangFirst(string $a_def_language, array $a_languages): array
418  {
419  $languages = [];
420  if ($a_def_language !== "") {
421  $languages[] = $a_def_language;
422 
423  foreach ($a_languages as $val) {
424  if (!in_array($val, $languages, true)) {
425  $languages[] = $val;
426  }
427  }
428  }
429 
430  return $languages;
431  }
432 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFirstActiveServer()
Get first active server.
switchRTE()
Switch editor mode to richtext editor.
switchIPE()
Switch editor mode to ILIAS Page editor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
forwardToPageObject()
Forward to page editor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefLangFirst(string $a_def_language, array $a_languages)
returns an array of all installed languages, default language at the first position ...
global $DIC
Definition: feed.php:28
setValue($a_value)
Set Value.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showIliasEditor()
Show ILIAS page editor summary.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
form( $class_path, string $cmd, string $submit_caption="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
showRichtextEditor()
Show richtext editor ilRbacSystem $rbacsystem ilLanguage $lng ilSetting $ilSetting.
ilAuthLoginPageEditorSettings $settings
saveLoginInfo()
saves the login information data
This class represents a text area property in a property form.
ILIAS Style Content Object ObjectFacade $content_style_domain
$message
Definition: xapiexit.php:32
show()
Show current activated editor.
static getInstance()
Get singelton instance.
enableIliasEditor(string $a_langkey, bool $a_status)
Enable editor for language.
Refinery Factory $refinery