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