/// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        imgTextHint.ImageUrl      = GetImageUrl("Design/Forums/hint.gif");
        imgTextHint.AlternateText = "Hint";
        ScriptHelper.AppendTooltip(imgTextHint, GetString("ForumSearch.SearchTextHint"), "help");

        btnSearch.Text = GetString("general.search");

        if (EnableForumSelection)
        {
            plcForums.Visible = true;
            string selected  = ";" + QueryHelper.GetString("searchforums", "") + ";";
            bool   allForums = QueryHelper.GetBoolean("allforums", false);

            ForumPostsDataSource fpd = new ForumPostsDataSource();
            fpd.CacheMinutes       = 0;
            fpd.SelectedColumns    = "GroupID, GroupDisplayName, ForumID, ForumDisplayName,GroupOrder, ForumOrder, ForumName ";
            fpd.Distinct           = true;
            fpd.SelectOnlyApproved = false;
            fpd.SiteName           = SiteContext.CurrentSiteName;

            string where = "(GroupGroupID IS NULL) AND (GroupName != 'adhocforumgroup') AND (ForumOpen=1)";

            // Get only selected forum groups
            if (!String.IsNullOrEmpty(ForumGroups))
            {
                string groups = "";
                foreach (string group in ForumGroups.Split(';'))
                {
                    groups += " '" + SqlHelper.GetSafeQueryString(group) + "',";
                }

                // Add new part to where condition
                where += " AND (GroupName IN (" + groups.TrimEnd(',') + "))";
            }

            if (HideForumForUnauthorized)
            {
                where = ForumInfoProvider.CombineSecurityWhereCondition(where, 0);
            }
            fpd.WhereCondition = where;

            fpd.OrderBy = "GroupOrder, ForumOrder ASC, ForumName ASC";

            DataSet ds = fpd.DataSource as DataSet;
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int oldGroup = -1;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (oldGroup != ValidationHelper.GetInteger(dr["GroupID"], 0))
                    {
                        ListItem li = new ListItem(ResHelper.LocalizeString(Convert.ToString(dr["GroupDisplayName"])), "");
                        li.Attributes.Add("disabled", "disabled");
                        if (!listForums.Items.Contains(li))
                        {
                            listForums.Items.Add(li);
                        }
                        oldGroup = ValidationHelper.GetInteger(dr["GroupID"], 0);
                    }

                    string   forumId = Convert.ToString(dr["ForumID"]);
                    ListItem lif     = new ListItem(" \xA0\xA0\xA0\xA0 " + ResHelper.LocalizeString(Convert.ToString(dr["ForumDisplayName"])), forumId);
                    if ((selected.Contains(";" + forumId + ";")) && (!allForums))
                    {
                        lif.Selected = true;
                    }

                    // On postback on ASPX
                    if (!listForums.Items.Contains(lif))
                    {
                        listForums.Items.Add(lif);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        repLatestPosts.DataBindByDefault = false;
        pagerElem.PageControl            = repLatestPosts.ID;

        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            if (!String.IsNullOrEmpty(TransformationName))
            {
                // Basic control properties
                repLatestPosts.HideControlForZeroRows = HideControlForZeroRows;
                repLatestPosts.ZeroRowsText           = ZeroRowsText;

                // Set data source groupID according to group name
                if (!String.IsNullOrEmpty(GroupName))
                {
                    GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName);
                    if (gi != null)
                    {
                        forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0);
                    }
                    else
                    {
                        // Do nothing if no group is set
                        forumDataSource.StopProcessing = true;
                    }
                }

                if (!forumDataSource.StopProcessing)
                {
                    // Data source properties
                    forumDataSource.TopN               = SelectTopN;
                    forumDataSource.OrderBy            = OrderBy;
                    forumDataSource.CacheItemName      = CacheItemName;
                    forumDataSource.CacheDependencies  = CacheDependencies;
                    forumDataSource.CacheMinutes       = CacheMinutes;
                    forumDataSource.SourceFilterName   = FilterName;
                    forumDataSource.SelectOnlyApproved = SelectOnlyApproved;
                    forumDataSource.SiteName           = SiteName;
                    forumDataSource.SelectedColumns    = Columns;
                    forumDataSource.ShowGroupPosts     = ShowGroupPosts && String.IsNullOrEmpty(ForumGroups);


                    #region "Repeater template properties"

                    // Apply transformations if they exist
                    repLatestPosts.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName);

                    // Alternating item
                    if (!String.IsNullOrEmpty(AlternatingItemTransformationName))
                    {
                        repLatestPosts.AlternatingItemTemplate = CMSDataProperties.LoadTransformation(this, AlternatingItemTransformationName);
                    }

                    // Footer
                    if (!String.IsNullOrEmpty(FooterTransformationName))
                    {
                        repLatestPosts.FooterTemplate = CMSDataProperties.LoadTransformation(this, FooterTransformationName);
                    }

                    // Header
                    if (!String.IsNullOrEmpty(HeaderTransformationName))
                    {
                        repLatestPosts.HeaderTemplate = CMSDataProperties.LoadTransformation(this, HeaderTransformationName);
                    }

                    // Separator
                    if (!String.IsNullOrEmpty(SeparatorTransformationName))
                    {
                        repLatestPosts.SeparatorTemplate = CMSDataProperties.LoadTransformation(this, SeparatorTransformationName);
                    }

                    #endregion


                    // UniPager properties
                    pagerElem.PageSize       = PageSize;
                    pagerElem.GroupSize      = GroupSize;
                    pagerElem.QueryStringKey = QueryStringKey;
                    pagerElem.DisplayFirstLastAutomatically    = DisplayFirstLastAutomatically;
                    pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
                    pagerElem.HidePagerForSinglePage           = HidePagerForSinglePage;

                    // Set pager mode
                    switch (PagingMode.ToLowerCSafe())
                    {
                    case "postback":
                        pagerElem.PagerMode = UniPagerMode.PostBack;
                        break;

                    default:
                        pagerElem.PagerMode = UniPagerMode.Querystring;
                        break;
                    }


                    #region "UniPager template properties"

                    // UniPager template properties
                    if (!String.IsNullOrEmpty(PagesTemplate))
                    {
                        pagerElem.PageNumbersTemplate = CMSDataProperties.LoadTransformation(pagerElem, PagesTemplate);
                    }

                    // Current page
                    if (!String.IsNullOrEmpty(CurrentPageTemplate))
                    {
                        pagerElem.CurrentPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, CurrentPageTemplate);
                    }

                    // Separator
                    if (!String.IsNullOrEmpty(SeparatorTemplate))
                    {
                        pagerElem.PageNumbersSeparatorTemplate = CMSDataProperties.LoadTransformation(pagerElem, SeparatorTemplate);
                    }

                    // First page
                    if (!String.IsNullOrEmpty(FirstPageTemplate))
                    {
                        pagerElem.FirstPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, FirstPageTemplate);
                    }

                    // Last page
                    if (!String.IsNullOrEmpty(LastPageTemplate))
                    {
                        pagerElem.LastPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, LastPageTemplate);
                    }

                    // Previous page
                    if (!String.IsNullOrEmpty(PreviousPageTemplate))
                    {
                        pagerElem.PreviousPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousPageTemplate);
                    }

                    // Next page
                    if (!String.IsNullOrEmpty(NextPageTemplate))
                    {
                        pagerElem.NextPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextPageTemplate);
                    }

                    // Previous group
                    if (!String.IsNullOrEmpty(PreviousGroupTemplate))
                    {
                        pagerElem.PreviousGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousGroupTemplate);
                    }

                    // Next group
                    if (!String.IsNullOrEmpty(NextGroupTemplate))
                    {
                        pagerElem.NextGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextGroupTemplate);
                    }

                    // Direct page
                    if (!String.IsNullOrEmpty(DirectPageTemplate))
                    {
                        pagerElem.DirectPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, DirectPageTemplate);
                    }

                    // Layout
                    if (!String.IsNullOrEmpty(LayoutTemplate))
                    {
                        pagerElem.LayoutTemplate = CMSDataProperties.LoadTransformation(pagerElem, LayoutTemplate);
                    }

                    #endregion


                    #region "Complete where condition"

                    string where = "";
                    string[] groups = ForumGroups.Split(';');

                    // Create where condition for all forum groups
                    foreach (string group in groups)
                    {
                        if (group != "")
                        {
                            if (where != "")
                            {
                                where += "OR";
                            }
                            where += "(GroupName = N'" + SqlHelper.GetSafeQueryString(group, false) + "')";
                        }
                    }

                    // Add custom where condition
                    if (!string.IsNullOrEmpty(WhereCondition))
                    {
                        if (string.IsNullOrEmpty(where))
                        {
                            where = WhereCondition;
                        }
                        else
                        {
                            where = "(" + WhereCondition + ") AND (" + where + ")";
                        }
                    }

                    #endregion

                    // Set forum data source
                    forumDataSource.WhereCondition   = where;
                    forumDataSource.CheckPermissions = true;
                    repLatestPosts.DataSourceControl = forumDataSource;
                }
            }

            pagerElem.RebindPager();
            repLatestPosts.DataBind();
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            if (!String.IsNullOrEmpty(TransformationName))
            {
                repLatestPosts.ItemTemplate           = TransformationHelper.LoadTransformation(this, TransformationName);
                repLatestPosts.HideControlForZeroRows = HideControlForZeroRows;
                repLatestPosts.ZeroRowsText           = ZeroRowsText;

                // Set data source groupid according to group name
                if (!String.IsNullOrEmpty(GroupName))
                {
                    if (GroupName == PredefinedObjectType.COMMUNITY_CURRENT_GROUP)
                    {
                        forumDataSource.GroupID = ModuleCommands.CommunityGetCurrentGroupID();
                    }
                    else
                    {
                        GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName);
                        if (gi != null)
                        {
                            forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0);
                        }
                        else
                        {
                            forumDataSource.StopProcessing = true;
                        }
                    }
                }

                if (!forumDataSource.StopProcessing)
                {
                    forumDataSource.TopN               = SelectTopN;
                    forumDataSource.OrderBy            = "PostThreadLastPostTime DESC";
                    forumDataSource.CacheItemName      = CacheItemName;
                    forumDataSource.CacheDependencies  = CacheDependencies;
                    forumDataSource.CacheMinutes       = CacheMinutes;
                    forumDataSource.SelectOnlyApproved = false;
                    forumDataSource.SiteName           = SiteName;
                    forumDataSource.ShowGroupPosts     = ShowGroupPosts && String.IsNullOrEmpty(ForumGroups);
                    forumDataSource.SelectedColumns    = Columns;


                    #region "Complete where condition"

                    string where = "";

                    // Get groups part of where condition
                    string[] groups = ForumGroups.Split(';');
                    foreach (string group in groups)
                    {
                        if (group != "")
                        {
                            if (where != "")
                            {
                                where += " OR ";
                            }
                            where += "(GroupName = N'" + SqlHelper.GetSafeQueryString(group, false) + "')";
                        }
                    }
                    where = "(" + (where == "" ? "(GroupName NOT LIKE 'AdHoc%')" : "(" + where + ")") + " AND (PostLevel = 0))";

                    // Append where condition and set PostLevel to 0 (only threads are needed)
                    // and filter out AdHoc forums
                    if (!String.IsNullOrEmpty(WhereCondition))
                    {
                        where += " AND (" + WhereCondition + ")";
                    }

                    #endregion


                    forumDataSource.WhereCondition   = where;
                    forumDataSource.CheckPermissions = true;
                    repLatestPosts.DataSourceControl = forumDataSource;
                    repLatestPosts.DataBind();
                }
            }
        }
    }