private function build_form() { $security_config = SecurityConfig::load(); $activated_auth_types = AuthenticationService::get_activated_types_authentication(); $form = new HTMLForm(__CLASS__); $this->member_extended_fields_service = new MemberExtendedFieldsService($form); $fieldset = new FormFieldsetHTML('edit_profile', $this->lang['profile.edit']); $form->add_fieldset($fieldset); $fieldset->add_field(new FormFieldTextEditor('display_name', $this->lang['display_name'], $this->user->get_display_name(), array('maxlength' => 100, 'required' => true, 'description' => $this->lang['display_name.explain'], 'events' => array('blur' => ' if (!HTMLForms.getField("login").getValue() && HTMLForms.getField("display_name").validate() == "") { HTMLForms.getField("login").setValue(HTMLForms.getField("display_name").getValue().replace(/\\s/g, \'\')); HTMLForms.getField("login").enableValidationMessage(); HTMLForms.getField("login").liveValidate(); }')), array(new FormFieldConstraintLengthRange(3, 100), new FormFieldConstraintDisplayNameExists($this->user->get_id())))); $fieldset->add_field($email = new FormFieldMailEditor('email', $this->lang['email'], $this->user->get_email(), array('required' => true), array(new FormFieldConstraintMailExist($this->user->get_id())))); $fieldset->add_field(new FormFieldCheckbox('user_hide_mail', $this->lang['email.hide'], !$this->user->get_show_email())); $fieldset->add_field(new FormFieldCheckbox('delete_account', $this->lang['delete-account'], FormFieldCheckbox::UNCHECKED)); if (AppContext::get_current_user()->is_admin()) { $manage_fieldset = new FormFieldsetHTML('member_management', $this->lang['member-management']); $form->add_fieldset($manage_fieldset); $manage_fieldset->add_field(new FormFieldCheckbox('approbation', $this->lang['approbation'], $this->internal_auth_infos['approved'])); $manage_fieldset->add_field(new FormFieldRanksSelect('rank', $this->lang['rank'], $this->user->get_level())); $manage_fieldset->add_field(new FormFieldGroups('groups', $this->lang['groups'], $this->user->get_groups())); } $connect_fieldset = new FormFieldsetHTML('connect', $this->lang['connection']); $form->add_fieldset($connect_fieldset); $more_than_one_authentication_type = count($activated_auth_types) > 1; $has_custom_login = $this->user->get_email() !== $this->internal_auth_infos['login']; if ($more_than_one_authentication_type) { if (in_array(PHPBoostAuthenticationMethod::AUTHENTICATION_METHOD, $this->user_auth_types)) { $connect_fieldset->add_field(new FormFieldFree('internal_auth', $this->lang['internal_connection'] . ' <i class="fa fa-success"></i>', '<a onclick="javascript:HTMLForms.getField(\'custom_login\').enable();' . ($has_custom_login ? 'HTMLForms.getField(\'login\').enable();' : '') . 'HTMLForms.getField(\'password\').enable();HTMLForms.getField(\'password_bis\').enable();HTMLForms.getField(\'old_password\').enable();">' . LangLoader::get_message('edit', 'common') . '</a>')); } else { $connect_fieldset->add_field(new FormFieldFree('internal_auth', $this->lang['internal_connection'] . ' <i class="fa fa-error"></i>', '<a onclick="javascript:HTMLForms.getField(\'custom_login\').enable();HTMLForms.getField(\'password\').enable();HTMLForms.getField(\'password_bis\').enable();">Créer une authentification interne</a>')); } } $connect_fieldset->add_field(new FormFieldCheckbox('custom_login', $this->lang['login.custom'], $has_custom_login, array('description' => $this->lang['login.custom.explain'], 'hidden' => $more_than_one_authentication_type, 'events' => array('click' => ' if (HTMLForms.getField("custom_login").getValue()) { HTMLForms.getField("login").enable(); } else { HTMLForms.getField("login").disable(); }')))); $connect_fieldset->add_field($login = new FormFieldTextEditor('login', $this->lang['login'], $has_custom_login ? $this->internal_auth_infos['login'] : preg_replace('/\\s+/', '', $this->user->get_display_name()), array('required' => true, 'hidden' => $more_than_one_authentication_type || !$has_custom_login, 'maxlength' => 25), array(new FormFieldConstraintLengthRange(3, 25), new FormFieldConstraintPHPBoostAuthLoginExists($this->user->get_id())))); $connect_fieldset->add_field(new FormFieldPasswordEditor('old_password', $this->lang['password.old'], '', array('description' => $this->lang['password.old.explain'], 'hidden' => $more_than_one_authentication_type))); $connect_fieldset->add_field($password = new FormFieldPasswordEditor('password', $this->lang['password'], '', array('description' => StringVars::replace_vars($this->lang['password.explain'], array('number' => $security_config->get_internal_password_min_length())), 'hidden' => $more_than_one_authentication_type), array(new FormFieldConstraintLengthMin($security_config->get_internal_password_min_length()), new FormFieldConstraintPasswordStrength()))); $connect_fieldset->add_field($password_bis = new FormFieldPasswordEditor('password_bis', $this->lang['password.confirm'], '', array('hidden' => $more_than_one_authentication_type), array(new FormFieldConstraintLengthMin($security_config->get_internal_password_min_length()), new FormFieldConstraintPasswordStrength()))); $form->add_constraint(new FormConstraintFieldsEquality($password, $password_bis)); if ($security_config->are_login_and_email_forbidden_in_password()) { $form->add_constraint(new FormConstraintFieldsInequality($email, $password)); $form->add_constraint(new FormConstraintFieldsInequality($login, $password)); } if (in_array('facebook', $activated_auth_types)) { if (in_array(FacebookAuthenticationMethod::AUTHENTICATION_METHOD, $this->user_auth_types)) { $connect_fieldset->add_field(new FormFieldFree('fb_auth', $this->lang['fb_connection'] . ' <i class="fa fa-success"></i>', '<a href="' . UserUrlBuilder::edit_profile($this->user->get_id(), 'dissociate', 'fb')->absolute() . '">' . $this->lang['dissociate_account'] . '</a>')); } else { $connect_fieldset->add_field(new FormFieldFree('fb_auth', $this->lang['fb_connection'] . ' <i class="fa fa-error"></i>', '<a href="' . UserUrlBuilder::edit_profile($this->user->get_id(), 'associate', 'fb')->absolute() . '">' . $this->lang['associate_account'] . '</a>')); } } if (in_array('google', $activated_auth_types)) { if (in_array(GoogleAuthenticationMethod::AUTHENTICATION_METHOD, $this->user_auth_types)) { $connect_fieldset->add_field(new FormFieldFree('google_auth', $this->lang['google_connection'] . ' <i class="fa fa-success"></i>', '<a href="' . UserUrlBuilder::edit_profile($this->user->get_id(), 'dissociate', 'google')->absolute() . '">' . $this->lang['dissociate_account'] . '</a>')); } else { $connect_fieldset->add_field(new FormFieldFree('google_auth', $this->lang['google_connection'] . ' <i class="fa fa-error"></i>', '<a href="' . UserUrlBuilder::edit_profile($this->user->get_id(), 'associate', 'google')->absolute() . '">' . $this->lang['associate_account'] . '</a>')); } } $options_fieldset = new FormFieldsetHTML('options', LangLoader::get_message('options', 'main')); $form->add_fieldset($options_fieldset); $options_fieldset->add_field(new FormFieldTimezone('timezone', $this->lang['timezone.choice'], $this->user->get_timezone(), array('description' => $this->lang['timezone.choice.explain']))); if (count(ThemesManager::get_activated_and_authorized_themes_map()) > 1) { $options_fieldset->add_field(new FormFieldThemesSelect('theme', $this->lang['theme'], $this->user->get_theme(), array('check_authorizations' => true, 'events' => array('change' => $this->build_javascript_picture_themes())))); $options_fieldset->add_field(new FormFieldFree('preview_theme', $this->lang['theme.preview'], '<img id="img_theme" src="' . $this->get_picture_theme($this->user->get_theme()) . '" alt="' . $this->lang['theme.preview'] . '" title="' . $this->lang['theme.preview'] . '" class="preview-img" />')); } $options_fieldset->add_field(new FormFieldEditors('text-editor', $this->lang['text-editor'], $this->user->get_editor())); $options_fieldset->add_field(new FormFieldLangsSelect('lang', $this->lang['lang'], $this->user->get_locale(), array('check_authorizations' => true))); if (AppContext::get_current_user()->is_admin()) { $fieldset_punishment = new FormFieldsetHTML('punishment_management', $this->lang['punishment-management']); $form->add_fieldset($fieldset_punishment); $fieldset_punishment->add_field(new FormFieldMemberCaution('user_warning', $this->lang['caution'], $this->user->get_warning_percentage())); $fieldset_punishment->add_field(new FormFieldMemberSanction('user_readonly', $this->lang['readonly'], $this->user->get_delay_readonly())); $fieldset_punishment->add_field(new FormFieldMemberSanction('user_ban', $this->lang['banned'], $this->user->get_delay_banned())); } $this->member_extended_fields_service->display_form_fields($this->user->get_id()); $this->submit_button = new FormButtonDefaultSubmit(); $form->add_button($this->submit_button); $form->add_button(new FormButtonReset()); $this->form = $form; }