private static ForumPost PopulateForumPost(SqlDataReader dr)
		{
			ForumPost forumPost = new ForumPost();

			// Post specifics
			forumPost.Body			= Convert.ToString(dr["Body"]);
			forumPost.FlatSortOrder	= Convert.ToInt32(dr["FlatSortOrder"]);
			forumPost.Notify		= Convert.ToBoolean(dr["Notify"]);
			forumPost.ParentPostID	= Convert.ToInt32(dr["ParentPostID"]);
			forumPost.PostDate		= Convert.ToDateTime(dr["PostDate"]);
			forumPost.PostLevel		= Convert.ToInt32(dr["PostLevel"]);
			forumPost.RemoteAddr	= Convert.ToString(dr["RemoteAddr"]);
			forumPost.Subject		= Convert.ToString(dr["Subject"]);
			forumPost.ThreadID		= Convert.ToInt32(dr["ThreadID"]);
			forumPost.TreeSortOrder	= Convert.ToInt32(dr["TreeSortOrder"]);
			forumPost.FlatSortOrder	= Convert.ToInt32(dr["FlatSortOrder"]);

			forumPost.User = new User();

			// User specifics
			forumPost.User.Alias		= Convert.ToString(dr["Alias"]);
			forumPost.User.Avatar		= Convert.IsDBNull(dr["Avatar"]) ? string.Empty : Convert.ToString(dr["Avatar"]);
			forumPost.User.Email		= Convert.ToString(dr["Email"]);
			forumPost.User.PostCount	= Convert.ToInt32(dr["PostCount"]);
			forumPost.User.Password		= Convert.ToString(dr["Password"]);
			forumPost.User.UserID		= Convert.ToInt32(dr["UserID"]);
			forumPost.User.WebID		= Convert.ToInt32(dr["WebID"]);

			return forumPost;
		}
        public static int AddPostPinned(ForumPost forumPost, int forumID, DateTime pinnedDate)
        {
            SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["RiversideInternetForumsConnectionString"]);
            SqlCommand cmd = new SqlCommand("WS_AddPost", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@PostID", SqlDbType.Int, 4);
            cmd.Parameters.Add("@ParentPostID", SqlDbType.Int, 4);
            cmd.Parameters.Add("@ForumID", SqlDbType.Int, 4);
            cmd.Parameters.Add("@UserID", SqlDbType.Int, 4);
            cmd.Parameters.Add("@RemoteAddr", SqlDbType.NVarChar, 100);
            cmd.Parameters.Add("@Notify", SqlDbType.Bit, 1);
            cmd.Parameters.Add("@Subject", SqlDbType.NVarChar, 255);
            cmd.Parameters.Add("@Body", SqlDbType.Text);
            cmd.Parameters.Add("@PinnedDate", SqlDbType.DateTime);
            cmd.Parameters.Add("@PostDate", SqlDbType.DateTime);

            cmd.Parameters[0].Direction = ParameterDirection.Output;
            cmd.Parameters[1].Value = forumPost.ParentPostID;
            cmd.Parameters[2].Value = forumID;
            cmd.Parameters[3].Value = forumPost.User.UserID;
            cmd.Parameters[4].Value = forumPost.RemoteAddr;
            cmd.Parameters[5].Value = forumPost.Notify;
            cmd.Parameters[6].Value = forumPost.Subject;
            cmd.Parameters[7].Value = forumPost.Body;
            cmd.Parameters[8].Value = pinnedDate;
            cmd.Parameters[9].Value = DateTime.Now;

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

            forumPost.PostID = (int)cmd.Parameters[0].Value;

            return forumPost.PostID;
        }
        public static void UpdatePostPinned(ForumPost forumPost, DateTime pinnedDate)
        {
            SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["RiversideInternetForumsConnectionString"]);
            SqlCommand cmd = new SqlCommand("WS_UpdatePostPinned", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@PostID", SqlDbType.Int, 4);
            cmd.Parameters.Add("@Subject", SqlDbType.NVarChar, 255);
            cmd.Parameters.Add("@Body", SqlDbType.Text);
            cmd.Parameters.Add("@Notify", SqlDbType.Bit, 1);
            cmd.Parameters.Add("@PinnedDate", SqlDbType.DateTime);

            cmd.Parameters[0].Value = forumPost.PostID;
            cmd.Parameters[1].Value = forumPost.Subject;
            cmd.Parameters[2].Value = forumPost.Body;
            cmd.Parameters[3].Value = forumPost.Notify;
            cmd.Parameters[4].Value = pinnedDate;

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
 public static int AddPost(ForumPost forumPost, int forumID)
 {
     return AddPostPinned(forumPost, forumID, DateTime.Now);
 }
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            // Only allow an action to be completed if the subject and body validators
            // are valid - i.e. we will not allow empty strings in either text box.
            if (_bodyValidator.IsValid && _subjectValidator.IsValid)
            {
                // Create forum post object
                ForumPost forumPost = new ForumPost();

                // Post specific fields
                forumPost.Notify		= _notifyCheckBox.Checked;
                forumPost.Body			= _bodyTextBox.Text;
                forumPost.Subject		= _subjectTextBox.Text;
                forumPost.RemoteAddr	= Page.Request.ServerVariables["REMOTE_ADDR"];

                // User specific fields
                forumPost.User = new User();
                forumPost.User.UserID = _userID;

                // Perform action depending on button command name
                int postID = 0;
                string action = _submitButton.CommandName;

                // Perform new post, reply, quote or edit action
                switch (action)
                {
                    case "new":
                        postID = AddNew(forumPost);
                        break;

                    case "reply":
                    case "quote":
                        forumPost.ParentPostID = _postID;
                        postID = AddReply(forumPost);
                        break;

                    case "edit":
                        forumPost.PostID = _postID;
                        postID = _postID;
                        EditPost(forumPost);
                        break;
                }

                // Redirect user to page displaying new information
                string redirectURL = null;
                if (postID > 0)
                    redirectURL = WebSolutionUtils.GetURL(GetDocument(), Page, "postid=" + postID, "forumaction=&threadspage=&searchpage=");
                else
                    redirectURL = WebSolutionUtils.GetURL(GetDocument(), Page, "", "postid=&forumaction=&threadspage=&searchpage=");
                if (DocumentID > 0)
                    redirectURL = "../" + redirectURL;
                Page.Response.Redirect(redirectURL);
            }
        }
        private void PopulateUnits()
        {
            if (_action == "new" || _action == "reply" || _action == "quote")
            {
                ForumText aliasForumText = new ForumText(UserDB.GetUser(_userID).Alias);
                _nameLabel.Text = aliasForumText.ProcessSingleLine(GetImages());
            }

            if (_action == "edit" || _action == "reply" || _action == "quote")
            {
                _forumPost = ForumDB.GetPost(_postID);

                if (_action == "edit")
                {
                    if (LoggedOnUserID != _forumPost.User.UserID && !Page.User.IsInRole("ForumAdmin"))
                        RedirectUserHasNoAuthority();

                    ForumText postAliasForumText = new ForumText(_forumPost.User.Alias);
                    _nameLabel.Text = postAliasForumText.ProcessSingleLine(GetImages());
                    _subjectTextBox.Text = _forumPost.Subject;
                    _bodyTextBox.Text = _forumPost.Body;
                    _notifyCheckBox.Checked = _forumPost.Notify;
                }
                else
                {
                    // If action is quote or reply, make sure subject begins "Re:"
                    string subject = _forumPost.Subject;
                    string replySubject = subject;
                    if (replySubject.Length >= 3)
                    {
                        if (replySubject.Substring(0, 3) != "Re:")
                            replySubject = "Re: " + replySubject;
                    }
                    else
                    {
                        replySubject = "Re: " + replySubject;
                    }
                    _subjectTextBox.Text = replySubject;

                    // If action is quote, add message being replied to within QUOTE tags
                    if (_action == "quote")
                    {
                        ForumText forumText = new ForumText(_forumPost.Body);
                        _bodyTextBox.Text = forumText.ProcessQuoteBody(_forumPost.User.Alias);
                    }
                }
            }

            if (_pinnedDropDownList != null && !Page.IsPostBack)
            {
                _pinnedDropDownList.Items.Add(new ListItem("Not Sticky", "0"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Day", "1"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Days", "3"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Week", "7"));
                _pinnedDropDownList.Items.Add(new ListItem("2 Weeks", "14"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Month", "30"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Months", "90"));
                _pinnedDropDownList.Items.Add(new ListItem("6 Months", "180"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Year", "365"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Years", "1095"));
            }
        }
        private void EmailReplyNotification(ForumPost parentForumPost, ForumPost forumPost)
        {
            User user = UserDB.GetUser(forumPost.User.UserID);
            User userParent = UserDB.GetUser(parentForumPost.User.UserID);

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("A reply from {0} has been posted to your message entitled \"{1}\"\r\n\r\n", user.Alias, parentForumPost.Subject);
            sb.AppendFormat("Subject: \"{0}\"\r\n\r\n", forumPost.Subject);
            sb.AppendFormat("Reply: \r\n\r\n{0}\r\n\r\n", forumPost.Body);
            string url = "http://" + Page.Request.ServerVariables["SERVER_NAME"] + "/" + WebSolutionUtils.GetURL(GetDocument(), Page, "postid=" + forumPost.PostID + "#" + forumPost.PostID, "forumaction=&threadspage=&searchpage=");
            sb.Append("To view this reply at the forum, click on the following link:\r\n\r\n");
            sb.Append(url);

            MailMessage mailMessage = new MailMessage();
            mailMessage.To = userParent.Email;
            mailMessage.Subject = "Message board reply";
            mailMessage.Body = sb.ToString();
            mailMessage.BodyFormat = MailFormat.Text;
            string host = Page.Request.Url.Host;
            if (host.Length > 4 && host.Substring(0, 4) == "www.")
                host = host.Substring(4, host.Length - 4);
            mailMessage.From = "forums@" + host;

            SmtpMail.SmtpServer = Page.Request.ServerVariables["SERVER_NAME"];

            try
            {
                SmtpMail.Send(mailMessage);
            }
            catch (Exception)
            {
            }
        }
        private void EditPost(ForumPost forumPost)
        {
            if (_pinnedDropDownList == null)
            {
                ForumDB.UpdatePost(forumPost);
                return;
            }

            DateTime pinnedDate;
            GetPinnedInfo(out pinnedDate);

            ForumDB.UpdatePostPinned(forumPost, pinnedDate);
        }
        private int AddReply(ForumPost forumPost)
        {
            // Add reply
            int postID = ForumDB.AddPost(forumPost, ForumID);

            // Check to see whether author of parent post should be notified
            ForumPost parentForumPost = ForumDB.GetPost(forumPost.ParentPostID);

            // Send e-mail
            if (parentForumPost.Notify && parentForumPost.User.UserID != forumPost.User.UserID)
                EmailReplyNotification(parentForumPost, forumPost);

            // Return identifier of newly created post
            return postID;
        }
        private int AddNew(ForumPost forumPost)
        {
            if (_pinnedDropDownList == null)
                return ForumDB.AddPost(forumPost, ForumID);

            DateTime pinnedDate;
            GetPinnedInfo(out pinnedDate);

            return ForumDB.AddPostPinned(forumPost, ForumID, pinnedDate);
        }
Exemple #11
0
        private void PopulateUnits()
        {
            if (_action == "new" || _action == "reply" || _action == "quote")
            {
                ForumText aliasForumText = new ForumText(UserDB.GetUser(_userID).Alias);
                _nameLabel.Text = aliasForumText.ProcessSingleLine(GetImages());
            }

            if (_action == "edit" || _action == "reply" || _action == "quote")
            {
                _forumPost = ForumDB.GetPost(_postID);

                if (_action == "edit")
                {
                    if (LoggedOnUserID != _forumPost.User.UserID && !Page.User.IsInRole("ForumAdmin"))
                    {
                        RedirectUserHasNoAuthority();
                    }

                    ForumText postAliasForumText = new ForumText(_forumPost.User.Alias);
                    _nameLabel.Text         = postAliasForumText.ProcessSingleLine(GetImages());
                    _subjectTextBox.Text    = _forumPost.Subject;
                    _bodyTextBox.Text       = _forumPost.Body;
                    _notifyCheckBox.Checked = _forumPost.Notify;
                }
                else
                {
                    // If action is quote or reply, make sure subject begins "Re:"
                    string subject      = _forumPost.Subject;
                    string replySubject = subject;
                    if (replySubject.Length >= 3)
                    {
                        if (replySubject.Substring(0, 3) != "Re:")
                        {
                            replySubject = "Re: " + replySubject;
                        }
                    }
                    else
                    {
                        replySubject = "Re: " + replySubject;
                    }
                    _subjectTextBox.Text = replySubject;

                    // If action is quote, add message being replied to within QUOTE tags
                    if (_action == "quote")
                    {
                        ForumText forumText = new ForumText(_forumPost.Body);
                        _bodyTextBox.Text = forumText.ProcessQuoteBody(_forumPost.User.Alias);
                    }
                }
            }

            if (_pinnedDropDownList != null && !Page.IsPostBack)
            {
                _pinnedDropDownList.Items.Add(new ListItem("Not Sticky", "0"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Day", "1"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Days", "3"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Week", "7"));
                _pinnedDropDownList.Items.Add(new ListItem("2 Weeks", "14"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Month", "30"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Months", "90"));
                _pinnedDropDownList.Items.Add(new ListItem("6 Months", "180"));
                _pinnedDropDownList.Items.Add(new ListItem("1 Year", "365"));
                _pinnedDropDownList.Items.Add(new ListItem("3 Years", "1095"));
            }
        }
Exemple #12
0
 public static int AddPost(ForumPost forumPost, int forumID)
 {
     return(AddPostPinned(forumPost, forumID, DateTime.Now));
 }