using System; using System.Data; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Community; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SettingsProvider; using CMS.SiteProvider; public partial class CMSWebParts_Community_Membership_MySentInvitations : CMSAbstractWebPart { #region "Private variables" private int mUserId = 0; protected string mDeleteImageUrl = string.Empty; protected string mResendImageUrl = string.Empty; protected string mDeleteToolTip = string.Empty; protected string mResendToolTip = string.Empty; protected string mUserName = String.Empty; #endregion #region "Public properties" /// /// Gets or sets URL of the delete button image. /// public string DeleteImageUrl { get { return URLHelper.ResolveUrl(DataHelper.GetNotEmpty(GetValue("DeleteImageUrl"), GetImageUrl("Design/Controls/UniGrid/Actions/delete.png"))); } set { mDeleteImageUrl = value; SetValue("DeleteImageUrl", value); } } /// /// Gets or sets URL of the accept button image. /// public string ResendImageUrl { get { return URLHelper.ResolveUrl(DataHelper.GetNotEmpty(GetValue("AcceptImageUrl"), GetImageUrl("Design/Controls/UniGrid/Actions/resendemail.png"))); } set { mDeleteImageUrl = value; SetValue("AcceptImageUrl", value); } } /// /// Gets or sets the value that indicates whether control should be hidden if no data found. /// public bool HideControlForZeroRows { get { return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), rptMySentInvitations.HideControlForZeroRows); } set { SetValue("HideControlForZeroRows", value); rptMySentInvitations.HideControlForZeroRows = value; } } /// /// Gets or sets the text which is displayed when there is no data. /// public string ZeroRowsText { get { return ValidationHelper.GetString(GetValue("ZeroRowsText"), rptMySentInvitations.ZeroRowsText); } set { SetValue("ZeroRowsText", value); rptMySentInvitations.ZeroRowsText = value; } } /// /// User ID. /// [Obsolete("Use UserName instead")] public int UserID { get { mUserId = ValidationHelper.GetInteger(GetValue("UserID"), 0); return (mUserId == 0) ? CMSContext.CurrentUser.UserID : mUserId; } set { SetValue("UserID", value); mUserId = value; } } /// /// User name. /// public string UserName { get { mUserName = ValidationHelper.GetString(GetValue("UserName"), String.Empty); if (mUserName != String.Empty) { return mUserName; } // 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 CMSContext.CurrentUser.UserName; } set { SetValue("UserName", value); mUserName = value; } } #endregion #region "Caption properties" public string ResendFailed { get { return DataHelper.GetNotEmpty(GetValue("ResendFailed"), GetString("groupinvitation.resendfailed")); } } public string ResendSuccess { get { return DataHelper.GetNotEmpty(GetValue("ResendSuccess"), GetString("groupinvitation.resendsuccess")); } } #endregion #region "Methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Reloads data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } protected void SetupControl() { if (StopProcessing) { Visible = false; // Do not load data } else { ltlMessage.Text = ScriptHelper.GetScript("var deleteMessage ='" + GetString("general.confirmdelete") + "';"); rptMySentInvitations.ZeroRowsText = ZeroRowsText; rptMySentInvitations.HideControlForZeroRows = HideControlForZeroRows; mDeleteImageUrl = DeleteImageUrl; mResendImageUrl = ResendImageUrl; mResendToolTip = GetString("general.resend"); mDeleteToolTip = GetString("general.delete"); BindData(); } } /// /// Deletes invitation. /// protected void btnDelete_OnCommand(object sender, CommandEventArgs e) { if (e.CommandName == "delete") { int invitationId = ValidationHelper.GetInteger(e.CommandArgument, 0); InvitationInfoProvider.DeleteInvitationInfo(invitationId); BindData(); } } /// /// Accepts invitation. /// protected void btnResend_OnCommand(object sender, CommandEventArgs e) { if (e.CommandName == "resend") { try { // Get invitation info object int invitationId = ValidationHelper.GetInteger(e.CommandArgument, 0); InvitationInfo invitation = InvitationInfoProvider.GetInvitationInfo(invitationId); if (invitation != null) { // Send invitation e-mail InvitationInfoProvider.SendInvitationEmail(invitation, CMSContext.CurrentSiteName); lblInfo.Text = ResendSuccess + "

"; } } catch { lblInfo.Text = ResendFailed + "

"; ; lblInfo.CssClass = "InvitationErrorLabel"; } lblInfo.Visible = true; } } /// /// Binds data to repeater. /// private void BindData() { if (UserName != String.Empty) { DataSet invitations = InvitationInfoProvider.GetMySentInvitations("InvitedByUserID IN (SELECT UserID FROM CMS_User WHERE UserName='" + SqlHelperClass.GetSafeQueryString(UserName, false) + "')", "InvitationCreated"); rptMySentInvitations.DataSource = invitations; rptMySentInvitations.DataBind(); // Hide control if no data if (DataHelper.DataSourceIsEmpty(invitations) && (HideControlForZeroRows)) { Visible = false; rptMySentInvitations.Visible = false; } } } /// /// Resolve text. /// /// Input value public string ResolveText(object value) { return HTMLHelper.HTMLEncode(ValidationHelper.GetString(value, "")); } #endregion }