Ejemplo n.º 1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Title += ApplicationAdapter.GetSiteName();

                // first time loaded, fill in properties
                lblUserName.Text = SessionAdapter.GetUserNickName();

                HttpContext hcCurrent          = HttpContext.Current;
                DataTable   bookmarkStatistics = null;

                // check if user is authenticated
                if (hcCurrent.Request.IsAuthenticated)
                {
                    lblWelcomeTextLoggedIn.Visible = true;
                    bookmarkStatistics             = UserGuiHelper.GetBookmarkStatisticsAsDataTable(SessionAdapter.GetUserID());
                }
                else
                {
                    lblWelcomeTextNotLoggedIn.Visible = true;
                    bookmarkStatistics = new DataTable();
                }

                // check if the user has the action right to approve attachments on some forum. If so, show the # of attachments which need approval
                List <int> forumsWithApprovalRight = SessionAdapter.GetForumsWithActionRight(ActionRights.ApproveAttachment);
                bool       canApproveAttachments   = ((forumsWithApprovalRight != null) && (forumsWithApprovalRight.Count > 0));
                if (canApproveAttachments)
                {
                    int numberOfAttachmentsToApprove = MessageGuiHelper.GetTotalNumberOfAttachmentsToApprove(
                        SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum),
                        SessionAdapter.GetForumsWithActionRight(ActionRights.ApproveAttachment),
                        SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID());
                    if (numberOfAttachmentsToApprove > 0)
                    {
                        phAttachmentsToApprove.Visible = true;
                        phAttentionRemarks.Visible     = true;
                    }
                }
                if (SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement))
                {
                    int numberOfThreadsInSupportQueues = SupportQueueGuiHelper.GetTotalNumberOfThreadsInSupportQueues(
                        SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum));
                    if (numberOfThreadsInSupportQueues > 0)
                    {
                        phThreadsToSupport.Visible = true;
                        phAttentionRemarks.Visible = true;
                    }
                }

                DateTime lastVisitDate = SessionAdapter.GetLastVisitDate();

                if (SessionAdapter.IsLastVisitDateValid())
                {
                    phLastVisitDate.Visible = true;
                    lblLastVisitDate.Text   = lastVisitDate.ToString("dd-MMM-yyyy HH:mm");
                }

                // Get all sections which possibly can be displayed. Obtain this from the cache, as it's hardly changing data, and
                // this page is read a lot.
                _sectionsToDisplay = CacheManager.GetAllSections();

                // Per section, create a view with all the forumdata and filter out the forums not visible for the current user.
                List <int> accessableForums            = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum);
                List <int> forumsWithThreadsFromOthers = SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers);
                _forumViewsPerDisplayedSection = ForumGuiHelper.GetAllAvailableForumsDataViews(_sectionsToDisplay, accessableForums,
                                                                                               forumsWithThreadsFromOthers, SessionAdapter.GetUserID());

                // filter out sections which do not have displayable forums for this user
                EntityView <SectionEntity> sectionsToUse = CreateFilteredSectionsCollection();

                // show the sections with displayable forums, thus the displayable sections.
                rpSections.DataSource = sectionsToUse;
                rpSections.DataBind();

                // get bookmarks and show them in the gui
                if ((bookmarkStatistics.Rows.Count <= 0) || ((bookmarkStatistics.Rows.Count == 1) && ((int)bookmarkStatistics.Rows[0][0] == 0)))
                {
                    // no bookmarks yet
                    lblAmountBookmarks.Text           = "0";
                    lblAmountPostingsInBookmarks.Text = "0";
                    lblBookmarksLastPostingDate.Text  = "Never";
                    imgIconBookmarkNoNewPosts.Visible = true;
                }
                else
                {
                    lblAmountBookmarks.Text           = bookmarkStatistics.Rows[0]["AmountThreads"].ToString();
                    lblAmountPostingsInBookmarks.Text = bookmarkStatistics.Rows[0]["AmountPostings"].ToString();
                    DateTime dateLastPosting = (DateTime)bookmarkStatistics.Rows[0]["LastPostingDate"];
                    lblBookmarksLastPostingDate.Text = dateLastPosting.ToString("dd-MMM-yyyy HH:mm");
                    if (dateLastPosting > lastVisitDate)
                    {
                        imgIconBookmarkNewPosts.Visible = true;
                    }
                    else
                    {
                        imgIconBookmarkNoNewPosts.Visible = true;
                    }
                }

                DataTable activeThreadsStatistics = ThreadGuiHelper.GetActiveThreadsStatisticsAsDataTable(accessableForums,
                                                                                                          CacheManager.GetSystemData().HoursThresholdForActiveThreads,
                                                                                                          SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID());
                if (activeThreadsStatistics != null)
                {
                    if ((activeThreadsStatistics.Rows.Count <= 0) || ((activeThreadsStatistics.Rows.Count == 1) && ((int)activeThreadsStatistics.Rows[0][0] == 0)))
                    {
                        lblAmountActiveThreads.Text            = "0";
                        lblAmountPostingsInActiveThreads.Text  = "0";
                        lblActiveThreadsLastPostingDate.Text   = "Never";
                        imgIconActiveThreadsNoNewPosts.Visible = true;
                    }
                    else
                    {
                        lblAmountActiveThreads.Text           = activeThreadsStatistics.Rows[0]["AmountThreads"].ToString();
                        lblAmountPostingsInActiveThreads.Text = activeThreadsStatistics.Rows[0]["AmountPostings"].ToString();
                        DateTime dateLastPosting = (DateTime)activeThreadsStatistics.Rows[0]["LastPostingDate"];
                        lblActiveThreadsLastPostingDate.Text = dateLastPosting.ToString("dd-MMM-yyyy HH:mm");
                        if (dateLastPosting > lastVisitDate)
                        {
                            imgIconActiveThreadsNewPosts.Visible = true;
                        }
                        else
                        {
                            imgIconActiveThreadsNoNewPosts.Visible = true;
                        }
                    }
                }
            }

            RegisterCollapseExpandClientScript();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]);

            _thread = ThreadGuiHelper.GetThread(threadID);
            if (_thread == null)
            {
                // not found, return to default page
                Response.Redirect("default.aspx", true);
            }

            _startAtMessage = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]);

            // Check credentials
            bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum);

            if (!userHasAccess)
            {
                // doesn't have access to this forum. redirect
                Response.Redirect("default.aspx", true);
            }

            // check if the user can view this thread. If not, don't continue.
            if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) &&
                !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) &&
                !_thread.IsSticky)
            {
                // can't view this thread, it isn't visible to the user
                Response.Redirect("default.aspx", true);
            }

            // Check if the current user is allowed to edit the memo
            if (!SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo))
            {
                // is not allowed to edit the memo
                Response.Redirect("Messages.aspx?ThreadID=" + threadID, true);
            }

            // User may edit memo, proceed
            if (!Page.IsPostBack)
            {
                // fill the page's content
                ForumEntity forum = CacheManager.GetForum(_thread.ForumID);
                if (forum == null)
                {
                    // Orphaned thread
                    Response.Redirect("default.aspx", true);
                }
                lnkThreads.Text               = HttpUtility.HtmlEncode(forum.ForumName);
                lnkThreads.NavigateUrl       += "?ForumID=" + _thread.ForumID;
                meMessageEditor.ForumName     = forum.ForumName;
                meMessageEditor.ThreadSubject = "Memo for thread: " + HttpUtility.HtmlEncode(_thread.Subject);
                lblSectionName.Text           = CacheManager.GetSectionName(forum.SectionID);
                lnkMessages.NavigateUrl      += threadID;
                lnkMessages.Text              = HttpUtility.HtmlEncode(_thread.Subject);

                string memoText = _thread.Memo;
                memoText += string.Format("{2}[b]-----------------------------------------------------------------{2}{1} [color value=\"0000AA\"]{0}[/color] wrote:[/b] ", SessionAdapter.GetUserNickName(), DateTime.Now.ToString(@"dd-MMM-yyyy HH:mm:ss"), Environment.NewLine);
                meMessageEditor.OriginalMessageText = memoText;
            }
        }