ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPersonalSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  var $tpl;
14  var $lng;
15  var $ilias;
16  var $ctrl;
17 
21  function __construct()
22  {
23  global $ilias, $tpl, $lng, $rbacsystem, $ilCtrl;
24 
25  include_once './Services/User/classes/class.ilUserDefinedFields.php';
26  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
27 
28  $this->tpl =& $tpl;
29  $this->lng =& $lng;
30  $this->ilias =& $ilias;
31  $this->ctrl =& $ilCtrl;
32  $this->settings = $ilias->getAllSettings();
33 // $lng->loadLanguageModule("jsmath");
34  $lng->loadLanguageModule('chatroom');
35  $lng->loadLanguageModule('chatroom_adm');
36  $this->upload_error = "";
37  $this->password_error = "";
38  $lng->loadLanguageModule("user");
39  $ilCtrl->saveParameter($this, "user_page");
40  }
41 
45  function &executeCommand()
46  {
47  global $ilUser, $ilCtrl, $tpl, $ilTabs, $lng;
48 
49  $next_class = $this->ctrl->getNextClass();
50 
51  switch($next_class)
52  {
53 
54  default:
55  $cmd = $this->ctrl->getCmd("showGeneralSettings");
56  $this->$cmd();
57  break;
58  }
59  return true;
60  }
61 
66  public function saveMailOptions()
67  {
75  global $ilUser, $lng, $ilTabs, $ilSetting, $rbacsystem;
76 
77  include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
78  if(!$rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
79  {
80  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
81  }
82 
83  $lng->loadLanguageModule('mail');
84 
85  $this->__initSubTabs('showMailOptions');
86  $ilTabs->activateTab('mail_settings');
87 
88  $this->setHeader();
89 
90  require_once 'Services/Mail/classes/class.ilMailOptions.php';
91  $mailOptions = new ilMailOptions($ilUser->getId());
92  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1' &&
93  $ilSetting->get('usr_settings_disable_mail_incoming_mail') != '1')
94  {
95  $incoming_type = (int)$_POST['incoming_type'];
96  }
97  else
98  {
99  $incoming_type = $mailOptions->getIncomingType();
100  }
101 
102  $this->initMailOptionsForm();
103  if($this->form->checkInput())
104  {
105  $mailOptions->updateOptions(
106  ilUtil::stripSlashes($_POST['signature']),
107  (int)$_POST['linebreak'],
108  $incoming_type,
109  (int)$_POST['cronjob_notification']
110  );
111 
112  ilUtil::sendSuccess($lng->txt('mail_options_saved'));
113  }
114 
115  if(!isset($_POST['incoming_type']))
116  {
117  $_POST['incoming_type'] = $mailOptions->getIncomingType();
118  }
119 
120  $this->form->setValuesByPost();
121 
122  $this->tpl->setContent($this->form->getHTML());
123  $this->tpl->show();
124  }
125 
129  private function initMailOptionsForm()
130  {
131  global $ilCtrl, $ilSetting, $lng, $ilUser;
132 
133  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
134  $this->form = new ilPropertyFormGUI();
135 
136  $this->form->setFormAction($ilCtrl->getFormAction($this, 'saveMailOptions'));
137  $this->form->setTitle($lng->txt('mail_settings'));
138 
139  // BEGIN INCOMING
140  include_once 'Services/Mail/classes/class.ilMailOptions.php';
141  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
142  {
143  $options = array(
144  IL_MAIL_LOCAL => $this->lng->txt('mail_incoming_local'),
145  IL_MAIL_EMAIL => $this->lng->txt('mail_incoming_smtp'),
146  IL_MAIL_BOTH => $this->lng->txt('mail_incoming_both')
147  );
148  $si = new ilSelectInputGUI($lng->txt('mail_incoming'), 'incoming_type');
149  $si->setOptions($options);
150  if(!strlen(ilObjUser::_lookupEmail($ilUser->getId())) ||
151  $ilSetting->get('usr_settings_disable_mail_incoming_mail') == '1')
152  {
153  $si->setDisabled(true);
154  }
155  $this->form->addItem($si);
156  }
157 
158  // BEGIN LINEBREAK_OPTIONS
159  $options = array();
160  for($i = 50; $i <= 80; $i++)
161  {
162  $options[$i] = $i;
163  }
164  $si = new ilSelectInputGUI($lng->txt('linebreak'), 'linebreak');
165  $si->setOptions($options);
166  $this->form->addItem($si);
167 
168  // BEGIN SIGNATURE
169  $ta = new ilTextAreaInputGUI($lng->txt('signature'), 'signature');
170  $ta->setRows(10);
171  $ta->setCols(60);
172  $this->form->addItem($ta);
173 
174  // BEGIN CRONJOB NOTIFICATION
175  if($ilSetting->get('mail_notification'))
176  {
177  $cb = new ilCheckboxInputGUI($lng->txt('cron_mail_notification'), 'cronjob_notification');
178  $cb->setInfo($lng->txt('mail_cronjob_notification_info'));
179  $cb->setValue(1);
180  $this->form->addItem($cb);
181  }
182 
183  $this->form->addCommandButton('saveMailOptions', $lng->txt('save'));
184  }
185 
189  private function setMailOptionsValuesByDB()
190  {
191  global $ilUser, $ilSetting;
192 
193  require_once 'Services/Mail/classes/class.ilMailOptions.php';
194  $mailOptions = new ilMailOptions($ilUser->getId());
195 
196  $data = array(
197  'linebreak' => $mailOptions->getLinebreak(),
198  'signature' => $mailOptions->getSignature(),
199  'cronjob_notification' => $mailOptions->getCronjobNotification()
200  );
201 
202  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
203  {
204  $data['incoming_type'] = $mailOptions->getIncomingType();
205  }
206 
207  $this->form->setValuesByArray($data);
208  }
209 
213  public function showMailOptions()
214  {
220  global $ilTabs, $lng, $rbacsystem;
221 
222  include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
223  if(!$rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
224  {
225  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
226  }
227 
228  $lng->loadLanguageModule('mail');
229 
230  $this->__initSubTabs('showMailOptions');
231  $ilTabs->activateTab('mail_settings');
232 
233  $this->setHeader();
234 
235  $this->initMailOptionsForm();
236  $this->setMailOptionsValuesByDB();
237 
238  $this->tpl->setContent($this->form->getHTML());
239  $this->tpl->show();
240  }
241 
242 /* function showjsMath()
243  {
244  global $lng, $ilCtrl, $tpl, $ilUser;
245 
246  $this->__initSubTabs("showjsMath");
247  $this->setHeader();
248 
249  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
250  $form = new ilPropertyFormGUI();
251  $form->setFormAction($ilCtrl->getFormAction($this));
252  $form->setTitle($lng->txt("jsmath_settings"));
253 
254  // Enable jsMath
255  include_once "./Services/Administration/classes/class.ilSetting.php";
256  $jsMathSetting = new ilSetting("jsMath");
257  $enable = new ilCheckboxInputGUI($lng->txt("jsmath_enable_user"), "enable");
258  $checked = ($ilUser->getPref("js_math") === FALSE) ? $jsMathSetting->get("makedefault") : $ilUser->getPref("js_math");
259  $enable->setChecked($checked);
260  $enable->setInfo($lng->txt("jsmath_enable_user_desc"));
261  $form->addItem($enable);
262 
263  $form->addCommandButton("savejsMath", $lng->txt("save"));
264  $form->addCommandButton("showjsMath", $lng->txt("cancel"));
265 
266  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
267  $this->tpl->show();
268  }
269 
270  function savejsMath()
271  {
272  global $ilCtrl, $ilUser;
273 
274  include_once "./Services/Administration/classes/class.ilSetting.php";
275  $jsMathSetting = new ilSetting("jsMath");
276  if ($jsMathSetting->get("enable"))
277  {
278  if ($_POST["enable"])
279  {
280  $ilUser->writePref("js_math", "1");
281  }
282  else
283  {
284  $ilUser->writePref("js_math", "0");
285  }
286  }
287  $ilCtrl->redirect($this, "showjsMath");
288  }
289 */
290  // init sub tabs
291  function __initSubTabs($a_cmd)
292  {
296  global $ilTabs, $ilSetting, $ilHelp, $rbacsystem, $ilUser;
297 
298  $ilHelp->setScreenIdComponent("user");
299 
300  $showPassword = ($a_cmd == 'showPassword') ? true : false;
301  $showGeneralSettings = ($a_cmd == 'showGeneralSettings') ? true : false;
302  $showMailOptions = ($a_cmd == 'showMailOptions') ? true : false;
303 // $showjsMath = ($a_cmd == 'showjsMath') ? true : false;
304  $showChatOptions = ($a_cmd == 'showChatOptions') ? true : false;
305 
306  // old profile
307 
308  // general settings
309  $ilTabs->addTarget("general_settings", $this->ctrl->getLinkTarget($this, "showGeneralSettings"),
310  "", "", "", $showGeneralSettings);
311 
312  // password
313  if ($this->allowPasswordChange())
314  {
315  $ilTabs->addTarget("password", $this->ctrl->getLinkTarget($this, "showPassword"),
316  "", "", "", $showPassword);
317  }
318 
319  include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
320  if($rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
321  {
322  $ilTabs->addTarget("mail_settings", $this->ctrl->getLinkTarget($this, "showMailOptions"), "", "", "", $showMailOptions);
323  }
324 
325  $chatSettings = new ilSetting('chatroom');
326  $notificationSettings = new ilSetting('notifications');
327  if(
328  $chatSettings->get('chat_enabled', false) &&
329  $notificationSettings->get('enable_osd', false) &&
330  $chatSettings->get('play_invitation_sound', false)
331  )
332  {
333  $ilTabs->addTarget('chat_settings', $this->ctrl->getLinkTarget($this, 'showChatOptions'), '', '', '', $showChatOptions);
334  }
335 
336  include_once "./Services/Administration/classes/class.ilSetting.php";
337 /* $jsMathSetting = new ilSetting("jsMath");
338  if ($jsMathSetting->get("enable"))
339  {
340  $ilTabs->addTarget("jsmath_extt_jsmath", $this->ctrl->getLinkTarget($this, "showjsMath"),
341  "", "", "", $showjsMath);
342  }*/
343 
344  if((bool)$ilSetting->get('user_delete_own_account') &&
345  $ilUser->getId() != SYSTEM_USER_ID)
346  {
347  $ilTabs->addTab("delacc", $this->lng->txt('user_delete_own_account'),
348  $this->ctrl->getLinkTarget($this, "deleteOwnAccount1"));
349  }
350  }
351 
355  private function getChatSettingsForm()
356  {
361  global $lng;
362 
363  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
364  $form = new ilPropertyFormGUI();
365 
366  $form->setFormAction($this->ctrl->getFormAction($this, 'saveChatOptions'));
367  $form->setTitle($lng->txt("chat_settings"));
368 
369  $chb = new ilCheckboxInputGUI('', 'play_invitation_sound');
370  $chb->setOptionTitle($this->lng->txt('play_invitation_sound'));
371  $form->addItem($chb);
372 
373  $form->addCommandButton("saveChatOptions", $lng->txt("save"));
374 
375  return $form;
376  }
377 
381  public function saveChatOptions()
382  {
389  global $ilUser, $lng, $ilCtrl;
390 
391  $chatSettings = new ilSetting('chatroom');
392  $notificationSettings = new ilSetting('notifications');
393  if(!(
394  $chatSettings->get('chat_enabled', false) &&
395  $notificationSettings->get('enable_osd', false) &&
396  $chatSettings->get('play_invitation_sound', false)
397  )
398  )
399  {
400  $ilCtrl->redirect($this);
401  }
402 
403  $form = $this->getChatSettingsForm();
404  if(!$form->checkInput())
405  {
406  $this->showChatOptions($form);
407  return;
408  }
409 
410  $ilUser->setPref('chat_play_invitation_sound', (int)$form->getInput('play_invitation_sound'));
411  $ilUser->writePrefs();
412 
413  ilUtil::sendSuccess($lng->txt('saved_successfully'));
414  $this->showChatOptions($form);
415  }
416 
420  public function setHeader()
421  {
422  $this->tpl->setVariable('HEADER', $this->lng->txt('personal_settings'));
423  }
424 
428  public function showChatOptions(ilPropertyFormGUI $form = null)
429  {
434  global $ilUser, $ilCtrl;
435 
436  $chatSettings = new ilSetting('chatroom');
437  $notificationSettings = new ilSetting('notifications');
438  if(!(
439  $chatSettings->get('chat_enabled', false) &&
440  $notificationSettings->get('enable_osd', false) &&
441  $chatSettings->get('play_invitation_sound', false)
442  ))
443  {
444  $ilCtrl->redirect($this);
445  }
446 
447  $this->__initSubTabs('showChatOptions');
448  $this->setHeader();
449 
450  if($form)
451  {
452  $form->setValuesByPost();
453  }
454  else
455  {
456  $form = $this->getChatSettingsForm();
457  $form->setValuesByArray(array(
458  'play_invitation_sound' => $ilUser->getPref('chat_play_invitation_sound')
459  ));
460  }
461 
462  $this->tpl->setContent($form->getHTML());
463  $this->tpl->show();
464  }
465 
466 
467  //
468  //
469  // PASSWORD FORM
470  //
471  //
472 
477  function showPassword($a_no_init = false, $hide_form = false)
478  {
479  global $ilTabs, $ilUser;
480 
481  $this->__initSubTabs("showPersonalData");
482  $ilTabs->activateTab("password");
483 
484  $this->setHeader();
485  // check whether password of user have to be changed
486  // due to first login or password of user is expired
487  if($ilUser->isPasswordChangeDemanded())
488  {
490  $this->lng->txt('password_change_on_first_login_demand')
491  );
492  }
493  else if($ilUser->isPasswordExpired())
494  {
495  $msg = $this->lng->txt('password_expired');
496  $password_age = $ilUser->getPasswordAge();
497  ilUtil::sendInfo(sprintf($msg, $password_age));
498  }
499 
500  if (!$a_no_init && !$hide_form)
501  {
502  $this->initPasswordForm();
503  }
504  $this->tpl->setContent(!$hide_form ? $this->form->getHTML() : '');
505  $this->tpl->show();
506  }
507 
513  public function initPasswordForm()
514  {
515  global $lng, $ilUser, $ilSetting;
516 
517  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
518  $this->form = new ilPropertyFormGUI();
519 
520  // Check whether password change is allowed
521  if ($this->allowPasswordChange())
522  {
523  // The current password needs to be checked for verification
524  // unless the user uses Shibboleth authentication with additional
525  // local authentication for WebDAV.
526  //if (
527  // ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || !$ilSetting->get("shib_auth_allow_local"))
528  //)
529  if($ilUser->getAuthMode(true) == AUTH_LOCAL)
530  {
531  // current password
532  $cpass = new ilPasswordInputGUI($lng->txt("current_password"), "current_password");
533  $cpass->setRetype(false);
534  $cpass->setSkipSyntaxCheck(true);
535  // only if a password exists.
536  if($ilUser->getPasswd())
537  {
538  $cpass->setRequired(true);
539  }
540  $this->form->addItem($cpass);
541  }
542 
543  // new password
544  $ipass = new ilPasswordInputGUI($lng->txt("desired_password"), "new_password");
545  $ipass->setRequired(true);
546  $ipass->setInfo(ilUtil::getPasswordRequirementsInfo());
547 
548  if ($ilSetting->get("passwd_auto_generate") == 1) // auto generation list
549  {
550  $ipass->setPreSelection(true);
551 
552  $this->form->addItem($ipass);
553  $this->form->addCommandButton("savePassword", $lng->txt("save"));
554  $this->form->addCommandButton("showPassword", $lng->txt("new_list_password"));
555  }
556  else // user enters password
557  {
558  $this->form->addItem($ipass);
559  $this->form->addCommandButton("savePassword", $lng->txt("save"));
560  }
561 
562  switch ($ilUser->getAuthMode(true))
563  {
564  case AUTH_LOCAL :
565  $this->form->setTitle($lng->txt("chg_password"));
566  break;
567 
568  case AUTH_SHIBBOLETH :
569  case AUTH_CAS:
570  require_once 'Services/WebDAV/classes/class.ilDAVServer.php';
572  {
573  $this->form->setTitle($lng->txt("chg_ilias_and_webfolder_password"));
574  }
575  else
576  {
577  $this->form->setTitle($lng->txt("chg_ilias_password"));
578  }
579  break;
580  default :
581  $this->form->setTitle($lng->txt("chg_ilias_password"));
582  break;
583  }
584  $this->form->setFormAction($this->ctrl->getFormAction($this));
585  }
586  }
587 
592  {
593  global $ilUser, $ilSetting;
594 
595 
596  return ilAuthUtils::isPasswordModificationEnabled($ilUser->getAuthMode(true));
597 
598  // Moved to ilAuthUtils
599 
600  // do nothing if auth mode is not local database
601  if ($ilUser->getAuthMode(true) != AUTH_LOCAL &&
602  ($ilUser->getAuthMode(true) != AUTH_CAS || !$ilSetting->get("cas_allow_local")) &&
603  ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || !$ilSetting->get("shib_auth_allow_local")) &&
604  ($ilUser->getAuthMode(true) != AUTH_SOAP || !$ilSetting->get("soap_auth_allow_local")) &&
605  ($ilUser->getAuthMode(true) != AUTH_OPENID)
606  )
607  {
608  return false;
609  }
610  if (!$this->userSettingVisible('password') ||
611  $this->ilias->getSetting('usr_settings_disable_password'))
612  {
613  return false;
614  }
615  return true;
616  }
617 
622  public function savePassword()
623  {
624  global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting;
625 
626  // normally we should not end up here
627  if (!$this->allowPasswordChange())
628  {
629  $ilCtrl->redirect($this, "showPersonalData");
630  return;
631  }
632 
633  $this->initPasswordForm();
634  if ($this->form->checkInput())
635  {
636  $cp = $this->form->getItemByPostVar("current_password");
637  $np = $this->form->getItemByPostVar("new_password");
638  $error = false;
639 
640  // The old password needs to be checked for verification
641  // unless the user uses Shibboleth authentication with additional
642  // local authentication for WebDAV.
643  #if ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || ! $ilSetting->get("shib_auth_allow_local"))
644  if($ilUser->getAuthMode(true) == AUTH_LOCAL)
645  {
646  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
647  if(!ilUserPasswordManager::getInstance()->verifyPassword($ilUser, ilUtil::stripSlashes($_POST['current_password'])))
648  {
649  $error = true;
650  $cp->setAlert($this->lng->txt('passwd_wrong'));
651  }
652  }
653 
654  // select password from auto generated passwords
655  if ($this->ilias->getSetting("passwd_auto_generate") == 1 &&
656  (!ilUtil::isPassword($_POST["new_password"])))
657  {
658  $error = true;
659  $np->setAlert($this->lng->txt("passwd_not_selected"));
660  }
661 
662 
663  if ($this->ilias->getSetting("passwd_auto_generate") != 1 &&
664  !ilUtil::isPassword($_POST["new_password"],$custom_error))
665  {
666  $error = true;
667  if ($custom_error != '')
668  {
669  $np->setAlert($custom_error);
670  }
671  else
672  {
673  $np->setAlert($this->lng->txt("passwd_invalid"));
674  }
675  }
676  $error_lng_var = '';
677  if(
678  $this->ilias->getSetting("passwd_auto_generate") != 1 &&
679  !ilUtil::isPasswordValidForUserContext($_POST["new_password"], $ilUser, $error_lng_var)
680  )
681  {
682  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
683  $np->setAlert($this->lng->txt($error_lng_var));
684  $error = true;
685  }
686  if ($this->ilias->getSetting("passwd_auto_generate") != 1 &&
687  ($ilUser->isPasswordExpired() || $ilUser->isPasswordChangeDemanded()) &&
688  ($_POST["current_password"] == $_POST["new_password"]))
689  {
690  $error = true;
691  $np->setAlert($this->lng->txt("new_pass_equals_old_pass"));
692  }
693 
694  if (!$error)
695  {
696  $ilUser->resetPassword($_POST["new_password"], $_POST["new_password"]);
697  if ($_POST["current_password"] != $_POST["new_password"])
698  {
699  $ilUser->setLastPasswordChangeToNow();
700  }
701 
702  if(ilSession::get('orig_request_target'))
703  {
704  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
705  $target = ilSession::get('orig_request_target');
706  ilSession::set('orig_request_target', '');
707  ilUtil::redirect($target);
708  }
709  else
710  {
711  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
712  $this->showPassword(true, true);
713  return;
714  }
715  }
716  }
717  $this->form->setValuesByPost();
718  $this->showPassword(true);
719  }
720 
721  //
722  //
723  // GENERAL SETTINGS FORM
724  //
725  //
726 
731  function workWithUserSetting($setting)
732  {
733  $result = TRUE;
734  if ($this->settings["usr_settings_hide_".$setting] == 1)
735  {
736  $result = FALSE;
737  }
738  if ($this->settings["usr_settings_disable_".$setting] == 1)
739  {
740  $result = FALSE;
741  }
742  return $result;
743  }
744 
749  function userSettingVisible($setting)
750  {
751  $result = TRUE;
752  if (isset($this->settings["usr_settings_hide_".$setting]) &&
753  $this->settings["usr_settings_hide_".$setting] == 1)
754  {
755  $result = FALSE;
756  }
757  return $result;
758  }
759 
764  function userSettingEnabled($setting)
765  {
766  $result = TRUE;
767  if ($this->settings["usr_settings_disable_".$setting] == 1)
768  {
769  $result = FALSE;
770  }
771  return $result;
772  }
773 
777  function showGeneralSettings($a_no_init = false)
778  {
779  global $ilTabs, $ilToolbar, $ilCtrl;
780 
781  // test to other base class
782 // $ilToolbar->addButton("test",
783 // $ilCtrl->getLinkTargetByClass(array("ilmailgui","ilmailformgui"), "mailUser"));
784 
785  $this->__initSubTabs("showPersonalData");
786  $ilTabs->activateTab("general_settings");
787 
788  $this->setHeader();
789 
790  if (!$a_no_init)
791  {
792  $this->initGeneralSettingsForm();
793  }
794  $this->tpl->setContent($this->form->getHTML());
795  $this->tpl->show();
796  }
797 
802  public function initGeneralSettingsForm()
803  {
804  global $lng, $ilUser, $styleDefinition, $ilSetting;
805 
806 
807  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
808  $this->form = new ilPropertyFormGUI();
809 
810  // language
811  if ($this->userSettingVisible("language"))
812  {
813  $languages = $this->lng->getInstalledLanguages();
814  $options = array();
815  foreach($languages as $lang_key)
816  {
817  $options[$lang_key] = ilLanguage::_lookupEntry($lang_key,"meta", "meta_l_".$lang_key);
818  }
819 
820  $si = new ilSelectInputGUI($this->lng->txt("language"), "language");
821  $si->setOptions($options);
822  $si->setValue($ilUser->getLanguage());
823  $si->setDisabled($ilSetting->get("usr_settings_disable_language"));
824  $this->form->addItem($si);
825  }
826 
827  // skin/style
828  include_once("./Services/Style/classes/class.ilObjStyleSettings.php");
829  if ($this->userSettingVisible("skin_style"))
830  {
831  $templates = $styleDefinition->getAllTemplates();
832  if (is_array($templates))
833  {
834  $si = new ilSelectInputGUI($this->lng->txt("skin_style"), "skin_style");
835 
836  $options = array();
837  foreach($templates as $template)
838  {
839  // get styles information of template
840  $styleDef = new ilStyleDefinition($template["id"]);
841  $styleDef->startParsing();
842  $styles = $styleDef->getStyles();
843 
844  foreach($styles as $style)
845  {
846  if (!ilObjStyleSettings::_lookupActivatedStyle($template["id"],$style["id"]))
847  {
848  continue;
849  }
850 
851  $options[$template["id"].":".$style["id"]] =
852  $styleDef->getTemplateName()." / ".$style["name"];
853  }
854  }
855  $si->setOptions($options);
856  $si->setValue($ilUser->skin.":".$ilUser->prefs["style"]);
857  $si->setDisabled($ilSetting->get("usr_settings_disable_skin_style"));
858  $this->form->addItem($si);
859  }
860  }
861 
862  // screen reader optimization
863  if ($this->userSettingVisible("screen_reader_optimization"))
864  {
865  $cb = new ilCheckboxInputGUI($this->lng->txt("user_screen_reader_optimization"), "screen_reader_optimization");
866  $cb->setChecked($ilUser->prefs["screen_reader_optimization"]);
867  $cb->setDisabled($ilSetting->get("usr_settings_disable_screen_reader_optimization"));
868  $cb->setInfo($this->lng->txt("user_screen_reader_optimization_info"));
869  $this->form->addItem($cb);
870  }
871 
872  // hits per page
873  if ($this->userSettingVisible("hits_per_page"))
874  {
875  $si = new ilSelectInputGUI($this->lng->txt("hits_per_page"), "hits_per_page");
876 
877  $hits_options = array(10,15,20,30,40,50,100,9999);
878  $options = array();
879 
880  foreach($hits_options as $hits_option)
881  {
882  $hstr = ($hits_option == 9999)
883  ? $this->lng->txt("no_limit")
884  : $hits_option;
885  $options[$hits_option] = $hstr;
886  }
887  $si->setOptions($options);
888  $si->setValue($ilUser->prefs["hits_per_page"]);
889  $si->setDisabled($ilSetting->get("usr_settings_disable_hits_per_page"));
890  $this->form->addItem($si);
891  }
892 
893  // Users Online
894  if ($this->userSettingVisible("show_users_online"))
895  {
896  $si = new ilSelectInputGUI($this->lng->txt("show_users_online"), "show_users_online");
897 
898  $options = array(
899  "y" => $this->lng->txt("users_online_show_y"),
900  "associated" => $this->lng->txt("users_online_show_associated"),
901  "n" => $this->lng->txt("users_online_show_n"));
902  $si->setOptions($options);
903  $si->setValue($ilUser->prefs["show_users_online"]);
904  $si->setDisabled($ilSetting->get("usr_settings_disable_show_users_online"));
905  $this->form->addItem($si);
906  }
907 
908  // Store last visited
909  $lv = new ilSelectInputGUI($this->lng->txt("user_store_last_visited"), "store_last_visited");
910  $options = array(
911  0 => $this->lng->txt("user_lv_keep_entries"),
912  1 => $this->lng->txt("user_lv_keep_only_for_session"),
913  2 => $this->lng->txt("user_lv_do_not_store"));
914  $lv->setOptions($options);
915  $lv->setValue((int) $ilUser->prefs["store_last_visited"]);
916  $this->form->addItem($lv);
917 
918  // hide_own_online_status
919  if ($this->userSettingVisible("hide_own_online_status"))
920  {
921  $cb = new ilCheckboxInputGUI($this->lng->txt("hide_own_online_status"), "hide_own_online_status");
922  $cb->setChecked($ilUser->prefs["hide_own_online_status"] == "y");
923  $cb->setDisabled($ilSetting->get("usr_settings_disable_hide_own_online_status"));
924  $this->form->addItem($cb);
925  }
926 
927  include_once 'Services/Authentication/classes/class.ilSessionReminder.php';
928  if(ilSessionReminder::isGloballyActivated())
929  {
930  $cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
931  $cb->setInfo($this->lng->txt('session_reminder_info'));
932  $cb->setValue(1);
933  $cb->setChecked((int)$ilUser->getPref('session_reminder_enabled'));
934 
936  $lead_time_gui = new ilNumberInputGUI($this->lng->txt('session_reminder_lead_time'), 'session_reminder_lead_time');
937  $lead_time_gui->setInfo(sprintf($this->lng->txt('session_reminder_lead_time_info'), ilFormat::_secondsToString($expires, true)));
938 
940  $max_value = max($min_value, ((int)$expires / 60) - 1);
941 
942  $current_user_value = $ilUser->getPref('session_reminder_lead_time');
943  if($current_user_value < $min_value ||
944  $current_user_value > $max_value)
945  {
946  $current_user_value = ilSessionReminder::SUGGESTED_LEAD_TIME;
947  }
948  $value = min(
949  max(
950  $min_value, $current_user_value
951  ),
952  $max_value
953  );
954 
955  $lead_time_gui->setValue($value);
956  $lead_time_gui->setSize(3);
957  $lead_time_gui->setMinValue($min_value);
958  $lead_time_gui->setMaxValue($max_value);
959  $cb->addSubItem($lead_time_gui);
960 
961  $this->form->addItem($cb);
962  }
963 
964  // calendar settings (copied here to be reachable when calendar is inactive)
965  // they cannot be hidden/deactivated
966 
967  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
968  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
969  $lng->loadLanguageModule("dateplaner");
970  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
971 
972  $select = new ilSelectInputGUI($lng->txt('cal_user_timezone'),'timezone');
974  $select->setInfo($lng->txt('cal_timezone_info'));
975  $select->setValue($user_settings->getTimeZone());
976  $this->form->addItem($select);
977 
978  $year = date("Y");
979  $select = new ilSelectInputGUI($lng->txt('cal_user_date_format'),'date_format');
980  $select->setOptions(array(
981  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.'.$year,
982  ilCalendarSettings::DATE_FORMAT_YMD => $year."-10-31",
983  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/".$year));
984  $select->setInfo($lng->txt('cal_date_format_info'));
985  $select->setValue($user_settings->getDateFormat());
986  $this->form->addItem($select);
987 
988  $select = new ilSelectInputGUI($lng->txt('cal_user_time_format'),'time_format');
989  $select->setOptions(array(
992  $select->setInfo($lng->txt('cal_time_format_info'));
993  $select->setValue($user_settings->getTimeFormat());
994  $this->form->addItem($select);
995 
996 
997  // starting point
998  include_once "Services/User/classes/class.ilUserUtil.php";
1000  {
1001  $this->lng->loadLanguageModule("administration");
1002  $si = new ilRadioGroupInputGUI($this->lng->txt("adm_user_starting_point"), "usr_start");
1003  $si->setRequired(true);
1004  $si->setInfo($this->lng->txt("adm_user_starting_point_info"));
1005  $def_opt = new ilRadioOption($this->lng->txt("adm_user_starting_point_inherit"), 0);
1006  $def_opt->setInfo($this->lng->txt("adm_user_starting_point_inherit_info"));
1007  $si->addOption($def_opt);
1008  foreach(ilUserUtil::getPossibleStartingPoints() as $value => $caption)
1009  {
1010  $si->addOption(new ilRadioOption($caption, $value));
1011  }
1014  : 0);
1015  $this->form->addItem($si);
1016 
1017  // starting point: repository object
1018  $repobj = new ilRadioOption($lng->txt("adm_user_starting_point_object"), ilUserUtil::START_REPOSITORY_OBJ);
1019  $repobj_id = new ilTextInputGUI($lng->txt("adm_user_starting_point_ref_id"), "usr_start_ref_id");
1020  $repobj_id->setRequired(true);
1021  $repobj_id->setSize(5);
1022  if($si->getValue() == ilUserUtil::START_REPOSITORY_OBJ)
1023  {
1024  $start_ref_id = ilUserUtil::getPersonalStartingObject();
1025  $repobj_id->setValue($start_ref_id);
1026  if($start_ref_id)
1027  {
1028  $start_obj_id = ilObject::_lookupObjId($start_ref_id);
1029  if($start_obj_id)
1030  {
1031  $repobj_id->setInfo($lng->txt("obj_".ilObject::_lookupType($start_obj_id)).
1032  ": ".ilObject::_lookupTitle($start_obj_id));
1033  }
1034  }
1035  }
1036  $repobj->addSubItem($repobj_id);
1037  $si->addOption($repobj);
1038  }
1039 
1040  // selector for unicode characters
1041  global $ilSetting;
1042  if ($ilSetting->get('char_selector_availability') > 0)
1043  {
1044  require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
1046  $char_selector->getConfig()->setAvailability($ilUser->getPref('char_selector_availability'));
1047  $char_selector->getConfig()->setDefinition($ilUser->getPref('char_selector_definition'));
1048  $char_selector->addFormProperties($this->form);
1049  $char_selector->setFormValues($this->form);
1050  }
1051 
1052  $this->form->addCommandButton("saveGeneralSettings", $lng->txt("save"));
1053  $this->form->setTitle($lng->txt("general_settings"));
1054  $this->form->setFormAction($this->ctrl->getFormAction($this));
1055 
1056  }
1057 
1061  public function saveGeneralSettings()
1062  {
1063  global $tpl, $lng, $ilCtrl, $ilUser;
1064 
1065  $this->initGeneralSettingsForm();
1066  if ($this->form->checkInput())
1067  {
1068  if ($this->workWithUserSetting("skin_style"))
1069  {
1070  //set user skin and style
1071  if ($_POST["skin_style"] != "")
1072  {
1073  $sknst = explode(":", $_POST["skin_style"]);
1074 
1075  if ($ilUser->getPref("style") != $sknst[1] ||
1076  $ilUser->getPref("skin") != $sknst[0])
1077  {
1078  $ilUser->setPref("skin", $sknst[0]);
1079  $ilUser->setPref("style", $sknst[1]);
1080  }
1081  }
1082  }
1083 
1084  // language
1085  if ($this->workWithUserSetting("language"))
1086  {
1087  $ilUser->setLanguage($_POST["language"]);
1088  }
1089 
1090  // hits per page
1091  if ($this->workWithUserSetting("hits_per_page"))
1092  {
1093  if ($_POST["hits_per_page"] != "")
1094  {
1095  $ilUser->setPref("hits_per_page",$_POST["hits_per_page"]);
1096  }
1097  }
1098 
1099  // set show users online
1100  if ($this->workWithUserSetting("show_users_online"))
1101  {
1102  $ilUser->setPref("show_users_online", $_POST["show_users_online"]);
1103  }
1104 
1105  // store last visited?
1106  global $ilNavigationHistory;
1107  $ilUser->setPref("store_last_visited", (int) $_POST["store_last_visited"]);
1108  if ((int) $_POST["store_last_visited"] > 0)
1109  {
1110  $ilNavigationHistory->deleteDBEntries();
1111  if ((int) $_POST["store_last_visited"] == 2)
1112  {
1113  $ilNavigationHistory->deleteSessionEntries();
1114  }
1115  }
1116 
1117  // set hide own online_status
1118  if ($this->workWithUserSetting("hide_own_online_status"))
1119  {
1120  if ($_POST["hide_own_online_status"] == 1)
1121  {
1122  $ilUser->setPref("hide_own_online_status","y");
1123  }
1124  else
1125  {
1126  $ilUser->setPref("hide_own_online_status","n");
1127  }
1128  }
1129 
1130  // set show users online
1131  if ($this->workWithUserSetting("screen_reader_optimization"))
1132  {
1133  $ilUser->setPref("screen_reader_optimization", $_POST["screen_reader_optimization"]);
1134  }
1135 
1136  // session reminder
1137  include_once 'Services/Authentication/classes/class.ilSessionReminder.php';
1138  if(ilSessionReminder::isGloballyActivated())
1139  {
1140  $ilUser->setPref('session_reminder_enabled', (int)$this->form->getInput('session_reminder_enabled'));
1141  $ilUser->setPref('session_reminder_lead_time', $this->form->getInput('session_reminder_lead_time'));
1142  }
1143 
1144  // starting point
1145  include_once "Services/User/classes/class.ilUserUtil.php";
1147  {
1148  ilUserUtil::setPersonalStartingPoint($this->form->getInput('usr_start'),
1149  $this->form->getInput('usr_start_ref_id'));
1150  }
1151 
1152  // selector for unicode characters
1153  global $ilSetting;
1154  if ($ilSetting->get('char_selector_availability') > 0)
1155  {
1156  require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
1158  $char_selector->getFormValues($this->form);
1159  $ilUser->setPref('char_selector_availability', $char_selector->getConfig()->getAvailability());
1160  $ilUser->setPref('char_selector_definition', $char_selector->getConfig()->getDefinition());
1161  }
1162 
1163  $ilUser->update();
1164 
1165  // calendar settings
1166  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
1167  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
1168  $user_settings->setTimeZone($this->form->getInput("timezone"));
1169  $user_settings->setDateFormat((int)$this->form->getInput("date_format"));
1170  $user_settings->setTimeFormat((int)$this->form->getInput("time_format"));
1171  $user_settings->save();
1172 
1173  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1174  $ilCtrl->redirect($this, "showGeneralSettings");
1175  }
1176 
1177  $this->form->setValuesByPost();
1178  $this->showGeneralSettings(true);
1179  }
1180 
1184  protected function deleteOwnAccount1()
1185  {
1186  global $ilTabs, $ilToolbar, $ilUser, $ilSetting;
1187 
1188  if(!(bool)$ilSetting->get('user_delete_own_account') ||
1189  $ilUser->getId() == SYSTEM_USER_ID)
1190  {
1191  $this->ctrl->redirect($this, "showGeneralSettings");
1192  }
1193 
1194  // too make sure
1195  $ilUser->removeDeletionFlag();
1196 
1197  $this->setHeader();
1198  $this->__initSubTabs("deleteOwnAccount");
1199  $ilTabs->activateTab("delacc");
1200 
1201  ilUtil::sendInfo($this->lng->txt('user_delete_own_account_info'));
1202  $ilToolbar->addButton($this->lng->txt('btn_next'),
1203  $this->ctrl->getLinkTarget($this, 'deleteOwnAccount2'));
1204 
1205  $this->tpl->show();
1206  }
1207 
1211  protected function deleteOwnAccount2()
1212  {
1213  global $ilTabs, $ilUser, $ilSetting;
1214 
1215  if(!(bool)$ilSetting->get('user_delete_own_account') ||
1216  $ilUser->getId() == SYSTEM_USER_ID)
1217  {
1218  $this->ctrl->redirect($this, "showGeneralSettings");
1219  }
1220 
1221  $this->setHeader();
1222  $this->__initSubTabs("deleteOwnAccount");
1223  $ilTabs->activateTab("delacc");
1224 
1225  include_once "Services/Utilities/classes/class.ilConfirmationGUI.php";
1226  $cgui = new ilConfirmationGUI();
1227  $cgui->setHeaderText($this->lng->txt('user_delete_own_account_logout_confirmation'));
1228  $cgui->setFormAction($this->ctrl->getFormAction($this));
1229  $cgui->setCancel($this->lng->txt("cancel"), "abortDeleteOwnAccount");
1230  $cgui->setConfirm($this->lng->txt("user_delete_own_account_logout_button"), "deleteOwnAccountLogout");
1231  $this->tpl->setContent($cgui->getHTML());
1232  $this->tpl->show();
1233  }
1234 
1235  protected function abortDeleteOwnAccount()
1236  {
1237  global $ilCtrl, $ilUser;
1238 
1239  $ilUser->removeDeletionFlag();
1240 
1241  ilUtil::sendInfo($this->lng->txt("user_delete_own_account_aborted"), true);
1242  $ilCtrl->redirect($this, "showGeneralSettings");
1243  }
1244 
1245  protected function deleteOwnAccountLogout()
1246  {
1247  global $ilAuth, $ilUser;
1248 
1249  // we are setting the flag and ending the session in the same step
1250 
1251  $ilUser->activateDeletionFlag();
1252 
1253  // see ilStartupGUI::showLogout()
1255  $ilAuth->logout();
1256  session_destroy();
1257 
1258  ilUtil::redirect("login.php?target=usr_".md5("usrdelown"));
1259  }
1260 
1264  protected function deleteOwnAccount3()
1265  {
1266  global $ilTabs, $ilUser, $ilSetting;
1267 
1268  if(!(bool)$ilSetting->get('user_delete_own_account') ||
1269  $ilUser->getId() == SYSTEM_USER_ID ||
1270  !$ilUser->hasDeletionFlag())
1271  {
1272  $this->ctrl->redirect($this, "showGeneralSettings");
1273  }
1274 
1275  $this->setHeader();
1276  $this->__initSubTabs("deleteOwnAccount");
1277  $ilTabs->activateTab("delacc");
1278 
1279  include_once "Services/Utilities/classes/class.ilConfirmationGUI.php";
1280  $cgui = new ilConfirmationGUI();
1281  $cgui->setHeaderText($this->lng->txt('user_delete_own_account_final_confirmation'));
1282  $cgui->setFormAction($this->ctrl->getFormAction($this));
1283  $cgui->setCancel($this->lng->txt("cancel"), "abortDeleteOwnAccount");
1284  $cgui->setConfirm($this->lng->txt("confirm"), "deleteOwnAccount4");
1285  $this->tpl->setContent($cgui->getHTML());
1286  $this->tpl->show();
1287  }
1288 
1292  protected function deleteOwnAccount4()
1293  {
1294  global $ilUser, $ilAuth, $ilSetting, $ilLog;
1295 
1296  if(!(bool)$ilSetting->get('user_delete_own_account') ||
1297  $ilUser->getId() == SYSTEM_USER_ID ||
1298  !$ilUser->hasDeletionFlag())
1299  {
1300  $this->ctrl->redirect($this, "showGeneralSettings");
1301  }
1302 
1303  // build notification
1304 
1305  include_once "./Services/Notification/classes/class.ilSystemNotification.php";
1306  $ntf = new ilSystemNotification();
1307  $ntf->setLangModules(array("user"));
1308  $ntf->addAdditionalInfo("profile", $ilUser->getProfileAsString($this->lng), true);
1309 
1310  // mail message
1312  $ntf->setIntroductionDirect(
1313  sprintf($this->lng->txt("user_delete_own_account_email_body"),
1314  $ilUser->getLogin(),
1315  ILIAS_HTTP_PATH,
1317 
1318  $message = $ntf->composeAndGetMessage($ilUser->getId(), null, null, true);
1319  $subject = $this->lng->txt("user_delete_own_account_email_subject");
1320 
1321 
1322  // send notification
1323 
1324  include_once "Services/Mail/classes/class.ilMail.php";
1325  $mail = new ilMail(ANONYMOUS_USER_ID);
1326 
1327  $user_email = $ilUser->getEmail();
1328  $admin_mail = $ilSetting->get("user_delete_own_account_email");
1329 
1330  // to user, admin as bcc
1331  if($user_email)
1332  {
1333  $mail->sendMimeMail($user_email, null, $admin_mail, $subject, $message, null, true);
1334  }
1335  // admin only
1336  else if($admin_mail)
1337  {
1338  $mail->sendMimeMail($admin_mail, null, null, $subject, $message, null, true);
1339  }
1340 
1341  $ilLog->write("Account deleted: ".$ilUser->getLogin()." (".$ilUser->getId().")");
1342 
1343  $ilUser->delete();
1344 
1345  // terminate session
1346  $ilAuth->logout();
1347  session_destroy();
1348 
1349  ilUtil::redirect("login.php?accdel=1");
1350  }
1351 }
1352 ?>