/// <summary>
    /// Returns string with site ids where user is member.
    /// </summary>
    private string GetIndexSites()
    {
        var siteIDs = SearchIndexSiteInfoProvider.GetIndexSiteBindings(indexId).Column("IndexSiteID").Select(x => x.IndexSiteID).ToList();

        if (siteIDs.Count > 0)
        {
            return(TextHelper.Join(";", siteIDs));
        }

        return(String.Empty);
    }
    /// <summary>
    /// Resets all boxes.
    /// </summary>
    public void LoadControls()
    {
        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID);

        string siteWhere = String.Empty;

        // Load only those site to which the index is assigned
        var siteIDs = SearchIndexSiteInfoProvider.GetIndexSiteBindings(ItemID).Column("IndexSiteID").Select(X => X.IndexSiteID.ToString()).ToList();

        if (siteIDs.Count > 0)
        {
            siteWhere = SqlHelper.GetWhereCondition <string>("SiteID", siteIDs, false);

            // Preselect current site if it is assigned to index
            if (!RequestHelper.IsPostBack() && siteIDs.Contains(SiteContext.CurrentSiteID.ToString()))
            {
                selSite.Value = SiteContext.CurrentSiteName;
            }

            selSite.UniSelector.WhereCondition = siteWhere;
            selSite.Reload(false);
        }
        else
        {
            pnlForm.Visible = false;

            ShowError(GetString("srch.index.nositeselected"));
        }

        // If we are editing existing search index
        if (sii != null)
        {
            SearchIndexSettings sis = new SearchIndexSettings();
            sis.LoadData(sii.IndexSettings.GetData());
            SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(ItemGUID);
            if (sisi != null)
            {
                selectForm.Value       = ValidationHelper.GetString(sisi.GetValue("FormName"), "");
                txtWhere.TextArea.Text = sisi.WhereCondition;
                selSite.Value          = sisi.SiteName;
            }
        }

        // Init controls
        SetControlsStatus(false);
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Module forums is not available
        if (!(ModuleManager.IsModuleLoaded(ModuleName.FORUMS)))
        {
            return;
        }

        selForum = LoadUserControl("~/CMSModules/Forums/FormControls/ForumSelector.ascx") as FormEngineUserControl;
        if (selForum != null)
        {
            // Set default vaules for forum selector
            selForum.IsLiveSite = false;
            selForum.SetValue("selectionmode", SelectionModeEnum.MultipleTextBox);
            selForum.SetValue("DisplayAdHocOption", false);

            plcForumSelector.Controls.Add(selForum);
        }

        // Set events and default values for site selector
        selSite.AllowAll = false;
        selSite.UseCodeNameForSelection           = true;
        selSite.DropDownSingleSelect.AutoPostBack = true;
        selSite.UniSelector.OnSelectionChanged   += UniSelector_OnSelectionChanged;

        LoadControls();

        if (ItemType == SearchIndexSettingsInfo.TYPE_ALLOWED)
        {
            selSite.AllowAll = true;
        }

        var siteIDs = SearchIndexSiteInfoProvider.GetIndexSiteBindings(ItemID).Select(x => x.IndexSiteID).ToList();

        if (siteIDs.Any())
        {
            // Preselect current site if it is assigned to index
            var sisiId = QueryHelper.GetGuid("guid", Guid.Empty);
            var isNew  = sisiId == Guid.Empty;
            if (!RequestHelper.IsPostBack() && isNew && siteIDs.Contains(SiteContext.CurrentSiteID))
            {
                selSite.Value = SiteContext.CurrentSiteName;
            }

            selSite.UniSelector.WhereCondition = SqlHelper.GetWhereInCondition("SiteID", siteIDs, false, false);
        }
        else
        {
            selSite.Enabled  = false;
            selForum.Enabled = false;
            btnOk.Enabled    = false;

            ShowError(GetString("srch.index.nositeselected"));
        }

        selSite.Reload(true);

        selForum.SetValue("SiteName", Convert.ToString(selSite.Value));

        // Init controls
        if (!RequestHelper.IsPostBack())
        {
            SetControlsStatus();
        }
    }