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'));
94 $this->tpl->setVariable(
'FORM', $this->form->getHTML());
102 include_once
'Services/jQuery/classes/class.iljQueryUtil.php';
105 include_once(
"Services/Form/classes/class.ilPropertyFormGUI.php");
107 $this->form->setFormAction($this->ctrl->getFormAction($this));
112 if($this->code_enabled)
114 include_once
'Services/Registration/classes/class.ilRegistrationCode.php';
115 $code =
new ilTextInputGUI($lng->txt(
"registration_code"),
"usr_registration_code");
118 if((
bool)$this->registration_settings->registrationCodeRequired())
120 $code->setRequired(
true);
121 $code->setInfo($lng->txt(
"registration_code_required_info"));
125 $code->setInfo($lng->txt(
"registration_code_optional_info"));
127 $this->form->addItem($code);
133 $user_defined_data = $ilUser->getUserDefinedData();
135 include_once
'./Services/User/classes/class.ilUserDefinedFields.php';
137 $custom_fields = array();
138 foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
142 $custom_fields[
"udf_".$definition[
'field_id']] =
143 new ilTextInputGUI($definition[
'field_name'],
"udf_".$definition[
'field_id']);
144 $custom_fields[
"udf_".$definition[
'field_id']]->setValue($user_defined_data[
"f_".$field_id]);
145 $custom_fields[
"udf_".$definition[
'field_id']]->setMaxLength(255);
146 $custom_fields[
"udf_".$definition[
'field_id']]->setSize(40);
150 $custom_fields[
"udf_".$definition[
'field_id']] =
152 $custom_fields[
"udf_".$definition[
'field_id']]->setValue($user_defined_data[
"f_".$field_id]);
153 $custom_fields[
"udf_".$definition[
'field_id']]->setUseRte(
true);
157 $custom_fields[
"udf_".$definition[
'field_id']] =
158 new ilSelectInputGUI($definition[
'field_name'],
"udf_".$definition[
'field_id']);
159 $custom_fields[
"udf_".$definition[
'field_id']]->setValue($user_defined_data[
"f_".$field_id]);
160 $custom_fields[
"udf_".$definition[
'field_id']]->setOptions(
161 $user_defined_fields->fieldValuesToSelectArray($definition[
'field_values']));
163 if($definition[
'required'])
165 $custom_fields[
"udf_".$definition[
'field_id']]->setRequired(
true);
168 if($definition[
'field_type'] ==
UDF_TYPE_SELECT && !$user_defined_data[
"f_".$field_id])
170 $options = array(
""=>$lng->txt(
"please_select")) + $custom_fields[
"udf_".$definition[
'field_id']]->getOptions();
171 $custom_fields[
"udf_".$definition[
'field_id']]->setOptions(
$options);
176 include_once(
"./Services/User/classes/class.ilUserProfile.php");
179 $up->skipGroup(
"preferences");
181 $up->setAjaxCallback(
182 $this->ctrl->getLinkTarget($this,
'doProfileAutoComplete',
'',
true)
185 $lng->loadLanguageModule(
"user");
188 $up->addStandardFieldsToForm($this->form, NULL, $custom_fields);
189 unset($custom_fields);
193 $flang = $this->form->getItemByPostVar(
"usr_language");
196 $flang->setValue($lng->getLangKey());
200 if($this->code_enabled)
202 $role = $this->form->getItemByPostVar(
"usr_roles");
203 if($role && $role->getType() ==
"select")
205 $role->setInfo($lng->txt(
"registration_code_role_info"));
211 foreach($this->registration_settings->getAllowedDomains() as $item)
220 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
221 $mail_obj->setInfo(sprintf($lng->txt(
"reg_email_domains"),
222 implode(
", ", $domains)).
"<br />".
223 ($this->code_enabled ? $lng->txt(
"reg_email_domains_code") :
""));
229 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
232 $mail_obj->setRequired(
true);
236 if(ilTermsOfServiceHelper::isEnabled())
240 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
243 $field->setTitle($lng->txt(
'usr_agreement'));
244 $this->form->addItem($field);
247 $field->setHTML(
'<div id="agreement">' . $document->getContent() .
'</div>');
248 $this->form->addItem($field);
250 $field =
new ilCheckboxInputGUI($lng->txt(
'accept_usr_agreement'),
'accept_terms_of_service');
253 $this->form->addItem($field);
260 require_once
'Services/Captcha/classes/class.ilCaptchaUtil.php';
261 if(ilCaptchaUtil::isActiveForRegistration())
263 require_once
'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
266 $this->form->addItem($captcha);
269 $this->form->addCommandButton(
"saveForm", $lng->txt(
"register"));
277 $form_valid = $this->form->checkInput();
279 require_once
'Services/User/classes/class.ilObjUser.php';
284 $valid_code = $valid_role =
false;
287 if($this->code_enabled)
289 $code = $this->form->getInput(
'usr_registration_code');
294 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
297 $code_obj = $this->form->getItemByPostVar(
'usr_registration_code');
298 $code_obj->setAlert($lng->txt(
'registration_code_not_valid'));
307 if($role_id && $rbacreview->isGlobalRole($role_id))
309 $valid_role = $role_id;
319 $email = $this->form->getInput(
"usr_email");
324 foreach($this->registration_settings->getAllowedDomains() as $item)
334 foreach($domains as $domain)
336 $domain = str_replace(
"*",
"~~~", $domain);
337 $domain = preg_quote($domain);
338 $domain = str_replace(
"~~~",
".+", $domain);
339 if(preg_match(
"/^".$domain.
"$/", $email, $hit))
347 $mail_obj = $this->form->getItemByPostVar(
'usr_email');
348 $mail_obj->setAlert(sprintf($lng->txt(
"reg_email_domains"),
349 implode(
", ", $domains)));
358 !$this->registration_settings->passwordGenerationEnabled() &&
362 $passwd_obj = $this->form->getItemByPostVar(
'usr_password');
363 $passwd_obj->setAlert($lng->txt($error_lng_var));
367 if(ilTermsOfServiceHelper::isEnabled() && !$this->form->getInput(
'accept_terms_of_service'))
369 $agr_obj = $this->form->getItemByPostVar(
'accept_terms_of_service');
372 $agr_obj->setAlert($lng->txt(
'force_accept_usr_agreement'));
385 if ($this->registration_settings->roleSelectionEnabled())
387 include_once
"./Services/AccessControl/classes/class.ilObjRole.php";
388 $selected_role = $this->form->getInput(
"usr_roles");
391 $valid_role = (int)$selected_role;
397 include_once
'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
399 $valid_role = (int)$registration_role_assignments->getRoleByEmail($this->form->getInput(
"usr_email"));
411 $login_obj = $this->form->getItemByPostVar(
'username');
412 $login = $this->form->getInput(
"username");
415 $login_obj->setAlert($lng->txt(
"login_invalid"));
420 $login_obj->setAlert($lng->txt(
"login_exists"));
423 else if ((
int)$ilSetting->get(
'allow_change_loginname') &&
424 (int)$ilSetting->get(
'reuse_of_loginnames') == 0 &&
427 $login_obj->setAlert($lng->txt(
'login_exists'));
437 $password = $this->__createUser($valid_role);
439 $this->login($password);
443 $this->form->setValuesByPost();
444 $this->displayForm();
448 protected function __createUser($a_role)
462 $ilias->raiseError(
"Invalid role selection in registration".
463 ", IP: ".$_SERVER[
"REMOTE_ADDR"], $ilias->error_obj->FATAL);
469 include_once(
"./Services/User/classes/class.ilUserProfile.php");
474 $up->skipGroup(
"preferences");
475 $up->skipGroup(
"settings");
476 $up->skipGroup(
"instant_messengers");
477 $up->skipField(
"password");
478 $up->skipField(
"birthday");
479 $up->skipField(
"upload");
480 foreach ($up->getStandardFields() as $k => $v)
484 $method =
"set".substr($v[
"method"], 3);
485 if(method_exists($this->userObj, $method))
487 if ($k !=
"username")
491 $field_obj = $this->form->getItemByPostVar($k);
495 $this->userObj->$method($this->form->getInput($k));
501 $this->userObj->setFullName();
503 $birthday_obj = $this->form->getItemByPostVar(
"usr_birthday");
506 $birthday = $this->form->getInput(
"usr_birthday");
507 $birthday = $birthday[
"date"];
510 if(!is_array($birthday))
512 $this->userObj->setBirthday($birthday);
517 $map = array(
"icq",
"yahoo",
"msn",
"aim",
"skype",
"jabber",
"voip");
520 $field =
"usr_im_".$client;
521 $field_obj = $this->form->getItemByPostVar($field);
524 $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
528 $this->userObj->setTitle($this->userObj->getFullname());
529 $this->userObj->setDescription($this->userObj->getEmail());
531 if ($this->registration_settings->passwordGenerationEnabled())
534 $password = $password[0];
538 $password = $this->form->getInput(
"usr_password");
540 $this->userObj->setPasswd($password);
544 include_once
'./Services/User/classes/class.ilUserDefinedFields.php';
546 $defs = $user_defined_fields->getRegistrationDefinitions();
548 foreach (
$_POST as $k => $v)
550 if (substr($k, 0, 4) ==
"udf_")
556 $this->userObj->setUserDefinedData($udf);
558 $this->userObj->setTimeLimitOwner(7);
561 $access_limit = null;
563 $this->code_was_used =
false;
564 if($this->code_enabled)
566 $code_local_roles = $code_has_access_limit = null;
569 $code = $this->form->getInput(
'usr_registration_code');
572 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
576 $this->code_was_used =
true;
580 if($code_data[
"role_local"])
583 $code_local_roles = explode(
";", $code_data[
"role_local"]);
585 if($code_data[
"alimit"])
588 $code_has_access_limit =
true;
590 switch($code_data[
"alimit"])
593 $abs = date_parse($code_data[
"alimitdt"]);
594 $access_limit = mktime(23, 59, 59, $abs[
'month'], $abs[
'day'], $abs[
'year']);
598 $rel = unserialize($code_data[
"alimitdt"]);
599 $access_limit = $rel[
"d"] * 86400 + $rel[
"m"] * 2592000 +
600 $rel[
"y"] * 31536000 + time();
608 if (!($this->code_was_used && $code_has_access_limit) &&
609 $this->registration_settings->getAccessLimitation())
611 include_once
'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
613 switch($access_limitations_obj->getMode($a_role))
616 $access_limit = $access_limitations_obj->getAbsolute($a_role);
620 $rel_d = (int) $access_limitations_obj->getRelative($a_role,
'd');
621 $rel_m = (int) $access_limitations_obj->getRelative($a_role,
'm');
622 $rel_y = (int) $access_limitations_obj->getRelative($a_role,
'y');
623 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
630 $this->userObj->setTimeLimitUnlimited(0);
631 $this->userObj->setTimeLimitUntil($access_limit);
635 $this->userObj->setTimeLimitUnlimited(1);
636 $this->userObj->setTimeLimitUntil(time());
639 $this->userObj->setTimeLimitFrom(time());
641 include_once
'./Services/User/classes/class.ilUserCreationContext.php';
644 $this->userObj->create();
647 if($this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
648 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
651 $this->userObj->setActive(1,0);
653 else if($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION)
655 $this->userObj->setActive(0,0);
659 $this->userObj->setActive(0,0);
662 $this->userObj->updateOwner();
666 $this->userObj->setLastPasswordChangeTS( time() );
668 $this->userObj->setIsSelfRegistered(
true);
671 $this->userObj->saveAsNew();
675 require_once
'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
683 $this->userObj->setLanguage($this->form->getInput(
'usr_language'));
684 $hits_per_page = $ilSetting->get(
"hits_per_page");
685 if ($hits_per_page < 10)
689 $this->userObj->setPref(
"hits_per_page", $hits_per_page);
690 $show_online = $ilSetting->get(
"show_users_online");
691 if ($show_online ==
"")
695 $this->userObj->setPref(
"show_users_online", $show_online);
696 $this->userObj->writePrefs();
699 $rbacadmin->assignUser((
int)$a_role, $this->userObj->getId());
702 if($this->code_was_used && is_array($code_local_roles))
704 foreach(array_unique($code_local_roles) as $local_role_obj_id)
709 $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
712 $role_obj =
$GLOBALS[
'rbacreview']->getObjectOfRole($local_role_obj_id);
718 $role_ref = end($role_refs);
733 include_once
'./Services/Language/classes/class.ilLanguage.php';
734 include_once
'./Services/User/classes/class.ilObjUser.php';
735 include_once
"Services/Mail/classes/class.ilFormatMail.php";
736 include_once
'./Services/Registration/classes/class.ilRegistrationMailNotification.php';
743 $mail->setRecipients($this->registration_settings->getApproveRecipients());
744 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
751 $mail->setRecipients($this->registration_settings->getApproveRecipients());
752 $mail->setAdditionalInformation(array(
'usr' => $this->userObj));
761 include_once
'./Services/Registration/classes/class.ilRegistrationMimeMailNotification.php';
765 $mail->setRecipients(array($this->userObj));
766 $mail->setAdditionalInformation(
768 'usr' => $this->userObj,
769 'hash_lifetime' => $this->registration_settings->getRegistrationHashLifetime()
777 include_once(
"Services/Mail/classes/class.ilAccountMail.php");
778 include_once
'./Services/User/classes/class.ilObjUserFolder.php';
781 if (trim($amail[
"body"]) ==
"" || trim($amail[
"subject"]) ==
"")
785 if (trim($amail[
"body"]) !=
"" && trim($amail[
"subject"]) !=
"")
788 $acc_mail->setUser($this->userObj);
789 if ($this->registration_settings->passwordGenerationEnabled())
791 $acc_mail->setUserPassword($password);
794 if($amail[
"att_file"])
796 include_once
"Services/User/classes/class.ilFSStorageUserFolder.php";
799 $path = $fs->getAbsolutePath().
"/";
801 $acc_mail->addAttachment(
$path.
"/".$amail[
"lang"], $amail[
"att_file"]);
808 include_once
"Services/Mail/classes/class.ilMimeMail.php";
811 $mmail->autoCheck(
false);
812 $mmail->From($ilSetting->get(
"admin_email"));
813 $mmail->To($this->userObj->getEmail());
816 $subject = $this->lng->txt(
"reg_mail_subject");
819 $body = $this->lng->txt(
"reg_mail_body_salutation").
" ".$this->userObj->getFullname().
",\n\n".
820 $this->lng->txt(
"reg_mail_body_text1").
"\n\n".
821 $this->lng->txt(
"reg_mail_body_text2").
"\n".
822 ILIAS_HTTP_PATH.
"/login.php?client_id=".CLIENT_ID.
"\n";
823 $body .= $this->lng->txt(
"login").
": ".$this->userObj->getLogin().
"\n";
825 if ($this->registration_settings->passwordGenerationEnabled())
827 $body.= $this->lng->txt(
"passwd").
": ".$password.
"\n";
834 $body .= ($this->lng->txt(
'reg_mail_body_pwd_generation').
"\n\n");
837 $body .= ($this->lng->txt(
"reg_mail_body_text3").
"\n\r");
838 $body .= $this->userObj->getProfileAsString($this->lng);
839 $mmail->Subject($subject);
849 public function login($password)
856 ilStartUpGUI::initStartUpTemplate(array(
'tpl.usr_registered.html',
'Services/Registration'),
false);
857 $this->tpl->setVariable(
'TXT_PAGEHEADLINE', $this->lng->txt(
'registration'));
859 $this->tpl->setVariable(
"TXT_WELCOME", $lng->txt(
"welcome") .
", " . $this->userObj->getTitle() .
"!");
862 $this->registration_settings->getRegistrationType() ==
IL_REG_DIRECT ||
863 $this->registration_settings->getRegistrationType() ==
IL_REG_CODES ||
866 !$this->registration_settings->passwordGenerationEnabled()
869 $this->tpl->setCurrentBlock(
'activation');
870 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_registered'));
874 $this->tpl->setVariable(
'FORMACTION',
'./login.php?forceShoppingCartRedirect=1');
876 $this->tpl->setVariable(
'TARGET',
'target="_parent"');
877 $this->tpl->setVariable(
'TXT_LOGIN', $lng->txt(
'login_to_ilias'));
878 $this->tpl->setVariable(
'USERNAME', $this->userObj->getLogin());
879 $this->tpl->setVariable(
'PASSWORD', $password);
880 $this->tpl->parseCurrentBlock();
882 else if($this->registration_settings->getRegistrationType() ==
IL_REG_APPROVE)
884 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_submitted'));
886 if(IS_PAYMENT_ENABLED ==
true)
890 $this->tpl->setCurrentBlock(
'activation');
891 include_once
'Services/Payment/classes/class.ilShopLinkBuilder.php';
893 $this->tpl->setVariable(
'FORMACTION', $shop_link->buildLink(
'ilshopshoppingcartgui',
'_forceShoppingCartRedirect_user=' . $this->userObj->getId()));
894 $this->tpl->setVariable(
'TARGET',
'target=\'_parent\'');
896 $this->lng->loadLanguageModule(
'payment');
897 $this->tpl->setVariable(
'TXT_LOGIN', $lng->txt(
'pay_goto_shopping_cart'));
898 $this->tpl->parseCurrentBlock();
899 $this->lng->loadLanguageModule(
'registration');
903 else if($this->registration_settings->getRegistrationType() ==
IL_REG_ACTIVATION)
905 $login_url =
'./login.php?cmd=force_login&lang=' . $this->userObj->getLanguage();
906 $this->tpl->setVariable(
'TXT_REGISTERED', sprintf($lng->txt(
'reg_confirmation_link_successful'), $login_url));
907 $this->tpl->setVariable(
'REDIRECT_URL', $login_url);
911 $this->tpl->setVariable(
'TXT_REGISTERED', $lng->txt(
'txt_registered_passw_gen'));
920 include_once
"Services/User/classes/class.ilPublicUserProfileGUI.php";
924 include_once
'Services/JSON/classes/class.ilJsonUtil.php';