public function get_content()
 {
     $user = AppContext::get_current_user();
     $theme_id = AppContext::get_request()->get_string('switchtheme', '');
     if (!empty($theme_id)) {
         $theme = ThemesManager::get_theme($theme_id);
         if ($theme !== null) {
             if ($theme->is_activated() && $theme->check_auth()) {
                 $user->update_theme($theme->get_id());
             }
         }
         $query_string = preg_replace('`switchtheme=[^&]+`', '', QUERY_STRING);
         AppContext::get_response()->redirect(trim(HOST . SCRIPT . (!empty($query_string) ? '?' . $query_string : '')));
     }
     $tpl = new FileTemplate('ThemesSwitcher/themeswitcher.tpl');
     $tpl->add_lang(LangLoader::get('themeswitcher_common', 'ThemesSwitcher'));
     foreach (ThemesManager::get_activated_and_authorized_themes_map() as $id => $theme) {
         $selected = $user->get_theme() == $id ? ' selected="selected"' : '';
         $tpl->assign_block_vars('themes', array('NAME' => $theme->get_configuration()->get_name(), 'IDNAME' => $id, 'SELECTED' => $selected));
     }
     $tpl->put('DEFAULT_THEME', UserAccountsConfig::load()->get_default_theme());
     return $tpl;
 }
    private function build_form()
    {
        $security_config = SecurityConfig::load();
        $form = new HTMLForm(__CLASS__);
        $this->member_extended_fields_service = new MemberExtendedFieldsService($form);
        $fieldset = new FormFieldsetHTML('registration', $this->lang['registration']);
        $form->add_fieldset($fieldset);
        $fieldset->add_field(new FormFieldHTML('validation_method', $this->get_accounts_validation_method_explain()));
        $fieldset->add_field(new FormFieldTextEditor('display_name', $this->lang['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())));
        $fieldset->add_field($email = new FormFieldMailEditor('email', $this->lang['email'], '', array('required' => true), array(new FormFieldConstraintMailExist())));
        $fieldset->add_field(new FormFieldCheckbox('user_hide_mail', $this->lang['email.hide'], FormFieldCheckbox::CHECKED));
        $fieldset->add_field(new FormFieldCheckbox('custom_login', $this->lang['login.custom'], false, array('description' => $this->lang['login.custom.explain'], 'events' => array('click' => '
				if (HTMLForms.getField("custom_login").getValue()) {
					HTMLForms.getField("login").enable();
				} else { 
					HTMLForms.getField("login").disable();
				}'))));
        $fieldset->add_field($login = new FormFieldTextEditor('login', $this->lang['login'], '', array('hidden' => true, 'maxlength' => 25), array(new FormFieldConstraintLengthRange(3, 25), new FormFieldConstraintPHPBoostAuthLoginExists())));
        $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())), 'required' => true, 'maxlength' => 500), array(new FormFieldConstraintLengthMin($security_config->get_internal_password_min_length()), new FormFieldConstraintPasswordStrength())));
        $fieldset->add_field($password_bis = new FormFieldPasswordEditor('password_bis', $this->lang['password.confirm'], '', array('required' => true, 'maxlength' => 500), 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));
        }
        $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'], GeneralConfig::load()->get_site_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_accounts_config->get_default_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() . '" title="' . $this->lang['theme.preview'] . '" alt="' . $this->lang['theme.preview'] . '" class="preview-img" />'));
        }
        $options_fieldset->add_field(new FormFieldEditors('text-editor', $this->lang['text-editor'], ContentFormattingConfig::load()->get_default_editor()));
        $options_fieldset->add_field(new FormFieldLangsSelect('lang', $this->lang['lang'], $this->user_accounts_config->get_default_lang(), array('check_authorizations' => true)));
        $this->member_extended_fields_service->display_form_fields();
        $agreement_text = FormatingHelper::second_parse($this->user_accounts_config->get_registration_agreement());
        if (!empty($agreement_text)) {
            $agreement_fieldset = new FormFieldsetHTML('agreement_fieldset', $this->lang['agreement']);
            $form->add_fieldset($agreement_fieldset);
            $agreement = new FormFieldHTML('agreement.required', $this->lang['agreement.agree.required'] . '<br /><br />');
            $agreement_fieldset->add_field($agreement);
            $agreement = new FormFieldHTML('agreement', '<div id="id-message-helper" class="notice user-agreement">' . $agreement_text . '</div>');
            $agreement_fieldset->add_field($agreement);
            $agreement_fieldset->add_field(new FormFieldCheckbox('agree', $this->lang['agreement.agree'], FormFieldCheckbox::UNCHECKED, array('required' => $this->lang['agreement.agree.required'])));
        }
        $this->submit_button = new FormButtonDefaultSubmit();
        $form->add_button($this->submit_button);
        $form->add_button(new FormButtonReset());
        $this->form = $form;
    }
    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;
    }