Esempio n. 1
0
    /// <summary>
    /// Gets and updates message board. Called when the "Get and update board" button is pressed.
    /// Expects the CreateMessageBoard method to be run first.
    /// </summary>
    private bool GetAndUpdateMessageBoard()
    {
        // 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 updateBoard = BoardInfoProvider.GetBoardInfo("MyNewBoard", root.DocumentID);
            if (updateBoard != null)
            {
                // Update the property
                updateBoard.BoardDisplayName = updateBoard.BoardDisplayName.ToLowerCSafe();

                // Update the message board
                BoardInfoProvider.SetBoardInfo(updateBoard);

                return(true);
            }
        }

        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Gets and bulk updates message boards. Called when the "Get and bulk update boards" button is pressed.
    /// Expects the CreateMessageBoard method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateMessageBoards()
    {
        // Prepare the parameters
        string where = "BoardName LIKE N'MyNewBoard%'";

        // Get the data
        DataSet boards = BoardInfoProvider.GetMessageBoards(where, null);

        if (!DataHelper.DataSourceIsEmpty(boards))
        {
            // Loop through the individual items
            foreach (DataRow boardDr in boards.Tables[0].Rows)
            {
                // Create object from DataRow
                BoardInfo modifyBoard = new BoardInfo(boardDr);

                // Update the property
                modifyBoard.BoardDisplayName = modifyBoard.BoardDisplayName.ToUpper();

                // Update the message board
                BoardInfoProvider.SetBoardInfo(modifyBoard);
            }

            return(true);
        }

        return(false);
    }
Esempio n. 3
0
    /// <summary>
    /// Creates message board. Called when the "Create board" button is pressed.
    /// </summary>
    private bool CreateMessageBoard()
    {
        // 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)
        {
            // Create new message board object
            BoardInfo newBoard = new BoardInfo();

            // Set the properties
            newBoard.BoardDisplayName         = "My new board";
            newBoard.BoardName                = "MyNewBoard";
            newBoard.BoardDescription         = "MyNewBoard";
            newBoard.BoardOpened              = true;
            newBoard.BoardEnabled             = true;
            newBoard.BoardAccess              = 0;
            newBoard.BoardModerated           = true;
            newBoard.BoardUseCaptcha          = false;
            newBoard.BoardMessages            = 0;
            newBoard.BoardEnableSubscriptions = true;
            newBoard.BoardSiteID              = SiteContext.CurrentSiteID;
            newBoard.BoardDocumentID          = root.DocumentID;

            // Create the message board
            BoardInfoProvider.SetBoardInfo(newBoard);

            return(true);
        }

        return(false);
    }
Esempio n. 4
0
    /// <summary>
    /// Board moderated checkbox change.
    /// </summary>
    protected void chkBoardModerated_CheckedChanged(object sender, EventArgs e)
    {
        if (!canModify || (Board == null))
        {
            return;
        }

        Board.BoardModerated = chkBoardModerated.Checked;
        BoardInfoProvider.SetBoardInfo(Board);

        ShowChangesSaved();

        ShouldReloadData = true;
    }
Esempio n. 5
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check permissions
        if (!CheckPermissions("cms.messageboards", PERMISSION_MODIFY))
        {
            return;
        }

        // Check if board exists
        if (Board != null)
        {
            if (radOnlyUsers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AuthenticatedUsers;
            }

            if (radAllUsers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AllUsers;
            }

            if (radOnlyRoles.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AuthorizedRoles;
            }

            if (radOnlyGroupAdmin.Visible && radOnlyGroupAdmin.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.GroupAdmin;
            }

            if (radGroupMembers.Visible && radGroupMembers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.GroupMembers;
            }

            if (radOnlyOwner.Visible && radOnlyOwner.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.Owner;
            }

            Board.BoardUseCaptcha = chkUseCaptcha.Checked;

            // Save changes
            BoardInfoProvider.SetBoardInfo(Board);

            ShowChangesSaved();
        }
    }
Esempio n. 6
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.messageboards", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        if (Board != null)
        {
            if (radOnlyUsers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AuthenticatedUsers;
            }

            if (radAllUsers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AllUsers;
            }

            if (radOnlyRoles.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.AuthorizedRoles;
            }

            if (radOnlyGroupAdmin.Visible && radOnlyGroupAdmin.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.GroupAdmin;
            }

            if (radGroupMembers.Visible && radGroupMembers.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.GroupMembers;
            }

            if (radOnlyOwner.Visible && radOnlyOwner.Checked)
            {
                Board.BoardAccess = SecurityAccessEnum.Owner;
            }

            Board.BoardUseCaptcha = chkUseCaptcha.Checked;

            BoardInfoProvider.SetBoardInfo(Board);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.Changessaved");
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Board moderated checkbox change.
    /// </summary>
    protected void chkBoardModerated_CheckedChanged(object sender, EventArgs e)
    {
        if (!canModify)
        {
            return;
        }

        if (Board != null)
        {
            Board.BoardModerated = chkBoardModerated.Checked;
            BoardInfoProvider.SetBoardInfo(Board);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.Changessaved");

            this.ShouldReloadData = true;
        }
    }
    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);
        }
    }
Esempio n. 9
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();
        }
    }
Esempio n. 10
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.messageboards", PERMISSION_MODIFY))
        {
            return;
        }

        if (Board != null)
        {
            string errMsg = ValidateForm();

            // If the entries were valid
            if (string.IsNullOrEmpty(errMsg))
            {
                // Get info on existing board

                try
                {
                    // Update board information
                    if (plcCodeName.Visible)
                    {
                        Board.BoardName = txtBoardCodeName.Text;
                    }

                    Board.BoardDisplayName = txtBoardDisplayName.Text;
                    Board.BoardDescription = txtBoardDescription.Text;
                    Board.BoardEnabled     = chkBoardEnable.Checked;
                    Board.BoardOpened      = chkBoardOpen.Checked;
                    Board.BoardOpenedFrom  = dtpBoardOpenFrom.SelectedDateTime;
                    Board.BoardOpenedTo    = dtpBoardOpenTo.SelectedDateTime;
                    if (!IsLiveSite)
                    {
                        Board.BoardUnsubscriptionURL = chkInheritUnsubUrl.Checked ? null : txtUnsubscriptionUrl.Text.Trim();
                        Board.BoardBaseURL           = chkInheritBaseUrl.Checked ? null : txtBaseUrl.Text.Trim();
                    }
                    Board.BoardRequireEmails       = chkBoardRequireEmail.Checked;
                    Board.BoardEnableSubscriptions = chkSubscriptionsEnable.Checked;

                    if (plcOnline.Visible)
                    {
                        Board.BoardLogActivity = chkLogActivity.Checked;
                    }

                    // Double opt-in
                    Board.BoardOptInApprovalURL = chkInheritOptInURL.Checked ? null : txtOptInURL.Text.Trim();
                    chkEnableOptIn.SetThreeStateValue(Board, "BoardEnableOptIn");
                    chkSendOptInConfirmation.SetThreeStateValue(Board, "BoardSendOptInConfirmation");

                    // Save changes
                    BoardInfoProvider.SetBoardInfo(Board);

                    // Inform user on success
                    ShowChangesSaved();

                    // Refresh tree if external parent
                    if (ExternalParent)
                    {
                        ltlScript.Text = ScriptHelper.GetScript("window.parent.parent.frames['tree'].RefreshNode('" + Board.BoardDisplayName + "', '" + BoardID + "')");
                    }

                    // Refresh the fields initialized with JavaScript
                    ReloadData();

                    ScriptHelper.RefreshTabHeader(Page, txtBoardDisplayName.Text);
                }
                catch (Exception ex)
                {
                    ShowError(GetString("general.saveerror"), ex.Message, null);
                }
            }
            else
            {
                // Inform user on error
                ShowError(errMsg);
            }
        }
    }
    /// <summary>
    /// OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check banned IP
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            ShowError(GetString("General.BannedIP"));
            return;
        }

        // Check input fields
        string email  = txtEmail.Text.Trim();
        string result = new Validator().NotEmpty(email, rfvEmailRequired.ErrorMessage)
                        .IsEmail(email, GetString("general.correctemailformat")).Result;

        // Try to subscribe new subscriber
        if (result == "")
        {
            // Try to create a new board
            BoardInfo boardInfo = null;
            if (BoardID == 0)
            {
                // Create new message board according to webpart properties
                boardInfo = new BoardInfo(BoardProperties);
                BoardInfoProvider.SetBoardInfo(boardInfo);

                // Update information on current message board
                BoardID = boardInfo.BoardID;

                // Set board-role relationship
                BoardRoleInfoProvider.SetBoardRoles(BoardID, BoardProperties.BoardRoles);

                // Set moderators
                BoardModeratorInfoProvider.SetBoardModerators(BoardID, BoardProperties.BoardModerators);
            }

            if (BoardID > 0)
            {
                // Check for duplicit e-mails
                DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("(SubscriptionApproved <> 0) AND (SubscriptionBoardID=" + BoardID +
                                                                            ") AND (SubscriptionEmail='" + SqlHelperClass.GetSafeQueryString(email, false) + "')", null);
                if (DataHelper.DataSourceIsEmpty(ds))
                {
                    BoardSubscriptionInfo bsi = new BoardSubscriptionInfo();
                    bsi.SubscriptionBoardID = BoardID;
                    bsi.SubscriptionEmail   = email;
                    if ((CMSContext.CurrentUser != null) && !CMSContext.CurrentUser.IsPublic())
                    {
                        bsi.SubscriptionUserID = CMSContext.CurrentUser.UserID;
                    }
                    BoardSubscriptionInfoProvider.Subscribe(bsi, DateTime.Now, true, true);

                    // Clear form
                    txtEmail.Text = "";
                    if (boardInfo == null)
                    {
                        boardInfo = BoardInfoProvider.GetBoardInfo(BoardID);
                    }

                    // If subscribed, log activity
                    if (bsi.SubscriptionApproved)
                    {
                        ShowConfirmation(GetString("board.subscription.beensubscribed"));
                        LogActivity(bsi, boardInfo);
                    }
                    else
                    {
                        string confirmation  = GetString("general.subscribed.doubleoptin");
                        int    optInInterval = BoardInfoProvider.DoubleOptInInterval(CMSContext.CurrentSiteName);
                        if (optInInterval > 0)
                        {
                            confirmation += "<br />" + string.Format(GetString("general.subscription_timeintervalwarning"), optInInterval);
                        }
                        ShowConfirmation(confirmation);
                    }
                }
                else
                {
                    result = GetString("board.subscription.emailexists");
                }
            }
        }

        if (result != String.Empty)
        {
            ShowError(result);
        }
    }
Esempio n. 12
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.messageboards", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        this.Board = BoardInfoProvider.GetBoardInfo(this.BoardID);
        if (this.Board != null)
        {
            string errMsg = ValidateForm();

            // If the entries were valid
            if (string.IsNullOrEmpty(errMsg))
            {
                // Get info on existing board

                try
                {
                    // Update board information
                    if (this.plcCodeName.Visible)
                    {
                        this.Board.BoardName = this.txtBoardCodeName.Text;
                    }

                    this.Board.BoardDisplayName = this.txtBoardDisplayName.Text;
                    this.Board.BoardDescription = this.txtBoardDescription.Text;
                    this.Board.BoardEnabled     = this.chkBoardEnable.Checked;
                    this.Board.BoardOpened      = this.chkBoardOpen.Checked;
                    this.Board.BoardOpenedFrom  = this.dtpBoardOpenFrom.SelectedDateTime;
                    this.Board.BoardOpenedTo    = this.dtpBoardOpenTo.SelectedDateTime;
                    if (!IsLiveSite)
                    {
                        this.Board.BoardUnsubscriptionURL = chkInheritUnsubUrl.Checked ? null : this.txtUnsubscriptionUrl.Text.Trim();
                        this.Board.BoardBaseURL           = chkInheritBaseUrl.Checked ? null : this.txtBaseUrl.Text.Trim();
                    }
                    this.Board.BoardRequireEmails       = this.chkBoardRequireEmail.Checked;
                    this.Board.BoardEnableSubscriptions = this.chkSubscriptionsEnable.Checked;

                    if (plcOnline.Visible)
                    {
                        this.Board.BoardLogActivity = this.chkLogActivity.Checked;
                    }

                    // Save changes
                    BoardInfoProvider.SetBoardInfo(this.Board);

                    // Inform user on success
                    this.lblInfo.Text    = GetString("general.changessaved");
                    this.lblInfo.Visible = true;

                    // Refresh tree if external parent
                    if (this.ExternalParent)
                    {
                        ltlScript.Text = ScriptHelper.GetScript("window.parent.parent.frames['tree'].RefreshNode('" + this.Board.BoardDisplayName + "', '" + this.Board.BoardID + "')");
                    }

                    // Refresh the fields initiaized with JavaScript
                    ReloadData();
                }
                catch (Exception ex)
                {
                    this.lblError.Visible = true;
                    this.lblError.Text    = GetString("general.erroroccurred") + " " + ex.Message;
                }
            }
            else
            {
                // Inform user on error
                this.lblError.Visible = true;
                this.lblError.Text    = errMsg;
            }
        }
    }
    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);
        }
    }
Esempio n. 14
0
    /// <summary>
    /// OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("General.BannedIP");
            return;
        }

        // Check input fields
        string email  = txtEmail.Text.Trim();
        string result = new Validator().NotEmpty(email, rfvEmailRequired.ErrorMessage)
                        .IsEmail(email, GetString("general.correctemailformat")).Result;

        // Try to subscribe new subscriber
        if (result == "")
        {
            // Try to create a new board
            BoardInfo boardInfo = null;
            if (this.BoardID == 0)
            {
                // Create new message board according to webpart properties
                boardInfo = new BoardInfo(this.BoardProperties);
                BoardInfoProvider.SetBoardInfo(boardInfo);

                // Update information on current message board
                this.BoardID = boardInfo.BoardID;

                // Set board-role relationship
                BoardRoleInfoProvider.SetBoardRoles(this.BoardID, this.BoardProperties.BoardRoles);

                // Set moderators
                BoardModeratorInfoProvider.SetBoardModerators(this.BoardID, this.BoardProperties.BoardModerators);
            }

            if (this.BoardID > 0)
            {
                // Check for duplicit e-mails
                DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("SubscriptionBoardID=" + this.BoardID +
                                                                            " AND SubscriptionEmail='" + SqlHelperClass.GetSafeQueryString(email, false) + "'", null);
                if (DataHelper.DataSourceIsEmpty(ds))
                {
                    BoardSubscriptionInfo bsi = new BoardSubscriptionInfo();
                    bsi.SubscriptionBoardID = this.BoardID;
                    bsi.SubscriptionEmail   = email;
                    if ((CMSContext.CurrentUser != null) && !CMSContext.CurrentUser.IsPublic())
                    {
                        bsi.SubscriptionUserID = CMSContext.CurrentUser.UserID;
                    }
                    BoardSubscriptionInfoProvider.SetBoardSubscriptionInfo(bsi);
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("board.subscription.beensubscribed");

                    // Clear form
                    txtEmail.Text = "";
                    if (boardInfo == null)
                    {
                        boardInfo = BoardInfoProvider.GetBoardInfo(this.BoardID);
                    }
                    LogActivity(bsi, boardInfo);
                }
                else
                {
                    result = GetString("board.subscription.emailexists");
                }
            }
        }

        if (result != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = result;
        }
    }