Example #1
0
        protected void PostMessageHandler(object sender, System.EventArgs e)
        {
            int userID = SessionAdapter.GetUserID();

            // store the new message in the given thread
            string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.ThreadUpdatedNotification);
            int    messageID    = ThreadManager.CreateNewMessageInThread(_thread.ThreadID, userID, meMessageEditor.MessageText, meMessageEditor.MessageTextHTML,
                                                                         Request.UserHostAddress.ToString(), meMessageEditor.MessageTextXML, meMessageEditor.SubscribeToThread,
                                                                         mailTemplate, ApplicationAdapter.GetEmailData(), CacheManager.GetSystemData().SendReplyNotifications);

            // invalidate forum RSS in cache
            ApplicationAdapter.InvalidateCachedForumRSS(_thread.ForumID);

            // if auditing is required, we've to do this now.
            if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditNewMessage))
            {
                SecurityManager.AuditNewMessage(userID, messageID);
            }

            // invalidate forum in asp.net cache
            CacheManager.InvalidateCachedItem(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, _thread.ForumID));

            // all ok, redirect to message list
            int startAtMessageIndex = ThreadGuiHelper.GetStartAtMessageForGivenMessageAndThread(_thread.ThreadID, messageID, SessionAdapter.GetUserDefaultNumberOfMessagesPerPage());

            if (meMessageEditor.AddAttachment)
            {
                // redirect to manage attachment form for this message
                Response.Redirect(string.Format("Attachments.aspx?SourceType=1&MessageID={0}", messageID), true);
            }
            else
            {
                Response.Redirect(string.Format("Messages.aspx?ThreadID={0}&StartAtMessage={1}&#{2}", _thread.ThreadID, startAtMessageIndex, messageID), true);
            }
        }
Example #2
0
 private void btnResetPassword_ServerClick(object sender, System.EventArgs e)
 {
     if (Page.IsValid)
     {
         try
         {
             // user has filled in all fields, let's reset the password.
             string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.RegistrationReply);
             bool   result       = UserManager.ResetPassword(tbxNickName.Value, tbxEmailAddress.Value, mailTemplate, ApplicationAdapter.GetEmailData());
             if (result)
             {
                 // ok
                 Response.Redirect("ResetPasswordSuccessful.aspx", true);
             }
             // not ok
             lblErrorMessage.Text = "Something went wrong with the reset action. Please try again.";
         }
         catch (NickNameNotFoundException ex)
         {
             lblErrorMessage.Text = ex.Message;
         }
         catch (EmailAddressDoesntMatchException ex)
         {
             lblErrorMessage.Text = ex.Message;
         }
         // bubble up others.
     }
 }
Example #3
0
        protected void PostMessageHandler(object sender, System.EventArgs e)
        {
            string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.ThreadUpdatedNotification);
            // store the new message in the given thread and close it directly.
            int messageID = ThreadManager.CreateNewMessageInThreadAndCloseThread(_thread.ThreadID, SessionAdapter.GetUserID(), meMessageEditor.MessageText,
                                                                                 meMessageEditor.MessageTextHTML, Request.UserHostAddress.ToString(), meMessageEditor.MessageTextXML,
                                                                                 mailTemplate, ApplicationAdapter.GetEmailData(), CacheManager.GetSystemData().SendReplyNotifications);

            // all ok, redirect to message list
            int startAtMessageID = ThreadGuiHelper.GetStartAtMessageForGivenMessageAndThread(_thread.ThreadID, messageID, SessionAdapter.GetUserDefaultNumberOfMessagesPerPage());

            Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + startAtMessageID + "&#" + messageID, true);
        }
Example #4
0
        /// <summary>
        /// Registers the collapse expand client script.
        /// </summary>
        private void RegisterCollapseExpandClientScript()
        {
            StringBuilder script = new StringBuilder(File.ReadAllText(Path.Combine(ApplicationAdapter.GetDataFilesMapPath(), "CollapseExpandScript.template")));

            script.Replace("[RootCookieName]", ApplicationAdapter.GetSiteName());
            ClientScriptManager scriptManager = this.ClientScript;
            Type typeToUse = this.GetType();

            if (!scriptManager.IsStartupScriptRegistered("CollapseExpandScript"))
            {
                // register
                scriptManager.RegisterStartupScript(typeToUse, "CollapseExpandScript", script.ToString(), true);
            }
        }
Example #5
0
        /// <summary>
        /// Gets the user preference DefaultNumberOfMessagesPerPage for the current user
        /// </summary>
        /// <returns>the default # of messages per page as set by this user.</returns>
        public static int GetUserDefaultNumberOfMessagesPerPage()
        {
            UserEntity user = GetUserObject();

            if (user != null)
            {
                int toReturn = user.DefaultNumberOfMessagesPerPage;
                if (toReturn <= 0)
                {
                    return(ApplicationAdapter.GetMaxAmountMessagesPerPage());
                }
                else
                {
                    return(toReturn);
                }
            }

            return(ApplicationAdapter.GetMaxAmountMessagesPerPage());
        }
Example #6
0
        /// <summary>
        /// Cache validator routine.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="data"></param>
        /// <param name="status"></param>
        public void Validate(HttpContext context, Object data, ref HttpValidationStatus status)
        {
            // get flag
            Hashtable cacheFlags = ApplicationAdapter.GetCacheFlags();

            bool isValid = true;

            if (cacheFlags.ContainsKey(_forum.ForumID))
            {
                isValid = (bool)cacheFlags[_forum.ForumID];
            }

            if (isValid)
            {
                status = HttpValidationStatus.Valid;
            }
            else
            {
                status = HttpValidationStatus.Invalid;
            }
        }
Example #7
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Hashtable noiseWords  = ApplicationAdapter.GetNoiseWords();
                ArrayList sortedWords = new ArrayList(noiseWords.Keys);
                sortedWords.Sort();
                StringBuilder[] wordLists = new StringBuilder[5];
                for (int i = 0; i < 5; i++)
                {
                    wordLists[i] = new StringBuilder();
                }

                int numWords = sortedWords.Count;
                int colSize  = numWords / 5;

                for (int i = 0; i < colSize; i++)
                {
                    wordLists[0].AppendFormat("{0}<br>", sortedWords[i]);
                    wordLists[1].AppendFormat("{0}<br>", sortedWords[i + colSize]);
                    wordLists[2].AppendFormat("{0}<br>", sortedWords[i + (colSize * 2)]);
                    wordLists[3].AppendFormat("{0}<br>", sortedWords[i + (colSize * 3)]);
                    wordLists[4].AppendFormat("{0}<br>", sortedWords[i + (colSize * 4)]);
                }

                int rest = numWords - (5 * colSize);               // at least 0, at most 4

                for (int i = 1; i <= rest; i++)
                {
                    wordLists[i - 1].AppendFormat("{0}<br>", sortedWords[(i - 1) + (colSize * 5)]);
                }

                lblWordList1.Text = wordLists[0].ToString();
                lblWordList2.Text = wordLists[1].ToString();
                lblWordList3.Text = wordLists[2].ToString();
                lblWordList4.Text = wordLists[3].ToString();
                lblWordList5.Text = wordLists[4].ToString();
            }
        }
Example #8
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string banComplainAddress = ApplicationAdapter.GetIPBanComplainEmailAddress();
                lnkBanComplaintEmailAddress.Text         = banComplainAddress;
                lnkBanComplaintEmailAddress.NavigateUrl += banComplainAddress;

                // get the set of IP-bans for the given IP address
                string      ipAddressUser = Request.UserHostAddress;
                IPBanEntity matchingBan   = SecurityGuiHelper.GetIPBanMatchingUserIPAddress(CacheManager.GetAllIPBans(), ipAddressUser);

                if (matchingBan != null)
                {
                    // has to match a ban
                    lblIPBanDate.Text  = matchingBan.IPBanSetOn.ToString("dd-MMM-yyyy HH:mm:ss");
                    lblIPBanRange.Text = string.Format("{0}.{1}.{2}.{3} / {4}", matchingBan.IPSegment1, matchingBan.IPSegment2, matchingBan.IPSegment3,
                                                       matchingBan.IPSegment4, matchingBan.Range);
                    lblIPBanReason.Text = matchingBan.Reason;
                }
            }
        }
Example #9
0
        protected void PostMessageHandler(object sender, System.EventArgs e)
        {
            int userID    = SessionAdapter.GetUserID();
            int messageID = 0;
            // store the new message as a new thread in the current forum.
            bool isSticky = meMessageEditor.IsSticky;

            if (!_userCanCreateNormalThreads && _userCanCreateStickyThreads)
            {
                // always sticky
                isSticky = true;
            }
            int threadID = ForumManager.CreateNewThreadInForum(_forum.ForumID, userID, meMessageEditor.NewThreadSubject,
                                                               meMessageEditor.MessageText, meMessageEditor.MessageTextHTML, isSticky,
                                                               Request.UserHostAddress.ToString(), _forum.DefaultSupportQueueID, meMessageEditor.SubscribeToThread, out messageID);

            // invalidate forum RSS in cache
            ApplicationAdapter.InvalidateCachedForumRSS(_forum.ForumID);

            if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditNewThread))
            {
                SecurityManager.AuditNewThread(userID, threadID);
            }

            // invalidate Forum in ASP.NET cache
            CacheManager.InvalidateCachedItem(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, _forum.ForumID));

            if (meMessageEditor.AddAttachment)
            {
                // go to attachment management.
                Response.Redirect(string.Format("Attachments.aspx?SourceType=2&MessageID={0}", messageID), true);
            }
            else
            {
                // all ok, redirect to thread list
                Response.Redirect("Threads.aspx?ForumID=" + _forum.ForumID, true);
            }
        }
Example #10
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)
        {
            _siteName = HttpUtility.HtmlEncode(ApplicationAdapter.GetSiteName());

            int forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]);

            _forum = CacheManager.GetForum(forumID);
            if ((_forum != null) && _forum.HasRSSFeed)
            {
                _forumURL = "http://" + Request.Url.Host + ApplicationAdapter.GetVirtualRoot() + String.Format(@"Threads.aspx?ForumID={0}", forumID);

                // get the messages
                ForumMessagesTypedList messages = ForumGuiHelper.GetLastPostedMessagesInForum(10, forumID);
                rptRSS.DataSource = messages;
                rptRSS.DataBind();

                Response.Cache.SetExpires(DateTime.Now.AddDays(7));
                Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.Cache.SetValidUntilExpires(true);
                Response.Cache.VaryByParams["ForumID"] = true;
                Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(Validate), null);
            }
        }
Example #11
0
        protected void rptRSS_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
            case ListItemType.AlternatingItem:
            case ListItemType.Item:
                DataRowView currentRow = (DataRowView)e.Item.DataItem;
                string      nickName   = currentRow["NickName"].ToString();
                string      message    = currentRow["MessageTextAsHTML"].ToString();
                string      subject    = currentRow["Subject"].ToString();
                Literal     title      = (Literal)e.Item.FindControl("title");
                title.Text = HttpUtility.HtmlEncode(String.Format("{0} by {1}", subject, nickName));

                Literal description = (Literal)e.Item.FindControl("description");
                description.Text = HttpUtility.HtmlEncode(message);

                Literal link           = (Literal)e.Item.FindControl("itemLink");
                int     threadID       = (int)currentRow["ThreadID"];
                int     messageID      = (int)currentRow["MessageID"];
                int     startAtMessage = ThreadGuiHelper.GetStartAtMessageForGivenMessageAndThread(threadID, messageID, ApplicationAdapter.GetMaxAmountMessagesPerPage());
                link.Text = HttpUtility.HtmlEncode("http://" + Request.Url.Host + ApplicationAdapter.GetVirtualRoot() + String.Format(@"Messages.aspx?ThreadID=" + threadID + "&StartAtMessage=" + startAtMessage + "#" + messageID));

                Literal permaLink = (Literal)e.Item.FindControl("permaLink");
                permaLink.Text = link.Text;

                Literal pubDate = (Literal)e.Item.FindControl("pubDate");
                pubDate.Text = String.Format("{0:R}", ((DateTime)currentRow["PostingDate"]).AddHours(-2));

                Literal author = (Literal)e.Item.FindControl("author");
                author.Text = nickName;

                Literal category = (Literal)e.Item.FindControl("threadName");
                category.Text = HttpUtility.HtmlEncode(subject);
                break;
            }
        }
Example #12
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);
            }

            _startAtMessageIndex = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]);
            _quoteMessageID      = HnDGeneralUtils.TryConvertToInt(Request.QueryString["QuoteMessageID"]);

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

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

            // Check if the current user is allowed to add new messages to the thread.
            bool userMayAddNewMessages = false;

            if (!_thread.IsClosed)
            {
                if (_thread.IsSticky)
                {
                    if (SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessageInSticky))
                    {
                        userMayAddNewMessages = true;
                    }
                }
                else
                {
                    if (SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessage))
                    {
                        userMayAddNewMessages = true;
                    }
                }
            }

            if (!userMayAddNewMessages)
            {
                // is not allowed to post a new message
                Response.Redirect("Messages.aspx?ThreadID=" + threadID, true);
            }

            // use BL class. We could have used Lazy loading, though for the sake of separation, we'll call into the BL class.
            ForumEntity forum = CacheManager.GetForum(_thread.ForumID);

            if (forum == null)
            {
                // orphaned thread
                Response.Redirect("default.aspx");
            }

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

            meMessageEditor.ShowAddAttachment = ((forum.MaxNoOfAttachmentsPerMessage > 0) &&
                                                 SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment));
            meMessageEditor.ShowSubscribeToThread = !UserGuiHelper.CheckIfThreadIsAlreadySubscribed(SessionAdapter.GetUserID(), _thread.ThreadID);

            // User is able to post a new message to the current thread.
            if (!Page.IsPostBack)
            {
                // fill the page's content
                lnkThreads.Text               = HttpUtility.HtmlEncode(forum.ForumName);
                lnkThreads.NavigateUrl       += "?ForumID=" + _thread.ForumID;
                meMessageEditor.ForumName     = forum.ForumName;
                meMessageEditor.ThreadSubject = _thread.Subject;
                lblSectionName.Text           = CacheManager.GetSectionName(forum.SectionID);
                lnkMessages.NavigateUrl      += threadID;
                lnkMessages.Text              = HttpUtility.HtmlEncode(_thread.Subject);
                phLastPostingInThread.Visible = (_quoteMessageID <= 0);

                bool userMayEditMemo = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo);

                // get quoted message if passed in.
                if (_quoteMessageID > 0)
                {
                    // get message and insert it into the textbox including quote tags.
                    MessageEntity messageToQuote = MessageGuiHelper.GetMessage(_quoteMessageID);
                    if (messageToQuote != null)
                    {
                        // message found.
                        UserEntity quotedUser = UserGuiHelper.GetUser(messageToQuote.PostedByUserID);
                        if (quotedUser != null)
                        {
                            // user found. proceed
                            meMessageEditor.OriginalMessageText = TextParser.MakeStringQuoted(messageToQuote.MessageText, quotedUser.NickName);
                        }
                    }
                }
                else
                {
                    // no quoted message. Load the last message from the active thread and display it in the form. This
                    // message entity has the poster user entity prefetched, together with the usertitle of the user.
                    MessageEntity lastMessageInThread = ThreadGuiHelper.GetLastMessageInThreadWithUserInfo(threadID);
                    if (lastMessageInThread != null)
                    {
                        litMessageBody.Text = lastMessageInThread.MessageTextAsHTML;
                        lblPostingDate.Text = lastMessageInThread.PostingDate.ToString("dd-MMM-yyyy HH:mm:ss");
                        if (lastMessageInThread.PostedByUser != null)
                        {
                            UserEntity messagePoster = lastMessageInThread.PostedByUser;
                            if (messagePoster.UserTitle != null)
                            {
                                lblUserTitleDescription.Text = messagePoster.UserTitle.UserTitleDescription;
                            }
                            lblLocation.Text = messagePoster.Location;
                            if (messagePoster.JoinDate.HasValue)
                            {
                                lblJoinDate.Text = messagePoster.JoinDate.Value.ToString("dd-MMM-yyyy HH:mm:ss");
                            }
                            if (messagePoster.AmountOfPostings.HasValue)
                            {
                                lblAmountOfPostings.Text = messagePoster.AmountOfPostings.Value.ToString();
                            }
                            if (messagePoster.SignatureAsHTML != null)
                            {
                                litSignature.Text = messagePoster.SignatureAsHTML;
                            }
                            lblNickname.Text = messagePoster.NickName;
                        }
                    }
                }

                if ((_thread.Memo.Length > 0) && userMayEditMemo)
                {
                    // convert memo contents to HTML so it's displayed above the thread.
                    string parserLog, messageTextXml;
                    bool   errorsOccured = false;
                    string memoAsHTML    = TextParser.TransformUBBMessageStringToHTML(_thread.Memo, ApplicationAdapter.GetParserData(), out parserLog, out errorsOccured, out messageTextXml);
                    lblMemo.Text = memoAsHTML;
                }
                phMemo.Visible = userMayEditMemo;
            }
        }
Example #13
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();
        }
Example #14
0
        /// <summary>
        /// Event handler for PostMessage. This message is bubbled up
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnPostMessage(EventArgs e)
        {
            if (Page.IsValid)
            {
                if (!_allowEmptyMessage || (tbxMessage.Text.Length > 0))
                {
                    _messageText      = tbxMessage.Text;
                    _messageTextHTML  = TextParser.TransformUBBMessageStringToHTML(_messageText, ApplicationAdapter.GetParserData(), out _parserLog, out _parserErrorsOccured, out _messageTextXML);
                    _isSticky         = chkIsSticky.Checked;
                    _newThreadSubject = tbxSubject.Value.Replace("<", "&lt;");
                }

                // bubble the message through the eventhandler chain
                if (PostMessage != null)
                {
                    PostMessage(this, e);
                }
            }
        }
Example #15
0
 /// <summary>
 /// Event handler for PreviewMessage
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnPreviewMessage(EventArgs e)
 {
     if (Page.IsValid)
     {
         lblPreviewBody.Text     = TextParser.TransformUBBMessageStringToHTML(tbxMessage.Text, ApplicationAdapter.GetParserData(), out _parserLog, out _parserErrorsOccured, out _messageTextXML);
         lblPreviewPostedOn.Text = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
         phPreviewRow.Visible    = true;
     }
 }
Example #16
0
        private void btnUpdate_ServerClick(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                // user has filled in the right values, update the user's data.
                string   nickName             = string.Empty;
                DateTime?dateOfBirth          = null;
                string   emailAddress         = string.Empty;
                bool     emailAddressIsPublic = false;
                string   iconURL                = string.Empty;
                string   ipNumber               = string.Empty;
                string   location               = string.Empty;
                string   occupation             = string.Empty;
                string   password               = string.Empty;
                string   signature              = string.Empty;
                string   website                = string.Empty;
                bool     autoSubscribeThreads   = true;
                short    defaultMessagesPerPage = 10;

                if (tbxPassword1.Value.Length > 0)
                {
                    password = tbxPassword1.Value;
                }

                emailAddress = tbxEmailAddress.Value;
                iconURL      = tbxIconURL.Value;

                if (tbxDateOfBirth.Value.Length > 0)
                {
                    try
                    {
                        dateOfBirth = System.DateTime.Parse(tbxDateOfBirth.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                    }
                    catch (FormatException)
                    {
                        // format exception, date invalid, ignore, will resolve to default.
                    }
                }

                emailAddressIsPublic = !chkEmailAddressIsHidden.Checked;
                location             = tbxLocation.Value;
                occupation           = tbxOccupation.Value;
                signature            = tbxSignature.Value;
                website = tbxWebsite.Value;

                //Preferences
                autoSubscribeThreads = chkAutoSubscribeToThread.Checked;
                if (tbxDefaultNumberOfMessagesPerPage.Value.Length > 0)
                {
                    defaultMessagesPerPage = HnDGeneralUtils.TryConvertToShort(tbxDefaultNumberOfMessagesPerPage.Value);
                }

                bool result = UserManager.UpdateUserProfile(SessionAdapter.GetUserID(), dateOfBirth, emailAddress, emailAddressIsPublic, iconURL, location, occupation, password,
                                                            signature, website, SessionAdapter.GetUserTitleID(), ApplicationAdapter.GetParserData(), autoSubscribeThreads, defaultMessagesPerPage);

                if (result)
                {
                    // get user back and update session object.
                    UserEntity user = UserGuiHelper.GetUser(SessionAdapter.GetUserID());
                    if (user != null)
                    {
                        SessionAdapter.AddUserObject(user);
                    }
                    // all ok
                    Response.Redirect("EditProfileSuccessful.aspx", true);
                }
            }
        }
Example #17
0
        /// <summary>
        /// Handles the click event on the register button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRegister_ServerClick(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                string nickName = HttpUtility.HtmlEncode(tbxNickName.Value);

                // check if the nickname is already taken.
                bool nickNameAlreadyExists = UserGuiHelper.CheckIfNickNameExists(nickName);
                if (nickNameAlreadyExists)
                {
                    // already exists
                    lblNickNameError.Visible = true;
                }
                else
                {
                    // doesn't exist. Form is valid, so write the data into the database.
                    DateTime?dateOfBirth          = null;
                    string   emailAddress         = string.Empty;
                    bool     emailAddressIsPublic = false;
                    string   iconURL                = string.Empty;
                    string   ipNumber               = string.Empty;
                    string   location               = string.Empty;
                    string   occupation             = string.Empty;
                    string   password               = string.Empty;
                    string   signature              = string.Empty;
                    string   website                = string.Empty;
                    bool     autoSubscribeThreads   = true;
                    short    defaultMessagesPerPage = 10;

                    if (tbxDateOfBirth.Value.Length > 0)
                    {
                        try
                        {
                            dateOfBirth = System.DateTime.Parse(tbxDateOfBirth.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                        }
                        catch (FormatException)
                        {
                            // format exception, date invalid, ignore, will resolve to the default : null
                        }
                    }

                    emailAddress         = tbxEmailAddress.Value;
                    emailAddressIsPublic = !chkEmailAddressIsHidden.Checked;
                    if (tbxIconURL.Value.Length > 0)
                    {
                        iconURL = tbxIconURL.Value;
                    }
                    ipNumber = lblIPNumber.Text;
                    if (tbxLocation.Value.Length > 0)
                    {
                        location = tbxLocation.Value;
                    }
                    if (tbxOccupation.Value.Length > 0)
                    {
                        occupation = tbxOccupation.Value;
                    }

                    if (tbxSignature.Value.Length > 0)
                    {
                        signature = tbxSignature.Value;
                    }
                    if (tbxWebsite.Value.Length > 0)
                    {
                        website = tbxWebsite.Value;
                    }

                    //Preferences
                    autoSubscribeThreads = chkAutoSubscribeToThread.Checked;
                    if (tbxDefaultNumberOfMessagesPerPage.Value.Length > 0)
                    {
                        defaultMessagesPerPage = HnDGeneralUtils.TryConvertToShort(tbxDefaultNumberOfMessagesPerPage.Value);
                    }

                    // add it
                    string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.RegistrationReply);
                    int    userID       = UserManager.RegisterNewUser(nickName, dateOfBirth, emailAddress, emailAddressIsPublic, iconURL, ipNumber, location,
                                                                      occupation, signature, website, mailTemplate, ApplicationAdapter.GetEmailData(), ApplicationAdapter.GetParserData(), autoSubscribeThreads, defaultMessagesPerPage);

                    Response.Redirect("registrationsuccessful.aspx", true);
                }
            }
        }
Example #18
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 start page
                Response.Redirect("default.aspx");
            }

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

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

            _startMessageNo = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]);
            bool highLightSearchResults = (HnDGeneralUtils.TryConvertToInt(Request.QueryString["HighLight"]) == 1);

            if (!_thread.IsClosed)
            {
                if (_thread.IsSticky)
                {
                    _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessageInSticky);
                }
                else
                {
                    _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessage);
                }
                // set show*link class members. These have to be set despite the postback status, as they're used in the repeater. Only set
                // them to true if the thread isn't closed. They've been initialized to false already.
                _showEditMessageLink   = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditDeleteOtherUsersMessages);
                _showDeleteMessageLink = _showEditMessageLink;
                _showQuoteMessageLink  = _userMayAddNewMessages;
            }

            // show user IP addresses if the user has system admin rights, security admin rights or user admin rights.
            _showIPAddresses = (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement) ||
                                SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement) ||
                                SessionAdapter.HasSystemActionRight(ActionRights.UserManagement));
            // Get the forum entity related to the thread. Use BL class. We could have used Lazy loading, though for the sake of separation, we'll
            // call into the BL class.
            ForumEntity forum = CacheManager.GetForum(_thread.ForumID);

            if (forum == null)
            {
                // not found, orphaned thread, return to default page.
                Response.Redirect("default.aspx");
            }
            _forumAllowsAttachments = (forum.MaxNoOfAttachmentsPerMessage > 0);

            // 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);
            }

            _threadStartedByCurrentUser = (_thread.StartedByUserID == SessionAdapter.GetUserID());
            _userMayAddAttachments      = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment);
            _userCanCreateThreads       = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddNormalThread) ||
                                          SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddStickyThread);
            _userMayDoForumSpecificThreadManagement = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ForumSpecificThreadManagement);
            _userMayDoSystemWideThreadManagement    = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement);
            _userMayEditMemo                   = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo);
            _userMayMarkThreadAsDone           = (SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.FlagThreadAsDone) || _threadStartedByCurrentUser);
            _userMayManageSupportQueueContents = SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement);
            _userMayDoBasicThreadOperations    = (SessionAdapter.GetUserID() > 0);

            if (!Page.IsPostBack)
            {
                plPageListBottom.HighLight = highLightSearchResults;
                plPageListTop.HighLight    = highLightSearchResults;
                litHighLightLogic.Visible  = highLightSearchResults;

                if (highLightSearchResults)
                {
                    // make highlighting of search results possible
                    string searchTerms = SessionAdapter.GetSearchTerms();
                    if (searchTerms == null)
                    {
                        searchTerms = string.Empty;
                    }
                    this.ClientScript.RegisterHiddenField("searchTerms", searchTerms.Replace("AND", "").Replace("OR", "").Replace("and", "").Replace("or", "").Replace("\"", ""));
                }
                else
                {
                    // replace hightlighting scriptblock.
                    this.ClientScript.RegisterClientScriptBlock(this.GetType(), "onLoad", "<script language=\"javascript\"  type=\"text/javascript\">function SearchHighlight() {}</script>");
                }

                if (_userMayManageSupportQueueContents)
                {
                    // fill support queue management area with data.
                    SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues();
                    cbxSupportQueues.DataSource = supportQueues;
                    cbxSupportQueues.DataBind();

                    SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(_thread.ThreadID);
                    if (containingQueue != null)
                    {
                        cbxSupportQueues.SelectedValue = containingQueue.QueueID.ToString();
                        // get claim info
                        SupportQueueThreadEntity supportQueueThreadInfo = SupportQueueGuiHelper.GetSupportQueueThreadInfo(_thread.ThreadID, true);
                        if ((supportQueueThreadInfo != null) && supportQueueThreadInfo.ClaimedByUserID.HasValue)
                        {
                            // claimed by someone
                            lblClaimDate.Text             = supportQueueThreadInfo.ClaimedOn.Value.ToString("dd-MMM-yyyy HH:mm.ss", DateTimeFormatInfo.InvariantInfo);
                            lnkClaimerThread.Visible      = true;
                            lblNotClaimed.Visible         = false;
                            lnkClaimerThread.Text         = supportQueueThreadInfo.ClaimedByUser.NickName;
                            lnkClaimerThread.NavigateUrl += supportQueueThreadInfo.ClaimedByUserID.ToString();
                            btnClaim.Visible              = false;
                            btnRelease.Visible            = true;
                        }
                        else
                        {
                            // not claimed
                            lblClaimDate.Text  = string.Empty;
                            btnClaim.Visible   = true;
                            btnRelease.Visible = false;
                        }
                    }
                }
                phSupportQueueManagement.Visible = _userMayManageSupportQueueContents;

                if ((_thread.Memo.Length > 0) && _userMayEditMemo)
                {
                    // convert memo contents to HTML so it's displayed above the thread.
                    string parserLog, messageTextXml;
                    bool   errorsOccured = false;
                    string memoAsHTML    = TextParser.TransformUBBMessageStringToHTML(_thread.Memo, ApplicationAdapter.GetParserData(), out parserLog, out errorsOccured, out messageTextXml);
                    lblMemo.Text = memoAsHTML;
                }
                phMemo.Visible = _userMayEditMemo;

                bool isBookmarked = UserGuiHelper.CheckIfThreadIsAlreadyBookmarked(SessionAdapter.GetUserID(), threadID);
                bool isSubscribed = UserGuiHelper.CheckIfThreadIsAlreadySubscribed(SessionAdapter.GetUserID(), threadID);
                btnBookmarkThread.Visible   = !isBookmarked && _userMayDoBasicThreadOperations;
                btnUnbookmarkThread.Visible = isBookmarked && _userMayDoBasicThreadOperations;
                bool sendReplyNotifications = CacheManager.GetSystemData().SendReplyNotifications;
                btnSubscribeToThread.Visible     = !isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications;
                btnUnsubscribeFromThread.Visible = isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications;

                // fill the page's content
                lnkThreads.Text          = HttpUtility.HtmlEncode(forum.ForumName);
                lnkThreads.NavigateUrl  += "?ForumID=" + _thread.ForumID;
                lblForumName_Header.Text = forum.ForumName;
                lblSectionName.Text      = CacheManager.GetSectionName(forum.SectionID);

                // Check if the current user is allowed to add new messages to the thread.

                // these controls are not visible by default, show them if necessary
                if (_userMayDoForumSpecificThreadManagement || _userMayDoSystemWideThreadManagement)
                {
                    if (!_thread.IsClosed && _userMayAddNewMessages)
                    {
                        lnkCloseThread.Visible      = true;
                        lnkCloseThread.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo;
                    }
                    lnkEditThreadProperties.Visible      = true;
                    lnkEditThreadProperties.NavigateUrl += "?ThreadID=" + threadID;
                }

                if (_userMayDoSystemWideThreadManagement)
                {
                    lnkMoveThread.Visible        = true;
                    lnkMoveThread.NavigateUrl   += "?ThreadID=" + threadID;
                    lnkDeleteThread.Visible      = true;
                    lnkDeleteThread.NavigateUrl += "?ThreadID=" + threadID;
                }

                btnThreadDone.Visible    = _thread.MarkedAsDone;
                btnThreadNotDone.Visible = !_thread.MarkedAsDone;
                btnThreadDone.Enabled    = _userMayMarkThreadAsDone;
                btnThreadNotDone.Enabled = _userMayMarkThreadAsDone;

                if (_userMayEditMemo)
                {
                    lnkEditMemo.Visible      = true;
                    lnkEditMemo.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo;
                }

                // These controls are visible by default. Hide them when the user can't create threads on this forum
                if (_userCanCreateThreads)
                {
                    lnkNewThreadBottom.NavigateUrl += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo;
                    lnkNewThreadTop.NavigateUrl    += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo;
                }
                else
                {
                    lnkNewThreadBottom.Visible = false;
                    lnkNewThreadTop.Visible    = false;
                }

                if (_userMayAddNewMessages)
                {
                    lnkNewMessageBottom.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo;
                    lnkNewMessageTop.NavigateUrl    += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo;
                }
                else
                {
                    lnkNewMessageBottom.Visible = false;
                    lnkNewMessageTop.Visible    = false;
                }
                lblSeparatorTop.Visible    = (_userMayAddNewMessages && _userCanCreateThreads);
                lblSeparatorBottom.Visible = (_userMayAddNewMessages && _userCanCreateThreads);

                // The amount of postings in this thread are in the dataview row, which should contain just 1 row.
                int maxAmountMessagesPerPage = SessionAdapter.GetUserDefaultNumberOfMessagesPerPage();
                int amountOfMessages         = ThreadGuiHelper.GetTotalNumberOfMessagesInThread(threadID);
                int amountOfPages            = ((amountOfMessages - 1) / maxAmountMessagesPerPage) + 1;
                int currentPageNo            = (_startMessageNo / maxAmountMessagesPerPage) + 1;
                lblCurrentPage.Text = currentPageNo.ToString();
                lblTotalPages.Text  = amountOfPages.ToString();

                lnkPrintThread.NavigateUrl += "?ThreadID=" + threadID;

                plPageListBottom.AmountMessages = amountOfMessages;
                plPageListBottom.StartMessageNo = _startMessageNo;
                plPageListBottom.ThreadID       = threadID;
                plPageListTop.AmountMessages    = amountOfMessages;
                plPageListTop.StartMessageNo    = _startMessageNo;
                plPageListTop.ThreadID          = threadID;

                // Get messages and bind it to the repeater control. Use the startmessage to get only the message visible on the current page.
                MessagesInThreadTypedList messages = ThreadGuiHelper.GetAllMessagesInThreadAsTypedList(threadID, currentPageNo, maxAmountMessagesPerPage);
                rptMessages.DataSource = messages;
                rptMessages.DataBind();
            }
        }