/// <summary> /// Reloads the board messages related to the currently processed message board. /// </summary> private void ReloadBoardMessages() { this.SetContext(); // If user isn't allowed to read comments if (!CMSContext.CurrentUser.IsAuthenticated() && !this.BoardProperties.BoardEnableAnonymousRead) { // Do not display existing messages to anonymous user, but inform on situation this.lblNoMessages.Visible = true; this.lblNoMessages.Text = GetString("board.messagelist.anonymousreadnotallowed"); } else { // If the message board ID was specified if (this.MessageBoardID > 0) { string where = "(MessageBoardID = " + this.MessageBoardID.ToString() + ")"; // If the user should be displayed with all messages not just approved ones if (!BoardInfoProvider.IsUserAuthorizedToManageMessages(bi)) { where += " AND (MessageApproved = 1) AND ((MessageIsSpam IS NULL) OR (MessageIsSpam = 0))"; } // Get board messages this.rptBoardMessages.WhereCondition = where; this.rptBoardMessages.ReloadData(true); } } this.ReleaseContext(); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { BoardMessageInfo message = BoardMessageInfoProvider.GetBoardMessageInfo(Convert.ToInt32(actionArgument)); BoardInfo bi = BoardInfoProvider.GetBoardInfo(message.MessageBoardID); string[] argument = null; switch (actionName) { case "delete": case "approve": // Check whether user is board moderator first if (!BoardInfoProvider.IsUserAuthorizedToManageMessages(bi)) { // Then check modify to messageboards if (!CheckPermissions("cms.messageboards", CMSAdminControl.PERMISSION_MODIFY)) { return; } } break; } switch (actionName) { case "delete": if (message != null) { BoardMessageInfoProvider.DeleteBoardMessageInfo(message); } break; case "approve": if (message != null) { if (message.MessageApproved) { // Reject message message.MessageApproved = false; message.MessageApprovedByUserID = 0; } else { // Approve message message.MessageApproved = true; message.MessageApprovedByUserID = CMSContext.CurrentUser.UserID; } BoardMessageInfoProvider.SetBoardMessageInfo(message); } break; default: break; } this.RaiseOnAction(actionName, ((argument == null) ? actionArgument : argument)); }
private void boardMsgActions_OnMessageAction(string actionName, object argument) { // Get current board message ID int boardMessageId = ValidationHelper.GetInteger(argument, 0); BoardMessageInfo message = BoardMessageInfoProvider.GetBoardMessageInfo(boardMessageId); // Handle not existing message if (message == null) { return; } if ((bi != null) && BoardInfoProvider.IsUserAuthorizedToManageMessages(bi)) { switch (actionName.ToLowerCSafe()) { case "delete": // Delete message BoardMessageInfoProvider.DeleteBoardMessageInfo(message); rptBoardMessages.ClearCache(); ReloadData(); break; case "approve": // Approve board message if (MembershipContext.AuthenticatedUser != null) { message.MessageApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; message.MessageApproved = true; BoardMessageInfoProvider.SetBoardMessageInfo(message); } rptBoardMessages.ClearCache(); ReloadData(); break; case "reject": // Reject board message if (MembershipContext.AuthenticatedUser != null) { message.MessageApprovedByUserID = 0; message.MessageApproved = false; BoardMessageInfoProvider.SetBoardMessageInfo(message); } rptBoardMessages.ClearCache(); ReloadData(); break; } } }
private void msgEdit_OnAfterMessageSaved(BoardMessageInfo message) { if ((bi == null) && (message != null) && (message.MessageBoardID > 0)) { MessageBoardID = message.MessageBoardID; // Get updated board information bi = BoardInfoProvider.GetBoardInfo(message.MessageBoardID); userVerified = BoardInfoProvider.IsUserAuthorizedToManageMessages(bi); } rptBoardMessages.ClearCache(); ReloadData(); }
private void messageEditElem_OnBeforeMessageSaved() { bool isOwner = false; BoardInfo board = BoardInfoProvider.GetBoardInfo(messageEditElem.MessageBoardID); if (board != null) { // Check if the current user is allowed to modify the message isOwner = BoardInfoProvider.IsUserAuthorizedToManageMessages(board); } if (!isOwner && !MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.MessageBoards", "Modify")) { RedirectToAccessDenied(GetString("board.messageedit.notallowed")); } }
private void messageEditElem_OnBeforeMessageSaved() { bool isOwner = false; BoardInfo board = BoardInfoProvider.GetBoardInfo(mBoardId); if (board != null) { // Check if the current user is allowed to modify the message isOwner = BoardInfoProvider.IsUserAuthorizedToManageMessages(board); } if (!isOwner && !MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.MessageBoards", CMSAdminControl.PERMISSION_MODIFY)) { RedirectToAccessDenied("cms.messageboards", CMSAdminControl.PERMISSION_MODIFY); } }
/// <summary> /// Reloads the board messages related to the currently processed message board. /// </summary> private void ReloadBoardMessages() { SetContext(); // If user isn't allowed to read comments if (!(AuthenticationHelper.IsAuthenticated() || BoardProperties.BoardEnableAnonymousRead)) { // Do not display existing messages to anonymous user, but inform on situation lblNoMessages.Visible = true; lblNoMessages.Text = GetString("board.messagelist.anonymousreadnotallowed"); HideMessages(); } else { // If the message board ID was specified if (MessageBoardID > 0) { string where = "(MessageBoardID = " + MessageBoardID.ToString() + ")"; // If the user should be displayed with all messages not just approved ones if (!BoardInfoProvider.IsUserAuthorizedToManageMessages(bi)) { where += " AND (MessageApproved = 1) AND ((MessageIsSpam IS NULL) OR (MessageIsSpam = 0))"; } // Get board messages zeroRowsText.Visible = false; rptBoardMessages.StopProcessing = false; rptBoardMessages.Visible = true; rptBoardMessages.WhereCondition = where; rptBoardMessages.ReloadData(true); } } // Update update panel if needed if (ControlsHelper.IsInUpdatePanel(this)) { ControlsHelper.UpdateCurrentPanel(this); } ReleaseContext(); }
/// <summary> /// Creates where condition based on data access permissions. /// </summary> private string GetWhereCondition() { string where = String.Empty; bool isAuthorized = false; if (SelectedBoardID > 0) { BoardInfo selectedBoard = BoardInfoProvider.GetBoardInfo(SelectedBoardID); if (selectedBoard != null) { isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(selectedBoard); } } // Show messages to boards only where user is moderator if (!isAuthorized && (!(MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.MessageBoards", "Modify") || MembershipContext.AuthenticatedUser.IsGroupAdministrator(GroupID)))) { where = SqlHelper.AddWhereCondition(where, "BoardID IN (SELECT BoardID FROM Board_Moderator WHERE Board_Moderator.UserID = " + MembershipContext.AuthenticatedUser.UserID + " )"); } // Group restriction if (GroupID > 0) { where = SqlHelper.AddWhereCondition(where, "BoardGroupID =" + mGroupId); } else { where = SqlHelper.AddWhereCondition(where, "(BoardGroupID = 0 OR BoardGroupID IS NULL)"); } // Site restriction if (SelectedSiteID > 0) { where = SqlHelper.AddWhereCondition(where, "BoardSiteID = " + SelectedSiteID); } return(where); }
protected void btnOk_Click(object sender, EventArgs e) { // Let the parent control now new message is being saved if (OnBeforeMessageSaved != null) { OnBeforeMessageSaved(); } // Check if message board is opened if (!IsBoardOpen()) { return; } // Check banned IP if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { ShowError(GetString("General.BannedIP")); return; } // Validate form string errorMessage = ValidateForm(); if (errorMessage == String.Empty) { // Check flooding when message being inserted through the LiveSite if (CheckFloodProtection && IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { ShowError(GetString("General.FloodProtection")); return; } var currentUser = MembershipContext.AuthenticatedUser; BoardMessageInfo message; if (MessageID > 0) { // Get message info message = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID); MessageBoardID = message.MessageBoardID; } else { // Create new info message = new BoardMessageInfo(); // User IP address message.MessageUserInfo.IPAddress = RequestContext.UserHostAddress; // User agent message.MessageUserInfo.Agent = Request.UserAgent; } // Setup message info message.MessageEmail = txtEmail.Text.Trim(); message.MessageText = txtMessage.Text.Trim(); // Handle message URL string url = txtURL.Text.Trim(); if (!String.IsNullOrEmpty(url)) { string protocol = URLHelper.GetProtocol(url); if (String.IsNullOrEmpty(protocol)) { url = "http://" + url; } } message.MessageURL = TextHelper.LimitLength(url, txtURL.MaxLength); message.MessageURL = message.MessageURL.ToLowerCSafe().Replace("javascript", "_javascript"); message.MessageUserName = TextHelper.LimitLength(txtUserName.Text.Trim(), txtUserName.MaxLength); if ((message.MessageID <= 0) && (!currentUser.IsPublic())) { message.MessageUserID = currentUser.UserID; if (!plcUserName.Visible) { message.MessageUserName = GetDefaultUserName(); } } message.MessageIsSpam = ValidationHelper.GetBoolean(chkSpam.Checked, false); if (BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0)) { message.MessageRatingValue = ratingControl.CurrentRating; // Update document rating, remember rating in cookie TreeProvider.RememberRating(DocumentContext.CurrentDocument); } BoardInfo boardInfo; // If there is message board if (MessageBoardID > 0) { // Load message board boardInfo = Board; } else { // Create new message board according to webpart properties boardInfo = new BoardInfo(BoardProperties); BoardInfoProvider.SetBoardInfo(boardInfo); // Update information on current message board MessageBoardID = boardInfo.BoardID; // Set board-role relationship BoardRoleInfoProvider.SetBoardRoles(MessageBoardID, BoardProperties.BoardRoles); // Set moderators BoardModeratorInfoProvider.SetBoardModerators(MessageBoardID, BoardProperties.BoardModerators); } if (boardInfo != null) { if (BoardInfoProvider.IsUserAuthorizedToAddMessages(boardInfo)) { // If the very new message is inserted if (MessageID == 0) { // If creating message set inserted to now and assign to board message.MessageInserted = DateTime.Now; message.MessageBoardID = MessageBoardID; // Handle auto approve action bool isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(boardInfo); if (isAuthorized) { message.MessageApprovedByUserID = currentUser.UserID; message.MessageApproved = true; } else { // Is board moderated ? message.MessageApprovedByUserID = 0; message.MessageApproved = !boardInfo.BoardModerated; } } else { if (chkApproved.Checked) { // Set current user as approver message.MessageApproved = true; message.MessageApprovedByUserID = currentUser.UserID; } else { message.MessageApproved = false; message.MessageApprovedByUserID = 0; } } if (!AdvancedMode) { if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { // Columns to check Dictionary <string, int> collumns = new Dictionary <string, int>(); collumns.Add("MessageText", 0); collumns.Add("MessageUserName", 250); // Perform bad words check bool validateUserName = plcUserName.Visible; errorMessage = BadWordsHelper.CheckBadWords(message, collumns, "MessageApproved", "MessageApprovedByUserID", message.MessageText, currentUser.UserID, () => ValidateMessage(message, validateUserName)); // Additionally check empty fields if (errorMessage == string.Empty) { if (!ValidateMessage(message, validateUserName)) { errorMessage = GetString("board.messageedit.emptybadword"); } } } } // Subscribe this user to message board if (chkSubscribe.Checked) { string email = message.MessageEmail; // Check for duplicate e-mails DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("((SubscriptionApproved = 1) OR (SubscriptionApproved IS NULL)) AND SubscriptionBoardID=" + MessageBoardID + " AND SubscriptionEmail='" + SqlHelper.GetSafeQueryString(email, false) + "'", null); if (DataHelper.DataSourceIsEmpty(ds)) { BoardSubscriptionInfo bsi = new BoardSubscriptionInfo(); bsi.SubscriptionBoardID = MessageBoardID; bsi.SubscriptionEmail = email; if (!currentUser.IsPublic()) { bsi.SubscriptionUserID = currentUser.UserID; } BoardSubscriptionInfoProvider.Subscribe(bsi, DateTime.Now, true, true); ClearForm(); if (bsi.SubscriptionApproved) { ShowConfirmation(GetString("board.subscription.beensubscribed")); Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(bsi.SubscriptionEmail, MembershipContext.AuthenticatedUser); LogSubscribingActivity(bsi, boardInfo); } else { string confirmation = GetString("general.subscribed.doubleoptin"); int optInInterval = BoardInfoProvider.DoubleOptInInterval(SiteContext.CurrentSiteName); if (optInInterval > 0) { confirmation += "<br />" + String.Format(GetString("general.subscription_timeintervalwarning"), optInInterval); } ShowConfirmation(confirmation); } } else { errorMessage = GetString("board.subscription.emailexists"); } } if (errorMessage == "") { try { // Save message info BoardMessageInfoProvider.SetBoardMessageInfo(message); Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(message.MessageEmail, MembershipContext.AuthenticatedUser); LogCommentActivity(message, boardInfo); if (BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0)) { LogRatingActivity(ratingControl.CurrentRating); } // If the message is not approved let the user know message is waiting for approval if (message.MessageApproved == false) { ShowInformation(GetString("board.messageedit.waitingapproval")); } // Rise after message saved event if (OnAfterMessageSaved != null) { OnAfterMessageSaved(message); } // Hide message form if user has rated and empty rating is not allowed if (BoardProperties.CheckIfUserRated) { if (!BoardProperties.AllowEmptyRating && TreeProvider.HasRated(DocumentContext.CurrentDocument)) { pnlMessageEdit.Visible = false; lblAlreadyrated.Visible = true; } else { // Hide rating form if user has rated if (BoardProperties.EnableContentRating && (ratingControl != null) && ratingControl.GetCurrentRating() > 0) { plcRating.Visible = false; } } } // Clear form content ClearForm(); } catch (Exception ex) { errorMessage = ex.Message; } } } else if (String.IsNullOrEmpty(errorMessage)) { errorMessage = ResHelper.GetString("general.actiondenied"); } } } if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); } }
/// <summary> /// Initializes the control elements. /// </summary> private void SetupControl() { // If the control shouldn't proceed further if (BoardProperties.StopProcessing) { Visible = false; return; } btnLeaveMessage.Attributes.Add("onclick", "ShowSubscription(0, '" + hdnSelSubsTab.ClientID + "','" + pnlMsgEdit.ClientID + "','" + pnlMsgSubscription.ClientID + "'); return false; "); btnSubscribe.Attributes.Add("onclick", " ShowSubscription(1, '" + hdnSelSubsTab.ClientID + "','" + pnlMsgEdit.ClientID + "','" + pnlMsgSubscription.ClientID + "'); return false; "); // Show/hide appropriate control based on current selection form hidden field if (ValidationHelper.GetInteger(hdnSelSubsTab.Value, 0) == 0) { pnlMsgEdit.Style.Remove("display"); pnlMsgEdit.Style.Add("display", "block"); pnlMsgSubscription.Style.Remove("display"); pnlMsgSubscription.Style.Add("display", "none"); } else { pnlMsgSubscription.Style.Remove("display"); pnlMsgSubscription.Style.Add("display", "block"); pnlMsgEdit.Style.Remove("display"); pnlMsgEdit.Style.Add("display", "none"); } // Set the repeater rptBoardMessages.QueryName = "board.message.selectall"; rptBoardMessages.ZeroRowsText = HTMLHelper.HTMLEncode(NoMessagesText) + "<br /><br />"; rptBoardMessages.ItemDataBound += rptBoardMessages_ItemDataBound; rptBoardMessages.TransformationName = MessageTransformation; // Set the labels msgEdit.ResourcePrefix = FormResourcePrefix; lblLeaveMessage.ResourceString = "board.messageboard.leavemessage"; lblNewSubscription.ResourceString = "board.newsubscription"; btnSubscribe.Text = GetString("board.messageboard.subscribe"); btnLeaveMessage.Text = GetString("board.messageboard.leavemessage"); // Pass the properties down to the message edit control msgEdit.BoardProperties = BoardProperties; msgEdit.MessageBoardID = MessageBoardID; msgEdit.OnAfterMessageSaved += msgEdit_OnAfterMessageSaved; msgSubscription.BoardProperties = BoardProperties; plcBtnSubscribe.Visible = BoardProperties.BoardEnableSubscriptions; pnlMsgSubscription.Visible = BoardProperties.BoardEnableSubscriptions; // If the message board exist and is enabled bi = BoardInfoProvider.GetBoardInfo(MessageBoardID); if (bi != null) { // Get basic info on users permissions userVerified = BoardInfoProvider.IsUserAuthorizedToManageMessages(bi); if (bi.BoardEnabled) { // If the board is moderated remember it if (bi.BoardModerated) { BoardProperties.BoardModerated = true; } // Reload messages ReloadBoardMessages(); // If the message board is opened users can add the messages bool displayAddMessageForm = BoardInfoProvider.IsUserAuthorizedToAddMessages(bi); // Hide 'add message' form when anonymous read disabled and user is not authenticated displayAddMessageForm &= (BoardProperties.BoardEnableAnonymousRead || AuthenticationHelper.IsAuthenticated()); if (displayAddMessageForm) { // Display the 'add the message' control DisplayAddMessageForm(); } else { HideAddMessageForm(); } msgSubscription.BoardID = bi.BoardID; } else { // Hide the control Visible = false; } } else { // The repeater is not rendered, but the NoMessageText has to be visible. HideMessages(); zeroRowsText.Visible = true; zeroRowsText.Text = rptBoardMessages.ZeroRowsText; // Decide whether the 'Leave message' dialog should be displayed if (BoardInfoProvider.IsUserAuthorizedToAddMessages(BoardProperties)) { DisplayAddMessageForm(); } else { // Hide the dialog, but set message board ID in case that board closed just while entering HideAddMessageForm(); } } }
protected void btnOk_Click(object sender, EventArgs e) { // Let the parent control now new message is being saved if (OnBeforeMessageSaved != null) { OnBeforeMessageSaved(); } // Check banned ip if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } // Validate form string errorMessage = ValidateForm(); if (errorMessage == "") { // Check flooding when message being inserted through the LiveSite if (this.CheckFloodProtection && this.IsLiveSite && FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser)) { lblError.Visible = true; lblError.Text = GetString("General.FloodProtection"); return; } CurrentUserInfo currentUser = CMSContext.CurrentUser; BoardMessageInfo messageInfo = null; if (MessageID > 0) { // Get message info messageInfo = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID); MessageBoardID = messageInfo.MessageBoardID; } else { // Create new info messageInfo = new BoardMessageInfo(); // User IP adress messageInfo.MessageUserInfo.IPAddress = Request.UserHostAddress; // User agent messageInfo.MessageUserInfo.Agent = Request.UserAgent; } // Setup message info messageInfo.MessageEmail = txtEmail.Text.Trim(); messageInfo.MessageText = txtMessage.Text.Trim(); // Handle message URL string url = txtURL.Text.Trim(); if ((url != "http://") && (url != "https://") && (url != "")) { if ((!url.ToLower().StartsWith("http://")) && (!url.ToLower().StartsWith("https://"))) { url = "http://" + url; } } else { url = ""; } messageInfo.MessageURL = url; messageInfo.MessageURL = messageInfo.MessageURL.ToLower().Replace("javascript", "_javascript"); messageInfo.MessageUserName = this.txtUserName.Text.Trim(); if (!currentUser.IsPublic()) { messageInfo.MessageUserID = currentUser.UserID; } messageInfo.MessageIsSpam = ValidationHelper.GetBoolean(this.chkSpam.Checked, false); if (this.BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0)) { messageInfo.MessageRatingValue = ratingControl.CurrentRating; } BoardInfo boardInfo = null; // If there is message board if (MessageBoardID > 0) { // Load message board boardInfo = Board; } else { // Create new message board according to webpart properties boardInfo = new BoardInfo(this.BoardProperties); BoardInfoProvider.SetBoardInfo(boardInfo); // Update information on current message board this.MessageBoardID = boardInfo.BoardID; // Set board-role relationship BoardRoleInfoProvider.SetBoardRoles(this.MessageBoardID, this.BoardProperties.BoardRoles); // Set moderators BoardModeratorInfoProvider.SetBoardModerators(this.MessageBoardID, this.BoardProperties.BoardModerators); } if (boardInfo != null) { // If the very new message is inserted if (this.MessageID == 0) { // If creating message set inserted to now and assign to board messageInfo.MessageInserted = currentUser.DateTimeNow; messageInfo.MessageBoardID = MessageBoardID; // Handle auto approve action bool isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(boardInfo); if (isAuthorized) { messageInfo.MessageApprovedByUserID = currentUser.UserID; messageInfo.MessageApproved = true; } else { // Is board moderated ? messageInfo.MessageApprovedByUserID = 0; messageInfo.MessageApproved = !boardInfo.BoardModerated; } } else { if (this.chkApproved.Checked) { // Set current user as approver messageInfo.MessageApproved = true; messageInfo.MessageApprovedByUserID = currentUser.UserID; } else { messageInfo.MessageApproved = false; messageInfo.MessageApprovedByUserID = 0; } } if (!AdvancedMode) { if (!BadWordInfoProvider.CanUseBadWords(CMSContext.CurrentUser, CMSContext.CurrentSiteName)) { // Columns to check Dictionary <string, int> collumns = new Dictionary <string, int>(); collumns.Add("MessageText", 0); collumns.Add("MessageUserName", 250); // Perform bad words check errorMessage = BadWordsHelper.CheckBadWords(messageInfo, collumns, "MessageApproved", "MessageApprovedByUserID", messageInfo.MessageText, currentUser.UserID); // Additionaly check empty fields if (errorMessage == string.Empty) { if (!ValidateMessage(messageInfo)) { errorMessage = GetString("board.messageedit.emptybadword"); } } } } // Subscribe this user to message board if (chkSubscribe.Checked) { string email = messageInfo.MessageEmail; // Check for duplicit e-mails DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("SubscriptionBoardID=" + this.MessageBoardID + " AND SubscriptionEmail='" + SqlHelperClass.GetSafeQueryString(email, false) + "'", null); if (DataHelper.DataSourceIsEmpty(ds)) { BoardSubscriptionInfo bsi = new BoardSubscriptionInfo(); bsi.SubscriptionBoardID = this.MessageBoardID; bsi.SubscriptionEmail = email; if (!currentUser.IsPublic()) { bsi.SubscriptionUserID = currentUser.UserID; } BoardSubscriptionInfoProvider.SetBoardSubscriptionInfo(bsi); ClearForm(); LogSubscribingActivity(bsi, boardInfo); } else { errorMessage = GetString("board.subscription.emailexists"); } } if (errorMessage == "") { try { // Save message info BoardMessageInfoProvider.SetBoardMessageInfo(messageInfo); LogCommentActivity(messageInfo, boardInfo); // If the board is moderated let the user know message is waiting for approval if (boardInfo.BoardModerated && (messageInfo.MessageApproved == false)) { this.lblInfo.Text = GetString("board.messageedit.waitingapproval"); this.lblInfo.Visible = true; } // Rise after message saved event if (OnAfterMessageSaved != null) { OnAfterMessageSaved(messageInfo); } // Clear form content ClearForm(); } catch (Exception ex) { errorMessage = ex.Message; } } } } if (errorMessage != "") { lblError.Text = errorMessage; lblError.Visible = true; } else { // Regenerate new captcha captchaElem.GenerateNew(); } }
protected void btnOk_Click(object sender, EventArgs e) { // Let the parent control now new message is being saved if (OnBeforeMessageSaved != null) { OnBeforeMessageSaved(); } // Check banned IP if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { ShowError(GetString("General.BannedIP")); return; } // Validate form string errorMessage = ValidateForm(); if (errorMessage == "") { // Check flooding when message being inserted through the LiveSite if (CheckFloodProtection && IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { ShowError(GetString("General.FloodProtection")); return; } CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser; BoardMessageInfo messageInfo = null; if (MessageID > 0) { // Get message info messageInfo = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID); MessageBoardID = messageInfo.MessageBoardID; } else { // Create new info messageInfo = new BoardMessageInfo(); // User IP address messageInfo.MessageUserInfo.IPAddress = RequestContext.UserHostAddress; // User agent messageInfo.MessageUserInfo.Agent = Request.UserAgent; } // Setup message info messageInfo.MessageEmail = txtEmail.Text.Trim(); messageInfo.MessageText = txtMessage.Text.Trim(); // Handle message URL string url = txtURL.Text.Trim(); if ((url != "http://") && (url != "https://") && (url != "")) { if ((!url.ToLowerCSafe().StartsWithCSafe("http://")) && (!url.ToLowerCSafe().StartsWithCSafe("https://"))) { url = "http://" + url; } } else { url = ""; } messageInfo.MessageURL = url; messageInfo.MessageURL = messageInfo.MessageURL.ToLowerCSafe().Replace("javascript", "_javascript"); messageInfo.MessageUserName = txtUserName.Text.Trim(); if ((MessageID <= 0) && (!currentUser.IsPublic())) { messageInfo.MessageUserID = currentUser.UserID; } messageInfo.MessageIsSpam = ValidationHelper.GetBoolean(chkSpam.Checked, false); if (BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0)) { messageInfo.MessageRatingValue = ratingControl.CurrentRating; // Remember rating in cookie string docs = CookieHelper.GetValue(CookieName.RatedDocuments) ?? "|"; if (!docs.Contains("|" + DocumentContext.CurrentDocument.DocumentID + "|")) { docs += DocumentContext.CurrentDocument.DocumentID + "|"; // Actualize the cookie CookieHelper.SetValue(CookieName.RatedDocuments, docs, DateTime.Now.AddYears(1)); } } BoardInfo boardInfo = null; // If there is message board if (MessageBoardID > 0) { // Load message board boardInfo = Board; } else { // Create new message board according to webpart properties boardInfo = new BoardInfo(BoardProperties); BoardInfoProvider.SetBoardInfo(boardInfo); // Update information on current message board MessageBoardID = boardInfo.BoardID; // Set board-role relationship BoardRoleInfoProvider.SetBoardRoles(MessageBoardID, BoardProperties.BoardRoles); // Set moderators BoardModeratorInfoProvider.SetBoardModerators(MessageBoardID, BoardProperties.BoardModerators); } if (boardInfo != null) { // If the very new message is inserted if (MessageID == 0) { // If creating message set inserted to now and assign to board messageInfo.MessageInserted = currentUser.DateTimeNow; messageInfo.MessageBoardID = MessageBoardID; // Handle auto approve action bool isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(boardInfo); if (isAuthorized) { messageInfo.MessageApprovedByUserID = currentUser.UserID; messageInfo.MessageApproved = true; } else { // Is board moderated ? messageInfo.MessageApprovedByUserID = 0; messageInfo.MessageApproved = !boardInfo.BoardModerated; } } else { if (chkApproved.Checked) { // Set current user as approver messageInfo.MessageApproved = true; messageInfo.MessageApprovedByUserID = currentUser.UserID; } else { messageInfo.MessageApproved = false; messageInfo.MessageApprovedByUserID = 0; } } if (!AdvancedMode) { if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { // Columns to check Dictionary <string, int> collumns = new Dictionary <string, int>(); collumns.Add("MessageText", 0); collumns.Add("MessageUserName", 250); // Perform bad words check errorMessage = BadWordsHelper.CheckBadWords(messageInfo, collumns, "MessageApproved", "MessageApprovedByUserID", messageInfo.MessageText, currentUser.UserID, () => { return(ValidateMessage(messageInfo)); }); // Additionally check empty fields if (errorMessage == string.Empty) { if (!ValidateMessage(messageInfo)) { errorMessage = GetString("board.messageedit.emptybadword"); } } } } // Subscribe this user to message board if (chkSubscribe.Checked) { string email = messageInfo.MessageEmail; // Check for duplicate e-mails DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("((SubscriptionApproved = 1) OR (SubscriptionApproved IS NULL)) AND SubscriptionBoardID=" + MessageBoardID + " AND SubscriptionEmail='" + SecurityHelper.GetSafeQueryString(email, false) + "'", null); if (DataHelper.DataSourceIsEmpty(ds)) { BoardSubscriptionInfo bsi = new BoardSubscriptionInfo(); bsi.SubscriptionBoardID = MessageBoardID; bsi.SubscriptionEmail = email; if (!currentUser.IsPublic()) { bsi.SubscriptionUserID = currentUser.UserID; } BoardSubscriptionInfoProvider.Subscribe(bsi, DateTime.Now, true, true); ClearForm(); if (bsi.SubscriptionApproved) { LogSubscribingActivity(bsi, boardInfo); } } else { errorMessage = GetString("board.subscription.emailexists"); } } if (errorMessage == "") { try { // Save message info BoardMessageInfoProvider.SetBoardMessageInfo(messageInfo); LogCommentActivity(messageInfo, boardInfo); if (BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0)) { LogRatingActivity(ratingControl.CurrentRating); } // If the message is not approved let the user know message is waiting for approval if (messageInfo.MessageApproved == false) { ShowError(GetString("board.messageedit.waitingapproval")); } // Rise after message saved event if (OnAfterMessageSaved != null) { OnAfterMessageSaved(messageInfo); } // Hide message form if user has rated and empty rating is not allowed if (!BoardProperties.AllowEmptyRating && TreeProvider.HasRated(DocumentContext.CurrentDocument)) { pnlMessageEdit.Visible = false; lblAlreadyrated.Visible = true; } else { // Hide rating form if user has rated if (BoardProperties.EnableContentRating && (ratingControl != null) && ratingControl.GetCurrentRating() > 0) { plcRating.Visible = false; } } // Clear form content ClearForm(); } catch (Exception ex) { errorMessage = ex.Message; } } } } if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); } }
/// <summary> /// Initializes the controls. /// </summary> private void SetupControls() { btnFilter.Text = GetString("general.show"); btnOk.Text = GetString("general.ok"); // Mass actions this.gridElem.GridOptions.ShowSelection = this.AllowMassActions; this.rowActions.Visible = this.AllowMassActions; lblSiteName.AssociatedControlClientID = siteSelector.DropDownSingleSelect.ClientID; lblBoardName.AssociatedControlClientID = boardSelector.DropDownSingleSelect.ClientID; gridElem.IsLiveSite = this.IsLiveSite; gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction); gridElem.OnExternalDataBound += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound); gridElem.ZeroRowsText = GetString("general.nodatafound"); this.btnOk.OnClientClick += "return MassConfirm('" + this.drpActions.ClientID + "'," + ScriptHelper.GetString(GetString("General.ConfirmGlobalDelete")) + ");"; ScriptHelper.RegisterDialogScript(this.Page); if (this.GroupID == 0) { this.GroupID = QueryHelper.GetInteger("groupid", 0); } ReloadFilter(); if (!RequestHelper.IsPostBack()) { // Preselect filter data PreselectFilter(";;" + this.GroupID + ";;;NO;;"); } if (this.GroupID > 0) { // Hide site selection this.plcSite.Visible = false; } if (this.BoardID > 0) { // Hide board selection this.plcBoard.Visible = false; // Hide site selection this.plcSite.Visible = false; if ((this.GroupID > 0) && this.IsLiveSite) { InitializeGroupNewMessage(); } } siteSelector.UniSelector.OnSelectionChanged += new EventHandler(UniSelector_OnSelectionChanged); // Reload message list script string board = (this.BoardID > 0 ? this.BoardID.ToString() : this.boardSelector.Value.ToString()); string group = this.GroupID.ToString(); string user = HTMLHelper.HTMLEncode(this.txtUserName.Text); string message = HTMLHelper.HTMLEncode(this.txtMessage.Text); string approved = this.drpApproved.SelectedItem.Value; string spam = this.drpSpam.SelectedItem.Value; bool changemaster = QueryHelper.GetBoolean("changemaster", false); // Set site selector siteSelector.DropDownSingleSelect.AutoPostBack = true; siteSelector.AllowAll = true; siteSelector.IsLiveSite = this.IsLiveSite; boardSelector.IsLiveSite = this.IsLiveSite; boardSelector.GroupID = this.GroupID; if (!ShowFilter) { SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteName); if (si != null) { siteId = si.SiteID; } if (SiteName == TreeProvider.ALL_SITES) { siteId = -1; } } else { siteId = ValidationHelper.GetInteger(siteSelector.Value, 0); IsApproved = drpApproved.SelectedValue.ToLower(); IsSpam = drpSpam.SelectedValue.ToLower(); } if (siteId == 0) { siteId = CMSContext.CurrentSiteID; siteSelector.Value = siteId; } string cmdArg = siteId + ";" + board + ";" + group + ";" + user.Replace(";", "#sc#") + ";" + message.Replace(";", "#sc#") + ";" + approved + ";" + spam + ";" + changemaster; this.btnRefreshHdn.CommandArgument = cmdArg; this.mPostBackRefference = ControlsHelper.GetPostBackEventReference(this.btnRefreshHdn, null); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "RefreshBoardList", ScriptHelper.GetScript("function RefreshBoardList(){" + mPostBackRefference + "}")); this.siteSelector.OnlyRunningSites = this.IsLiveSite; string where = ""; // Sites dropdownlist if (siteId > 0) { where += "BoardSiteID = " + siteId + " AND"; } // Approved dropdownlist switch (IsApproved.ToLower()) { case "yes": where += " MessageApproved = 1 AND"; break; case "no": where += " MessageApproved = 0 AND"; break; } // Spam dropdownlist switch (IsSpam.ToLower()) { case "yes": where += " MessageIsSpam = 1 AND"; break; case "no": where += " MessageIsSpam = 0 AND"; break; } int selectedBoardId = 0; if (mBoardId > 0) { where += " MessageBoardID = " + mBoardId.ToString() + " AND"; selectedBoardId = mBoardId; } else { // Board dropdownlist selectedBoardId = ValidationHelper.GetInteger(boardSelector.Value, 0); if (selectedBoardId > 0) { where += " MessageBoardID = " + selectedBoardId + " AND"; } } if (txtUserName.Text.Trim() != "") { where += " MessageUserName LIKE '%" + txtUserName.Text.Trim().Replace("'", "''") + "%' AND"; } if (txtMessage.Text.Trim() != "") { where += " MessageText LIKE '%" + txtMessage.Text.Trim().Replace("'", "''") + "%' AND"; } bool isAuthorized = false; if (selectedBoardId > 0) { BoardInfo selectedBoard = BoardInfoProvider.GetBoardInfo(selectedBoardId); if (selectedBoard != null) { isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(selectedBoard); } } // Show messages to boards only where user is moderator if (!isAuthorized && (!(CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.MessageBoards", "Modify") || CMSContext.CurrentUser.IsGroupAdministrator(this.mGroupId)))) { where += " BoardID IN (SELECT BoardID FROM Board_Moderator WHERE Board_Moderator.UserID = " + CMSContext.CurrentUser.UserID + " ) AND "; } if (this.mGroupId > 0) { where += " BoardGroupID =" + this.mGroupId; } else { where += "(BoardGroupID =0 OR BoardGroupID IS NULL)"; } gridElem.WhereCondition = where; if ((!RequestHelper.IsPostBack()) && (!string.IsNullOrEmpty(ItemsPerPage))) { gridElem.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1); } if (!String.IsNullOrEmpty(OrderBy)) { gridElem.OrderBy = OrderBy; } }