protected void Page_Load(object sender, EventArgs e)
    {
        process = true;
        // If control is not visible don't process anything
        if (!Visible || StopProcessing)
        {
            process         = false;
            EnableViewState = false;
            return;
        }
        string forumIDs = null;
        // Group where condition part
        string groupWhere = String.Empty;

        if (SiteName == string.Empty)
        {
            SiteName = SiteContext.CurrentSiteName;
        }
        if (SiteName != TreeProvider.ALL_SITES)
        {
            groupWhere = "GroupSiteID IN (SELECT SiteID FROM CMS_Site WHERE SiteName = N'" + SqlHelper.GetSafeQueryString(SiteName, false) + "')";
        }

        if (CommunityGroupId > 0)
        {
            groupWhere = SqlHelper.AddWhereCondition(groupWhere, "GroupGroupID = " + CommunityGroupId);
        }

        // Add where condition from property
        if (WhereCondition != String.Empty)
        {
            groupWhere = SqlHelper.AddWhereCondition(groupWhere, WhereCondition);
        }

        bool hasGroupRights = false;

        if (CommunityGroupId > 0)
        {
            if (MembershipContext.AuthenticatedUser.IsGroupAdministrator(CommunityGroupId) ||
                MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.groups", "Manage"))
            {
                hasGroupRights = true;
            }
        }

        // Get forums moderated by current user
        else if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
        {
            // Get forumId where the user is moderator and forum satisfy group where condition
            string whereCond = "UserID =" + MembershipContext.AuthenticatedUser.UserID;
            if (groupWhere != String.Empty)
            {
                whereCond += " AND ForumID IN ( SELECT ForumID FROM Forums_Forum WHERE " +
                             "ForumGroupID IN (SELECT GroupID FROM Forums_ForumGroup WHERE " + groupWhere + "))";
            }

            // Get forums where user is moderator
            DataSet ds = ForumModeratorInfoProvider.GetGroupForumsModerators(whereCond, null);

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                forumIDs = "";

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    forumIDs += ValidationHelper.GetString(dr["ForumID"], "") + ",";
                }

                // Remove ending ,
                forumIDs = forumIDs.TrimEnd(',');
            }
        }

        string zeroRowText = String.Empty;

        if (ZeroRowText == String.Empty)
        {
            zeroRowText = GetString("general.nodatafound");
        }
        else
        {
            zeroRowText = HTMLHelper.HTMLEncode(ZeroRowText);
        }

        // Hide approvals
        if ((!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) && (String.IsNullOrEmpty(forumIDs)) && (hasGroupRights == false))
        {
            if (!HideControlForNoData)
            {
                gridApprove.StopProcessing = true;
                process         = false;
                lblInfo.Text    = zeroRowText;
                lblInfo.Visible = true;
                return;
            }
            else
            {
                Visible = false;
            }
        }

        gridApprove.ZeroRowsText           = zeroRowText;
        gridApprove.OnAction              += gridApprove_OnAction;
        gridApprove.GridView.AllowSorting  = false;
        gridApprove.OnExternalDataBound   += gridApprove_OnExternalDataBound;
        gridApprove.IsLiveSite             = IsLiveSite;
        gridApprove.HideControlForZeroRows = false;

        if ((!RequestHelper.IsPostBack()) && (!string.IsNullOrEmpty(ItemsPerPage)))
        {
            gridApprove.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1);
        }

        if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) || hasGroupRights)
        {
            if (groupWhere != String.Empty)
            {
                gridApprove.WhereCondition = "(PostApproved IS NULL OR PostApproved = 0) AND (PostForumID IN (SELECT ForumID FROM [Forums_Forum] WHERE ForumGroupID IN (SELECT GroupID FROM [Forums_ForumGroup] WHERE " + groupWhere + ")))";
            }
            // Show only posts waiting for approval
            else
            {
                gridApprove.WhereCondition = "(PostApproved IS NULL OR PostApproved = 0)";
            }
        }
        else if (forumIDs != null)
        {
            gridApprove.WhereCondition = "((PostApproved IS NULL) OR (PostApproved = 0)) AND (PostForumID IN  (SELECT ForumID FROM [Forums_Forum] WHERE (ForumID IN (" +
                                         forumIDs + "))";
            if (groupWhere != String.Empty)
            {
                gridApprove.WhereCondition += " AND (ForumGroupID IN (SELECT GroupID FROM [Forums_ForumGroup] WHERE " + groupWhere + "))))";
            }
            else
            {
                gridApprove.WhereCondition += "))";
            }
        }


        //Filter group names
        if (GroupNames != String.Empty)
        {
            string where = String.Empty;
            string   parsedNames = String.Empty;
            string[] names       = GroupNames.Split(';');
            if (names.Length > 0)
            {
                foreach (string name in names)
                {
                    parsedNames += "'" + SqlHelper.GetSafeQueryString(name, false) + "',";
                }
                parsedNames = parsedNames.TrimEnd(',');
                where       = "(PostForumID IN (SELECT ForumID FROM [Forums_Forum] WHERE (ForumGroupID IN (SELECT GroupID FROM [Forums_ForumGroup] WHERE GroupName IN (" + parsedNames + ")))))";
                gridApprove.WhereCondition = SqlHelper.AddWhereCondition(gridApprove.WhereCondition, where);
            }
        }
    }