18 require_once
'./Services/Registration/classes/class.ilRegistrationSettings.php';
19 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
37 $this->ctrl->saveParameter($this,
'lang');
40 $this->lng->loadLanguageModule(
'registration');
44 $this->code_enabled = ($this->registration_settings->registrationCodeRequired() ||
45 $this->registration_settings->getAllowCodes());
52 if($this->registration_settings->getRegistrationType() ==
IL_REG_DISABLED)
54 $ilErr->raiseError($this->lng->txt(
'reg_disabled'),$ilErr->FATAL);
57 $next_class = $this->ctrl->getNextClass($this);
58 $cmd = $this->ctrl->getCmd();
80 public function displayForm()
87 ilStartUpGUI::initStartUpTemplate(array(
'tpl.usr_registration.html',
'Services/Registration'),
true);
88 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->lng->txt(
'registration'));
91 foreach($lng->getInstalledLanguages() as $lang_key)
97 if(
sizeof($lang_opts) > 1)
100 foreach($lang_opts as $lang_key => $lang_caption)
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())
107 $this->tpl->setVariable(
'LANG_HEADLINE_LANGUAGES_SELECTED_LANG',
' selected="selected"');
109 $this->tpl->parseCurrentBlock();
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');
124 $this->tpl->setVariable(
'FORM', $this->form->getHTML());
131 include_once(
"Services/Form/classes/class.ilPropertyFormGUI.php");
133 $this->form->setFormAction($this->ctrl->getFormAction($this));
138 if($this->code_enabled)
140 include_once
'Services/Registration/classes/class.ilRegistrationCode.php';
141 $code =
new ilTextInputGUI($lng->txt(
"registration_code"),
"usr_registration_code");
144 if((
bool)$this->registration_settings->registrationCodeRequired())
146 $code->setRequired(
true);
147 $code->setInfo($lng->txt(
"registration_code_required_info"));
151 $code->setInfo($lng->txt(
"registration_code_optional_info"));
153 $this->form->addItem($code);
159 $user_defined_data = $ilUser->getUserDefinedData();
161 include_once
'./Services/User/classes/class.ilUserDefinedFields.php';
163 $custom_fields = array();
164 foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
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);
176 $custom_fields[
"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);
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']));
189 if($definition[
'required'])
191 $custom_fields[
"udf_".$definition[
'field_id']]->setRequired(
true);
194 if($definition[
'field_type'] ==
UDF_TYPE_SELECT && !$user_defined_data[
"f_".$field_id])
196 $options = array(
""=>$lng->txt(
"please_select")) + $custom_fields[
"udf_".$definition[
'field_id']]->getOptions();
197 $custom_fields[
"udf_".$definition[
'field_id']]->setOptions(
$options);
202 include_once(
"./Services/User/classes/class.ilUserProfile.php");
205 $up->skipGroup(
"preferences");
208 $up->addStandardFieldsToForm($this->form, NULL, $custom_fields);
209 unset($custom_fields);
213 $flang = $this->form->getItemByPostVar(
"usr_language");
216 $flang->setValue($lng->getLangKey());
220 if($this->code_enabled)
222 $role = $this->form->getItemByPostVar(
"usr_roles");
223 if($role && $role->getType() ==
"select")
225 $role->setInfo($lng->txt(
"registration_code_role_info"));
231 foreach($this->registration_settings->getAllowedDomains() as $item)
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") :
""));
249 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
252 $mail_obj->setRequired(
true);
256 if(ilTermsOfServiceHelper::isEnabled())
260 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
263 $field->setTitle($lng->txt(
'usr_agreement'));
264 $this->form->addItem($field);
267 $field->setHTML(
'<div id="agreement">' . $document->getContent() .
'</div>');
268 $this->form->addItem($field);
270 $field =
new ilCheckboxInputGUI($lng->txt(
'accept_usr_agreement'),
'accept_terms_of_service');
273 $this->form->addItem($field);
280 require_once
'Services/Captcha/classes/class.ilCaptchaUtil.php';
281 if(ilCaptchaUtil::isActiveForRegistration())
283 require_once
'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
286 $this->form->addItem($captcha);
289 $this->form->addCommandButton(
"saveForm", $lng->txt(
"register"));
297 $form_valid = $this->form->checkInput();
299 require_once
'Services/User/classes/class.ilObjUser.php';
304 $valid_code = $valid_role =
false;
307 if($this->code_enabled)
309 $code = $this->form->getInput(
'usr_registration_code');
314 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
317 $code_obj = $this->form->getItemByPostVar(
'usr_registration_code');
318 $code_obj->setAlert($lng->txt(
'registration_code_not_valid'));
327 if($role_id && $rbacreview->isGlobalRole($role_id))
329 $valid_role = $role_id;
339 $email = $this->form->getInput(
"usr_email");
344 foreach($this->registration_settings->getAllowedDomains() as $item)
354 foreach($domains as $domain)
356 $domain = str_replace(
"*",
"~~~", $domain);
357 $domain = preg_quote($domain);
358 $domain = str_replace(
"~~~",
".+", $domain);
359 if(preg_match(
"/^".$domain.
"$/", $email, $hit))
367 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
368 $mail_obj->setAlert(sprintf($lng->txt(
"reg_email_domains"),
369 implode(
", ", $domains)));
378 !$this->registration_settings->passwordGenerationEnabled() &&
382 $passwd_obj = $this->form->getItemByPostVar(
'usr_password');
383 $passwd_obj->setAlert($lng->txt($error_lng_var));
387 if(ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput(
'accept_terms_of_service'))
389 $agr_obj = $this->form->getItemByPostVar(
'accept_terms_of_service');
390 $agr_obj->setAlert($lng->txt(
'force_accept_usr_agreement'));
398 if ($this->registration_settings->roleSelectionEnabled())
400 include_once
"./Services/AccessControl/classes/class.ilObjRole.php";
401 $selected_role = $this->form->getInput(
"usr_roles");
404 $valid_role = (int)$selected_role;
410 include_once
'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
412 $valid_role = (int)$registration_role_assignments->getRoleByEmail($this->form->getInput(
"usr_email"));
424 $login_obj = $this->form->getItemByPostVar(
'username');
425 $login = $this->form->getInput(
"username");
428 $login_obj->setAlert($lng->txt(
"login_invalid"));
433 $login_obj->setAlert($lng->txt(
"login_exists"));
436 else if ((
int)$ilSetting->get(
'allow_change_loginname') &&
437 (int)$ilSetting->get(
'reuse_of_loginnames') == 0 &&
440 $login_obj->setAlert($lng->txt(
'login_exists'));
450 $password = $this->__createUser($valid_role);
452 $this->login($password);
456 $this->form->setValuesByPost();
457 $this->displayForm();
461 protected function __createUser($a_role)
475 $ilias->raiseError(
"Invalid role selection in registration".
476 ", IP: ".$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
482 include_once(
"./Services/User/classes/class.ilUserProfile.php");
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)
497 $method =
"set".substr($v[
"method"], 3);
498 if(method_exists($this->userObj, $method))
500 if ($k !=
"username")
504 $field_obj = $this->form->getItemByPostVar($k);
508 $this->userObj->$method($this->form->getInput($k));
514 $this->userObj->setFullName();
516 $birthday_obj = $this->form->getItemByPostVar(
"usr_birthday");
519 $birthday = $this->form->getInput(
"usr_birthday");
520 $birthday = $birthday[
"date"];
523 if(!is_array($birthday))
525 $this->userObj->setBirthday($birthday);
530 $map = array(
"icq",
"yahoo",
"msn",
"aim",
"skype",
"jabber",
"voip");
533 $field =
"usr_im_".$client;
534 $field_obj = $this->form->getItemByPostVar($field);
537 $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
541 $this->userObj->setTitle($this->userObj->getFullname());
542 $this->userObj->setDescription($this->userObj->getEmail());
544 if ($this->registration_settings->passwordGenerationEnabled())
547 $password = $password[0];
551 $password = $this->form->getInput(
"usr_password");
553 $this->userObj->setPasswd($password);
557 include_once
'./Services/User/classes/class.ilUserDefinedFields.php';
559 $defs = $user_defined_fields->getRegistrationDefinitions();
561 foreach (
$_POST as $k => $v)
563 if (substr($k, 0, 4) ==
"udf_")
569 $this->userObj->setUserDefinedData($udf);
571 $this->userObj->setTimeLimitOwner(7);
574 $access_limit = null;
576 $this->code_was_used =
false;
577 if($this->code_enabled)
579 $code_local_roles = $code_has_access_limit = null;
582 $code = $this->form->getInput(
'usr_registration_code');
585 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
589 $this->code_was_used =
true;
593 if($code_data[
"role_local"])
596 $code_local_roles = explode(
";", $code_data[
"role_local"]);
598 if($code_data[
"alimit"])
601 $code_has_access_limit =
true;
603 switch($code_data[
"alimit"])
606 $abs = date_parse($code_data[
"alimitdt"]);
607 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
611 $rel = unserialize($code_data[
"alimitdt"]);
612 $access_limit = $rel[
"d"] * 86400 + $rel[
"m"] * 2592000 +
613 $rel[
"y"] * 31536000 + time();
621 if (!($this->code_was_used && $code_has_access_limit) &&
622 $this->registration_settings->getAccessLimitation())
624 include_once
'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
626 switch($access_limitations_obj->getMode($a_role))
629 $access_limit = $access_limitations_obj->getAbsolute($a_role);
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();
643 $this->userObj->setTimeLimitUnlimited(0);
644 $this->userObj->setTimeLimitUntil($access_limit);
648 $this->userObj->setTimeLimitUnlimited(1);
649 $this->userObj->setTimeLimitUntil(time());
652 $this->userObj->setTimeLimitFrom(time());
654 $this->userObj->create();
657 if($this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
658 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
661 $this->userObj->setActive(1,0);
663 else if($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION)
665 $this->userObj->setActive(0,0);
669 $this->userObj->setActive(0,0);
672 $this->userObj->updateOwner();
676 $this->userObj->setLastPasswordChangeTS( time() );
678 $this->userObj->setIsSelfRegistered(
true);
681 $this->userObj->saveAsNew();
685 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
693 $this->userObj->setLanguage($this->form->getInput(
'usr_language'));
694 $hits_per_page = $ilSetting->get(
"hits_per_page");
695 if ($hits_per_page < 10)
699 $this->userObj->setPref(
"hits_per_page", $hits_per_page);
700 $show_online = $ilSetting->get(
"show_users_online");
701 if ($show_online ==
"")
705 $this->userObj->setPref(
"show_users_online", $show_online);
706 $this->userObj->writePrefs();
709 $rbacadmin->assignUser((
int)$a_role, $this->userObj->getId());
712 if($this->code_was_used && is_array($code_local_roles))
714 foreach(array_unique($code_local_roles) as $local_role_obj_id)
719 $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
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';
741 $mail->setRecipients($this->registration_settings->getApproveRecipients());
742 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
749 $mail->setRecipients($this->registration_settings->getApproveRecipients());
750 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
759 include_once
'./Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
763 $mail->setRecipients(array($this->userObj));
764 $mail->setAdditionalInformation(
766 'usr' => $this->userObj,
767 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
775 include_once(
"Services/Mail/classes/class.ilAccountMail.php");
776 include_once
'./Services/User/classes/class.ilObjUserFolder.php';
779 if (trim($amail[
"body"]) ==
"" || trim($amail[
"subject"]) ==
"")
783 if (trim($amail[
"body"]) !=
"" && trim($amail[
"subject"]) !=
"")
786 $acc_mail->setUser($this->userObj);
787 if ($this->registration_settings->passwordGenerationEnabled())
789 $acc_mail->setUserPassword($password);
792 if($amail[
"att_file"])
794 include_once
"Services/User/classes/class.ilFSStorageUserFolder.php";
797 $path = $fs->getAbsolutePath().
"/";
799 $acc_mail->addAttachment(
$path.
"/".$amail[
"lang"], $amail[
"att_file"]);
806 include_once
"Services/Mail/classes/class.ilMimeMail.php";
809 $mmail->autoCheck(
false);
810 $mmail->From($ilSetting->get(
"admin_email"));
811 $mmail->To($this->userObj->getEmail());
814 $subject = $this->lng->txt(
"reg_mail_subject");
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";
823 if ($this->registration_settings->passwordGenerationEnabled())
825 $body.= $this->lng->txt(
"passwd").
": ".$password.
"\n";
832 $body .= ($this->lng->txt(
'reg_mail_body_pwd_generation').
"\n\n");
835 $body .= ($this->lng->txt(
"reg_mail_body_text3").
"\n\r");
836 $body .= $this->userObj->getProfileAsString($this->lng);
837 $mmail->Subject($subject);
847 public function login($password)
854 ilStartUpGUI::initStartUpTemplate(array(
'tpl.usr_registered.html',
'Services/Registration'),
false);
855 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->lng->txt(
'registration'));
857 $this->tpl->setVariable(
"TXT_WELCOME", $lng->txt(
"welcome") .
", " . $this->userObj->getTitle() .
"!");
860 $this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
861 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
864 !$this->registration_settings->passwordGenerationEnabled()
867 $this->tpl->setCurrentBlock(
'activation');
868 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_registered'));
872 $this->tpl->setVariable(
'FORMACTION',
'./login.php?forceShoppingCartRedirect=1');
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();
880 else if($this->registration_settings->getRegistrationType() ==
IL_REG_APPROVE)
882 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_submitted'));
884 if(IS_PAYMENT_ENABLED ==
true)
888 $this->tpl->setCurrentBlock(
'activation');
889 include_once
'Services/Payment/classes/class.ilShopLinkBuilder.php';
891 $this->tpl->setVariable(
'FORMACTION', $shop_link->buildLink(
'ilshopshoppingcartgui',
'_forceShoppingCartRedirect_user=' . $this->userObj->getId()));
892 $this->tpl->setVariable(
'TARGET',
'target=\'_parent\'');
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');
901 else if($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION)
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);
909 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_registered_passw_gen'));