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.UIControls; public partial class CMSModules_ContactManagement_FormControls_ContactGroupSelector : FormEngineUserControl { #region "Variables" private int mSiteId = -1; #endregion #region "Public properties" /// /// Allows to display accounts only for specified site id. Default value is current site id. /// public int SiteID { get { if (mSiteId == -1) { mSiteId = CMSContext.CurrentSiteID; } return mSiteId; } set { mSiteId = value; } } /// /// Indicates what objects can be displayed. -5 stands for global and site objects. -4 stands for global objects. -1 stands for all objects. /// public int ObjectsRange { get; set; } /// /// Gets selected contact group ID. /// public int ContactGroupID { get { return ValidationHelper.GetInteger(Value, 0); } } /// /// Returns Uniselector. /// public UniSelector UniSelector { get { EnsureChildControls(); return uniSelector; } } /// /// Gets or sets field value. /// public override object Value { get { EnsureChildControls(); return uniSelector.Value; } set { EnsureChildControls(); uniSelector.Value = ValidationHelper.GetString(value, ""); } } /// /// SQL WHERE condition of uniselector. /// public string WhereCondition { get; set; } #endregion #region "Methods" protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { uniSelector.StopProcessing = true; } else { ReloadData(); } } /// /// Reloads the data in the selector. /// public void ReloadData() { bool authorizedSite = ContactGroupHelper.AuthorizedReadContactGroup(SiteID, false); bool authorizedGlobal = ContactGroupHelper.AuthorizedReadContactGroup(UniSelector.US_GLOBAL_RECORD, false); // Site objects if (ObjectsRange == 0) { if (authorizedSite) { uniSelector.WhereCondition = SqlHelperClass.AddWhereCondition(WhereCondition, "(ContactGroupSiteID = " + SiteID + ")"); } else { uniSelector.WhereCondition = "(1=0)"; } } // Global objects else if (ObjectsRange == UniSelector.US_GLOBAL_RECORD) { if (authorizedGlobal) { uniSelector.WhereCondition = SqlHelperClass.AddWhereCondition(WhereCondition, "(ContactGroupSiteID IS NULL)"); } else { uniSelector.WhereCondition = "(1=0)"; } } // Global or site objects else if (ObjectsRange == UniSelector.US_GLOBAL_OR_SITE_RECORD) { if (authorizedSite && authorizedGlobal) { uniSelector.WhereCondition = "(ContactGroupSiteID IS NULL OR ContactGroupSiteID = " +SiteID + ")"; uniSelector.AddGlobalObjectSuffix = true; } else if (authorizedGlobal) { uniSelector.WhereCondition = "ContactGroupSiteID IS NULL"; } else if (authorizedSite) { uniSelector.WhereCondition = "ContactGroupSiteID = " + SiteID; } else { uniSelector.WhereCondition = "(1=0)"; } } // Display all objects else if ((ObjectsRange == UniSelector.US_ALL_RECORDS) && CMSContext.CurrentUser.UserSiteManagerAdmin) { uniSelector.WhereCondition = "(ContactGroupSiteID IS NULL OR ContactGroupSiteID > 0)"; uniSelector.AddGlobalObjectSuffix = true; } // Not enough permissions else { uniSelector.WhereCondition = "(1=0)"; } // Initialize selector uniSelector.DialogLink.CssClass = "MenuItemEdit Pad"; uniSelector.IsLiveSite = false; uniSelector.ButtonImage = GetImageUrl("/Objects/OM_ContactGroup/add.png"); uniSelector.Reload(true); } /// /// Overrides base GetValue method and enables to return UniSelector control with 'uniselector' property name. /// /// Property name public override object GetValue(string propertyName) { if (propertyName.EqualsCSafe("uniselector", true)) { // Return uniselector control return UniSelector; } // Return other values return base.GetValue(propertyName); } #endregion }