ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthLoginPageEditorGUI.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 include_once './Services/Authentication/classes/class.ilAuthLoginPageEditorSettings.php';
5 
16 {
20  protected $ctrl = null;
21  protected $lng = null;
22 
23  private $ref_id = 0;
24  private $settings = null;
25 
26 
27 
33  public function __construct($a_ref_id)
34  {
35  global $ilCtrl,$lng;
36 
37  $this->ctrl = $ilCtrl;
38  $this->lng = $lng;
39  $this->lng->loadLanguageModule('auth');
40  $this->ref_id = $a_ref_id;
41 
43  }
44 
49  public function getSettings()
50  {
51  return $this->settings;
52  }
53 
57  public function getRefId()
58  {
59  return $this->ref_id;
60  }
61 
65  public function executeCommand()
66  {
67  switch($this->ctrl->getNextClass($this))
68  {
69  case 'ilpageobjectgui':
70  $GLOBALS['ilTabs']->clearTargets();
71  $GLOBALS['ilTabs']->setBackTarget(
72  $this->lng->txt('back'),
73  $this->ctrl->getLinkTarget($this,'show'),
74  '_top'
75  );
76 
77  if ($_GET["redirectSource"] != "ilinternallinkgui")
78  {
79  $this->forwardToPageObject();
80  }
81  else
82  {
83  return '';
84  }
85  break;
86 
87  default:
88  if(!$cmd = $this->ctrl->getCmd())
89  {
90  $cmd = 'show';
91  }
92  $this->$cmd();
93  break;
94  }
95  }
96 
97 
101  protected function forwardToPageObject()
102  {
103  global $lng,$tpl;
104 
105  $key = (int) $_REQUEST['key'];
106  $this->ctrl->saveParameter($this,'key',$key);
107 
108  include_once("./Services/COPage/classes/class.ilPageObject.php");
109  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
110  include_once './Services/Style/classes/class.ilObjStyleSheet.php';
111 
112  $lng->loadLanguageModule("content");
113 
114  if (!ilPageObject::_exists('auth',$key))
115  {
116  // doesn't exist -> create new one
117  $new_page_object = new ilPageObject('auth');
118  $new_page_object->setParentId($key);
119  $new_page_object->setId($key);
120  $new_page_object->createFromXML();
121  }
122 
123  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
124  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",ilObjStyleSheet::getContentStylePath(0));
125  $tpl->setCurrentBlock("SyntaxStyle");
126  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",ilObjStyleSheet::getSyntaxStylePath());
127  $tpl->parseCurrentBlock();
128 
129 
130  $this->ctrl->setReturnByClass('ilpageobjectgui', "edit");
131  $page_gui = new ilPageObjectGUI('auth',$key);
132 
133  $page_gui->setIntLinkHelpDefault("RepositoryItem",$key);
134  $page_gui->setTemplateTargetVar("ADM_CONTENT");
135  $page_gui->setLinkXML($link_xml);
136  //$page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
137  //$page_gui->setFileDownloadLink($this->ctrl->getLinkTarget($this, "downloadFile"));
138  //$page_gui->setFullscreenLink($this->ctrl->getLinkTarget($this, "showMediaFullscreen"));
139  //$page_gui->setLinkParams($this->ctrl->getUrlParameterString()); // todo
140 // $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTarget($this, ""));
141  $page_gui->setPresentationTitle("");
142  $page_gui->setTemplateOutput(false);
143  //$page_gui->setLocator($contObjLocator);
144  $page_gui->setHeader("");
145  $page_gui->setEnabledRepositoryObjects(true);
146  $page_gui->setEnabledLoginPage(true);
147  $page_gui->setEnabledFileLists(false);
148  $page_gui->setEnabledMaps(true);
149  $page_gui->setEnabledPCTabs(true);
150  $page_gui->setEnabledInternalLinks(true);
151 
152  // style tab
153  //$page_gui->setTabHook($this, "addPageTabs");
154 
155  if($this->ctrl->getCmd() == 'editPage')
156  $this->ctrl->setCmd('edit');
157  $html = $this->ctrl->forwardCommand($page_gui);
158 
159  $tpl->setContent($html);
160  }
161 
166  protected function show()
167  {
168  $this->addEditorSwitch();
169 
170  switch($this->getSettings()->getMode())
171  {
173  return $this->showRichtextEditor();
174 
176  return $this->showIliasEditor();
177  }
178  }
179 
184  protected function addEditorSwitch()
185  {
186  global $ilToolbar;
187 
188  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
189  switch($this->getSettings()->getMode())
190  {
192 
193  $ilToolbar->addButton(
194  $this->lng->txt('login_page_switch_ipe'),
195  $this->ctrl->getLinkTarget($this,'switchIPE')
196  );
197  break;
198 
200 
201  $ilToolbar->addButton(
202  $this->lng->txt('login_page_switch_rte'),
203  $this->ctrl->getLinkTarget($this,'switchRTE')
204  );
205  break;
206  }
207  return;
208  }
209 
213  protected function switchIPE()
214  {
216  $this->getSettings()->update();
217 
218  ilUtil::sendSuccess($this->lng->txt('login_page_editor_switched'),true);
219  $this->ctrl->redirect($this,'show');
220  }
221 
225  protected function switchRTE()
226  {
228  $this->getSettings()->update();
229 
230  ilUtil::sendSuccess($this->lng->txt('login_page_editor_switched'),true);
231  $this->ctrl->redirect($this,'show');
232  }
233 
237  protected function activate()
238  {
240  foreach((array) $_POST['visible_languages'] as $lang_key)
241  {
242  $settings->enableIliasEditor($lang_key, in_array($lang_key,(array) $_POST['languages']));
243  }
244  $settings->update();
245 
246  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
247  $this->ctrl->redirect($this,'show');
248  }
249 
253  protected function showIliasEditor()
254  {
255  global $tpl;
256 
257  include_once './Services/Authentication/classes/class.ilAuthLoginPageEditorTableGUI.php';
258  $tbl = new ilAuthLoginPageEditorTableGUI($this,'show');
259  $tbl->parse();
260 
261  $tpl->setContent($tbl->getHTML());
262  }
263 
271  protected function showRichtextEditor()
272  {
273  global $rbacsystem, $lng,$ilSetting,$tpl;
274 
275  if(!$rbacsystem->checkAccess("visible,read", $this->getRefId()))
276  {
277  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
278  }
279  $lng->loadLanguageModule("meta");
280 
281  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.auth_login_messages.html",
282  "Services/Authentication");
283  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
284  $tpl->setVariable("TXT_HEADLINE", $this->lng->txt("login_information"));
285  $tpl->setVariable("TXT_DESCRIPTION", $this->lng->txt("login_information_desc"));
286  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
287  $this->initLoginForm();
288  $tpl->setVariable('LOGIN_INFO',$this->form->getHTML());
289  }
290 
297  protected function saveLoginInfo()
298  {
299  global $rbacsystem, $lng,$ilSetting;
300 
301  if(!$rbacsystem->checkAccess("write",$this->getRefId()))
302  {
303  $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->MESSAGE);
304  }
305 
306  $this->initLoginForm();
307  if ($this->form->checkInput())
308  {
309  if (is_array($_POST))
310  {
311  // @todo: Move settings ilAuthLoginPageSettings
312  $this->loginSettings = new ilSetting("login_settings");
313 
314  foreach ($_POST as $key => $val)
315  {
316  if (substr($key, 0, 14) == "login_message_")
317  {
318  $this->loginSettings->set($key, $val);
319  }
320  }
321  }
322 
323  if($_POST['default_auth_mode'])
324  {
325  $ilSetting->set('default_auth_mode',(int) $_POST['default_auth_mode']);
326  }
327 
328  ilUtil::sendSuccess($this->lng->txt("login_information_settings_saved"),true);
329  }
330 
331  $this->ctrl->redirect($this,'show');
332  }
333 
337  protected function initLoginForm()
338  {
339  global $rbacsystem, $lng,$ilSetting;
340 
341  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
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  include_once('Services/LDAP/classes/class.ilLDAPServer.php');
350  include_once('Services/Radius/classes/class.ilRadiusSettings.php');
351  $rad_settings = ilRadiusSettings::_getInstance();
352  if($ldap_id = ilLDAPServer::_getFirstActiveServer() or $rad_settings->isActive())
353  {
354  $select = new ilSelectInputGUI($this->lng->txt('default_auth_mode'),'default_auth_mode');
355  $select->setValue($ilSetting->get('default_auth_mode',AUTH_LOCAL));
356  $select->setInfo($this->lng->txt('default_auth_mode_info'));
357  $options[AUTH_LOCAL] = $this->lng->txt('auth_local');
358  if($ldap_id)
359  {
360  $options[AUTH_LDAP] = $this->lng->txt('auth_ldap');
361  }
362  if($rad_settings->isActive())
363  {
364  $options [AUTH_RADIUS] = $this->lng->txt('auth_radius');
365  }
366  $select->setOptions($options);
367  $this->form->addItem($select);
368  }
369 
370  if (!is_object($this->loginSettings))
371  {
372  $this->loginSettings = new ilSetting("login_settings");
373  }
374 
375  $login_settings = $this->loginSettings->getAll();
376  $languages = $lng->getInstalledLanguages();
377  $def_language = $lng->getDefaultLanguage();
378 
379  foreach ($this->setDefLangFirst($def_language, $languages) as $lang_key)
380  {
381  $add = "";
382  if ($lang_key == $def_language)
383  {
384  $add = " (".$lng->txt("default").")";
385  }
386 
387  $textarea = new ilTextAreaInputGUI($lng->txt("meta_l_".$lang_key).$add,
388  'login_message_'.$lang_key);
389  $textarea->setRows(10);
390  $textarea->setValue($login_settings["login_message_".$lang_key]);
391  $textarea->setUseRte(true);
392  $textarea->setRteTagSet("extended");
393  $this->form->addItem($textarea);
394 
395  unset($login_settings["login_message_".$lang_key]);
396  }
397 
398  foreach ($login_settings as $key => $message)
399  {
400  $lang_key = substr($key, strrpos($key, "_") + 1, strlen($key) - strrpos($key, "_"));
401 
402  $textarea = new ilTextAreaInputGUI($lng->txt("meta_l_".$lang_key).$add,
403  'login_message_'.$lang_key);
404  $textarea->setRows(10);
405  $textarea->setValue($message);
406  $textarea->setUseRte(true);
407  $textarea->setRteTagSet("extended");
408  if(!in_array($lang_key,$languages))
409  {
410  $textarea->setAlert($lng->txt("not_installed"));
411  }
412  $this->form->addItem($textarea);
413  }
414  }
415 
427  protected function setDefLangFirst($a_def_language, $a_languages)
428  {
429  if (is_array($a_languages) && $a_def_language != "")
430  {
431  $languages = array();
432  $languages[] = $a_def_language;
433 
434  foreach ($a_languages as $val)
435  {
436  if (!in_array($val, $languages))
437  {
438  $languages[] = $val;
439  }
440  }
441 
442  return $languages;
443  }
444  else
445  {
446  return array();
447  }
448  }
449 }
450 ?>