//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web;
using System.Web.UI;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls
{
    /// <summary>
    /// Non UI class used to prepopulate search dropdown filter
    /// 
    /// This control provides NO security checks
    /// </summary>
    public class SearchFilters : Control
    {
        protected override void OnInit(EventArgs e)
        {
            CSContext cntx = CSContext.Current;

            if (cntx.SectionID > 0)
            {
                Forum f = Forums.GetForum(cntx.SectionID);
                if (f != null)
                {
                    SetFilters(f,ForumGroups.GetForumGroup(f.GroupID), Context);
                }
            }
            else if (cntx.GroupID > 0)
            {
                SetFilters(null,ForumGroups.GetForumGroup(cntx.GroupID),Context);
            }

            base.OnInit(e);
        }

        public static void SetFilters(Forum f, Group g, HttpContext context)
        {
            if (f != null)
            {
                TitleBar.AddSectionToSearch(f.SectionID, string.Format(ResourceManager.GetString("forum_searchfilter"),HttpUtility.HtmlDecode(f.Name)), context);
            }

            if (g != null)
            {
                    TitleBar.AddGroupToSearch(g.GroupID, string.Format(ResourceManager.GetString("group_searchfilter"),HttpUtility.HtmlDecode(g.Name)), context);
            }
        }

    }
}