ILIAS  Release_4_2_x_branch Revision 61807
 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  $this->upload_error = "";
35  $this->password_error = "";
36  $lng->loadLanguageModule("user");
37  $ilCtrl->saveParameter($this, "user_page");
38  }
39 
43  function &executeCommand()
44  {
45  global $ilUser, $ilCtrl, $tpl, $ilTabs, $lng;
46 
47  $next_class = $this->ctrl->getNextClass();
48 
49  switch($next_class)
50  {
51 
52  default:
53  $cmd = $this->ctrl->getCmd("showGeneralSettings");
54 
55  // check whether password of user have to be changed
56  // due to first login or password of user is expired
57  if( $ilUser->isPasswordChangeDemanded() && $cmd != 'savePassword' )
58  {
59  $cmd = 'showPassword';
60 
62  $this->lng->txt('password_change_on_first_login_demand'), true
63  );
64  }
65  elseif( $ilUser->isPasswordExpired() && $cmd != 'savePassword' )
66  {
67  $cmd = 'showPassword';
68 
69  $msg = $this->lng->txt('password_expired');
70  $password_age = $ilUser->getPasswordAge();
71 
72  ilUtil::sendInfo( sprintf($msg,$password_age), true );
73  }
74 
75  $this->$cmd();
76  break;
77  }
78  return true;
79  }
80 
81 
82 
86  function changeUserPassword()
87  {
88  global $ilUser, $ilSetting;
89 
90  // do nothing if auth mode is not local database
91  if ($ilUser->getAuthMode(true) != AUTH_LOCAL &&
92  ($ilUser->getAuthMode(true) != AUTH_CAS || !$ilSetting->get("cas_allow_local")) &&
93  ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || !$ilSetting->get("shib_auth_allow_local")) &&
94  ($ilUser->getAuthMode(true) != AUTH_SOAP || !$ilSetting->get("soap_auth_allow_local"))
95  )
96  {
97  $this->password_error = $this->lng->txt("not_changeable_for_non_local_auth");
98  }
99 
100  // select password from auto generated passwords
101  if ($this->ilias->getSetting("passwd_auto_generate") == 1)
102  {
103  // The old password needs to be checked for verification
104  // unless the user uses Shibboleth authentication with additional
105  // local authentication for WebDAV.
106  if ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || ! $ilSetting->get("shib_auth_allow_local"))
107  {
108  // check old password
109  if (md5($_POST["current_password"]) != $ilUser->getPasswd())
110  {
111  $this->password_error = $this->lng->txt("passwd_wrong");
112  }
113  }
114  // validate transmitted password
115  if (!ilUtil::isPassword($_POST["new_passwd"]))
116  {
117  $this->password_error = $this->lng->txt("passwd_not_selected");
118  }
119 
120  if (empty($this->password_error))
121  {
122  ilUtil::sendSuccess($this->lng->txt("saved_successfully"));
123  $ilUser->updatePassword($_POST["current_password"], $_POST["new_passwd"], $_POST["new_passwd"]);
124  }
125  }
126  else
127  {
128  // check old password
129  if (md5($_POST["current_password"]) != $ilUser->getPasswd())
130  {
131  $this->password_error = $this->lng->txt("passwd_wrong");
132  }
133  // check new password
134  else if ($_POST["desired_password"] != $_POST["retype_password"])
135  {
136  $this->password_error = $this->lng->txt("passwd_not_match");
137  }
138  // validate password
139  else if (!ilUtil::isPassword($_POST["desired_password"],$custom_error))
140  {
141  if( $custom_error != '' )
142  $this->password_error = $custom_error;
143  else $this->password_error = $this->lng->txt("passwd_invalid");
144  }
145  else if ($_POST["current_password"] != "" and empty($this->password_error))
146  {
147  if( $ilUser->isPasswordExpired() || $ilUser->isPasswordChangeDemanded() )
148  {
149  if( $_POST["current_password"] != $_POST["desired_password"] )
150  {
151  if( $ilUser->updatePassword($_POST["current_password"], $_POST["desired_password"], $_POST["retype_password"]) )
152  {
153  ilUtil::sendSuccess($this->lng->txt("saved_successfully"));
154  $ilUser->setLastPasswordChangeToNow();
155  }
156  }
157  else
158  {
159  $this->password_error = $this->lng->txt("new_pass_equals_old_pass");
160  }
161  }
162  else
163  {
164  ilUtil::sendSuccess($this->lng->txt("saved_successfully"));
165  $ilUser->updatePassword($_POST["current_password"], $_POST["desired_password"], $_POST["retype_password"]);
166  $ilUser->setLastPasswordChangeToNow();
167  }
168  }
169  }
170 
171  $this->saveProfile();
172  }
173 
174 
179  public function saveMailOptions()
180  {
181  global $ilUser, $lng, $ilTabs, $ilSetting;
182 
183  $lng->loadLanguageModule('mail');
184 
185  $this->__initSubTabs('showMailOptions');
186  $ilTabs->activateTab('mail_settings');
187 
188  $this->setHeader();
189 
190  require_once 'Services/Mail/classes/class.ilMailOptions.php';
191  $mailOptions = new ilMailOptions($ilUser->getId());
192  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1' &&
193  $ilSetting->get('usr_settings_disable_mail_incoming_mail') != '1')
194  {
195  $incoming_type = (int)$_POST['incoming_type'];
196  }
197  else
198  {
199  $incoming_type = $mailOptions->getIncomingType();
200  }
201 
202  $this->initMailOptionsForm();
203  if($this->form->checkInput())
204  {
205  $mailOptions->updateOptions(
206  ilUtil::stripSlashes($_POST['signature']),
207  (int)$_POST['linebreak'],
208  $incoming_type,
209  (int)$_POST['cronjob_notification']
210  );
211 
212  ilUtil::sendSuccess($lng->txt('mail_options_saved'));
213  }
214 
215  if(!isset($_POST['incoming_type']))
216  {
217  $_POST['incoming_type'] = $mailOptions->getIncomingType();
218  }
219 
220  $this->form->setValuesByPost();
221 
222  $this->tpl->setContent($this->form->getHTML());
223  $this->tpl->show();
224  }
225 
229  private function initMailOptionsForm()
230  {
231  global $ilCtrl, $ilSetting, $lng, $ilUser;
232 
233  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
234  $this->form = new ilPropertyFormGUI();
235 
236  $this->form->setFormAction($ilCtrl->getFormAction($this, 'saveMailOptions'));
237  $this->form->setTitle($lng->txt('mail_settings'));
238 
239  // BEGIN INCOMING
240  include_once 'Services/Mail/classes/class.ilMailOptions.php';
241  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
242  {
243  $options = array(
244  IL_MAIL_LOCAL => $this->lng->txt('mail_incoming_local'),
245  IL_MAIL_EMAIL => $this->lng->txt('mail_incoming_smtp'),
246  IL_MAIL_BOTH => $this->lng->txt('mail_incoming_both')
247  );
248  $si = new ilSelectInputGUI($lng->txt('mail_incoming'), 'incoming_type');
249  $si->setOptions($options);
250  if(!strlen(ilObjUser::_lookupEmail($ilUser->getId())) ||
251  $ilSetting->get('usr_settings_disable_mail_incoming_mail') == '1')
252  {
253  $si->setDisabled(true);
254  }
255  $this->form->addItem($si);
256  }
257 
258  // BEGIN LINEBREAK_OPTIONS
259  $options = array();
260  for($i = 50; $i <= 80; $i++)
261  {
262  $options[$i] = $i;
263  }
264  $si = new ilSelectInputGUI($lng->txt('linebreak'), 'linebreak');
265  $si->setOptions($options);
266  $this->form->addItem($si);
267 
268  // BEGIN SIGNATURE
269  $ta = new ilTextAreaInputGUI($lng->txt('signature'), 'signature');
270  $ta->setRows(10);
271  $ta->setCols(60);
272  $this->form->addItem($ta);
273 
274  // BEGIN CRONJOB NOTIFICATION
275  if($ilSetting->get('mail_notification'))
276  {
277  $cb = new ilCheckboxInputGUI($lng->txt('cron_mail_notification'), 'cronjob_notification');
278  $cb->setInfo($lng->txt('mail_cronjob_notification_info'));
279  $cb->setValue(1);
280  $this->form->addItem($cb);
281  }
282 
283  $this->form->addCommandButton('saveMailOptions', $lng->txt('save'));
284  }
285 
289  private function setMailOptionsValuesByDB()
290  {
291  global $ilUser, $ilSetting;
292 
293  require_once 'Services/Mail/classes/class.ilMailOptions.php';
294  $mailOptions = new ilMailOptions($ilUser->getId());
295 
296  $data = array(
297  'linebreak' => $mailOptions->getLinebreak(),
298  'signature' => $mailOptions->getSignature(),
299  'cronjob_notification' => $mailOptions->getCronjobNotification()
300  );
301 
302  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
303  {
304  $data['incoming_type'] = $mailOptions->getIncomingType();
305  }
306 
307  $this->form->setValuesByArray($data);
308  }
309 
313  public function showMailOptions()
314  {
315  global $ilTabs, $lng;
316 
317  $lng->loadLanguageModule('mail');
318 
319  $this->__initSubTabs('showMailOptions');
320  $ilTabs->activateTab('mail_settings');
321 
322  $this->setHeader();
323 
324  $this->initMailOptionsForm();
325  $this->setMailOptionsValuesByDB();
326 
327  $this->tpl->setContent($this->form->getHTML());
328  $this->tpl->show();
329  }
330 
331  function showjsMath()
332  {
333  global $lng, $ilCtrl, $tpl, $ilUser;
334 
335  $this->__initSubTabs("showjsMath");
336  $this->setHeader();
337 
338  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
339  $form = new ilPropertyFormGUI();
340  $form->setFormAction($ilCtrl->getFormAction($this));
341  $form->setTitle($lng->txt("jsmath_settings"));
342 
343  // Enable jsMath
344  include_once "./Services/Administration/classes/class.ilSetting.php";
345  $jsMathSetting = new ilSetting("jsMath");
346  $enable = new ilCheckboxInputGUI($lng->txt("jsmath_enable_user"), "enable");
347  $checked = ($ilUser->getPref("js_math") === FALSE) ? $jsMathSetting->get("makedefault") : $ilUser->getPref("js_math");
348  $enable->setChecked($checked);
349  $enable->setInfo($lng->txt("jsmath_enable_user_desc"));
350  $form->addItem($enable);
351 
352  $form->addCommandButton("savejsMath", $lng->txt("save"));
353  $form->addCommandButton("showjsMath", $lng->txt("cancel"));
354 
355  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
356  $this->tpl->show();
357  }
358 
359  function savejsMath()
360  {
361  global $ilCtrl, $ilUser;
362 
363  include_once "./Services/Administration/classes/class.ilSetting.php";
364  $jsMathSetting = new ilSetting("jsMath");
365  if ($jsMathSetting->get("enable"))
366  {
367  if ($_POST["enable"])
368  {
369  $ilUser->writePref("js_math", "1");
370  }
371  else
372  {
373  $ilUser->writePref("js_math", "0");
374  }
375  }
376  $ilCtrl->redirect($this, "showjsMath");
377  }
378 
379  // init sub tabs
380  function __initSubTabs($a_cmd)
381  {
382  global $ilTabs, $ilSetting;
383 
384  $showPassword = ($a_cmd == 'showPassword') ? true : false;
385  $showGeneralSettings = ($a_cmd == 'showGeneralSettings') ? true : false;
386  $showMailOptions = ($a_cmd == 'showMailOptions') ? true : false;
387  $showjsMath = ($a_cmd == 'showjsMath') ? true : false;
388  $showChatOptions = ($a_cmd == 'showChatOptions') ? true : false;
389 
390  // old profile
391 
392  // general settings
393  $ilTabs->addTarget("general_settings", $this->ctrl->getLinkTarget($this, "showGeneralSettings"),
394  "", "", "", $showGeneralSettings);
395 
396  // password
397  if ($this->allowPasswordChange())
398  {
399  $ilTabs->addTarget("password", $this->ctrl->getLinkTarget($this, "showPassword"),
400  "", "", "", $showPassword);
401  }
402 
403 
404  $ilTabs->addTarget("mail_settings", $this->ctrl->getLinkTarget($this, "showMailOptions"),
405  "", "", "", $showMailOptions);
406 
407  if(((int)$ilSetting->get('chat_sound_status') &&
408  ((int)$ilSetting->get('chat_new_invitation_sound_status') ||
409  (int)$ilSetting->get('chat_new_message_sound_status'))) ||
410  (int)$ilSetting->get('chat_message_notify_status') == 1)
411  {
412  $ilTabs->addTarget("chat_settings", $this->ctrl->getLinkTarget($this, "showChatOptions"),
413  "", "", "", $showChatOptions);
414  }
415 
416  include_once "./Services/Administration/classes/class.ilSetting.php";
417  $jsMathSetting = new ilSetting("jsMath");
418  if ($jsMathSetting->get("enable"))
419  {
420  $ilTabs->addTarget("jsmath_extt_jsmath", $this->ctrl->getLinkTarget($this, "showjsMath"),
421  "", "", "", $showjsMath);
422  }
423  }
424 
425 
426 
427  private function getChatSettingsForm()
428  {
429  global $ilCtrl, $ilSetting, $lng;
430 
431  $lng->loadLanguageModule('chat');
432 
433  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
434  $form = new ilPropertyFormGUI();
435 
436  $form->setFormAction($this->ctrl->getFormAction($this, 'saveChatOptions'));
437  $form->setTitle($lng->txt("chat_settings"));
438 
439  if((int)$ilSetting->get('chat_message_notify_status'))
440  {
441  // chat message notification in ilias
442  //$rg_parent = new ilRadioGroupInputGUI($this->lng->txt('chat_message_notify'), 'chat_message_notify_status');
443  //$rg_parent->setValue(0);
444 
445  $ro_parent = new ilCheckboxInputGUI($this->lng->txt('chat_message_notify_activate'), 'chat_message_notify_activate');
446  //$rg_parent->addOption($ro_parent);
447  #$ro_parent->setValue(0);
448 
449  if((int)$ilSetting->get('chat_sound_status') &&
450  ((int)$ilSetting->get('chat_new_invitation_sound_status') ||
451  (int)$ilSetting->get('chat_new_message_sound_status')))
452  {
453  // sound activation/deactivation for new chat invitations and messages
454  #$rg = new ilRadioGroupInputGUI($this->lng->txt('chat_sounds'), 'chat_sound_status');
455  #$rg->setValue(0);
456  #$ro = new ilCheckboxInputGUI($this->lng->txt('chat_sound_status_activate'), 1);
457  if((int)$ilSetting->get('chat_new_invitation_sound_status'))
458  {
459  $chb = new ilCheckboxInputGUI('', 'chat_new_invitation_sound_status');
460  $chb->setOptionTitle($this->lng->txt('chat_new_invitation_sound_status'));
461  $chb->setChecked(false);
462  $ro_parent->addSubItem($chb);
463  }
464 
465  if((int)$ilSetting->get('chat_new_message_sound_status'))
466  {
467  $chb = new ilCheckBoxInputGUI('','chat_new_message_sound_status');
468  $chb->setOptionTitle($this->lng->txt('chat_new_message_sound_status'));
469  $chb->setChecked(false);
470  $ro_parent->addSubItem($chb);
471  }
472  #$rg->addOption($ro);
473 
474  //$ro = new ilRadioOption($this->lng->txt('chat_sound_status_deactivate'), 0);
475  //$rg->addOption($ro);
476 
477  #$ro_parent->addSubItem($rg);
478  //$form->addItem($rg);
479  }
480 
481 
482  #$ro_parent = new ilRadioOption($this->lng->txt('chat_message_notify_deactivate'), 0);
483  #$rg_parent->addOption($ro_parent);
484  $form->addItem($ro_parent);
485  }
486 
487  $form->addCommandButton("saveChatOptions", $lng->txt("save"));
488  return $form;
489  }
490 
491  public function saveChatOptions()
492  {
493  global $ilUser, $ilSetting, $lng;
494 
495  if((int)$ilSetting->get('chat_message_notify_status'))
496  {
497  $ilUser->setPref('chat_message_notify_status', (int)$_POST['chat_message_notify_activate']);
498  }
499 
500  if((int)$ilSetting->get('chat_sound_status') &&
501  ((int)$ilSetting->get('chat_new_invitation_sound_status') ||
502  (int)$ilSetting->get('chat_new_message_sound_status')))
503  {
504  $ilUser->setPref('chat_sound_status', (int)$_POST['chat_sound_status']);
505  if((int)$ilSetting->get('chat_new_invitation_sound_status'))
506  {
507  $ilUser->setPref('chat_new_invitation_sound_status', (int)$_POST['chat_new_invitation_sound_status']);
508  }
509  if((int)$ilSetting->get('chat_new_message_sound_status'))
510  {
511  $ilUser->setPref('chat_new_message_sound_status', (int)$_POST['chat_new_message_sound_status']);
512  }
513  }
514 
515  $ilUser->writePrefs();
516 
517  ilUtil::sendSuccess($lng->txt('saved'));
518 
519  $this->showChatOptions(true);
520  }
521 
525  function setHeader()
526  {
527 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"), "");
528  $this->tpl->setVariable('HEADER', $this->lng->txt('personal_settings'));
529  }
530 
534  public function showChatOptions($by_post = false)
535  {
536  global $ilCtrl, $ilSetting, $lng, $ilUser;
537 
538  $this->__initSubTabs('showChatOptions');
539 
540  $this->setHeader();
541 
542  $form = false;
543  if($by_post)
544  {
545  $form = $this->getChatSettingsForm();
546  $form->setValuesByPost();
547  }
548  else
549  {
550  $values = array();
551  $values['chat_message_notify_status'] = $ilUser->getPref('chat_message_notify_status');
552  $values['chat_message_notify_activate'] = $ilUser->getPref('chat_message_notify_status');
553 
554  $values['chat_sound_status'] = $ilUser->getPref('chat_sound_status');
555  $values['chat_new_invitation_sound_status'] = $ilUser->getPref('chat_new_invitation_sound_status');
556  $values['chat_new_message_sound_status'] = $ilUser->getPref('chat_new_message_sound_status');
557 
558  $form = $this->getChatSettingsForm();
559  $form->setValuesByArray($values);
560 
561  }
562  $this->tpl->setVariable('ADM_CONTENT', $form->getHTML());
563  $this->tpl->show();
564  }
565 
566 
567  //
568  //
569  // PASSWORD FORM
570  //
571  //
572 
576  function showPassword($a_no_init = false)
577  {
578  global $ilTabs;
579 
580  $this->__initSubTabs("showPersonalData");
581  $ilTabs->activateTab("password");
582 
583  $this->setHeader();
584 
585  if (!$a_no_init)
586  {
587  $this->initPasswordForm();
588  }
589  $this->tpl->setContent($this->form->getHTML());
590  $this->tpl->show();
591  }
592 
598  public function initPasswordForm()
599  {
600  global $lng, $ilUser, $ilSetting;
601 
602  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
603  $this->form = new ilPropertyFormGUI();
604 
605  // Check whether password change is allowed
606  if ($this->allowPasswordChange())
607  {
608  // The current password needs to be checked for verification
609  // unless the user uses Shibboleth authentication with additional
610  // local authentication for WebDAV.
611  //if (
612  // ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || !$ilSetting->get("shib_auth_allow_local"))
613  //)
614  if($ilUser->getAuthMode(true) == AUTH_LOCAL)
615  {
616  // current password
617  $cpass = new ilPasswordInputGUI($lng->txt("current_password"), "current_password");
618  $cpass->setRetype(false);
619  $cpass->setSkipSyntaxCheck(true);
620  // only if a password exists.
621  if($ilUser->getPasswd())
622  {
623  $cpass->setRequired(true);
624  }
625  $this->form->addItem($cpass);
626  }
627 
628  // new password
629  $ipass = new ilPasswordInputGUI($lng->txt("desired_password"), "new_password");
630  $ipass->setRequired(true);
631  $ipass->setInfo(ilUtil::getPasswordRequirementsInfo());
632 
633  if ($ilSetting->get("passwd_auto_generate") == 1) // auto generation list
634  {
635  $ipass->setPreSelection(true);
636 
637  $this->form->addItem($ipass);
638  $this->form->addCommandButton("savePassword", $lng->txt("save"));
639  $this->form->addCommandButton("showPassword", $lng->txt("new_list_password"));
640  }
641  else // user enters password
642  {
643  $this->form->addItem($ipass);
644  $this->form->addCommandButton("savePassword", $lng->txt("save"));
645  }
646 
647  switch ($ilUser->getAuthMode(true))
648  {
649  case AUTH_LOCAL :
650  $this->form->setTitle($lng->txt("chg_password"));
651  break;
652 
653  case AUTH_SHIBBOLETH :
654  case AUTH_CAS:
655  require_once 'Services/WebDAV/classes/class.ilDAVServer.php';
657  {
658  $this->form->setTitle($lng->txt("chg_ilias_and_webfolder_password"));
659  }
660  else
661  {
662  $this->form->setTitle($lng->txt("chg_ilias_password"));
663  }
664  break;
665  default :
666  $this->form->setTitle($lng->txt("chg_ilias_password"));
667  break;
668  }
669  $this->form->setFormAction($this->ctrl->getFormAction($this));
670  }
671  }
672 
677  {
678  global $ilUser, $ilSetting;
679 
680 
681  return ilAuthUtils::isPasswordModificationEnabled($ilUser->getAuthMode(true));
682 
683  // Moved to ilAuthUtils
684 
685  // do nothing if auth mode is not local database
686  if ($ilUser->getAuthMode(true) != AUTH_LOCAL &&
687  ($ilUser->getAuthMode(true) != AUTH_CAS || !$ilSetting->get("cas_allow_local")) &&
688  ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || !$ilSetting->get("shib_auth_allow_local")) &&
689  ($ilUser->getAuthMode(true) != AUTH_SOAP || !$ilSetting->get("soap_auth_allow_local")) &&
690  ($ilUser->getAuthMode(true) != AUTH_OPENID)
691  )
692  {
693  return false;
694  }
695  if (!$this->userSettingVisible('password') ||
696  $this->ilias->getSetting('usr_settings_disable_password'))
697  {
698  return false;
699  }
700  return true;
701  }
702 
707  public function savePassword()
708  {
709  global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting;
710 
711  // normally we should not end up here
712  if (!$this->allowPasswordChange())
713  {
714  $ilCtrl->redirect($this, "showPersonalData");
715  return;
716  }
717 
718  $this->initPasswordForm();
719  if ($this->form->checkInput())
720  {
721  $cp = $this->form->getItemByPostVar("current_password");
722  $np = $this->form->getItemByPostVar("new_password");
723  $error = false;
724 
725  // The old password needs to be checked for verification
726  // unless the user uses Shibboleth authentication with additional
727  // local authentication for WebDAV.
728  #if ($ilUser->getAuthMode(true) != AUTH_SHIBBOLETH || ! $ilSetting->get("shib_auth_allow_local"))
729  if($ilUser->getAuthMode(true) == AUTH_LOCAL)
730  {
731  // check current password
732  if (md5($_POST["current_password"]) != $ilUser->getPasswd() and
733  $ilUser->getPasswd())
734  {
735  $error = true;
736  $cp->setAlert($this->lng->txt("passwd_wrong"));
737  }
738  }
739 
740  // select password from auto generated passwords
741  if ($this->ilias->getSetting("passwd_auto_generate") == 1 &&
742  (!ilUtil::isPassword($_POST["new_password"])))
743  {
744  $error = true;
745  $np->setAlert($this->lng->txt("passwd_not_selected"));
746  }
747 
748 
749  if ($this->ilias->getSetting("passwd_auto_generate") != 1 &&
750  !ilUtil::isPassword($_POST["new_password"],$custom_error))
751  {
752  $error = true;
753  if ($custom_error != '')
754  {
755  $np->setAlert($custom_error);
756  }
757  else
758  {
759  $np->setAlert($this->lng->txt("passwd_invalid"));
760  }
761  }
762  if ($this->ilias->getSetting("passwd_auto_generate") != 1 &&
763  ($ilUser->isPasswordExpired() || $ilUser->isPasswordChangeDemanded()) &&
764  ($_POST["current_password"] == $_POST["new_password"]))
765  {
766  $error = true;
767  $np->setAlert($this->lng->txt("new_pass_equals_old_pass"));
768  }
769 
770  if (!$error)
771  {
772  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
773  $ilUser->resetPassword($_POST["new_password"], $_POST["new_password"]);
774  if ($_POST["current_password"] != $_POST["new_password"])
775  {
776  $ilUser->setLastPasswordChangeToNow();
777  }
778  $ilCtrl->redirect($this, "showPassword");
779  }
780  }
781  $this->form->setValuesByPost();
782  $this->showPassword(true);
783  }
784 
785  //
786  //
787  // GENERAL SETTINGS FORM
788  //
789  //
790 
795  function workWithUserSetting($setting)
796  {
797  $result = TRUE;
798  if ($this->settings["usr_settings_hide_".$setting] == 1)
799  {
800  $result = FALSE;
801  }
802  if ($this->settings["usr_settings_disable_".$setting] == 1)
803  {
804  $result = FALSE;
805  }
806  return $result;
807  }
808 
813  function userSettingVisible($setting)
814  {
815  $result = TRUE;
816  if (isset($this->settings["usr_settings_hide_".$setting]) &&
817  $this->settings["usr_settings_hide_".$setting] == 1)
818  {
819  $result = FALSE;
820  }
821  return $result;
822  }
823 
828  function userSettingEnabled($setting)
829  {
830  $result = TRUE;
831  if ($this->settings["usr_settings_disable_".$setting] == 1)
832  {
833  $result = FALSE;
834  }
835  return $result;
836  }
837 
841  function showGeneralSettings($a_no_init = false)
842  {
843  global $ilTabs;
844 
845  $this->__initSubTabs("showPersonalData");
846  $ilTabs->activateTab("general_settings");
847 
848  $this->setHeader();
849 
850  if (!$a_no_init)
851  {
852  $this->initGeneralSettingsForm();
853  }
854  $this->tpl->setContent($this->form->getHTML());
855  $this->tpl->show();
856  }
857 
862  public function initGeneralSettingsForm()
863  {
864  global $lng, $ilUser, $styleDefinition, $ilSetting;
865 
866 
867  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
868  $this->form = new ilPropertyFormGUI();
869 
870  // language
871  if ($this->userSettingVisible("language"))
872  {
873  $languages = $this->lng->getInstalledLanguages();
874  $options = array();
875  foreach($languages as $lang_key)
876  {
877  $options[$lang_key] = ilLanguage::_lookupEntry($lang_key,"meta", "meta_l_".$lang_key);
878  }
879 
880  $si = new ilSelectInputGUI($this->lng->txt("language"), "language");
881  $si->setOptions($options);
882  $si->setValue($ilUser->getLanguage());
883  $si->setDisabled($ilSetting->get("usr_settings_disable_language"));
884  $this->form->addItem($si);
885  }
886 
887  // skin/style
888  include_once("./Services/Style/classes/class.ilObjStyleSettings.php");
889  if ($this->userSettingVisible("skin_style"))
890  {
891  $templates = $styleDefinition->getAllTemplates();
892  if (is_array($templates))
893  {
894  $si = new ilSelectInputGUI($this->lng->txt("skin_style"), "skin_style");
895 
896  $options = array();
897  foreach($templates as $template)
898  {
899  // get styles information of template
900  $styleDef = new ilStyleDefinition($template["id"]);
901  $styleDef->startParsing();
902  $styles = $styleDef->getStyles();
903 
904  foreach($styles as $style)
905  {
906  if (!ilObjStyleSettings::_lookupActivatedStyle($template["id"],$style["id"]))
907  {
908  continue;
909  }
910 
911  $options[$template["id"].":".$style["id"]] =
912  $styleDef->getTemplateName()." / ".$style["name"];
913  }
914  }
915  $si->setOptions($options);
916  $si->setValue($ilUser->skin.":".$ilUser->prefs["style"]);
917  $si->setDisabled($ilSetting->get("usr_settings_disable_skin_style"));
918  $this->form->addItem($si);
919  }
920  }
921 
922  // screen reader optimization
923  if ($this->userSettingVisible("screen_reader_optimization"))
924  {
925  $cb = new ilCheckboxInputGUI($this->lng->txt("user_screen_reader_optimization"), "screen_reader_optimization");
926  $cb->setChecked($ilUser->prefs["screen_reader_optimization"]);
927  $cb->setDisabled($ilSetting->get("usr_settings_disable_screen_reader_optimization"));
928  $cb->setInfo($this->lng->txt("user_screen_reader_optimization_info"));
929  $this->form->addItem($cb);
930  }
931 
932  // hits per page
933  if ($this->userSettingVisible("hits_per_page"))
934  {
935  $si = new ilSelectInputGUI($this->lng->txt("hits_per_page"), "hits_per_page");
936 
937  $hits_options = array(10,15,20,30,40,50,100,9999);
938  $options = array();
939 
940  foreach($hits_options as $hits_option)
941  {
942  $hstr = ($hits_option == 9999)
943  ? $this->lng->txt("no_limit")
944  : $hits_option;
945  $options[$hits_option] = $hstr;
946  }
947  $si->setOptions($options);
948  $si->setValue($ilUser->prefs["hits_per_page"]);
949  $si->setDisabled($ilSetting->get("usr_settings_disable_hits_per_page"));
950  $this->form->addItem($si);
951  }
952 
953  // Users Online
954  if ($this->userSettingVisible("show_users_online"))
955  {
956  $si = new ilSelectInputGUI($this->lng->txt("show_users_online"), "show_users_online");
957 
958  $options = array(
959  "y" => $this->lng->txt("users_online_show_y"),
960  "associated" => $this->lng->txt("users_online_show_associated"),
961  "n" => $this->lng->txt("users_online_show_n"));
962  $si->setOptions($options);
963  $si->setValue($ilUser->prefs["show_users_online"]);
964  $si->setDisabled($ilSetting->get("usr_settings_disable_show_users_online"));
965  $this->form->addItem($si);
966  }
967 
968  // hide_own_online_status
969  if ($this->userSettingVisible("hide_own_online_status"))
970  {
971  $cb = new ilCheckboxInputGUI($this->lng->txt("hide_own_online_status"), "hide_own_online_status");
972  $cb->setChecked($ilUser->prefs["hide_own_online_status"] == "y");
973  $cb->setDisabled($ilSetting->get("usr_settings_disable_hide_own_online_status"));
974  $this->form->addItem($cb);
975  }
976 
977  // session reminder
978  if((int)$ilSetting->get('session_handling_type') == 0 &&
979  (int)$ilSetting->get('session_reminder_enabled'))
980  {
981  $cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
982  $cb->setInfo($this->lng->txt('session_reminder_info'));
983  $cb->setValue(1);
984  $cb->setChecked((int)$ilUser->getPref('session_reminder_enabled'));
985 
986  $expires = ilSession::getSessionExpireValue();
987  $lead_time_gui = new ilTextInputGUI($this->lng->txt('session_reminder_lead_time'), 'session_reminder_lead_time');
988  $lead_time_gui->setInfo(sprintf($this->lng->txt('session_reminder_lead_time_info'), ilFormat::_secondsToString($expires, true)));
989  $lead_time_gui->setValue($ilUser->getPref('session_reminder_lead_time'));
990  $lead_time_gui->setMaxLength(10);
991  $lead_time_gui->setSize(10);
992  $cb->addSubItem($lead_time_gui);
993 
994  $this->form->addItem($cb);
995  }
996 
997 
998  // calendar settings (copied here to be reachable when calendar is inactive)
999  // they cannot be hidden/deactivated
1000 
1001  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
1002  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
1003  $lng->loadLanguageModule("dateplaner");
1004  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
1005 
1006  $select = new ilSelectInputGUI($lng->txt('cal_user_timezone'),'timezone');
1008  $select->setInfo($lng->txt('cal_timezone_info'));
1009  $select->setValue($user_settings->getTimeZone());
1010  $this->form->addItem($select);
1011 
1012  $year = date("Y");
1013  $select = new ilSelectInputGUI($lng->txt('cal_user_date_format'),'date_format');
1014  $select->setOptions(array(
1015  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.'.$year,
1016  ilCalendarSettings::DATE_FORMAT_YMD => $year."-10-31",
1017  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/".$year));
1018  $select->setInfo($lng->txt('cal_date_format_info'));
1019  $select->setValue($user_settings->getDateFormat());
1020  $this->form->addItem($select);
1021 
1022  $select = new ilSelectInputGUI($lng->txt('cal_user_time_format'),'time_format');
1023  $select->setOptions(array(
1025  ilCalendarSettings::TIME_FORMAT_12 => '1:00pm'));
1026  $select->setInfo($lng->txt('cal_time_format_info'));
1027  $select->setValue($user_settings->getTimeFormat());
1028  $this->form->addItem($select);
1029 
1030 
1031  $this->form->addCommandButton("saveGeneralSettings", $lng->txt("save"));
1032  $this->form->setTitle($lng->txt("general_settings"));
1033  $this->form->setFormAction($this->ctrl->getFormAction($this));
1034 
1035  }
1036 
1040  public function saveGeneralSettings()
1041  {
1042  global $tpl, $lng, $ilCtrl, $ilUser;
1043 
1044  $this->initGeneralSettingsForm();
1045  if ($this->form->checkInput())
1046  {
1047  if ($this->workWithUserSetting("skin_style"))
1048  {
1049  //set user skin and style
1050  if ($_POST["skin_style"] != "")
1051  {
1052  $sknst = explode(":", $_POST["skin_style"]);
1053 
1054  if ($ilUser->getPref("style") != $sknst[1] ||
1055  $ilUser->getPref("skin") != $sknst[0])
1056  {
1057  $ilUser->setPref("skin", $sknst[0]);
1058  $ilUser->setPref("style", $sknst[1]);
1059  }
1060  }
1061  }
1062 
1063  // language
1064  if ($this->workWithUserSetting("language"))
1065  {
1066  $ilUser->setLanguage($_POST["language"]);
1067  }
1068 
1069  // hits per page
1070  if ($this->workWithUserSetting("hits_per_page"))
1071  {
1072  if ($_POST["hits_per_page"] != "")
1073  {
1074  $ilUser->setPref("hits_per_page",$_POST["hits_per_page"]);
1075  }
1076  }
1077 
1078  // set show users online
1079  if ($this->workWithUserSetting("show_users_online"))
1080  {
1081  $ilUser->setPref("show_users_online", $_POST["show_users_online"]);
1082  }
1083 
1084  // set hide own online_status
1085  if ($this->workWithUserSetting("hide_own_online_status"))
1086  {
1087  if ($_POST["hide_own_online_status"] == 1)
1088  {
1089  $ilUser->setPref("hide_own_online_status","y");
1090  }
1091  else
1092  {
1093  $ilUser->setPref("hide_own_online_status","n");
1094  }
1095  }
1096 
1097  // set show users online
1098  if ($this->workWithUserSetting("screen_reader_optimization"))
1099  {
1100  $ilUser->setPref("screen_reader_optimization", $_POST["screen_reader_optimization"]);
1101  }
1102 
1103  // session reminder
1104  global $ilSetting;
1105  if((int)$ilSetting->get('session_handling_type') == 0 &&
1106  (int)$ilSetting->get('session_reminder_enabled'))
1107  {
1108  $ilUser->setPref('session_reminder_enabled', (int)$_POST['session_reminder_enabled']);
1109 
1110  if(!preg_match('/^([0]|([1-9][0-9]*))([\.][0-9][0-9]*)?$/', $_POST['session_reminder_lead_time']))
1111  $_POST['session_reminder_lead_time'] = 0;
1112  $ilUser->setPref('session_reminder_lead_time', $_POST['session_reminder_lead_time']);
1113  }
1114 
1115  $ilUser->update();
1116 
1117  // calendar settings
1118  include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
1119  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
1120  $user_settings->setTimeZone($this->form->getInput("timezone"));
1121  $user_settings->setDateFormat((int)$this->form->getInput("date_format"));
1122  $user_settings->setTimeFormat((int)$this->form->getInput("time_format"));
1123  $user_settings->save();
1124 
1125  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1126  $ilCtrl->redirect($this, "showGeneralSettings");
1127  }
1128 
1129  $this->form->setValuesByPost();
1130  $tpl->showGeneralSettings(true);
1131  }
1132 }
1133 ?>