protected void DebateList_InsertCommand(object sender, TreeListCommandEventArgs e) { string ConnString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString; string commandText = @"INSERT INTO uDebate_Forum_Posts (ThreadID, ParentID, UserID, PostLevel, SortOrder, Subject, Message, PostDate, IsPublished, PostType, Active, Published_Date, Complaint_Count, ModuleID) VALUES (@ThreadID, @ParentID, " + UserInfo.UserID + @", 1, 1, @Subject, @Message, getDate(), 1, @PostType,1,getDate(),0," + ModuleId + ")"; SqlConnection conn = new SqlConnection(ConnString); SqlCommand command = new SqlCommand(commandText, conn); Hashtable table = new Hashtable(); TreeListEditFormInsertItem item = e.Item as TreeListEditFormInsertItem; table["Subject"] = (item.FindControl("txtSubjectPost") as TextBox).Text; table["Message"] = (item.FindControl("txtReply") as DotNetNuke.Web.UI.WebControls.DnnEditor).GetHtml(EditorStripHtmlOptions.None).Replace("'", "\""); RadioButton Issue = (item.FindControl("IssueRadio") as RadioButton); RadioButton Alter = (item.FindControl("AlterRadio") as RadioButton); RadioButton Pro = (item.FindControl("ProRadio") as RadioButton); RadioButton Con = (item.FindControl("ConRadio") as RadioButton); RadioButton Comment = (item.FindControl("CommentRadio") as RadioButton); String selection = String.Empty; if (Issue.Checked) { selection = "1"; } else if (Alter.Checked) { selection = "2"; } else if (Pro.Checked) { selection = "3"; } else if (Con.Checked) { selection = "4"; } else if (Comment.Checked) { selection = "8"; } table["PostType"] = selection; command.Parameters.AddWithValue("ThreadID", Thread_ID); command.Parameters.AddWithValue("Subject", table["Subject"]); command.Parameters.AddWithValue("Message", table["Message"]); command.Parameters.AddWithValue("PostType", table["PostType"]); object parentValue; if (item.ParentItem != null) { parentValue = item.ParentItem.GetDataKeyValue("ID"); } else { parentValue = "0"; } command.Parameters.AddWithValue("ParentID", parentValue); conn.Open(); try { command.ExecuteNonQuery(); /*if the new post is a reply we have to disable edit mode of parent and expand it */ if (item.ParentItem != null) { item.ParentItem.Expanded = true; item.ParentItem.IsChildInserted = false; } DebateList.IsItemInserted = false; DebateList.Rebind(); DataRow lastPost = getLatestPostOfThread(Thread_ID); if (lastPost != null) { FindAndSelectItem(Convert.ToInt32(lastPost["ID"])); } } finally { conn.Close(); } /* If a user posts to a thread we add him to the notification list*/ AddUserToNotified(Thread_ID); notifyCheck.Checked = true; string fromAddress = "*****@*****.**"; string subject = "OGP Ireland - New Post"; string body = "Hi, <br /><br/>A new post has been submitted to the OGP Ireland thread \"<b>" + getDescription(Thread_ID) + "\"</b>.<br /> To see this post, visit " + ConfigurationManager.AppSettings["DomainName"] +/* "/" + * System.Threading.Thread.CurrentThread.CurrentCulture.Name +*/ "/udebatediscussion.aspx?Thread=" + Thread_ID + "<br /><br/>Kind Regards,<br /><br/>" + PortalSettings.PortalName + "<br /><a href='" + PortalSettings.DefaultPortalAlias + "'>" + PortalSettings.DefaultPortalAlias + "</a>" + "<br /><br />" + "<img src='http://" + PortalSettings.DefaultPortalAlias + "/Portals/0/pbp_logo270.jpg'/>"; SendTokenizedBulkEmail mailer = new SendTokenizedBulkEmail(); /* Notify moderators of the new post*/ switch (getPostLanguageByThread(Thread_ID).ToLower()) { case "el-gr": Entities.Users.UserInfo user = new Entities.Users.UserInfo(); user.Email = "*****@*****.**"; mailer.AddAddressedUser(user); break; /* case "es-es": * Entities.Users.UserInfo user3 = new Entities.Users.UserInfo(); * user3.Email = "*****@*****.**"; * mailer.AddAddressedUser(user3); * Entities.Users.UserInfo user4 = new Entities.Users.UserInfo(); * user4.Email = "*****@*****.**"; * mailer.AddAddressedUser(user4); * Entities.Users.UserInfo user5 = new Entities.Users.UserInfo(); * user5.Email = "*****@*****.**"; * mailer.AddAddressedUser(user5); * break; * case "it-it": * Entities.Users.UserInfo user7 = new Entities.Users.UserInfo(); * user7.Email = "*****@*****.**"; * mailer.AddAddressedUser(user7); * break; * case "hu-hu": * Entities.Users.UserInfo user9 = new Entities.Users.UserInfo(); * user9.Email = "*****@*****.**"; * mailer.AddAddressedUser(user9); * break; * case "en-gb": * Entities.Users.UserInfo user11 = new Entities.Users.UserInfo(); * user11.Email = "*****@*****.**"; * mailer.AddAddressedUser(user11); * Entities.Users.UserInfo user12 = new Entities.Users.UserInfo(); * user12.Email = "*****@*****.**"; * mailer.AddAddressedUser(user12); * break;*/ default: break; } Entities.Users.UserInfo user14 = new Entities.Users.UserInfo(); user14.Email = "*****@*****.**"; mailer.AddAddressedUser(user14); mailer.Priority = DotNetNuke.Services.Mail.MailPriority.Normal; mailer.AddressMethod = DotNetNuke.Services.Mail.SendTokenizedBulkEmail.AddressMethods.Send_TO; Entities.Users.UserInfo senderUser = new Entities.Users.UserInfo(); senderUser.Email = "*****@*****.**"; mailer.SendingUser = senderUser; mailer.ReportRecipients = false; mailer.Subject = subject; mailer.Body = body; mailer.BodyFormat = DotNetNuke.Services.Mail.MailFormat.Html; Thread objThread = new Thread(mailer.Send); objThread.Start(); /* Send an email to all the subscribed users of this thread*/ string subjectNotify = "OGP Ireland - There is a new post in the thread you are following"; string bodyNotify = "Hi, <br /><br/>A new post has been submitted to the OGP Ireland thread \"<b>" + getDescription(Thread_ID) + "\"</b>.<br /> To see this post, visit " + ConfigurationManager.AppSettings["DomainName"] + /*"/" + * System.Threading.Thread.CurrentThread.CurrentCulture.Name +*/ "/udebatediscussion.aspx?Thread=" + Thread_ID + "<br /><br/>Kind Regards,<br /><br/>" + PortalSettings.PortalName + "<br /><a href='" + PortalSettings.DefaultPortalAlias + "'>" + PortalSettings.DefaultPortalAlias + "</a>" + "<br /><br />" + "<img src='http://" + PortalSettings.DefaultPortalAlias + "/Portals/0/pbp_logo270.jpg'/>"; string SQL_notified = "SELECT userID,userEmail FROM uDebate_Forum_Notifications where threadID=" + Thread_ID; try { DataSet ds = ATC.Database.sqlExecuteDataSet(SQL_notified); if (ds.Tables[0].Rows.Count > 0) { SendTokenizedBulkEmail notificationMailer = new SendTokenizedBulkEmail(); foreach (DataRow row in ds.Tables[0].Rows) { // Only send email to users different than the current one (the post writer) if (UserId != Int32.Parse(row["userID"].ToString())) { int numRecs = 100; ArrayList findEmailinRegistered = Entities.Users.UserController.GetUsersByEmail(PortalId, row["userEmail"].ToString(), 0, 10, ref numRecs, false, false); //Check that the user is still registered if (findEmailinRegistered.Count > 0) { Entities.Users.UserInfo newUser = new Entities.Users.UserInfo(); newUser.Email = row["userEmail"].ToString(); notificationMailer.AddAddressedUser(newUser); } //if no, remove him from the list of notified users else { RemoveUserFromNotified(row["userEmail"].ToString()); } } } notificationMailer.Priority = DotNetNuke.Services.Mail.MailPriority.Normal; notificationMailer.AddressMethod = DotNetNuke.Services.Mail.SendTokenizedBulkEmail.AddressMethods.Send_TO; Entities.Users.UserInfo sendingUser = new Entities.Users.UserInfo(); sendingUser.Email = "*****@*****.**"; notificationMailer.SendingUser = sendingUser; notificationMailer.ReportRecipients = true; notificationMailer.Subject = subjectNotify; notificationMailer.Body = bodyNotify; notificationMailer.BodyFormat = DotNetNuke.Services.Mail.MailFormat.Html; Thread objThread1 = new Thread(notificationMailer.Send); objThread1.Start(); } } catch (Exception ex) { Response.Write(ex.Message); } }
/***************** Version 2 functions **************************/ protected void DebateList_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e) { if (e.Item is TreeListDataItem) { TreeListDataItem itm = e.Item as TreeListDataItem; itm["PostType"].Text = "<img src='" + ModulePath + getImageIconUrl(itm["PostType"].Text) + "'>"; HyperLink userProfile = new HyperLink(); userProfile.NavigateUrl = DotNetNuke.Common.Globals.UserProfileURL(Convert.ToInt32(itm["UserId"].Text)); if (!itm["Post_Author"].Text.Equals(" ")) { userProfile.Text = itm["Post_Author"].Text + " " + itm.GetDataKeyValue("ID"); itm["Post_Author"].Controls.Add(userProfile); } else { itm["Post_Author"].Text = "guest"; } if (itm.IsChildInserted) { itm.CssClass = "whiteBack"; } } else if (e.Item is TreeListDetailTemplateItem) { TreeListDetailTemplateItem itm = e.Item as TreeListDetailTemplateItem; HiddenField hiddenpostId = (HiddenField)itm.FindControl("hiddenPostID"); /*LinkButton printPostBtn = (LinkButton)itm.FindControl("printPostLink"); * printPostBtn.Attributes.Add("onclick", "openSelectedPostPrinter(" + hiddenpostId.Value + ");return false;");*/ if (DotNetNuke.Security.PortalSecurity.IsInRoles("Pilot Leaders")) { HyperLink publishPost = (HyperLink)itm.FindControl("publishPost"); HyperLink deletePost = (HyperLink)itm.FindControl("deletePost"); publishPost.Visible = true; deletePost.Visible = true; string href = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("Thread") + 7) + ATC.Tools.URLParam("Thread"); /* if post is published admins can unpublish or delete */ deletePost.NavigateUrl = href + "&PostAction=Delete&Post=" + hiddenpostId.Value; if (itm.ParentItem["IsPublished"].Text == "1") { publishPost.NavigateUrl = href + "&PostAction=Reject&Post=" + hiddenpostId.Value; publishPost.Text = "Unpublish"; } else // Post unpublished { publishPost.NavigateUrl = href + "&PostAction=Accept&Post=" + hiddenpostId.Value; publishPost.Text = "Re-publish"; } } if (statusLbl.Visible) // Thread is closed { LinkButton newPostBtn = (LinkButton)itm.FindControl("newPostBtn"); newPostBtn.Enabled = false; notifyCheck.Visible = false; notifyLabel.Visible = false; } else { if (itm.ParentItem.IsChildInserted) { //itm.CssClass = "whiteBack"; LinkButton newPostBtn = (LinkButton)itm.FindControl("newPostBtn"); newPostBtn.CssClass = "newPostActive"; } } } else if (e.Item is TreeListEditFormInsertItem) { /* If a new discussion is to be created, the post type can only be issue*/ if (DebateList.IsItemInserted) { TreeListEditFormInsertItem itm = e.Item as TreeListEditFormInsertItem; RadioButton Issue = (itm.FindControl("IssueRadio") as RadioButton); RadioButton Alter = (itm.FindControl("AlterRadio") as RadioButton); RadioButton Pro = (itm.FindControl("ProRadio") as RadioButton); RadioButton Con = (itm.FindControl("ConRadio") as RadioButton); RadioButton Comment = (itm.FindControl("CommentRadio") as RadioButton); Comment.Checked = false; Issue.Checked = true; Alter.Enabled = false; Pro.Enabled = false; Con.Enabled = false; Comment.Enabled = false; } } }