using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SiteProvider; using CMS.UIControls; public partial class CMSWebParts_DashBoard_EmailQueue : CMSAbstractWebPart { #region "Properties" /// /// Site name (empty string for all sites). /// public string SiteName { get { return ValidationHelper.GetString(GetValue("SiteName"), "").Replace("##currentsite##", CMSContext.CurrentSiteName); } set { SetValue("SiteName", value); } } /// /// Order by. /// public string OrderBy { get { return ValidationHelper.GetString(GetValue("OrderBy"), "EmailLastSendAttempt"); } set { SetValue("OrderBy", value); } } /// /// Sorting. /// public string Sorting { get { return ValidationHelper.GetString(GetValue("Sorting"), "desc"); } set { SetValue("Sorting", value); } } /// /// Items per page. /// public string ItemsPerPage { get { return ValidationHelper.GetString(GetValue("ItemsPerPage"), "25"); } set { SetValue("ItemsPerPage", value); } } #endregion #region "Stop processing" /// /// Returns true if the control processing should be stopped. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; emailQueue.StopProcessing = value; } } #endregion #region "Methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do not process } else { // Register the dialog script ScriptHelper.RegisterDialogScript(Page); // Register script for modal dialog ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "displayModal", ScriptHelper.GetScript( "function DisplayRecipients(emailId) { \n" + " if ( emailId != 0 ) { \n" + " modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/EmailQueue/MassEmails_Recipients.aspx") + "?emailid=' + emailId, 'emailrecipients', 920, 700); \n" + " } } \n ")); if ((!RequestHelper.IsPostBack()) && (!string.IsNullOrEmpty(ItemsPerPage))) { emailQueue.EmailGrid.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1); } emailQueue.EmailGrid.OrderBy = OrderBy + " " + Sorting; emailQueue.EmailGrid.WhereCondition = GenerateWhereCondition(); emailQueue.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(emailQueue_OnCheckPermissions); } } /// /// OnLoad handler. /// protected override void OnLoad(EventArgs e) { emailQueue.ReloadData(); base.OnLoad(e); } /// /// Reloads the control data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); emailQueue.ReloadData(); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // Remove selection checkboxes emailQueue.EmailGrid.GridView.Columns[0].Visible = false; } /// /// Check permission. /// /// Permission type /// Sender private void emailQueue_OnCheckPermissions(string permissionType, CMSAdminControl sender) { if ((CMSContext.CurrentUser == null) || !CMSContext.CurrentUser.UserSiteManagerAdmin) { sender.StopProcessing = true; emailQueue.Visible = false; messageElem.Visible = true; messageElem.ErrorMessage = GetString("general.nopermission"); } } /// /// Generates complete filter where condition. /// private string GenerateWhereCondition() { string whereCond = ""; // Append site condition if siteid given SiteInfo siteObj = SiteInfoProvider.GetSiteInfo(SiteName); int siteId = -1; if (siteObj != null) { siteId = siteObj.SiteID; } // create where condition for SiteID if (siteId > 0) { whereCond += " (EmailSiteID=" + siteId + ")"; } return whereCond; } #endregion }