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