using System; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Community; using CMS.ExtendedControls; using CMS.GlobalHelper; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.UIControls; using CMS.WebAnalytics; using TreeNode = CMS.DocumentEngine.TreeNode; public partial class CMSModules_Groups_Controls_GroupLeave : CMSAdminControl { #region "Variables" private string mLeaveText; private string mSuccessfulLeaveText; private string mUnSuccessfulLeaveText; private GroupInfo mGroup = null; private bool mIsOnModalPage = true; private CMSButton mLeaveButton = null; private CMSButton mCancelButton = null; #endregion #region "Private properties" /// /// Returns group name of current group. /// private string GroupName { get { if (Group != null) { return " " + Group.GroupDisplayName; } return ""; } } #endregion #region "Public properties" /// /// Gets or sets the text which should be displayed on join dialog. /// public string LeaveText { get { return DataHelper.GetNotEmpty(mLeaveText, GetString("Community.Group.Leave") + HTMLHelper.HTMLEncode(GroupName) + "?"); } set { mLeaveText = value; } } /// /// Gets or sets the text which should be displayed on join dialog after successful join action. /// public string SuccessfulLeaveText { get { return DataHelper.GetNotEmpty(mSuccessfulLeaveText, GetString("Community.Group.SuccessfulLeave").Replace("##GroupName##", HTMLHelper.HTMLEncode(GroupName))); } set { mSuccessfulLeaveText = value; } } /// /// Gets or sets the text which should be displayed on join dialog if join action was unsuccessful. /// public string UnSuccessfulLeaveText { get { return DataHelper.GetNotEmpty(mUnSuccessfulLeaveText, GetString("Community.Group.UnSuccessfulLeave")); } set { mUnSuccessfulLeaveText = value; } } /// /// Gets or sets the group info object for destination group. /// public GroupInfo Group { get { return mGroup; } set { mGroup = value; } } /// /// Specifies if control is placed on modal page or not. /// public bool IsOnModalPage { get { return mIsOnModalPage; } set { mIsOnModalPage = value; } } /// /// Indicates if control buttons should be displayed. /// public bool DisplayButtons { get { return plcButtons.Visible; } set { plcButtons.Visible = value; } } /// /// Leave button. /// public CMSButton LeaveButton { get { if (mLeaveButton == null) { mLeaveButton = btnLeave; } return mLeaveButton; } set { mLeaveButton = value; } } /// /// Cancel button. /// public CMSButton CancelButton { get { if (mCancelButton == null) { mCancelButton = btnCancel; } return mCancelButton; } set { mCancelButton = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterWOpenerScript(Page); LeaveButton.Click += new EventHandler(btnLeave_Click); LeaveButton.Text = GetString("General.Yes"); CancelButton.Text = GetString("General.No"); // Set up js action if webpart is placed on modal page if (IsOnModalPage) { CancelButton.OnClientClick = "CloseDialog()"; } else { // Get return url string returnUrl = QueryHelper.GetString("returnurl", ""); if (!string.IsNullOrEmpty(returnUrl)) { // Redirect URLHelper.Redirect(returnUrl); } } lblInfo.Text = LeaveText; } /// /// Join handler. /// /// Sender /// EventArgs protected void btnLeave_Click(object sender, EventArgs e) { LeaveButton.Visible = false; // Set up js action if webpart is placed on modal page if (IsOnModalPage) { CancelButton.Text = GetString("General.Close"); CancelButton.OnClientClick = "if (wopener != null) {wopener.ReloadPage();} CloseDialog();"; } else { CancelButton.Text = GetString("General.Ok"); CancelButton.Click += new EventHandler(btnCancel_Click); } if (Group == null) { return; } // Get group member info GroupMemberInfo gmi = GroupMemberInfoProvider.GetGroupMemberInfo(CMSContext.CurrentUser.UserID, Group.GroupID); if (gmi != null) { GroupMemberInfoProvider.DeleteGroupMemberInfo(gmi); // Log activity LogLeaveActivity(gmi, Group); if (Group.GroupSendJoinLeaveNotification) { GroupMemberInfoProvider.SendNotificationMail("Groups.MemberLeave", CMSContext.CurrentSiteName, gmi, true); } lblInfo.Text = SuccessfulLeaveText; return; } lblInfo.Text = SuccessfulLeaveText; } /// /// Cancel click. /// protected void btnCancel_Click(object sender, EventArgs e) { URLHelper.Redirect(URLHelper.CurrentURL); } /// /// Log activity /// /// Member info /// Group object private void LogLeaveActivity(GroupMemberInfo gmi, GroupInfo group) { Activity activity = new ActivityLeaveGroup(gmi, group, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); activity.Log(); } }