using System; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Controls; using CMS.ExtendedControls; using CMS.GlobalHelper; using CMS.SettingsProvider; using CMS.DocumentEngine; public partial class CMSFormControls_Filters_DocumentFilter : CMSAbstractBaseFilterControl { #region "Variables" private bool mAllowSiteAutopostback = true; private bool mIncludeSiteCondition = false; private bool mLoadSites = false; #endregion #region "Properties" /// /// Gets show button. /// public LocalizedButton ShowButton { get { return btnShow; } } /// /// Gets sites placeholder. /// public PlaceHolder SitesPlaceHolder { get { return plcSites; } } /// /// Gets document name path placeholder. /// public PlaceHolder PathPlaceHolder { get { return plcPath; } } /// /// Gets class placeholder. /// public PlaceHolder ClassPlaceHolder { get { return plcClass; } } /// /// Determines whether to load site selector. /// public bool LoadSites { get { return mLoadSites; } set { mLoadSites = value; } } /// /// Determines whether to include condition for site to the resulting WHERE condition. /// public bool IncludeSiteCondition { get { return mIncludeSiteCondition; } set { mIncludeSiteCondition = value; } } /// /// Determines whether the site selector DDL has autopostback option on or off. /// public bool AllowSiteAutopostback { get { return mAllowSiteAutopostback; } set { mAllowSiteAutopostback = value; } } /// /// Returns selected site name. /// public string SelectedSite { get { Control postbackControl = ControlsHelper.GetPostBackControl(Page); return DataHelper.GetNotEmpty((postbackControl == btnShow) ? siteSelector.Value : ViewState["SelectedSite"], TreeProvider.ALL_SITES); } private set { ViewState["SelectedSite"] = value; } } /// /// Where condition. /// public override string WhereCondition { get { Control postbackControl = ControlsHelper.GetPostBackControl(Page); return DataHelper.GetNotEmpty((postbackControl == btnShow) ? CreateWhereCondition(base.WhereCondition) : ViewState["WhereCondition"], string.Empty); } set { base.WhereCondition = value; ViewState["WhereCondition"] = value; } } /// /// Determines whether filter is set. /// public bool FilterIsSet { get { return nameFilter.FilterIsSet || classFilter.FilterIsSet || (SelectedSite != TreeProvider.ALL_SITES); } } #endregion #region "Delegates and events" public event EventHandler OnSiteSelectionChanged; #endregion #region "Page events" protected void Page_Load(object sender, EventArgs e) { siteSelector.DropDownSingleSelect.Width = new Unit(305); if (LoadSites) { LoadSiteSelector(); } } #endregion #region "Methods" /// /// Loads the drop-down list with all the available sites. /// private void LoadSiteSelector() { CurrentUserInfo user = CMSContext.CurrentUser; // Get all user sites if (user.IsGlobalAdministrator) { // Set site selector siteSelector.DropDownSingleSelect.AutoPostBack = AllowSiteAutopostback; if (AllowSiteAutopostback) { siteSelector.UniSelector.OnSelectionChanged += OnSiteSelectionChanged; } // All options only if global admin has access to Site manager if (!user.UserSiteManagerDisabled) { siteSelector.AllowAll = false; siteSelector.UniSelector.SpecialFields = new string[1,2] { { ResHelper.GetString("general.selectall"), TreeProvider.ALL_SITES } }; } // Preselect all if (!RequestHelper.IsPostBack()) { siteSelector.Value = TreeProvider.ALL_SITES; } } else { plcSites.Visible = false; } } private string CreateWhereCondition(string originalWhere) { string where = originalWhere; // Add where conditions from filters string classCondition = classFilter.WhereCondition; if (!string.IsNullOrEmpty(classCondition)) { classCondition = string.Format("NodeClassID IN (SELECT ClassID FROM CMS_Class WHERE {0})", classCondition); } where = SqlHelperClass.AddWhereCondition(where, classCondition); where = SqlHelperClass.AddWhereCondition(where, nameFilter.WhereCondition); if (IncludeSiteCondition && !string.IsNullOrEmpty(siteSelector.SiteName) && (siteSelector.SiteName != TreeProvider.ALL_SITES)) { where = SqlHelperClass.AddWhereCondition(where, "SiteName = '" + SqlHelperClass.GetSafeQueryString(siteSelector.SiteName, false) + "'"); } return where; } #endregion #region "Control events" protected void btnShow_Click(object sender, EventArgs e) { WhereCondition = CreateWhereCondition(base.WhereCondition); SelectedSite = DataHelper.GetNotEmpty(siteSelector.Value, TreeProvider.ALL_SITES); } #endregion }