Example #1
0
        // *********************************************************************
        //  CreateChildControls
        //
        /// <summary>
        /// This event handler adds the children controls.
        /// </summary>
        //
        // ********************************************************************/
        protected override void CreateChildControls()
        {
            if (this.CheckUserPermissions && !((User)Users.GetUserInfo(Context.User.Identity.Name, true)).IsAdministrator)
            {
                // this user isn't an administrator
                Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnableToAdminister));
            }

            // make sure we have a ForumID
            if (ForumID == -1)
            {
                throw new Exception("You must pass in a valid ForumID in order to use the EditForum control.");
            }

            // create an instance of the CreateEditForum Web control
            editForum.ForumID = ForumID;
            editForum.Mode    = CreateEditForumMode.EditForum;
            Controls.Add(editForum);

            Panel panelModerators = new Panel();

            panelModerators.ID = "panelModerators";

            // add a separator
            panelModerators.Controls.Add(new LiteralControl(this.Separator));

            // add the list of users who moderate this forum
            moderatedForums.Mode    = ModeratedForumMode.ViewForForum;
            moderatedForums.ForumID = ForumID;
            panelModerators.Controls.Add(moderatedForums);

            // add the panel
            Controls.Add(panelModerators);

            // add a separator
            Controls.Add(new LiteralControl(this.Separator));

            // do we want to show the posts in the forum?
            if (ShowPostsInForum)
            {
                // add the label
                Label lblTmp = new Label();
                lblTmp.CssClass = "head";
                lblTmp.Text     = PostDisplayTitle + Globals.HtmlNewLine;
                Controls.Add(lblTmp);

                // add the listing of posts
                postListing.ForumID = ForumID;
                Controls.Add(this.postListing);
            }
            else
            {
                // add a hyperlink to the posts to edit
                HyperLink lnkTmp = new HyperLink();
                lnkTmp.Text        = "View the posts for this forum...";
                lnkTmp.CssClass    = "normalItalic";
                lnkTmp.NavigateUrl = Globals.UrlShowForumPostsForAdmin + ForumID.ToString();
                Controls.Add(lnkTmp);
            }
        }
Example #2
0
        public override int GetHashCode()
        {
            int hash = GetType().GetHashCode();

            hash = (hash * 397) ^ UserID.GetHashCode();
            hash = (hash * 397) ^ ForumID.GetHashCode();

            return(hash);
        }
        /***********************************************************************
         * // PostButton_Click
         * //
         * /// <summary>
         * /// This event handler fires when the preview button is clicked.  It needs
         * /// to show/hide the appropriate panels.
         * /// </summary>
         * /// <param name="sender"></param>
         * /// <param name="e"></param>
         ************************************************************************/
        private void PostButton_Click(Object sender, EventArgs e)
        {
            Control form;

            // Only proceed if the post is valid
            if (!Page.IsValid)
            {
                return;
            }

            // Get the user control that the click originated from
            form = ((Control)sender).Parent;

            // When we add a new post, we want to get back the NewPostID, so that we
            // can automagically redirect the user to the page showing the post.
            // If iNewPostID comes back as 0, though, that means that the post needs
            // to be approved first, so the user is taken to a page explaining this.
            Post newPost   = null;
            Post postToAdd = new Post();

            postToAdd.Username = Context.User.Identity.Name;
            postToAdd.ForumID  = postToAdd.ParentID = 0;
            postToAdd.Subject  = ((TextBox)form.FindControl("PostSubject")).Text;
            postToAdd.Body     = ((TextBox)form.FindControl("PostBody")).Text;
            postToAdd.IsLocked = allowNoReplies.Checked;

            // Are we in edit mode?

            /*
             * if (Mode == CreateEditPostMode.EditPost) {
             *  string editNotes = CreateEditNotes(form);
             *  postToAdd.Body = editNotes + postToAdd.Body;
             * }
             */

            // Are we pinning the post?
            if ((pinnedPost != null) && (Convert.ToInt32(pinnedPost.SelectedItem.Value) > 0))
            {
                switch (Convert.ToInt32(pinnedPost.SelectedItem.Value))
                {
                case 1:
                    postToAdd.PostDate = DateTime.Now.Date.AddDays(1);
                    break;

                case 3:
                    postToAdd.PostDate = DateTime.Now.Date.AddDays(3);
                    break;

                case 7:
                    postToAdd.PostDate = DateTime.Now.Date.AddDays(7);
                    break;

                case 14:
                    postToAdd.PostDate = DateTime.Now.Date.AddDays(14);
                    break;

                case 30:
                    postToAdd.PostDate = DateTime.Now.Date.AddMonths(1);
                    break;

                case 90:
                    postToAdd.PostDate = DateTime.Now.Date.AddMonths(3);
                    break;

                case 180:
                    postToAdd.PostDate = DateTime.Now.Date.AddMonths(6);
                    break;

                case 360:
                    postToAdd.PostDate = DateTime.Now.Date.AddYears(1);
                    break;

                case 999:
                    postToAdd.PostDate = DateTime.Now.Date.AddYears(25);
                    break;
                }
            }

            // Are we adding a new post, editing an existing one, or replying to an existing one?
            switch (Mode)
            {
            case CreateEditPostMode.NewPost:            // adding a new post
                postToAdd.ForumID = ForumID;            // specify the forum ID that the new post belongs

                try {
                    newPost = Posts.AddPost(postToAdd);
                }
                catch (PostDuplicateException) {
                    Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.DuplicatePost) + "&ForumId=" + ForumID);
                    Context.Response.End();
                }
                break;

            case CreateEditPostMode.ReplyToPost:        // replying to an existing post
                try {
//                        if (postView == ViewOptions.Threaded) {
                    postToAdd.ParentID = PostID;                                // specify the post we are replying to
//                        } else {
//                            postRepliedTo = Posts.GetPost(PostID, user.Username);
//                            postToAdd.ParentID = postRepliedTo.ThreadID;
//                        }

                    newPost = Posts.AddPost(postToAdd);
                }
                catch (Components.PostNotFoundException) {
                    // uh-oh, something is off... are we replying to a message that has been deleted?
                    Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.ProblemPosting));
                    Context.Response.End();
                }
                catch (PostDuplicateException) {
                    Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.DuplicatePost) + "&PostId=" + PostID);
                    Context.Response.End();
                }
                break;

            case CreateEditPostMode.EditPost:
                postToAdd.PostID = PostID;                      // specify the ID of the post we are updating
                string editedBy = Users.GetLoggedOnUser().Username;

                // update the post
                Posts.UpdatePost(postToAdd, editedBy);

                // send the user back to from where they came
                Context.Response.Redirect(RedirectURL);
                Context.Response.End();

                // exit from the event handler
                return;
            }

            // now that we've added the post, redirect the user to the post display (if the post
            // has been approved)
            if (newPost.Approved)
            {
                if (Mode == CreateEditPostMode.NewPost)
                {
                    Context.Response.Redirect(Globals.UrlShowPost + newPost.ThreadID);
                }
                else
                {
                    Context.Response.Redirect(Globals.UrlShowPost + newPost.ThreadID + "#" + newPost.PostID);
                }
                Context.Response.End();
            }
            else
            {
                // if the post HASN'T been approved, send the user to an explanation page, passing along the Post or ForumID
                String strRedirect = Globals.UrlMessage + Convert.ToInt32(Messages.PostPendingModeration);

                if (ForumID > 0)
                {
                    Context.Response.Redirect(strRedirect + "&ForumID=" + ForumID.ToString());
                }
                else
                {
                    Context.Response.Redirect(strRedirect + "&PostID=" + PostID.ToString());
                }
            }
        }
Example #4
0
 /// <summary>
 /// On insert.
 /// </summary>
 private void ForumNewPost1_OnInsertPost(object sender, EventArgs e)
 {
     ltlScript.Text += ScriptHelper.GetScript("parent.frames['posts_tree'].location.href = 'ForumPost_Tree.aspx?postid=" + PostEdit1.EditPostID + "&forumid=" + ForumID.ToString() + "';");
     ltlScript.Text += ScriptHelper.GetScript("parent.frames['posts_edit'].location.href = 'ForumPost_View.aspx?postid=" + PostEdit1.EditPostID + mListingParameter + "';");
 }
        // *********************************************************************
        //
        //  PostAction_Click Event Handler
        //
        /// <summary>
        /// This event handler fires when the user clicks one of the two ImageButtons
        /// (edit/delete) or when the user clicks the "Confirm Delete" button in
        ///	the Confirm Delete panel.  Appropriate action is taken based upon
        ///	the user's command.
        ///	</summary>
        //
        // ********************************************************************/
        private void PostAction_Click(Object sender, CommandEventArgs e)
        {
            // Read in the postID
            int iPostID = Convert.ToInt32(e.CommandArgument);

            // Decide what action to take
            switch (e.CommandName)
            {
            // Edit the post, so send the user to the proper URL
            case "edit":
                Context.Response.Redirect(Globals.UrlEditPostFromAdmin + iPostID.ToString() + "&ForumID=" + ForumID.ToString());
                break;


            // Delete the post, hide/show the appropriate panels
            case "delete":
                ((Panel)FindControl("panelConfirmDelete")).Visible = true;
                ((Panel)FindControl("panelPosts")).Visible         = false;

                // set the Confirm Delete button's CommandArgument to the PostID passed in
                ((Button)FindControl("btnConfirmDelete")).CommandArgument = iPostID.ToString();
                break;

            // Delete the post
            case "confirmdelete":
                if (deletePostStyle.ShowReasonsForDeletingTextBox)
                {
                    Posts.DeletePost(iPostID, ((TextBox)FindControl("txtDeleteReason")).Text, "undone");
                }
                else
                {
                    Posts.DeletePost(iPostID, "undone", "undone");
                }

                // Show the posts
                ((Panel)FindControl("panelConfirmDelete")).Visible = false;
                ((Panel)FindControl("panelPosts")).Visible         = true;

                // rebind the data
                BindData();
                break;
            }
        }
Example #6
0
        // *********************************************************************
        //  Initializeskin
        //
        /// <summary>
        /// Initialize the control template and populate the control with values
        /// </summary>
        // ***********************************************************************/
        override protected void InitializeSkin(Control skin)
        {
            Label title;
            Label body;

            // Do some processing on the messages
            message.Body = message.Body.Replace("<UrlHome>", "<a href=\"" + Globals.UrlHome + "\">" + Globals.SiteName + " Home</a>");
            message.Body = message.Body.Replace("<UrlLogin>", "<a href=\"" + Globals.UrlLogin + "\">" + Globals.SiteName + " Login</a>");
            message.Body = message.Body.Replace("<UrlProfile>", "<a href=\"" + Globals.UrlEditUserProfile + "\">user profile</a>");

            // Handle duplicate post messages or moderation messages
            if ((message.Body.IndexOf("<DuplicatePost>") > 0) || (message.Body.IndexOf("<PendingModeration>") > 0))
            {
                if (ForumID > 0)
                {
                    message.Body = message.Body.Replace("<DuplicatePost>", "<a href=\"" + Globals.UrlShowForum + ForumID.ToString() + "\">" + "Return to forum</a>");
                    message.Body = message.Body.Replace("<PendingModeration>", "<a href=\"" + Globals.UrlShowForum + ForumID.ToString() + "\">" + "Return to forum</a>");
                }
                else if (PostID > 0)
                {
                    message.Body = message.Body.Replace("<DuplicatePost>", "<a href=\"" + Globals.UrlShowPost + PostID.ToString() + "\">" + "Return to post</a>");
                    message.Body = message.Body.Replace("<PendingModeration>", "<a href=\"" + Globals.UrlShowPost + PostID.ToString() + "\">" + "Return to post</a>");
                }
            }

            // Find the title
            title = (Label)skin.FindControl("MessageTitle");
            if (title != null)
            {
                title.Text = message.Title;
            }

            // Find the title
            body = (Label)skin.FindControl("MessageBody");
            if (body != null)
            {
                body.Text = message.Body;
            }
        }
        // *********************************************************************
        //  Initializeskin
        //
        /// <summary>
        /// Initialize the control template and populate the control with values
        /// </summary>
        // ***********************************************************************/
        override protected void InitializeSkin(Control skin)
        {
            // We require a post id value
            if (PostID == -1)
            {
                throw new AspNetForums.Components.PostNotFoundException("You must set the PostID property of this control to the post being moderated.");
            }

            // Find the controls in our control template.

            // Approve Post
            approvePost = (LinkButton)skin.FindControl("ApprovePost");
            if (null != approvePost)
            {
                approvePost.Command += new CommandEventHandler(ApprovePost_Click);
            }

            // Approve Post and turn off moderation for the user
            approvePostAndTurnOffModeration = (LinkButton)skin.FindControl("ApprovePostAndTurnOffModeration");
            if (null != approvePostAndTurnOffModeration)
            {
                approvePostAndTurnOffModeration.Command += new CommandEventHandler(ApprovePostAndTurnOffModeration_Click);
            }

            // Approve Post and reply to the message
            approvePostAndReply = (LinkButton)skin.FindControl("ApprovePostAndReply");
            if (null != approvePostAndReply)
            {
                approvePostAndReply.Command += new CommandEventHandler(ApprovePostAndReply_Click);
            }

            // Approve Post and Edit
            approvePostAndEdit = (LinkButton)skin.FindControl("ApprovePostAndEdit");
            if (null != approvePostAndEdit)
            {
                approvePostAndEdit.Command += new CommandEventHandler(ApprovePostAndEdit_Click);
            }

            // Turn off moderation for this user
            turnOffModerationForUser = (LinkButton)skin.FindControl("TurnOffModeration");
            if (null != turnOffModerationForUser)
            {
                turnOffModerationForUser.CommandArgument = UsernamePostedBy;
                turnOffModerationForUser.Command        += new CommandEventHandler(TurnOffModerationForUser_Command);
            }

            // Delete the post/thread
            deletePost = (HyperLink)skin.FindControl("DeletePost");
            if (null != deletePost)
            {
                // Go to the delete view
                deletePost.NavigateUrl = Globals.UrlDeletePost + PostID + "&ReturnURL=" + Page.Server.UrlEncode(Page.Request.RawUrl);
            }

            // Moderation History
            moderationHistory = (HyperLink)skin.FindControl("ModerationHistory");
            if (null != moderationHistory)
            {
                // Go to the delete view
                moderationHistory.NavigateUrl = Globals.UrlModerationHistory + PostID + "&ReturnURL=" + Page.Server.UrlEncode(Page.Request.RawUrl);
            }

            // Move the post/thread
            movePost = (HyperLink)skin.FindControl("MovePost");
            if (null != movePost)
            {
                if (ThreadID == PostID)
                {
                    movePost.NavigateUrl = Globals.UrlMovePost + PostID + "&ReturnURL=" + Page.Server.UrlEncode(HttpContext.Current.Request.RawUrl);
                }
                else
                {
                    movePost.Enabled = false;
                }
            }

            // Edit the post
            editPost = (HyperLink)skin.FindControl("EditPost");
            if (null != editPost)
            {
                editPost.NavigateUrl = Globals.UrlEditPost + PostID;
            }

            // Moderate Thread
            moderateThread = (HyperLink)skin.FindControl("ModerateThread");
            if (null != moderateThread)
            {
                moderateThread.NavigateUrl = Globals.UrlModerateThread + PostID;
            }

            // Approve and move the post to a new forum
            approvePostAndMove = (DropDownList)skin.FindControl("ApprovePostAndMove");
            if (null != approvePostAndMove)
            {
                Forums forums   = new Forums();
                string username = base.ForumUser.Username;
                approvePostAndMove.AutoPostBack          = true;
                approvePostAndMove.SelectedIndexChanged += new System.EventHandler(ApprovePostAndMove_Changed);
                approvePostAndMove.DataValueField        = "Value";
                approvePostAndMove.DataTextField         = "Text";
                approvePostAndMove.DataSource            = forums.ForumListItemCollection(username, Forums.ForumListStyle.Flat);
                approvePostAndMove.DataBind();
                approvePostAndMove.Items.FindByValue("f-" + ForumID.ToString()).Selected = true;
            }

            // Username of user that created the post
            usernameLabel = (Label)skin.FindControl("Username");
            if (null != usernameLabel)
            {
                usernameLabel.Text = UsernamePostedBy;
            }

            // Display the PostID for the moderator
            postIDLabel = (Label)skin.FindControl("PostID");
            if (null != postIDLabel)
            {
                postIDLabel.Text = PostID.ToString();
            }
        }