using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using CMS.CMSHelper; using CMS.FormControls; using CMS.FormEngine; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SiteProvider; public partial class CMSWebParts_Membership_Users_UserPublicProfile : CMSAbstractWebPart { #region "Public properties" /// /// Name of the alternative form (ClassName.AlternativeFormName) /// Default value is CMS.User.DisplayProfile /// public string AlternativeFormName { get { return ValidationHelper.GetString(GetValue("AlternativeFormName"), "CMS.User.DisplayProfile"); } set { SetValue("AlternativeFormName", value); } } /// /// User name whose profile should be displayed. /// public string UserName { get { string userName = ValidationHelper.GetString(GetValue("UserName"), String.Empty); if (userName != String.Empty) { return userName; } // Back compatibility int userID = ValidationHelper.GetInteger(GetValue("UserID"), 0); if (userID != 0) { if (userID == CMSContext.CurrentUser.UserID) { return CMSContext.CurrentUser.UserName; } UserInfo ui = UserInfoProvider.GetUserInfo(userID); if (ui != null) { return ui.UserName; } } return String.Empty; } set { SetValue("UserName", value); } } /// /// User id whose profile should be displayed. /// [Obsolete("Use UserName instead")] public int UserID { get { return ValidationHelper.GetInteger(GetValue("UserID"), 0); } set { SetValue("UserID", value); } } /// /// No profile text. /// public string NoProfileText { get { return ValidationHelper.GetString(GetValue("NoProfileText"), ""); } set { SetValue("NoProfileText", value); } } /// /// Indicates if field visibility should be applied on user form. /// public bool ApplyVisibility { get { return ValidationHelper.GetBoolean(GetValue("ApplyVisibility"), false); } set { SetValue("ApplyVisibility", value); } } /// /// This name is used if ApplyVisibility is 'true' to get visibility definition of current user. /// public string VisibilityFormName { get { return ValidationHelper.GetString(GetValue("VisibilityFormName"), ""); } set { SetValue("VisibilityFormName", value); } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Reloads data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { // Get user info UserInfo ui = GetUser(); if (ui != null) { // Get alternative form info AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(AlternativeFormName); if (afi != null) { // Initialize data form formElem.Visible = true; formElem.Info = ui; formElem.AlternativeFormFullName = AlternativeFormName; formElem.IsLiveSite = true; formElem.ApplyVisibility = ApplyVisibility; formElem.VisibilityFormName = VisibilityFormName; formElem.BasicForm.SubmitButton.Visible = false; } else { lblError.Text = String.Format(GetString("altform.formdoesntexists"), AlternativeFormName); lblError.Visible = true; plcContent.Visible = false; } } else { // Hide data form formElem.Visible = false; lblNoProfile.Visible = true; lblNoProfile.Text = NoProfileText; } } } // Get user private UserInfo GetUser() { UserInfo ui = null; if (!String.IsNullOrEmpty(UserName)) { ui = UserInfoProvider.GetUserInfo(UserName); } // Otherwise select current user else { ui = SiteContext.CurrentUser; } return ui; } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // Alter username according to GetFormattedUserName function if ((formElem.BasicForm != null) && (formElem.BasicForm.FieldEditingControls != null)) { EditingFormControl userControl = formElem.BasicForm.FieldEditingControls["UserName"] as EditingFormControl; if (userControl != null) { string userName = ValidationHelper.GetString(userControl.Value, String.Empty); // Set back formatted username userControl.Value = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(userName, true)); } } } }