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; using CMS.ExtendedControls; public partial class CMSModules_ContactManagement_FormControls_AccountSelector : FormEngineUserControl { #region "Variables" private int mSiteId = -1; private CurrentUserInfo currentUser; #endregion #region "Public properties" /// /// Allows to display accounts only for specified site id. Use 0 for global objects. Default value is current site id. /// public int SiteID { get { return mSiteId; } set { mSiteId = value; } } /// /// Gets selected Account ID. /// public int AccountID { 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; } /// /// Gets or sets if control is placed in sitemanager. /// public bool IsSiteManager { get { return uniSelector.IsSiteManager; } set { uniSelector.IsSiteManager = value; } } #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() { string where = null; bool authorizedSiteAccounts = false; bool authorizedGlobalAccounts = AccountHelper.AuthorizedReadAccount(UniSelector.US_GLOBAL_RECORD, false); currentUser = CMSContext.CurrentUser; if (SiteID > 0) { authorizedSiteAccounts = AccountHelper.AuthorizedReadAccount(SiteID, false); } else { authorizedSiteAccounts = AccountHelper.AuthorizedReadAccount(CMSContext.CurrentSiteID, false); } // Filter site objects if (SiteID > 0) { if (authorizedSiteAccounts) { where = "(AccountSiteID = " + SiteID + " AND AccountMergedWithAccountID IS NULL)"; } else { where = "(1=0)"; } } // Filter only global objects else if ((SiteID == UniSelector.US_GLOBAL_RECORD) || (SiteID == 0)) { if (authorizedGlobalAccounts) { where = "(AccountSiteID IS NULL AND AccountGlobalAccountID IS NULL)"; } else { where = "(1=0)"; } } // Display current site and global contacts else if (SiteID == UniSelector.US_GLOBAL_OR_SITE_RECORD) { if (authorizedSiteAccounts && authorizedGlobalAccounts) { where = "(AccountSiteID IS NULL AND AccountGlobalAccountID IS NULL) OR (AccountSiteID = " + CMSContext.CurrentSiteID + " AND AccountMergedWithAccountID IS NULL)"; uniSelector.AddGlobalObjectSuffix = true; } else if (authorizedGlobalAccounts) { where = "(AccountSiteID IS NULL AND AccountMergedWithAccountID IS NULL)"; } else if (authorizedSiteAccounts) { where = "(AccountSiteID = " + CMSContext.CurrentSiteID + " AND AccountMergedWithAccountID IS NULL)"; } else { where = "(1=0)"; } } // Display all objects else if ((SiteID == UniSelector.US_ALL_RECORDS) && currentUser.UserSiteManagerAdmin) { where = "((AccountSiteID IS NULL AND AccountGlobalAccountID IS NULL) OR (AccountSiteID > 0 AND AccountMergedWithAccountID IS NULL))"; uniSelector.AddGlobalObjectSuffix = true; } // Not enough permissions else { where = "(1=0)"; } uniSelector.WhereCondition = SqlHelperClass.AddWhereCondition(WhereCondition, where); uniSelector.Reload(true); } #endregion }