using System; using System.Web.UI.WebControls; using CMS.FormControls; using CMS.GlobalHelper; using CMS.SiteProvider; using CMS.UIControls; using CMS.SettingsProvider; using CMS.CMSHelper; using CMS.ExtendedControls; using CMS.Chat; public partial class CMSModules_Chat_FormControls_RoomSelector : FormEngineUserControl { #region "Variables" private int mSiteId = 0; private string mResourcePrefix = String.Empty; private bool mHideDisabledRooms = true; private bool mDisplayRoomsFromAllSites = false; private bool mAllowAll = false; private bool mAllowEmpty = true; #endregion #region "Public properties" /// /// Gets or sets ID of the site. User of this site are displayed /// Use 0 for current siteid, -1 for all sites(no filter) /// Note: SiteID is not used if site filter is enabled /// public int SiteID { get { return mSiteId; } set { mSiteId = value; } } /// /// Gets or sets the value which determines whether to allow more than one user to select. /// public SelectionModeEnum SelectionMode { get { EnsureChildControls(); return usRooms.SelectionMode; } set { EnsureChildControls(); usRooms.SelectionMode = value; } } /// /// Gets or sets the text displayed if there are no data. /// public string ZeroRowsText { get { EnsureChildControls(); return usRooms.ZeroRowsText; } set { EnsureChildControls(); usRooms.ZeroRowsText = value; } } /// /// Gets or sets the enabled state of the control. /// public override bool Enabled { get { return base.Enabled; } set { EnsureChildControls(); base.Enabled = value; usRooms.Enabled = value; } } /// /// Gets or sets field value. /// public override object Value { get { EnsureChildControls(); return usRooms.Value; } set { EnsureChildControls(); usRooms.Value = value; } } /// /// Gets or sets if site filter should be shown or not. /// public bool ShowSiteFilter { get { return ValidationHelper.GetBoolean(GetValue("ShowSiteFilter"), true); } set { SetValue("ShowSiteFilter", value); } } /// /// Gets the current UniSelector instance. /// public UniSelector UniSelector { get { EnsureChildControls(); return usRooms; } } /// /// Gets or sets the value that indicates whether the UniSelector should apply WhereCondition for the selected value (default: false). This does not affect the modal dialog. /// public bool ApplyValueRestrictions { get { EnsureChildControls(); return usRooms.ApplyValueRestrictions; } set { EnsureChildControls(); usRooms.ApplyValueRestrictions = value; } } /// /// Gets the single select drop down field. /// public DropDownList DropDownSingleSelect { get { return usRooms.DropDownSingleSelect; } } /// /// Gets or sets the resource prefix of uni selector. If not set default values are used. /// public string ResourcePrefix { get { return mResourcePrefix; } set { mResourcePrefix = value; usRooms.ResourcePrefix = value; } } /// /// Indicates if control is used on live site. /// public override bool IsLiveSite { get { return base.IsLiveSite; } set { EnsureChildControls(); base.IsLiveSite = value; usRooms.IsLiveSite = value; } } /// /// If enabled disabled users aren't shown in selector. /// public bool HideDisabledRooms { get { return mHideDisabledRooms; } set { mHideDisabledRooms = value; } } /// /// If true selector will always display users from all sites. /// Suited for selecting users having access to the site. /// public bool DisplayRoomsFromAllSites { get { return mDisplayRoomsFromAllSites; } set { mDisplayRoomsFromAllSites = value; } } /// /// Enables or disables (all) item in selector. /// public bool AllowAll { get { return mAllowAll; } set { mAllowAll = value; EnsureChildControls(); usRooms.AllowAll = value; } } /// /// Enables or disables (empty) item in selector. /// public bool AllowEmpty { get { return mAllowEmpty; } set { mAllowEmpty = value; EnsureChildControls(); usRooms.AllowEmpty = value; } } /// /// Additional users to show identificated by user IDs. /// public int[] AdditionalRooms { get { return (int[])GetValue("AdditionalRooms"); } set { SetValue("AdditionalRooms", value); } } /// /// Where condition used to filter control data. /// public string WhereCondition { get; set; } #endregion #region "Control methods" protected override void OnInit(EventArgs e) { usRooms.UniGrid.Pager.UniPager.PageSize = 10; base.OnInit(e); } protected void Page_Load(object sender, EventArgs e) { if (!StopProcessing) { SetupControls(); ReloadData(); } else { usRooms.StopProcessing = true; } } protected void SetupControls() { usRooms.IconPath = UIHelper.GetImageUrl(Page, "Objects/CMS_ChatRoom/object.png"); //Display only current site's rooms usRooms.WhereCondition = SqlHelperClass.AddWhereCondition(usRooms.WhereCondition, string.Format("((ChatRoomSiteID = {0}) OR ChatRoomSiteID IS NULL) AND (ChatRoomPassword = '' ) AND (ChatRoomIsOneToOne = 0) AND (ChatRoomPrivate = 0)", (SiteID > 0) ? SiteID : CMSContext.CurrentSiteID)); // Set prefix if not set if (ResourcePrefix == String.Empty) { // Set resource prefix based on mode if ((SelectionMode == SelectionModeEnum.Multiple) || (SelectionMode == SelectionModeEnum.MultipleButton) || (SelectionMode == SelectionModeEnum.MultipleTextBox)) { usRooms.ResourcePrefix = "selectrooms"; } else { usRooms.ResourcePrefix = "selectroom"; } } // Hide disabled rooms if (HideDisabledRooms) { const string where = "ChatRoomEnabled = 1"; usRooms.WhereCondition = SqlHelperClass.AddWhereCondition(usRooms.WhereCondition, where); } // Add aditional rooms if ((AdditionalRooms != null) && (AdditionalRooms.Length > 0)) { usRooms.WhereCondition = SqlHelperClass.AddWhereCondition(usRooms.WhereCondition, SqlHelperClass.GetWhereCondition("ChatRoomID", AdditionalRooms), "OR"); } // Control where condition if (!String.IsNullOrEmpty(WhereCondition)) { usRooms.WhereCondition = SqlHelperClass.AddWhereCondition(usRooms.WhereCondition, WhereCondition); } pnlUpdate.ShowProgress = (this.SelectionMode == SelectionModeEnum.Multiple); } /// /// Creates child controls and loads update panle container if it is required. /// protected override void CreateChildControls() { // If selector is not defined load updat panel container if (usRooms == null) { pnlUpdate.LoadContainer(); } // Call base method base.CreateChildControls(); } /// /// Reloads the data of the UniSelector. /// public void ReloadData() { usRooms.Reload(true); pnlUpdate.Update(); } /// /// Reloads whole control including control settings and data. /// public void Reload() { SetupControls(); ReloadData(); } #endregion }