using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Controls; using CMS.GlobalHelper; using CMS.ISearchEngine; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.SiteProvider; using CMS.UIControls; using CMS.WebAnalytics; using SearchHelper = CMS.ISearchEngine.SearchHelper; public partial class CMSModules_SmartSearch_Controls_SearchDialog : CMSUserControl, ISearchFilterable { #region "Variables" private string mSearchForLabel = ResHelper.GetString("srch.dialog.searchfor"); private string mSearchButton = ResHelper.GetString("general.search"); private string mSearchModeLabel = ResHelper.GetString("srch.dialog.mode"); private SearchModeEnum mSearchMode = SearchModeEnum.AnyWord; private bool mShowSearchMode = true; private bool mShowOnlySearchButton = false; private string mFilterID = ""; private string mResultWebpartID = ""; // Filter support private List mFilterUrlParameters = null; #endregion #region "Properties" /// /// The text to show when the control has no value. /// public string WatermarkText { get { return txtSearchFor.WatermarkText; } set { txtSearchFor.WatermarkText = value; } } /// /// The CSS class to apply to the TextBox when it has no value (e.g. the watermark text is shown). /// public string WatermarkCssClass { get { return txtSearchFor.WatermarkCssClass; } set { txtSearchFor.WatermarkCssClass = value; } } /// /// Gets or sets the Filter URL parameters /// public List FilterUrlParameters { get { if (mFilterUrlParameters == null) { mFilterUrlParameters = new List(); } return mFilterUrlParameters; } set { mFilterUrlParameters = value; } } /// /// Gets or sets the label search for text. /// public string SearchForLabel { get { return mSearchForLabel; } set { mSearchForLabel = value; lblSearchFor.Text = value; } } /// /// Gets or sets the value that indicates whether search mode settings should be displayed. /// public bool ShowSearchMode { get { return mShowSearchMode; } set { mShowSearchMode = value; plcSearchMode.Visible = value; } } /// /// Gets or sets the value that indicates whether only search button should be displayed. /// public bool ShowOnlySearchButton { get { return mShowOnlySearchButton; } set { mShowOnlySearchButton = value; plcSearchOptions.Visible = !value; } } /// /// Gets or sets the search button text. /// public string SearchButton { get { return mSearchButton; } set { mSearchButton = value; btnSearch.Text = value; } } /// /// Gets or sets the search mode. /// public SearchModeEnum SearchMode { get { return mSearchMode; } set { mSearchMode = value; } } /// /// Gets or sets the search mode label text. /// public string SearchModeLabel { get { return mSearchModeLabel; } set { mSearchModeLabel = value; lblSearchMode.Text = value; } } /// /// Gets or sets the search filter id. /// public string FilterID { get { return mFilterID; } set { mFilterID = value; } } /// /// Gets or sets the search mode label text. /// public string ResultWebpartID { get { return mResultWebpartID; } set { mResultWebpartID = value; } } /// /// Gets or sets filter condition - not implemented. /// public string FilterSearchCondition { get { return null; } set { ; } } /// /// Gets or sets filter search sort - not implemented. /// public string FilterSearchSort { get { return null; } set { ; } } #endregion #region "Page and controls events" /// /// Page load. /// /// Sender /// Arguments protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { return; } else { // Set up drop down list if (ShowSearchMode) { if (!RequestHelper.IsPostBack()) { // Fill dropdownlist option with values DataHelper.FillListControlWithEnum(typeof(SearchModeEnum), drpSearchMode, "srch.dialog.", SearchHelper.GetSearchModeString); drpSearchMode.SelectedValue = QueryHelper.GetString("searchmode", SearchHelper.GetSearchModeString(SearchMode)); } } // Set up search text if (!RequestHelper.IsPostBack() && (!ShowOnlySearchButton)) { txtSearchFor.Text = QueryHelper.GetString("searchtext", ""); } } } /// /// Fires at btn search click. /// /// Sender /// Arguments protected void btnSearch_Click(object sender, EventArgs e) { string url = URLHelper.CurrentURL; // Remove pager query string url = URLHelper.RemoveParameterFromUrl(url, "page"); // Update search text parameter url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtSearchFor.Text)); // Update search mode parameter url = URLHelper.RemoveParameterFromUrl(url, "searchmode"); if (ShowSearchMode) { url = URLHelper.AddParameterToUrl(url, "searchmode", drpSearchMode.SelectedValue); } else { url = URLHelper.AddParameterToUrl(url, "searchmode", SearchHelper.GetSearchModeString(SearchMode)); } // Add filter params to url foreach (string urlParam in FilterUrlParameters) { string[] urlParams = urlParam.Split('='); url = URLHelper.UpdateParameterInUrl(url, urlParams[0], urlParams[1]); } // Log "internal search" activity Activity internalSearch = new ActivityInternalSearch(txtSearchFor.Text, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); internalSearch.Log(); // Redirect URLHelper.Redirect(url); } #endregion #region "Methods" /// /// Applies filter. /// /// Search condition /// Search sort public void ApplyFilter(string searchCondition, string searchSort) { // Call Result webpart id ISearchFilterable resultWebpart = (ISearchFilterable)CMSControlsHelper.GetFilter(ResultWebpartID); if (resultWebpart != null) { resultWebpart.ApplyFilter(searchCondition, searchSort); } } /// /// Adds filter option to url. /// /// Webpart id /// Options public void AddFilterOptionsToUrl(string searchWebpartID, string options) { FilterUrlParameters.Add(searchWebpartID + "=" + options); } /// /// Loads data. /// public void LoadData() { // Register control for filter CMSControlsHelper.SetFilter(FilterID, this); } #endregion }