ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccountRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
18 require_once './Services/Registration/classes/class.ilRegistrationSettings.php';
19 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
20 
25 {
26  protected $registration_settings; // [object]
27  protected $code_enabled; // [bool]
28  protected $code_was_used; // [bool]
29 
30  public function __construct()
31  {
32  global $ilCtrl,$tpl,$lng;
33 
34  $this->tpl =& $tpl;
35 
36  $this->ctrl =& $ilCtrl;
37  $this->ctrl->saveParameter($this,'lang');
38 
39  $this->lng =& $lng;
40  $this->lng->loadLanguageModule('registration');
41 
42  $this->registration_settings = new ilRegistrationSettings();
43 
44  $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
45  $this->registration_settings->getAllowCodes());
46  }
47 
48  public function executeCommand()
49  {
50  global $ilErr, $tpl;
51 
52  if($this->registration_settings->getRegistrationType() == IL_REG_DISABLED)
53  {
54  $ilErr->raiseError($this->lng->txt('reg_disabled'),$ilErr->FATAL);
55  }
56 
57  $next_class = $this->ctrl->getNextClass($this);
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  if($cmd)
64  {
65  $this->$cmd();
66  }
67  else
68  {
69  $this->displayForm();
70  }
71  break;
72  }
73  $tpl->show();
74  return true;
75  }
76 
80  public function displayForm()
81  {
85  global $lng;
86 
87  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registration.html', 'Services/Registration'), true);
88  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
89 
90  $lang_opts = array();
91  foreach($lng->getInstalledLanguages() as $lang_key)
92  {
93  $lang_opts[$lang_key] = ilLanguage::_lookupEntry($lang_key, 'meta', 'meta_l_' . $lang_key);
94  }
95 
96  // #11237
97  if(sizeof($lang_opts) > 1)
98  {
99  asort($lang_opts);
100  foreach($lang_opts as $lang_key => $lang_caption)
101  {
102  $this->tpl->setCurrentBlock('lang_headline_languages');
103  $this->tpl->setVariable('LANG_HEADLINE_LANGUAGES_LANG_NAME', $lang_caption);
104  $this->tpl->setVariable('LANG_HEADLINE_LANGUAGES_LANG_KEY', $lang_key);
105  if($lang_key == $lng->getLangKey())
106  {
107  $this->tpl->setVariable('LANG_HEADLINE_LANGUAGES_SELECTED_LANG', ' selected="selected"');
108  }
109  $this->tpl->parseCurrentBlock();
110  }
111 
112  $this->tpl->setCurrentBlock('lang_headline');
113  $this->tpl->setVariable('LANG_CHANGE_CMD', 'displayForm');
114  $this->tpl->setVariable('LANG_CHANGE_FORMACTION', $this->ctrl->getFormAction($this, 'displayForm'));
115  $this->tpl->setVariable('LANG_CHANGE_TXT_OK', $lng->txt('ok'));
116  $this->tpl->setVariable('LANG_CHANGE_TXT_CHOOSE_LANGUAGE', $lng->txt('choose_language'));
117  $this->tpl->setCurrentBlock('lang_headline');
118  }
119 
120  if(!$this->form)
121  {
122  $this->__initForm();
123  }
124  $this->tpl->setVariable('FORM', $this->form->getHTML());
125  }
126 
127  protected function __initForm()
128  {
129  global $lng, $ilUser;
130 
131  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
132  $this->form = new ilPropertyFormGUI();
133  $this->form->setFormAction($this->ctrl->getFormAction($this));
134 
135 
136  // code handling
137 
138  if($this->code_enabled)
139  {
140  include_once 'Services/Registration/classes/class.ilRegistrationCode.php';
141  $code = new ilTextInputGUI($lng->txt("registration_code"), "usr_registration_code");
142  $code->setSize(40);
143  $code->setMaxLength(ilRegistrationCode::CODE_LENGTH);
144  if((bool)$this->registration_settings->registrationCodeRequired())
145  {
146  $code->setRequired(true);
147  $code->setInfo($lng->txt("registration_code_required_info"));
148  }
149  else
150  {
151  $code->setInfo($lng->txt("registration_code_optional_info"));
152  }
153  $this->form->addItem($code);
154  }
155 
156 
157  // user defined fields
158 
159  $user_defined_data = $ilUser->getUserDefinedData();
160 
161  include_once './Services/User/classes/class.ilUserDefinedFields.php';
162  $user_defined_fields =& ilUserDefinedFields::_getInstance();
163  $custom_fields = array();
164  foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
165  {
166  if($definition['field_type'] == UDF_TYPE_TEXT)
167  {
168  $custom_fields["udf_".$definition['field_id']] =
169  new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
170  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
171  $custom_fields["udf_".$definition['field_id']]->setMaxLength(255);
172  $custom_fields["udf_".$definition['field_id']]->setSize(40);
173  }
174  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
175  {
176  $custom_fields["udf_".$definition['field_id']] =
177  new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
178  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
179  $custom_fields["udf_".$definition['field_id']]->setUseRte(true);
180  }
181  else
182  {
183  $custom_fields["udf_".$definition['field_id']] =
184  new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
185  $custom_fields["udf_".$definition['field_id']]->setValue($user_defined_data["f_".$field_id]);
186  $custom_fields["udf_".$definition['field_id']]->setOptions(
187  $user_defined_fields->fieldValuesToSelectArray($definition['field_values']));
188  }
189  if($definition['required'])
190  {
191  $custom_fields["udf_".$definition['field_id']]->setRequired(true);
192  }
193 
194  if($definition['field_type'] == UDF_TYPE_SELECT && !$user_defined_data["f_".$field_id])
195  {
196  $options = array(""=>$lng->txt("please_select")) + $custom_fields["udf_".$definition['field_id']]->getOptions();
197  $custom_fields["udf_".$definition['field_id']]->setOptions($options);
198  }
199  }
200 
201  // standard fields
202  include_once("./Services/User/classes/class.ilUserProfile.php");
203  $up = new ilUserProfile();
204  $up->setMode(ilUserProfile::MODE_REGISTRATION);
205  $up->skipGroup("preferences");
206 
207  // add fields to form
208  $up->addStandardFieldsToForm($this->form, NULL, $custom_fields);
209  unset($custom_fields);
210 
211 
212  // set language selection to current display language
213  $flang = $this->form->getItemByPostVar("usr_language");
214  if($flang)
215  {
216  $flang->setValue($lng->getLangKey());
217  }
218 
219  // add information to role selection (if not hidden)
220  if($this->code_enabled)
221  {
222  $role = $this->form->getItemByPostVar("usr_roles");
223  if($role && $role->getType() == "select")
224  {
225  $role->setInfo($lng->txt("registration_code_role_info"));
226  }
227  }
228 
229  // #11407
230  $domains = array();
231  foreach($this->registration_settings->getAllowedDomains() as $item)
232  {
233  if(trim($item))
234  {
235  $domains[] = $item;
236  }
237  }
238  if(sizeof($domains))
239  {
240  $mail_obj = $this->form->getItemByPostVar('usr_email');
241  $mail_obj->setInfo(sprintf($lng->txt("reg_email_domains"),
242  implode(", ", $domains))."<br />".
243  ($this->code_enabled ? $lng->txt("reg_email_domains_code") : ""));
244  }
245 
246  // #14272
247  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
248  {
249  $mail_obj = $this->form->getItemByPostVar('usr_email');
250  if($mail_obj) // #16087
251  {
252  $mail_obj->setRequired(true);
253  }
254  }
255 
256  if(ilTermsOfServiceHelper::isEnabled())
257  {
258  try
259  {
260  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
262  $field = new ilFormSectionHeaderGUI();
263  $field->setTitle($lng->txt('usr_agreement'));
264  $this->form->addItem($field);
265 
266  $field = new ilCustomInputGUI();
267  $field->setHTML('<div id="agreement">' . $document->getContent() . '</div>');
268  $this->form->addItem($field);
269 
270  $field = new ilCheckboxInputGUI($lng->txt('accept_usr_agreement'), 'accept_terms_of_service');
271  $field->setRequired(true);
272  $field->setValue(1);
273  $this->form->addItem($field);
274  }
276  {
277  }
278  }
279 
280  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
281  if(ilCaptchaUtil::isActiveForRegistration())
282  {
283  require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
284  $captcha = new ilCaptchaInputGUI($lng->txt("captcha_code"), 'captcha_code');
285  $captcha->setRequired(true);
286  $this->form->addItem($captcha);
287  }
288 
289  $this->form->addCommandButton("saveForm", $lng->txt("register"));
290  }
291 
292  public function saveForm()
293  {
294  global $lng, $ilSetting, $rbacreview;
295 
296  $this->__initForm();
297  $form_valid = $this->form->checkInput();
298 
299  require_once 'Services/User/classes/class.ilObjUser.php';
300 
301 
302  // custom validation
303 
304  $valid_code = $valid_role = false;
305 
306  // code
307  if($this->code_enabled)
308  {
309  $code = $this->form->getInput('usr_registration_code');
310  // could be optional
311  if($code)
312  {
313  // code validation
314  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
316  {
317  $code_obj = $this->form->getItemByPostVar('usr_registration_code');
318  $code_obj->setAlert($lng->txt('registration_code_not_valid'));
319  $form_valid = false;
320  }
321  else
322  {
323  $valid_code = true;
324 
325  // get role from code, check if (still) valid
326  $role_id = (int)ilRegistrationCode::getCodeRole($code);
327  if($role_id && $rbacreview->isGlobalRole($role_id))
328  {
329  $valid_role = $role_id;
330  }
331  }
332  }
333  }
334 
335  // valid codes override email domain check
336  if(!$valid_code)
337  {
338  // validate email against restricted domains
339  $email = $this->form->getInput("usr_email");
340  if($email)
341  {
342  // #10366
343  $domains = array();
344  foreach($this->registration_settings->getAllowedDomains() as $item)
345  {
346  if(trim($item))
347  {
348  $domains[] = $item;
349  }
350  }
351  if(sizeof($domains))
352  {
353  $mail_valid = false;
354  foreach($domains as $domain)
355  {
356  $domain = str_replace("*", "~~~", $domain);
357  $domain = preg_quote($domain);
358  $domain = str_replace("~~~", ".+", $domain);
359  if(preg_match("/^".$domain."$/", $email, $hit))
360  {
361  $mail_valid = true;
362  break;
363  }
364  }
365  if(!$mail_valid)
366  {
367  $mail_obj = $this->form->getItemByPostVar('usr_email');
368  $mail_obj->setAlert(sprintf($lng->txt("reg_email_domains"),
369  implode(", ", $domains)));
370  $form_valid = false;
371  }
372  }
373  }
374  }
375 
376  $error_lng_var = '';
377  if(
378  !$this->registration_settings->passwordGenerationEnabled() &&
379  !ilUtil::isPasswordValidForUserContext($this->form->getInput('usr_password'), $this->form->getInput('username'), $error_lng_var)
380  )
381  {
382  $passwd_obj = $this->form->getItemByPostVar('usr_password');
383  $passwd_obj->setAlert($lng->txt($error_lng_var));
384  $form_valid = false;
385  }
386 
387  if(ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput('accept_terms_of_service'))
388  {
389  $agr_obj = $this->form->getItemByPostVar('accept_terms_of_service');
390  $agr_obj->setAlert($lng->txt('force_accept_usr_agreement'));
391  $form_valid = false;
392  }
393 
394  // no need if role is attached to code
395  if(!$valid_role)
396  {
397  // manual selection
398  if ($this->registration_settings->roleSelectionEnabled())
399  {
400  include_once "./Services/AccessControl/classes/class.ilObjRole.php";
401  $selected_role = $this->form->getInput("usr_roles");
402  if ($selected_role && ilObjRole::_lookupAllowRegister($selected_role))
403  {
404  $valid_role = (int)$selected_role;
405  }
406  }
407  // assign by email
408  else
409  {
410  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
411  $registration_role_assignments = new ilRegistrationRoleAssignments();
412  $valid_role = (int)$registration_role_assignments->getRoleByEmail($this->form->getInput("usr_email"));
413  }
414  }
415 
416  // no valid role could be determined
417  if (!$valid_role)
418  {
419  ilUtil::sendInfo($lng->txt("registration_no_valid_role"));
420  $form_valid = false;
421  }
422 
423  // validate username
424  $login_obj = $this->form->getItemByPostVar('username');
425  $login = $this->form->getInput("username");
426  if (!ilUtil::isLogin($login))
427  {
428  $login_obj->setAlert($lng->txt("login_invalid"));
429  $form_valid = false;
430  }
431  else if (ilObjUser::_loginExists($login))
432  {
433  $login_obj->setAlert($lng->txt("login_exists"));
434  $form_valid = false;
435  }
436  else if ((int)$ilSetting->get('allow_change_loginname') &&
437  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
439  {
440  $login_obj->setAlert($lng->txt('login_exists'));
441  $form_valid = false;
442  }
443 
444  if(!$form_valid)
445  {
446  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
447  }
448  else
449  {
450  $password = $this->__createUser($valid_role);
451  $this->__distributeMails($password, $this->form->getInput("usr_language"));
452  $this->login($password);
453  return true;
454  }
455 
456  $this->form->setValuesByPost();
457  $this->displayForm();
458  return false;
459  }
460 
461  protected function __createUser($a_role)
462  {
468  global $ilSetting, $rbacadmin, $lng;
469 
470 
471  // something went wrong with the form validation
472  if(!$a_role)
473  {
474  global $ilias;
475  $ilias->raiseError("Invalid role selection in registration".
476  ", IP: ".$_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
477  }
478 
479 
480  $this->userObj = new ilObjUser();
481 
482  include_once("./Services/User/classes/class.ilUserProfile.php");
483  $up = new ilUserProfile();
484  $up->setMode(ilUserProfile::MODE_REGISTRATION);
485 
486  $map = array();
487  $up->skipGroup("preferences");
488  $up->skipGroup("settings");
489  $up->skipGroup("instant_messengers");
490  $up->skipField("password");
491  $up->skipField("birthday");
492  $up->skipField("upload");
493  foreach ($up->getStandardFields() as $k => $v)
494  {
495  if($v["method"])
496  {
497  $method = "set".substr($v["method"], 3);
498  if(method_exists($this->userObj, $method))
499  {
500  if ($k != "username")
501  {
502  $k = "usr_".$k;
503  }
504  $field_obj = $this->form->getItemByPostVar($k);
505  if($field_obj)
506  {
507 
508  $this->userObj->$method($this->form->getInput($k));
509  }
510  }
511  }
512  }
513 
514  $this->userObj->setFullName();
515 
516  $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
517  if ($birthday_obj)
518  {
519  $birthday = $this->form->getInput("usr_birthday");
520  $birthday = $birthday["date"];
521 
522  // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui
523  if(!is_array($birthday))
524  {
525  $this->userObj->setBirthday($birthday);
526  }
527  }
528 
529  // messenger
530  $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip");
531  foreach($map as $client)
532  {
533  $field = "usr_im_".$client;
534  $field_obj = $this->form->getItemByPostVar($field);
535  if($field_obj)
536  {
537  $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
538  }
539  }
540 
541  $this->userObj->setTitle($this->userObj->getFullname());
542  $this->userObj->setDescription($this->userObj->getEmail());
543 
544  if ($this->registration_settings->passwordGenerationEnabled())
545  {
546  $password = ilUtil::generatePasswords(1);
547  $password = $password[0];
548  }
549  else
550  {
551  $password = $this->form->getInput("usr_password");
552  }
553  $this->userObj->setPasswd($password);
554 
555 
556  // Set user defined data
557  include_once './Services/User/classes/class.ilUserDefinedFields.php';
558  $user_defined_fields =& ilUserDefinedFields::_getInstance();
559  $defs = $user_defined_fields->getRegistrationDefinitions();
560  $udf = array();
561  foreach ($_POST as $k => $v)
562  {
563  if (substr($k, 0, 4) == "udf_")
564  {
565  $f = substr($k, 4);
566  $udf[$f] = $v;
567  }
568  }
569  $this->userObj->setUserDefinedData($udf);
570 
571  $this->userObj->setTimeLimitOwner(7);
572 
573 
574  $access_limit = null;
575 
576  $this->code_was_used = false;
577  if($this->code_enabled)
578  {
579  $code_local_roles = $code_has_access_limit = null;
580 
581  // #10853 - could be optional
582  $code = $this->form->getInput('usr_registration_code');
583  if($code)
584  {
585  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
586 
587  // set code to used
589  $this->code_was_used = true;
590 
591  // handle code attached local role(s) and access limitation
592  $code_data = ilRegistrationCode::getCodeData($code);
593  if($code_data["role_local"])
594  {
595  // need user id before we can assign role(s)
596  $code_local_roles = explode(";", $code_data["role_local"]);
597  }
598  if($code_data["alimit"])
599  {
600  // see below
601  $code_has_access_limit = true;
602 
603  switch($code_data["alimit"])
604  {
605  case "absolute":
606  $abs = date_parse($code_data["alimitdt"]);
607  $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
608  break;
609 
610  case "relative":
611  $rel = unserialize($code_data["alimitdt"]);
612  $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 +
613  $rel["y"] * 31536000 + time();
614  break;
615  }
616  }
617  }
618  }
619 
620  // code access limitation will override any other access limitation setting
621  if (!($this->code_was_used && $code_has_access_limit) &&
622  $this->registration_settings->getAccessLimitation())
623  {
624  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
625  $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
626  switch($access_limitations_obj->getMode($a_role))
627  {
628  case 'absolute':
629  $access_limit = $access_limitations_obj->getAbsolute($a_role);
630  break;
631 
632  case 'relative':
633  $rel_d = (int) $access_limitations_obj->getRelative($a_role,'d');
634  $rel_m = (int) $access_limitations_obj->getRelative($a_role,'m');
635  $rel_y = (int) $access_limitations_obj->getRelative($a_role,'y');
636  $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
637  break;
638  }
639  }
640 
641  if($access_limit)
642  {
643  $this->userObj->setTimeLimitUnlimited(0);
644  $this->userObj->setTimeLimitUntil($access_limit);
645  }
646  else
647  {
648  $this->userObj->setTimeLimitUnlimited(1);
649  $this->userObj->setTimeLimitUntil(time());
650  }
651 
652  $this->userObj->setTimeLimitFrom(time());
653 
654  $this->userObj->create();
655 
656 
657  if($this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
658  $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
660  {
661  $this->userObj->setActive(1,0);
662  }
663  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
664  {
665  $this->userObj->setActive(0,0);
666  }
667  else
668  {
669  $this->userObj->setActive(0,0);
670  }
671 
672  $this->userObj->updateOwner();
673 
674  // set a timestamp for last_password_change
675  // this ts is needed by ilSecuritySettings
676  $this->userObj->setLastPasswordChangeTS( time() );
677 
678  $this->userObj->setIsSelfRegistered(true);
679 
680  //insert user data in table user_data
681  $this->userObj->saveAsNew();
682 
683  try
684  {
685  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
687  }
689  {
690  }
691 
692  // setup user preferences
693  $this->userObj->setLanguage($this->form->getInput('usr_language'));
694  $hits_per_page = $ilSetting->get("hits_per_page");
695  if ($hits_per_page < 10)
696  {
697  $hits_per_page = 10;
698  }
699  $this->userObj->setPref("hits_per_page", $hits_per_page);
700  $show_online = $ilSetting->get("show_users_online");
701  if ($show_online == "")
702  {
703  $show_online = "y";
704  }
705  $this->userObj->setPref("show_users_online", $show_online);
706  $this->userObj->writePrefs();
707 
708 
709  $rbacadmin->assignUser((int)$a_role, $this->userObj->getId());
710 
711  // local roles from code
712  if($this->code_was_used && is_array($code_local_roles))
713  {
714  foreach(array_unique($code_local_roles) as $local_role_obj_id)
715  {
716  // is given role (still) valid?
717  if(ilObject::_lookupType($local_role_obj_id) == "role")
718  {
719  $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
720  }
721  }
722  }
723 
724  return $password;
725  }
726 
727  protected function __distributeMails($password, $a_language = null)
728  {
729  global $ilSetting;
730 
731  include_once './Services/Language/classes/class.ilLanguage.php';
732  include_once './Services/User/classes/class.ilObjUser.php';
733  include_once "Services/Mail/classes/class.ilFormatMail.php";
734  include_once './Services/Registration/classes/class.ilRegistrationMailNotification.php';
735 
736  // Always send mail to approvers
737  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
738  {
739  $mail = new ilRegistrationMailNotification();
741  $mail->setRecipients($this->registration_settings->getApproveRecipients());
742  $mail->setAdditionalInformation(array('usr' => $this->userObj));
743  $mail->send();
744  }
745  else
746  {
747  $mail = new ilRegistrationMailNotification();
749  $mail->setRecipients($this->registration_settings->getApproveRecipients());
750  $mail->setAdditionalInformation(array('usr' => $this->userObj));
751  $mail->send();
752 
753  }
754  // Send mail to new user
755 
756  // Registration with confirmation link ist enabled
757  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION && !$this->code_was_used)
758  {
759  include_once './Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
760 
763  $mail->setRecipients(array($this->userObj));
764  $mail->setAdditionalInformation(
765  array(
766  'usr' => $this->userObj,
767  'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
768  )
769  );
770  $mail->send();
771  }
772  else
773  {
774  // try individual account mail in user administration
775  include_once("Services/Mail/classes/class.ilAccountMail.php");
776  include_once './Services/User/classes/class.ilObjUserFolder.php';
777 
778  $amail = ilObjUserFolder::_lookupNewAccountMail($a_language);
779  if (trim($amail["body"]) == "" || trim($amail["subject"]) == "")
780  {
781  $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
782  }
783  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
784  {
785  $acc_mail = new ilAccountMail();
786  $acc_mail->setUser($this->userObj);
787  if ($this->registration_settings->passwordGenerationEnabled())
788  {
789  $acc_mail->setUserPassword($password);
790  }
791 
792  if($amail["att_file"])
793  {
794  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
796  $fs->create();
797  $path = $fs->getAbsolutePath()."/";
798 
799  $acc_mail->addAttachment($path."/".$amail["lang"], $amail["att_file"]);
800  }
801 
802  $acc_mail->send();
803  }
804  else // do default mail
805  {
806  include_once "Services/Mail/classes/class.ilMimeMail.php";
807 
808  $mmail = new ilMimeMail();
809  $mmail->autoCheck(false);
810  $mmail->From($ilSetting->get("admin_email"));
811  $mmail->To($this->userObj->getEmail());
812 
813  // mail subject
814  $subject = $this->lng->txt("reg_mail_subject");
815 
816  // mail body
817  $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
818  $this->lng->txt("reg_mail_body_text1")."\n\n".
819  $this->lng->txt("reg_mail_body_text2")."\n".
820  ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID."\n";
821  $body .= $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
822 
823  if ($this->registration_settings->passwordGenerationEnabled())
824  {
825  $body.= $this->lng->txt("passwd").": ".$password."\n";
826  }
827  $body.= "\n";
828 
829  // Info about necessary approvement
830  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE && !$this->code_was_used)
831  {
832  $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
833  }
834 
835  $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
836  $body .= $this->userObj->getProfileAsString($this->lng);
837  $mmail->Subject($subject);
838  $mmail->Body($body);
839  $mmail->Send();
840  }
841  }
842  }
843 
847  public function login($password)
848  {
852  global $lng;
853 
854  ilStartUpGUI::initStartUpTemplate(array('tpl.usr_registered.html', 'Services/Registration'), false);
855  $this->tpl->setVariable('TXT_PAGEHEADLINE', $this->lng->txt('registration'));
856 
857  $this->tpl->setVariable("TXT_WELCOME", $lng->txt("welcome") . ", " . $this->userObj->getTitle() . "!");
858  if(
859  (
860  $this->registration_settings->getRegistrationType() == IL_REG_DIRECT ||
861  $this->registration_settings->getRegistrationType() == IL_REG_CODES ||
863  ) &&
864  !$this->registration_settings->passwordGenerationEnabled()
865  )
866  {
867  $this->tpl->setCurrentBlock('activation');
868  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_registered'));
869  $this->tpl->setVariable('FORMACTION', 'login.php?cmd=post&target=' . ilUtil::stripSlashes($_GET['target']));
870  if(ilSession::get('forceShoppingCartRedirect'))
871  {
872  $this->tpl->setVariable('FORMACTION', './login.php?forceShoppingCartRedirect=1');
873  }
874  $this->tpl->setVariable('TARGET', 'target="_parent"');
875  $this->tpl->setVariable('TXT_LOGIN', $lng->txt('login_to_ilias'));
876  $this->tpl->setVariable('USERNAME', $this->userObj->getLogin());
877  $this->tpl->setVariable('PASSWORD', $password);
878  $this->tpl->parseCurrentBlock();
879  }
880  else if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
881  {
882  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_submitted'));
883 
884  if(IS_PAYMENT_ENABLED == true)
885  {
886  if(ilSession::get('forceShoppingCartRedirect'))
887  {
888  $this->tpl->setCurrentBlock('activation');
889  include_once 'Services/Payment/classes/class.ilShopLinkBuilder.php';
890  $shop_link = new ilShopLinkBuilder();
891  $this->tpl->setVariable('FORMACTION', $shop_link->buildLink('ilshopshoppingcartgui', '_forceShoppingCartRedirect_user=' . $this->userObj->getId()));
892  $this->tpl->setVariable('TARGET', 'target=\'_parent\'');
893 
894  $this->lng->loadLanguageModule('payment');
895  $this->tpl->setVariable('TXT_LOGIN', $lng->txt('pay_goto_shopping_cart'));
896  $this->tpl->parseCurrentBlock();
897  $this->lng->loadLanguageModule('registration');
898  }
899  }
900  }
901  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
902  {
903  $login_url = './login.php?cmd=force_login&lang=' . $this->userObj->getLanguage();
904  $this->tpl->setVariable('TXT_REGISTERED', sprintf($lng->txt('reg_confirmation_link_successful'), $login_url));
905  $this->tpl->setVariable('REDIRECT_URL', $login_url);
906  }
907  else
908  {
909  $this->tpl->setVariable('TXT_REGISTERED', $lng->txt('txt_registered_passw_gen'));
910  }
911  }
912 }