private void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
    {
        int queryMarkIndex = Request.RawUrl.IndexOfCSafe('?');
        string filterParams = Request.RawUrl.Substring(queryMarkIndex);

        ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList('" + filterParams + "'); CloseDialog();");
    }
Exemplo n.º 2
0
    void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
    {
        int queryMarkIndex = this.Request.RawUrl.IndexOf('?');
        string filterParams = this.Request.RawUrl.Substring(queryMarkIndex);

        this.ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList('" + filterParams + "'); window.close();");
    }
Exemplo n.º 3
0
    /// <summary>
    /// Deletes message. Called when the "Delete message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool DeleteMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);
            if (board != null)
            {
                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(board.BoardID);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Get the message
                    BoardMessageInfo deleteMessage = new BoardMessageInfo(messages.Tables[0].Rows[0]);

                    // Delete the message
                    BoardMessageInfoProvider.DeleteBoardMessageInfo(deleteMessage);

                    return(deleteMessage != null);
                }
            }
        }

        return(false);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Log activity posting
    /// </summary>
    /// <param name="bsi">Board subscription info object</param>
    /// <param name="bi">Message board info</param>
    private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
    {
        string siteName = CMSContext.CurrentSiteName;

        if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bmi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) ||
            !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.MessageBoardPostsEnabled(siteName))
        {
            return;
        }

        int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID();
        Dictionary <string, object> contactData = new Dictionary <string, object>();

        contactData.Add("ContactEmail", bmi.MessageEmail);
        contactData.Add("ContactWebSite", bmi.MessageURL);
        contactData.Add("ContactLastName", bmi.MessageUserName);
        ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId);

        TreeNode currentDoc = CMSContext.CurrentDocument;
        var      data       = new ActivityData()
        {
            ContactID    = contactId,
            SiteID       = CMSContext.CurrentSiteID,
            Type         = PredefinedActivityType.MESSAGE_BOARD_COMMENT,
            TitleData    = bi.BoardDisplayName,
            ItemID       = bmi.MessageBoardID,
            URL          = URLHelper.CurrentRelativePath,
            ItemDetailID = bmi.MessageID,
            NodeID       = (currentDoc != null ? currentDoc.NodeID : 0),
            Culture      = (currentDoc != null ? currentDoc.DocumentCulture : null),
            Campaign     = CMSContext.Campaign
        };

        ActivityLogProvider.LogActivity(data);
    }
Exemplo n.º 5
0
    void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
    {
        int    queryMarkIndex = this.Request.RawUrl.IndexOf('?');
        string filterParams   = this.Request.RawUrl.Substring(queryMarkIndex);

        this.ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList('" + filterParams + "'); window.close();");
    }
Exemplo n.º 6
0
    /// <summary>
    /// Gets and updates message. Called when the "Get and update message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool GetAndUpdateMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);

            if (board != null)
            {
                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(board.BoardID);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Create object from DataRow
                    BoardMessageInfo updateMessage = new BoardMessageInfo(messages.Tables[0].Rows[0]);

                    // Update the properties
                    updateMessage.MessageText = updateMessage.MessageText.ToLowerCSafe();

                    // Update the message
                    BoardMessageInfoProvider.SetBoardMessageInfo(updateMessage);

                    return(true);
                }
            }
        }

        return(false);
    }
    /// <summary>
    /// Reloads the form data.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        if (MessageID > 0)
        {
            messageInfo = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID);
            if (messageInfo != null)
            {
                EditedObject = messageInfo;

                // Check whether edited message belongs to a board from current site
                if ((Board != null) && (Board.BoardSiteID != SiteContext.CurrentSiteID))
                {
                    EditedObject = null;
                }

                // Set textfields and checkboxes
                txtEmail.Text       = messageInfo.MessageEmail;
                txtMessage.Text     = messageInfo.MessageText;
                txtURL.Text         = messageInfo.MessageURL;
                txtUserName.Text    = messageInfo.MessageUserName;
                chkApproved.Checked = messageInfo.MessageApproved;
                chkSpam.Checked     = messageInfo.MessageIsSpam;
                lblInserted.Text    = TimeZoneUIMethods.ConvertDateTime(messageInfo.MessageInserted, this).ToString();
            }
        }
        else
        {
            ClearForm();
        }
    }
Exemplo n.º 8
0
    protected void CheckLocalPermissions()
    {
        int groupId = 0;
        int boardId = mBoardId;

        BoardMessageInfo bmi = BoardMessageInfoProvider.GetBoardMessageInfo(mMessageId);

        if (bmi != null)
        {
            boardId = bmi.MessageBoardID;
        }

        BoardInfo bi = BoardInfoProvider.GetBoardInfo(boardId);

        if (bi != null)
        {
            groupId = bi.BoardGroupID;
        }

        // Check 'Manage' permission
        if (MembershipContext.AuthenticatedUser.IsGroupAdministrator(groupId))
        {
            return;
        }

        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.groups", CMSAdminControl.PERMISSION_MANAGE))
        {
            RedirectToAccessDenied("cms.groups", CMSAdminControl.PERMISSION_MANAGE);
        }
    }
    private void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
    {
        int    queryMarkIndex = Request.RawUrl.IndexOfCSafe('?');
        string filterParams   = ScriptHelper.GetString(Request.RawUrl.Substring(queryMarkIndex));

        ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList(" + filterParams + "); CloseDialog();");
    }
Exemplo n.º 10
0
    /// <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));
    }
    /// <summary>
    /// Validates board message. Optionally skips user name validation.
    /// </summary>
    /// <param name="messageInfo">Board message to be validated.</param>
    /// <param name="validateUserName">Whether to validate user name.</param>
    /// <returns>True if message is valid, false otherwise.</returns>
    private static bool ValidateMessage(BoardMessageInfo messageInfo, bool validateUserName = true)
    {
        if ((messageInfo.MessageText == null) || (validateUserName && (messageInfo.MessageUserName == null)))
        {
            return(false);
        }

        return((messageInfo.MessageText.Trim() != "") && (!validateUserName || (messageInfo.MessageUserName.Trim() != "")));
    }
Exemplo n.º 12
0
    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;
            }
        }
    }
Exemplo n.º 13
0
    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();
    }
Exemplo n.º 14
0
    private void messageEditElem_OnBeforeMessageSaved()
    {
        bool isOwner = false;

        BoardMessageInfo message = BoardMessageInfoProvider.GetBoardMessageInfo(mMessageId);

        if (message != null)
        {
            // Check if the current user is allowed to modify the message
            isOwner = ((MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) || cu.IsGroupAdministrator(mGroupId) ||
                       (BoardModeratorInfoProvider.IsUserBoardModerator(MembershipContext.AuthenticatedUser.UserID, message.MessageBoardID)) ||
                       (message.MessageUserID == MembershipContext.AuthenticatedUser.UserID));
        }

        if (!isOwner && !cu.IsGroupAdministrator(mGroupId) && !MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.groups", CMSAdminControl.PERMISSION_MANAGE))
        {
            RedirectToAccessDenied(GetString("board.messageedit.notallowed"));
        }
    }
Exemplo n.º 15
0
    void messageEditElem_OnBeforeMessageSaved()
    {
        bool isOwner = false;

        BoardMessageInfo message = BoardMessageInfoProvider.GetBoardMessageInfo(this.mMessageId);

        if (message != null)
        {
            // Check if the current user is allowed to modify the message
            isOwner = ((CMSContext.CurrentUser.IsGlobalAdministrator) || cu.IsGroupAdministrator(this.mGroupId) ||
                       (BoardModeratorInfoProvider.IsUserBoardModerator(CMSContext.CurrentUser.UserID, message.MessageBoardID)) ||
                       (message.MessageUserID == CMSContext.CurrentUser.UserID));
        }

        if (!isOwner && !cu.IsGroupAdministrator(this.mGroupId) && !CMSContext.CurrentUser.IsAuthorizedPerResource("cms.groups", CMSAdminControl.PERMISSION_MANAGE))
        {
            RedirectToAccessDenied(GetString("board.messageedit.notallowed"));
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Gets and bulk updates messages. Called when the "Get and bulk update messages" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateMessages()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);
            if (board != null)
            {
                // Prepare the parameters
                string where = "MessageBoardID = " + board.BoardID;

                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(where, null);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Loop through the individual items
                    foreach (DataRow messageDr in messages.Tables[0].Rows)
                    {
                        // Create object from DataRow
                        BoardMessageInfo modifyMessage = new BoardMessageInfo(messageDr);

                        // Update the property
                        modifyMessage.MessageText = modifyMessage.MessageText.ToUpper();

                        // Update the message
                        BoardMessageInfoProvider.SetBoardMessageInfo(modifyMessage);
                    }

                    return(true);
                }
            }
        }

        return(false);
    }
Exemplo n.º 17
0
    /// <summary>
    /// Creates message. Called when the "Create message" button is pressed.
    /// </summary>
    private bool CreateMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);

            if (board != null)
            {
                // Create new message object
                BoardMessageInfo newMessage = new BoardMessageInfo();

                // Set the properties
                newMessage.MessageUserName = MembershipContext.AuthenticatedUser.UserName;
                newMessage.MessageText     = "My new message";
                newMessage.MessageEmail    = "*****@*****.**";
                newMessage.MessageURL      = "";
                newMessage.MessageIsSpam   = false;
                newMessage.MessageApproved = true;
                newMessage.MessageInserted = DateTime.Now;
                newMessage.MessageBoardID  = board.BoardID;

                // Create the message
                BoardMessageInfoProvider.SetBoardMessageInfo(newMessage);

                return(true);
            }
        }

        return(false);
    }
    /// <summary>
    /// Log activity posting
    /// </summary>
    /// <param name="bsi">Board subscription info object</param>
    /// <param name="bi">Message board info</param>
    private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
    {
        string siteName = CMSContext.CurrentSiteName;
        if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bmi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)
            || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.MessageBoardPostsEnabled(siteName))
        {
            return;
        }

        TreeNode currentDoc = CMSContext.CurrentDocument;
        var data = new ActivityData()
        {
            ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(),
            SiteID = CMSContext.CurrentSiteID,
            Type = PredefinedActivityType.MESSAGE_BOARD_COMMENT,
            TitleData = bi.BoardDisplayName,
            ItemID = bmi.MessageBoardID,
            URL = URLHelper.CurrentRelativePath,
            ItemDetailID = bmi.MessageID,
            NodeID = (currentDoc != null ? currentDoc.NodeID : 0),
            Culture = (currentDoc != null ? currentDoc.DocumentCulture : null),
            Campaign = CMSContext.Campaign
        };
        ActivityLogProvider.LogActivity(data);
    }
Exemplo n.º 19
0
    void msgEdit_OnAfterMessageSaved(BoardMessageInfo message)
    {
        if ((bi == null) && (message != null) && (message.MessageBoardID > 0))
        {
            this.MessageBoardID = message.MessageBoardID;

            // Get updated board informnation
            bi = BoardInfoProvider.GetBoardInfo(message.MessageBoardID);

            userVerified = BoardInfoProvider.IsUserAuthorizedToManageMessages(bi);
        }

        this.rptBoardMessages.ClearCache();

        ReloadData();
    }
Exemplo n.º 20
0
    private void rptBoardMessages_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.DataItem != null)
        {
            if (e.Item.Controls.Count > 0)
            {
                // Load 'MessageActions.ascx' control
                BoardMessageActions boardMsgActions = (BoardMessageActions)e.Item.Controls[0].FindControl("messageActions");

                Control pnlRating = e.Item.Controls[0].FindControl("pnlRating");

                if ((boardMsgActions != null) || (pnlRating != null))
                {
                    DataRow drvRow = ((DataRowView)e.Item.DataItem).Row;

                    // Create new comment info object
                    BoardMessageInfo bmi = new BoardMessageInfo(drvRow);

                    if (boardMsgActions != null)
                    {
                        // Initialize control
                        boardMsgActions.MessageID      = bmi.MessageID;
                        boardMsgActions.MessageBoardID = MessageBoardID;

                        // Register for OnAction event
                        boardMsgActions.OnMessageAction += boardMsgActions_OnMessageAction;

                        // Handle buttons displaying
                        boardMsgActions.ShowApprove = ((BoardProperties.ShowApproveButton) && (!bmi.MessageApproved) && userVerified);
                        boardMsgActions.ShowReject  = ((BoardProperties.ShowRejectButton) && (bmi.MessageApproved) && userVerified);
                        boardMsgActions.ShowDelete  = ((BoardProperties.ShowDeleteButton) && userVerified);
                        boardMsgActions.ShowEdit    = ((BoardProperties.ShowEditButton) && userVerified);
                    }

                    // Init content rating control if enabled and rating is greater than zero
                    if (pnlRating != null)
                    {
                        if ((bmi.MessageRatingValue > 0) && (BoardProperties.EnableContentRating))
                        {
                            pnlRating.Visible = true;
                            if (DocumentContext.CurrentDocument != null)
                            {
                                AbstractRatingControl usrControl;
                                try
                                {
                                    // Insert rating control to page
                                    usrControl = (AbstractRatingControl)(Page.LoadUserControl(AbstractRatingControl.GetRatingControlUrl(BoardProperties.RatingType + ".ascx")));
                                }
                                catch (Exception ex)
                                {
                                    Controls.Add(new LiteralControl(ex.Message));
                                    return;
                                }

                                // Init values
                                usrControl.ID            = "messageRating";
                                usrControl.MaxRating     = BoardProperties.MaxRatingValue;
                                usrControl.CurrentRating = bmi.MessageRatingValue;
                                usrControl.Visible       = true;
                                usrControl.Enabled       = false;

                                pnlRating.Controls.Clear();
                                pnlRating.Controls.Add(usrControl);
                            }
                        }
                        else
                        {
                            pnlRating.Visible = false;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// Creates message. Called when the "Create message" button is pressed.
    /// </summary>
    private bool CreateMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);
        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);

            if (board != null)
            {
                // Create new message object
                BoardMessageInfo newMessage = new BoardMessageInfo();

                // Set the properties
                newMessage.MessageUserName = CMSContext.CurrentUser.UserName;
                newMessage.MessageText = "My new message";
                newMessage.MessageEmail = "*****@*****.**";
                newMessage.MessageURL = "";
                newMessage.MessageIsSpam = false;
                newMessage.MessageApproved = true;
                newMessage.MessageInserted = DateTime.Now;
                newMessage.MessageBoardID = board.BoardID;

                // Create the message
                BoardMessageInfoProvider.SetBoardMessageInfo(newMessage);

                return true;
            }
        }

        return false;
    }
Exemplo n.º 22
0
    /// <summary>
    /// Gets and bulk updates messages. Called when the "Get and bulk update messages" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateMessages()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);
        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);
            if (board != null)
            {
                // Prepare the parameters
                string where = "MessageBoardID = " + board.BoardID;

                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(where, null);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Loop through the individual items
                    foreach (DataRow messageDr in messages.Tables[0].Rows)
                    {
                        // Create object from DataRow
                        BoardMessageInfo modifyMessage = new BoardMessageInfo(messageDr);

                        // Update the property
                        modifyMessage.MessageText = modifyMessage.MessageText.ToUpper();

                        // Update the message
                        BoardMessageInfoProvider.SetBoardMessageInfo(modifyMessage);
                    }

                    return true;
                }
            }
        }

        return false;
    }
    protected void btnOk_Clicked(object sender, EventArgs e)
    {
        // Check permissions
        if (!CheckPermissions("cms.messageboards", PERMISSION_MODIFY))
        {
            return;
        }

        if (drpActions.SelectedValue != "SELECT")
        {
            var list = gridElem.SelectedItems;
            if (list.Count > 0)
            {
                foreach (string messageId in list)
                {
                    BoardMessageInfo message = BoardMessageInfoProvider.GetBoardMessageInfo(Convert.ToInt32(messageId));
                    switch (drpActions.SelectedValue)
                    {
                    case "DELETE":
                        // Delete board
                        BoardMessageInfoProvider.DeleteBoardMessageInfo(message);
                        break;

                    case "APPROVE":
                        if (!message.MessageApproved)
                        {
                            message.MessageApproved         = true;
                            message.MessageApprovedByUserID = MembershipContext.AuthenticatedUser.UserID;
                            BoardMessageInfoProvider.SetBoardMessageInfo(message);
                        }
                        break;

                    case "REJECT":
                        // Reject message
                        if (message.MessageApproved)
                        {
                            message.MessageApproved         = false;
                            message.MessageApprovedByUserID = 0;
                            BoardMessageInfoProvider.SetBoardMessageInfo(message);
                        }
                        break;

                    case "SPAM":
                        if (!message.MessageIsSpam)
                        {
                            message.MessageIsSpam = true;
                            BoardMessageInfoProvider.SetBoardMessageInfo(message);
                        }
                        break;

                    case "NOSPAM":
                        if (message.MessageIsSpam)
                        {
                            message.MessageIsSpam = false;
                            BoardMessageInfoProvider.SetBoardMessageInfo(message);
                        }
                        break;
                    }
                }
            }
            else
            {
                ltlScript.Text += ScriptHelper.GetAlertScript(GetString("general.noitems"));
            }
        }

        gridElem.ResetSelection();

        ReloadData();
    }
    /// <summary>
    /// Validates board message. Optionally skips user name validation.
    /// </summary>
    /// <param name="messageInfo">Board message to be validated.</param>
    /// <param name="validateUserName">Whether to validate user name.</param>
    /// <returns>True if message is valid, false otherwise.</returns>
    private static bool ValidateMessage(BoardMessageInfo messageInfo, bool validateUserName = true)
    {
        if ((messageInfo.MessageText == null) || (validateUserName && (messageInfo.MessageUserName == null)))
        {
            return false;
        }

        return ((messageInfo.MessageText.Trim() != "") && (!validateUserName || (messageInfo.MessageUserName.Trim() != "")));
    }
    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);
        }
    }
Exemplo n.º 26
0
    /// <summary>
    /// Gets and updates message. Called when the "Get and update message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool GetAndUpdateMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);
        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);

            if (board != null)
            {
                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(board.BoardID);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Create object from DataRow
                    BoardMessageInfo updateMessage = new BoardMessageInfo(messages.Tables[0].Rows[0]);

                    // Update the properties
                    updateMessage.MessageText = updateMessage.MessageText.ToLower();

                    // Update the message
                    BoardMessageInfoProvider.SetBoardMessageInfo(updateMessage);

                    return true;
                }
            }
        }

        return false;
    }
    /// <summary>
    /// Reloads the form data.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        if (MessageID > 0)
        {
            messageInfo = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID);
            if (messageInfo != null)
            {
                EditedObject = messageInfo;

                // Check whether edited message belongs to a board from current site
                if ((Board != null) && (Board.BoardSiteID != SiteContext.CurrentSiteID))
                {
                    EditedObject = null;
                }

                // Set textfields and checkboxes
                txtEmail.Text = messageInfo.MessageEmail;
                txtMessage.Text = messageInfo.MessageText;
                txtURL.Text = messageInfo.MessageURL;
                txtUserName.Text = messageInfo.MessageUserName;
                chkApproved.Checked = messageInfo.MessageApproved;
                chkSpam.Checked = messageInfo.MessageIsSpam;
                lblInserted.Text = TimeZoneMethods.ConvertDateTime(messageInfo.MessageInserted, this).ToString();
            }
        }
        else
        {
            ClearForm();
        }
    }
Exemplo n.º 28
0
    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);
        }
    }
Exemplo n.º 29
0
    /// <summary>
    /// Log activity posting
    /// </summary>
    /// <param name="bsi">Board subscription info object</param>
    /// <param name="bi">Message board info</param>
    private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
    {
        string siteName = CMSContext.CurrentSiteName;
        if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bmi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)
            || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.MessageBoardPostsEnabled(siteName))
        {
            return;
        }

        int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID();
        Dictionary<string, object> contactData = new Dictionary<string, object>();
        contactData.Add("ContactEmail", bmi.MessageEmail);
        contactData.Add("ContactWebSite", bmi.MessageURL);
        contactData.Add("ContactLastName", bmi.MessageUserName);
        ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId);

        TreeNode currentDoc = CMSContext.CurrentDocument;
        var data = new ActivityData()
        {
            ContactID = contactId,
            SiteID = CMSContext.CurrentSiteID,
            Type = PredefinedActivityType.MESSAGE_BOARD_COMMENT,
            TitleData = bi.BoardDisplayName,
            ItemID = bmi.MessageBoardID,
            URL = URLHelper.CurrentRelativePath,
            ItemDetailID = bmi.MessageID,
            NodeID = (currentDoc != null ? currentDoc.NodeID : 0),
            Culture = (currentDoc != null ? currentDoc.DocumentCulture : null),
            Campaign = CMSContext.Campaign
        };
        ActivityLogProvider.LogActivity(data);
    }
Exemplo n.º 30
0
    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();
        }
    }
Exemplo n.º 31
0
    /// <summary>
    /// Log activity posting
    /// </summary>
    /// <param name="bmi">Board subscription info object</param>
    /// <param name="bi">Message board info</param>
    private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
    {
        Activity activity = new ActivityMessageBoardComment(bmi, bi, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables);

        activity.Log();
    }
Exemplo n.º 32
0
 void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
 {
     this.ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList(); window.close();");
 }
    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 == "")
        {
            // 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 messageInfo;

            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 = TextHelper.LimitLength(txtEmail.Text.Trim(), txtEmail.MaxLength);
            messageInfo.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;
                }
            }

            messageInfo.MessageURL = TextHelper.LimitLength(url, txtURL.MaxLength);
            messageInfo.MessageURL = messageInfo.MessageURL.ToLowerCSafe().Replace("javascript", "_javascript");

            messageInfo.MessageUserName = TextHelper.LimitLength(txtUserName.Text.Trim(), txtUserName.MaxLength);
            if ((messageInfo.MessageID <= 0) && (!currentUser.IsPublic()))
            {
                messageInfo.MessageUserID = currentUser.UserID;
                if (!plcUserName.Visible)
                {
                    messageInfo.MessageUserName = GetDefaultUserName();
                }
            }

            messageInfo.MessageIsSpam = ValidationHelper.GetBoolean(chkSpam.Checked, false);

            if (BoardProperties.EnableContentRating && (ratingControl != null) &&
                (ratingControl.GetCurrentRating() > 0))
            {
                messageInfo.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
                        messageInfo.MessageInserted = DateTime.Now;
                        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
                            bool validateUserName = plcUserName.Visible;
                            errorMessage = BadWordsHelper.CheckBadWords(messageInfo, collumns, "MessageApproved", "MessageApprovedByUserID",
                                                                        messageInfo.MessageText, currentUser.UserID, () => ValidateMessage(messageInfo, validateUserName));

                            // Additionally check empty fields
                            if (errorMessage == string.Empty)
                            {
                                if (!ValidateMessage(messageInfo, validateUserName))
                                {
                                    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='" + 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"));
                                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(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)
                            {
                                ShowInformation(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.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);
        }
    }
 private void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
 {
     ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList(); CloseDialog();");
 }
 /// <summary>
 /// Log activity posting
 /// </summary>
 /// <param name="bmi">Board subscription info object</param>
 /// <param name="bi">Message board info</param>
 private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
 {
     Activity activity = new ActivityMessageBoardComment(bmi, bi, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
     activity.Log();
 }
    /// <summary>
    /// Rloads the form data.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        if (this.mMessageID > 0)
        {
            messageInfo = BoardMessageInfoProvider.GetBoardMessageInfo(this.mMessageID);
            if (messageInfo != null)
            {
                // Set textfields and checkboxes
                txtEmail.Text = messageInfo.MessageEmail;
                txtMessage.Text = messageInfo.MessageText;
                txtURL.Text = messageInfo.MessageURL;
                txtUserName.Text = messageInfo.MessageUserName;
                chkApproved.Checked = messageInfo.MessageApproved;
                chkSpam.Checked = messageInfo.MessageIsSpam;
                lblInserted.Text = CMSContext.ConvertDateTime(messageInfo.MessageInserted, this).ToString();
            }
        }
        else
        {
            ClearForm();
        }
    }
Exemplo n.º 37
0
    void rptBoardMessages_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.DataItem != null)
        {
            if (e.Item.Controls.Count > 0)
            {
                // Load 'MessageActions.ascx' control
                BoardMessageActions boardMsgActions = (BoardMessageActions)e.Item.Controls[0].FindControl("messageActions");

                Control pnlRating = e.Item.Controls[0].FindControl("pnlRating");

                if ((boardMsgActions != null) || (pnlRating != null))
                {
                    DataRow drvRow = ((DataRowView)e.Item.DataItem).Row;

                    // Create new comment info object
                    BoardMessageInfo bmi = new BoardMessageInfo(drvRow);

                    if (boardMsgActions != null)
                    {
                        // Initialize control
                        boardMsgActions.MessageID = bmi.MessageID;
                        boardMsgActions.MessageBoardID = this.MessageBoardID;

                        // Register for OnAction event
                        boardMsgActions.OnMessageAction += new BoardMessageActions.OnBoardMessageAction(boardMsgActions_OnMessageAction);

                        // Handle buttons displaying
                        boardMsgActions.ShowApprove = ((this.BoardProperties.ShowApproveButton) && (!bmi.MessageApproved) && userVerified);
                        boardMsgActions.ShowReject = ((this.BoardProperties.ShowRejectButton) && (bmi.MessageApproved) && userVerified);
                        boardMsgActions.ShowDelete = ((this.BoardProperties.ShowDeleteButton) && userVerified);
                        boardMsgActions.ShowEdit = ((this.BoardProperties.ShowEditButton) && userVerified);
                    }

                    // Init content rating control if enabled and rating is greater than zero
                    if (pnlRating != null)
                    {
                        if ((bmi.MessageRatingValue > 0) && (this.BoardProperties.EnableContentRating))
                        {
                            pnlRating.Visible = true;
                            AbstractRatingControl usrControl = null;
                            if (CMSContext.CurrentDocument != null)
                            {
                                try
                                {
                                    // Insert rating control to page
                                    usrControl = (AbstractRatingControl)(this.Page.LoadControl(AbstractRatingControl.GetRatingControlUrl(this.BoardProperties.RatingType + ".ascx")));
                                }
                                catch (Exception ex)
                                {
                                    this.Controls.Add(new LiteralControl(ex.Message));
                                    return;
                                }

                                // Init values
                                usrControl.ID = "messageRating";
                                usrControl.MaxRating = this.BoardProperties.MaxRatingValue;
                                usrControl.CurrentRating = bmi.MessageRatingValue;
                                usrControl.Visible = true;
                                usrControl.Enabled = false;

                                pnlRating.Controls.Clear();
                                pnlRating.Controls.Add(usrControl);
                            }
                        }
                        else
                        {
                            pnlRating.Visible = false;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 38
0
    /// <summary>
    /// Deletes message. Called when the "Delete message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool DeleteMessage()
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);
        if (root != null)
        {
            // Get the message board
            BoardInfo board = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);
            if (board != null)
            {
                // Get the data
                DataSet messages = BoardMessageInfoProvider.GetMessages(board.BoardID);
                if (!DataHelper.DataSourceIsEmpty(messages))
                {
                    // Get the message
                    BoardMessageInfo deleteMessage = new BoardMessageInfo(messages.Tables[0].Rows[0]);

                    // Delete the message
                    BoardMessageInfoProvider.DeleteBoardMessageInfo(deleteMessage);

                    return (deleteMessage != null);
                }
            }
        }

        return false;
    }
 /// <summary>
 /// Log activity posting
 /// </summary>
 /// <param name="bmi">Board subscription info object</param>
 /// <param name="bi">Message board info</param>
 private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi)
 {
     mMessageBoardActivityLogger.LogMessageBoardCommentActivity(bmi, bi, DocumentContext.CurrentDocument);
 }
Exemplo n.º 40
0
    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();
        }
    }
 void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
 {
     this.ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList(); window.close();");
 }
 private void messageEditElem_OnAfterMessageSaved(BoardMessageInfo message)
 {
     ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshBoardList(); CloseDialog();");
 }