using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.FormControls; using CMS.GlobalHelper; using CMS.OnlineMarketing; using CMS.SettingsProvider; using CMS.SiteProvider; using CMS.UIControls; public partial class CMSModules_ContactManagement_FormControls_ContactStatusSelector : FormEngineUserControl { #region "Variables" private int mSiteID = CMSContext.CurrentSiteID; private bool? mIsSiteManager; #endregion #region "Properties" /// /// Gets or sets the enabled state of the control. /// public override bool Enabled { get { return base.Enabled; } set { EnsureChildControls(); base.Enabled = value; uniselector.Enabled = value; } } /// /// Gets or sets field value. /// public override object Value { get { EnsureChildControls(); if (uniselector.Value.ToString() == UniSelector.US_NONE_RECORD.ToString()) { return null; } else { return uniselector.Value; } } set { EnsureChildControls(); uniselector.Value = ValidationHelper.GetString(value, UniSelector.US_NONE_RECORD.ToString()); } } /// /// Gets or sets SiteID of contact statuses. /// public int SiteID { get { return mSiteID; } set { mSiteID = value; } } /// /// Returns Uniselector. /// public UniSelector UniSelector { get { if (uniselector == null) { pnlUpdate.LoadContainer(); } return uniselector; } } /// /// Dropdownlist used in Uniselector. /// public DropDownList DropDownList { get { if (uniselector == null) { pnlUpdate.LoadContainer(); } return uniselector.DropDownSingleSelect; } } /// /// Specifies, whether the selector allows selection of all items. If the dialog allows selection of all items, /// it displays the (all) field in the DDL variant and All button in the Textbox variant (default false). /// When property is selected then Uniselector doesn't load any data from DB, it just returns -1 value /// and external code must handle data loading. /// public bool AllowAllItem { get { return ValidationHelper.GetBoolean(GetValue("AllowAllItem"), true); } set { SetValue("AllowAllItem", value); } } /// /// Gets or sets if all contact statuses regardless of site should be displayed. /// public bool DisplayAll { get; set; } /// /// Gets or sets if only global and site statuses should be displayed. /// public bool DisplaySiteOrGlobal { get { return ValidationHelper.GetBoolean(GetValue("DisplaySiteOrGlobal"), false); } set { SetValue("DisplaySiteOrGlobal", value); } } /// /// Gets selected ContactStatusID. /// public int ContactStatusID { get { return ValidationHelper.GetInteger(Value, 0); } } /// /// SQL WHERE condition of uniselector. /// public string WhereCondition { get; set; } /// /// Gets or sets if current context is in sitemanager. /// public bool? IsSiteManager { get { return mIsSiteManager ?? QueryHelper.GetBoolean("issitemanager", false); } set { mIsSiteManager = value; } } #endregion #region "Methods" protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { uniselector.StopProcessing = true; } else { ReloadData(); } } /// /// Reloads control. /// public void ReloadData() { string where = WhereCondition; bool globalInCMSDesk = (SiteID == UniSelector.US_GLOBAL_RECORD) && SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".cmscmglobalconfiguration"); bool settingEnabledForSite = SettingsKeyProvider.GetBoolValue(SiteInfoProvider.GetSiteName(SiteID) + ".cmscmglobalconfiguration"); bool userInSiteManager = (IsSiteManager == true); bool userAuthorized = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false); bool allowGlobal = userAuthorized && (userInSiteManager || globalInCMSDesk || settingEnabledForSite); bool allowSite = ConfigurationHelper.AuthorizedReadConfiguration(SiteID > 0 ? SiteID : CMSContext.CurrentSiteID, false); uniselector.AllowAll = AllowAllItem; if (DisplayAll || DisplaySiteOrGlobal) { // Display all site and global statuses if (DisplayAll && allowSite && allowGlobal) { // No WHERE condition required } // Display current site and global statuses else if (DisplaySiteOrGlobal && allowSite && allowGlobal && (SiteID > 0)) { where = SqlHelperClass.AddWhereCondition(where, "ContactStatusSiteID IS NULL OR ContactStatusSiteID = " + (SiteID == 0 ? CMSContext.CurrentSiteID : SiteID)); } // Current site else if (allowSite && (SiteID > 0)) { where = SqlHelperClass.AddWhereCondition(where, "ContactStatusSiteID = " + SiteID); } // Display global statuses else if (allowGlobal) { where = SqlHelperClass.AddWhereCondition(where, "ContactStatusSiteID IS NULL "); } // Don't display anything if (String.IsNullOrEmpty(where) && !DisplayAll) { where = "(1=0)"; } } // Display either global or current site statuses else { // Current site if ((SiteID > 0) && allowSite) { where = SqlHelperClass.AddWhereCondition(where, "ContactStatusSiteID = " + SiteID); } // Display global statuses else if (((SiteID == UniSelector.US_GLOBAL_RECORD) || (SiteID == UniSelector.US_NONE_RECORD)) && allowGlobal) { where = SqlHelperClass.AddWhereCondition(where, "ContactStatusSiteID IS NULL "); } // Don't display anything if (String.IsNullOrEmpty(where)) { where = "(1=0)"; } } uniselector.WhereCondition = where; uniselector.Reload(true); } /// /// Gets where condition. /// public override string GetWhereCondition() { if (ValidationHelper.GetInteger(uniselector.Value, UniSelector.US_NONE_RECORD) == UniSelector.US_NONE_RECORD) { return FieldInfo.Name + " IS NULL"; } else { return FieldInfo.Name + " = " + uniselector.Value; } } #endregion }