using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using CMS.Blogs; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.SettingsProvider; using CMS.DocumentEngine; using CMS.UIControls; using CMS.DataEngine; using CMS.SiteProvider; using CMS.WebAnalytics; using CMS.ExtendedControls; public partial class CMSModules_Blogs_Controls_BlogPostSubscriptions : CMSAdminControl { #region "Variables" private int mUserId = 0; private int mSiteId = 0; private int mDisplayNameLength = 50; private string mSiteName; #endregion #region "Properties" /// /// Messages placeholder /// public override MessagesPlaceHolder MessagesPlaceHolder { get { return plcMess; } } /// /// Indicates if control is used on live site. /// public override bool IsLiveSite { get { return base.IsLiveSite; } set { plcMess.IsLiveSite = value; base.IsLiveSite = value; } } /// /// Maximum length of the displayname (whole display name is displayed in tooltip). /// public int DisplayNameLength { get { return mDisplayNameLength; } set { mDisplayNameLength = value; } } /// /// Gets or sets user ID. /// public int UserID { get { return mUserId; } set { mUserId = value; } } /// /// Gets or sets site ID. /// public int SiteID { get { return mSiteId; } set { mSiteId = value; } } /// /// If true, control does not process the data. /// public override bool StopProcessing { get { return ValidationHelper.GetBoolean(ViewState["StopProcessing"], false); } set { ViewState["StopProcessing"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { SetupControl(); } protected void SetupControl() { // In design mode is processing of control stopped if (StopProcessing) { // Do nothing } else { if (CMSContext.CurrentUser.UserID == UserID) { gridElem.ZeroRowsText = GetString("blogsubscripitons.userhasnosubscriptions"); } else { gridElem.ZeroRowsText = GetString("blogsubscripitons.NoDataUser"); } gridElem.IsLiveSite = IsLiveSite; gridElem.OnAction += gridElem_OnAction; gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.OnDataReload += gridElem_OnDataReload; gridElem.ShowActionsMenu = true; gridElem.Columns = "SubscriptionID, SubscriptionEmail, DocumentName, NodeAliasPath, DocumentCulture, SubscriptionApproved"; // Get all possible columns to retrieve IDataClass nodeClass = DataClassFactory.NewDataClass("CMS.Tree"); DocumentInfo di = new DocumentInfo(); BlogPostSubscriptionInfo bpsi = new BlogPostSubscriptionInfo(); gridElem.AllColumns = SqlHelperClass.MergeColumns(SqlHelperClass.MergeColumns(SqlHelperClass.MergeColumns(bpsi.ColumnNames), SqlHelperClass.MergeColumns(di.ColumnNames)), SqlHelperClass.MergeColumns(nodeClass.ColumnNames)); mSiteName = SiteInfoProvider.GetSiteName(SiteID); } } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (DataHelper.DataSourceIsEmpty(gridElem.GridView.DataSource)) { lblMessage.Visible = false; } } /// /// Overridden SetValue - because of subscriptions control. /// /// Name of the property to set /// Value to set public override void SetValue(string propertyName, object value) { base.SetValue(propertyName, value); switch (propertyName.ToLowerCSafe()) { case "userid": UserID = ValidationHelper.GetInteger(value, 0); break; case "siteid": SiteID = ValidationHelper.GetInteger(value, 0); break; case "islivesite": IsLiveSite = ValidationHelper.GetBoolean(value, true); break; } } /// /// Reloads data for unigrid. /// public override void ReloadData() { gridElem.ReloadData(); } #region "UniGrid events" protected DataSet gridElem_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords) { return BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptions(UserID, SiteID, completeWhere, currentTopN, currentOrder, columns, currentOffset, currentPageSize, ref totalRecords); } /// /// Handles the UniGrid's OnAction event. /// /// Name of item (button) that threw event /// ID (value of Primary key) of corresponding data row protected void gridElem_OnAction(string actionName, object actionArgument) { int subscriptionId = ValidationHelper.GetInteger(actionArgument, 0); switch (actionName.ToLowerCSafe()) { case "delete": if (RaiseOnCheckPermissions(PERMISSION_MANAGE, this)) { if (StopProcessing) { return; } } try { // Try to delete notification subscription BlogPostSubscriptionInfoProvider.DeleteBlogPostSubscriptionInfo(subscriptionId); } catch (Exception ex) { ShowError(ex.Message); } break; case "approve": if (RaiseOnCheckPermissions(PERMISSION_MANAGE, this)) { if (StopProcessing) { return; } } // Approve BlogPostSubscriptionInfo object BlogPostSubscriptionInfo bsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(subscriptionId); if ((bsi != null) && !bsi.SubscriptionApproved) { bsi.SubscriptionApproved = true; BlogPostSubscriptionInfoProvider.SetBlogPostSubscriptionInfo(bsi); // Log activity if (CMSContext.CurrentUser.UserID == UserID) { BlogPostSubscriptionInfoProvider.LogSubscriptionActivity(bsi, PredefinedActivityType.SUBSCRIPTION_BLOG_POST, false); } } break; } } /// /// Handles the UniGrid's OnExternalDataBound event. /// private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "documentname": DataRowView dr = (DataRowView)parameter; if (CMSContext.CurrentSite != null) { string url = ResolveUrl(TreePathUtils.GetUrl(ValidationHelper.GetString(dr["NodeAliasPath"], ""), null, mSiteName)); string lang = ValidationHelper.GetString(dr["DocumentCulture"], ""); if (!String.IsNullOrEmpty(lang)) { url += "?" + URLHelper.LanguageParameterName + "=" + lang; } return "" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentName"], "")) + ""; } else { return HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentName"], "")); } case "approved": return UniGridFunctions.ColoredSpanYesNo(parameter, true); case "approve": ImageButton button = ((ImageButton)sender); if (button != null) { bool isApproved = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["SubscriptionApproved"], true); if (isApproved) { button.Visible = false; } } break; } return parameter; } #endregion }