Ejemplo n.º 1
0
    /// <summary>
    /// Checks modify permission. Returns false if checking failed.
    /// </summary>
    /// <param name="pollId">Poll ID</param>
    private bool CheckModifyPermission(int pollId)
    {
        // Get parent of answer object and see if it is global poll or site poll
        PollInfo pi = null;

        if (pollId > 0) // non-zero value when creating new poll
        {
            pi = PollInfoProvider.GetPollInfo(pollId);
        }
        else if (PollAnswer.AnswerPollID > 0) // not null when modifying existing answer
        {
            pi = PollInfoProvider.GetPollInfo(PollAnswer.AnswerPollID);
        }
        if (pi != null)
        {
            return((pi.PollSiteID > 0) && CheckPermissions("cms.polls", PERMISSION_MODIFY) ||
                   (pi.PollSiteID <= 0) && CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY));
        }
        return(false);
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Required field validator error messages initialization
        rfvCodeName.ErrorMessage          = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage       = GetString("general.requiresdisplayname");
        rfvQuestion.ErrorMessage          = GetString("Polls_New.QuestionError");
        rfvMaxLength.ErrorMessage         = GetString("general.errortexttoolong");
        rfvMaxLengthResponse.ErrorMessage = GetString("general.errortexttoolong");

        // Set if it is live site
        txtDisplayName.IsLiveSite = txtTitle.IsLiveSite = txtQuestion.IsLiveSite = txtResponseMessage.IsLiveSite = this.IsLiveSite;

        if (!RequestHelper.IsPostBack())
        {
            // Show possible license limitation error relayed from new poll page
            string error = QueryHelper.GetText("error", null);
            if (!string.IsNullOrEmpty(error))
            {
                lblError.Text    = error;
                lblError.Visible = true;
            }
        }

        if (pollObj == null)
        {
            pollObj = PollInfoProvider.GetPollInfo(this.ItemID);
            if ((this.ItemID > 0) && !IsLiveSite)
            {
                EditedObject = pollObj;
            }
        }

        if (pollObj != null)
        {
            // Fill editing form
            if (!RequestHelper.IsPostBack() && !IsLiveSite)
            {
                ReloadData();
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
        }

        if (pollAnswerObj != null)
        {
            // Load the fields
            txtAnswerText.Text       = pollAnswerObj.AnswerText;
            chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
            txtVotes.Text            = pollAnswerObj.AnswerCount.ToString();
            pnlGeneral.GroupingText  = GetString("general.general");
            plcVotes.Visible         = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleEntry.BIZFORM, CMSContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked  = plcOpenAnswerSettings.Visible = pollAnswerObj.AnswerIsOpenEnded;
                bizFormElem.Value             = pollAnswerObj.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value     = pollAnswerObj.AnswerAlternativeForm;
                chkAnswerHideForm.Checked     = pollAnswerObj.AnswerHideForm;
                pnlAnswerForm.GroupingText    = GetString("polls.answerformsettings");
            }
        }
        else
        {
            txtAnswerText.Text      = String.Empty;
            plcVotes.Visible        = false;
            pnlGeneral.GroupingText = string.Empty;
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        // Force reloading of PollAnswer info object if ID changed. The getter does the actual load.
        if ((PollAnswer != null) && (ItemID != PollAnswer.AnswerPollID))
        {
            PollAnswer   = null;
            EditedObject = PollAnswer;
        }

        if ((PollAnswer != null) && (PollAnswer.AnswerPollID > 0))
        {
            // Load the fields
            txtAnswerText.Text        = PollAnswer.AnswerText;
            chkAnswerEnabled.Checked  = PollAnswer.AnswerEnabled;
            txtVotes.Text             = PollAnswer.AnswerCount.ToString();
            plcVotes.Visible          = true;
            pnlGeneralHeading.Visible = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntryManager.IsModuleLoaded(ModuleName.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleName.BIZFORM, SiteContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(PollAnswer.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked  = updPanelForm.Visible = plcOpenAnswerSettings.Visible = PollAnswer.AnswerIsOpenEnded;
                bizFormElem.Value             = PollAnswer.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value     = PollAnswer.AnswerAlternativeForm;
                chkAnswerHideForm.Checked     = PollAnswer.AnswerHideForm;
            }
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible   = false;
        }
    }
Ejemplo n.º 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int      pollId = QueryHelper.GetInteger("pollid", 0);
        PollInfo pi     = PollInfoProvider.GetPollInfo(pollId);

        EditedObject = pi;

        // Check global and site read permmision
        CheckPollsReadPermission(pi.PollSiteID);

        PollProperties.ItemID     = pollId;
        PollProperties.IsLiveSite = false;
        PollProperties.OnSaved   += PollProperties_OnSaved;

        PollProperties.Enabled = CheckPollsModifyPermission(pi.PollSiteID, false);

        if (pi.PollSiteID > 0)
        {
            PollProperties.SiteID  = pi.PollSiteID;
            PollProperties.GroupID = pi.PollGroupID;
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Deletes answer. Called when the "Delete answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool DeleteAnswer()
    {
        // Get the poll
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the answer
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo deleteAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Delete the answer
                PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);

                return(deleteAnswer != null);
            }
        }

        return(false);
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Creates answer. Called when the "Create answer" button is pressed.
    /// </summary>
    private bool CreateAnswer()
    {
        // Get the poll
        PollInfo poll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (poll != null)
        {
            // Create new answer object
            PollAnswerInfo newAnswer = new PollAnswerInfo();

            // Set the properties
            newAnswer.AnswerPollID  = poll.PollID;
            newAnswer.AnswerText    = "My new answer";
            newAnswer.AnswerEnabled = true;
            newAnswer.AnswerCount   = 0;

            // Save the answer
            PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get poll id from querystring
        pollId       = QueryHelper.GetInteger("pollId", 0);
        pi           = PollInfoProvider.GetPollInfo(pollId);
        EditedObject = pi;

        // Check global and site read permmision
        this.CheckPollsReadPermission(pi.PollSiteID);

        string[,] actions = new string[2, 7];

        // New item link
        actions[0, 0] = HeaderActions.TYPE_HYPERLINK;
        actions[0, 1] = GetString("Polls_Answer_List.NewItemCaption");
        actions[0, 2] = null;
        actions[0, 3] = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId.ToString());
        actions[0, 4] = null;
        actions[0, 5] = GetImageUrl("Objects/Polls_PollAnswer/add.png");

        // Reset answer button
        actions[1, 0] = HeaderActions.TYPE_LINKBUTTON;
        actions[1, 1] = GetString("Polls_Answer_List.ResetButton");
        actions[1, 2] = "return confirm(" + ScriptHelper.GetString(GetString("Polls_Answer_List.ResetConfirmation")) + ");";
        actions[1, 3] = null;
        actions[1, 4] = null;
        actions[1, 5] = GetImageUrl("CMSModules/CMS_Polls/resetanswers.png");
        actions[1, 6] = "btnReset_Click";

        this.CurrentMaster.HeaderActions.Actions          = actions;
        this.CurrentMaster.HeaderActions.ActionPerformed += new CommandEventHandler(HeaderActions_ActionPerformed);

        AnswerList.OnEdit    += new EventHandler(AnswerList_OnEdit);
        AnswerList.PollId     = pollId;
        AnswerList.IsLiveSite = false;
    }
    /// <summary>
    /// Loads data.
    /// </summary>
    public void ReloadData(bool forceReload)
    {
        if (!StopProcessing)
        {
            SetContext();

            lblInfo.Text    = string.Empty;
            lblInfo.Visible = false;

            if (pi == null)
            {
                pi            = PollInfoProvider.GetPollInfo(PollCodeName, PollSiteID, PollGroupID);
                hasPermission = HasPermission();
                isOpened      = IsOpened();
            }

            // Show poll if current user has permission or if poll should be displayed even if user is not authorized
            // and if poll is opened or if poll should be opened even if it is not opened
            // ... and show group poll if it is poll of current group
            bool showPoll = (pi != null) && (hasPermission || !HideWhenNotAuthorized) && (isOpened || !HideWhenNotOpened);
            // Show site poll only if it is poll of current site
            if (showPoll && (pi.PollSiteID > 0) && (pi.PollSiteID != SiteContext.CurrentSiteID))
            {
                showPoll = false;
            }

            // Show global poll only if it is allowed for current site
            if (showPoll && (pi.PollSiteID == 0))
            {
                showPoll = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSPollsAllowGlobal");
            }

            if (showPoll)
            {
                Visible = true;

                // Load title
                lblTitle.Text = HTMLHelper.HTMLEncode(pi.PollTitle);
                // Load question
                lblQuestion.Text = HTMLHelper.HTMLEncode(pi.PollQuestion);

                if ((!forceReload) || ((forceReload) && (ShowResultsAfterVote)))
                {
                    // Add answer section
                    CreateAnswerSection(forceReload, CheckVoted && PollInfoProvider.HasVoted(pi.PollID));
                }
                else
                {
                    // Hide answer panel
                    pnlAnswer.Visible = false;
                }

                if ((forceReload) && (isOpened))
                {
                    // Hide footer with vote button
                    pnlFooter.Visible = false;

                    // Add poll response after voting
                    if ((errMessage != null) && (errMessage.Trim() != ""))
                    {
                        // Display message if error occurs
                        lblInfo.Text     = errMessage;
                        lblInfo.CssClass = "ErrorMessage";
                    }
                    else
                    {
                        // Display poll response message
                        lblResult.Text = HTMLHelper.HTMLEncode(pi.PollResponseMessage);
                    }
                }
                else if (isOpened)
                {
                    if (hasPermission && !(CheckVoted && (PollInfoProvider.HasVoted(pi.PollID))))
                    {
                        // Display footer wiht vote button
                        pnlFooter.Visible = true;
                        btnVote.Text      = ButtonText;
                    }
                    else
                    {
                        pnlFooter.Visible = false;
                    }
                }
                else
                {
                    pnlFooter.Visible = false;
                    lblInfo.Text      = GetString("Polls.Closed");
                }
            }
            else
            {
                Visible = false;
            }

            ReleaseContext();
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (CreateGlobal)
        {
            if (!CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY))
            {
                return;
            }
        }
        else
        {
            if (!CheckPermissions("cms.polls", PERMISSION_MODIFY))
            {
                return;
            }
        }

        // Generate code name in simple mode
        string codeName = txtCodeName.Text.Trim();

        if (DisplayMode == ControlDisplayModeEnum.Simple)
        {
            codeName = ValidationHelper.GetCodeName(txtDisplayName.Text.Trim(), null, null);
        }

        // Perform validation
        string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).NotEmpty(txtQuestion.Text.Trim(), rfvQuestion.ErrorMessage).Result;

        // Check CodeName for identifier format
        if (!ValidationHelper.IsCodeName(codeName))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat");
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            // Create new
            Poll.PollAllowMultipleAnswers = false;
            Poll.PollAccess = SecurityAccessEnum.AllUsers;

            // Check if codename already exists on a group or is a global
            PollInfo pi;
            if (CreateGlobal)
            {
                pi = PollInfoProvider.GetPollInfo("." + codeName, 0);
                if ((pi != null) && (pi.PollSiteID <= 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }
            else
            {
                pi = PollInfoProvider.GetPollInfo(codeName, SiteID, GroupID);
                if ((pi != null) && (pi.PollSiteID > 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                // Set the fields
                Poll.PollCodeName    = codeName;
                Poll.PollDisplayName = txtDisplayName.Text.Trim();
                Poll.PollTitle       = txtTitle.Text.Trim();
                Poll.PollQuestion    = txtQuestion.Text.Trim();
                Poll.PollLogActivity = true;
                if (GroupID > 0)
                {
                    if (SiteID <= 0)
                    {
                        ShowError(GetString("polls.nositeid"));
                        return;
                    }

                    Poll.PollGroupID = GroupID;
                    Poll.PollSiteID  = SiteID;
                }
                else
                {
                    // Assigned poll to particular site if it is not global poll
                    if (!CreateGlobal)
                    {
                        if (!PollInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Polls, ObjectActionEnum.Insert))
                        {
                            LicenseError = GetString("LicenseVersion.Polls");
                        }
                        else
                        {
                            Poll.PollSiteID = SiteID;
                        }
                    }
                }

                // Save the object
                PollInfoProvider.SetPollInfo(Poll);
                ItemID = Poll.PollID;

                // Add global poll to current site
                if ((SiteContext.CurrentSite != null) && CreateGlobal)
                {
                    if (PollInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Polls, ObjectActionEnum.Insert))
                    {
                        if ((Poll.PollGroupID == 0) && (Poll.PollSiteID == 0))
                        {
                            // Bind only global polls to current site
                            PollInfoProvider.AddPollToSite(Poll.PollID, SiteContext.CurrentSiteID);
                        }
                    }
                    else
                    {
                        LicenseError = GetString("LicenseVersion.Polls");
                    }
                }

                // Redirect to edit mode
                if (!error)
                {
                    RaiseOnSaved();
                }
            }
            else
            {
                // Error message - code name already exists
                ShowError(GetString("polls.codenameexists"));
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error message - validation
            ShowError(errorMessage);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        pollId   = QueryHelper.GetInteger("pollId", 0);
        answerId = QueryHelper.GetInteger("answerId", 0);
        groupId  = QueryHelper.GetInteger("groupId", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        // Initialize AnswerEdit control
        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID              = answerId;
        AnswerEdit.PollId              = pollId;
        AnswerEdit.OnSaved            += new EventHandler(AnswerEdit_OnSaved);
        AnswerEdit.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(AnswerEdit_OnCheckPermissions);

        if (answerId > 0)
        {
            CurrentMaster.Title.HelpTopicName = "answer_edit";
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;
            if (pollAnswerObj != null)
            {
                // Check that poll belongs to the specified group
                if ((pollAnswerObj.AnswerPollID > 0) && (groupId > 0))
                {
                    PollInfo poll = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);

                    // Answer not found or doesn't belong to specified group
                    if ((poll == null) || (poll.PollGroupID != groupId))
                    {
                        RedirectToAccessDenied(GetString("community.group.pollnotassigned"));
                    }
                }

                // Set control
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }
        else
        {
            CurrentMaster.Title.HelpTopicName = "new_answer";
        }

        // Validate
        EditedObject = PollInfoProvider.GetPollInfo(pollId);

        // Initializes page title control
        string[,] breadcrumbs           = new string[2, 3];
        breadcrumbs[0, 0]               = GetString("Polls_Answer_Edit.ItemListLink");
        breadcrumbs[0, 1]               = "~/CMSModules/Groups/Tools/Polls/Polls_Edit_Answer_List.aspx?pollId=" + pollId + "&groupId=" + groupId;
        breadcrumbs[0, 2]               = "";
        breadcrumbs[1, 0]               = currentPollAnswer;
        breadcrumbs[1, 1]               = "";
        breadcrumbs[1, 2]               = "";
        CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        // New item link
        HeaderAction add = new HeaderAction()
        {
            ControlType = HeaderActionTypeEnum.Hyperlink,
            Text        = GetString("Polls_Answer_List.NewItemCaption"),
            RedirectUrl = ResolveUrl("Polls_Edit_Answer_Edit.aspx?pollId=" + pollId.ToString() + "&groupId=" + groupId),
            ImageUrl    = GetImageUrl("Objects/Polls_PollAnswer/add.png")
        };

        CurrentMaster.HeaderActions.AddAction(add);
    }
Ejemplo n.º 12
0
    protected void UniGrid_OnBeforeDataReload()
    {
        PollInfo pi = PollInfoProvider.GetPollInfo(PollId);

        uniGrid.GridView.Columns[4].Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0) && bizFormsAvailable;
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if ((this.SiteID > 0) && !CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }
        if ((this.SiteID <= 0) && !CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_GLOBALMODIFY))
        {
            return;
        }

        // Get trimmed inputs
        string codeName    = txtCodeName.Text.Trim();
        string displayName = txtDisplayName.Text.Trim();
        string question    = txtQuestion.Text.Trim();

        // Validate the fields
        string errorMessage = new Validator()
                              .NotEmpty(codeName, rfvCodeName.ErrorMessage)
                              .NotEmpty(displayName, rfvDisplayName.ErrorMessage)
                              .NotEmpty(question, rfvQuestion.ErrorMessage)
                              .Result;

        if (!ValidationHelper.IsCodeName(codeName))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentificatorFormat");
        }
        else
        {
            // From/to date validation
            if (!dtPickerOpenFrom.IsValidRange() || !dtPickerOpenTo.IsValidRange())
            {
                errorMessage = GetString("general.errorinvaliddatetimerange");
            }

            if (string.IsNullOrEmpty(errorMessage) &&
                (!ValidationHelper.IsIntervalValid(dtPickerOpenFrom.SelectedDateTime, dtPickerOpenTo.SelectedDateTime, true)))
            {
                errorMessage = GetString("General.DateOverlaps");
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error message - validation
            lblError.Visible = true;
            lblError.Text    = errorMessage;
            return;
        }

        // Check uniqeness
        PollInfo secondPoll = null;

        if (this.SiteID <= 0)
        {
            // Try to find poll in global polls (leading period denotes global poll)
            secondPoll = PollInfoProvider.GetPollInfo("." + codeName, 0);
        }
        else
        {
            // Try to find poll in site polls
            secondPoll = PollInfoProvider.GetPollInfo(codeName, this.SiteID, this.GroupID);
        }
        if (secondPoll != null && (secondPoll.PollID != this.ItemID))
        {
            // Error message - Code name already exist
            lblError.Visible = true;
            lblError.Text    = GetString("polls.codenameexists");
            return;
        }

        pollObj = pollObj ?? PollInfoProvider.GetPollInfo(this.ItemID);
        if (pollObj == null)
        {
            // Error message - Poll does not exist
            lblError.Visible = true;
            lblError.Text    = GetString("polls.pollnotexist");
            return;
        }

        if (pollObj.PollSiteID != this.SiteID)
        {
            throw new Exception("[PollProperties.ascx]: Wrong poll object received since SiteID parameter wasn't provided.");
        }

        // Store the fields
        pollObj.PollCodeName             = codeName;
        pollObj.PollDisplayName          = displayName;
        pollObj.PollTitle                = txtTitle.Text.Trim();
        pollObj.PollQuestion             = question;
        pollObj.PollOpenFrom             = dtPickerOpenFrom.SelectedDateTime;
        pollObj.PollOpenTo               = dtPickerOpenTo.SelectedDateTime;
        pollObj.PollResponseMessage      = txtResponseMessage.Text.Trim();
        pollObj.PollAllowMultipleAnswers = chkAllowMultipleAnswers.Checked;

        if (plcOnline.Visible)
        {
            pollObj.PollLogActivity = chkLogActivity.Checked;
        }
        // Save the data
        try
        {
            PollInfoProvider.SetPollInfo(pollObj);
        }
        catch (Exception ex)
        {
            lblError.Visible = true;
            lblError.Text    = ex.Message;
            return;
        }

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

        // Raise on saved event
        RaiseOnSaved();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        pollId   = QueryHelper.GetInteger("pollId", 0);
        answerId = QueryHelper.GetInteger("answerId", 0);
        groupId  = QueryHelper.GetInteger("groupId", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        // Initialize AnswerEdit control
        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID              = answerId;
        AnswerEdit.PollId              = pollId;
        AnswerEdit.OnSaved            += AnswerEdit_OnSaved;
        AnswerEdit.OnCheckPermissions += AnswerEdit_OnCheckPermissions;

        if (answerId > 0)
        {
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;
            if (pollAnswerObj != null)
            {
                // Check that poll belongs to the specified group
                if ((pollAnswerObj.AnswerPollID > 0) && (groupId > 0))
                {
                    PollInfo poll = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);

                    // Answer not found or doesn't belong to specified group
                    if ((poll == null) || (poll.PollGroupID != groupId))
                    {
                        RedirectToAccessDenied(GetString("community.group.pollnotassigned"));
                    }
                }

                // Set control
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }

        // Validate
        EditedObject = PollInfoProvider.GetPollInfo(pollId);

        // Initialize breadcrumbs
        PageBreadcrumbs.Items.Add(new BreadcrumbItem
        {
            Text        = GetString("Polls_Answer_Edit.ItemListLink"),
            RedirectUrl = ResolveUrl("~/CMSModules/Groups/Tools/Polls/Polls_Edit_Answer_List.aspx?pollId=" + pollId + "&groupId=" + groupId),
        });
        PageBreadcrumbs.Items.Add(new BreadcrumbItem
        {
            Text = currentPollAnswer,
        });

        // New item link
        HeaderAction add = new HeaderAction
        {
            Text        = GetString("Polls_Answer_List.NewItemCaption"),
            RedirectUrl = ResolveUrl("Polls_Edit_Answer_Edit.aspx?pollId=" + pollId.ToString() + "&groupId=" + groupId)
        };

        CurrentMaster.HeaderActions.AddAction(add);
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (this.CreateGlobal)
        {
            if (!CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_GLOBALMODIFY))
            {
                return;
            }
        }
        else
        {
            if (!CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_MODIFY))
            {
                return;
            }
        }

        // Generate code name in simple mode
        string codeName = txtCodeName.Text.Trim();

        if (DisplayMode == ControlDisplayModeEnum.Simple)
        {
            codeName = ValidationHelper.GetCodeName(txtDisplayName.Text.Trim(), null, null);
        }

        // Perform validation
        string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).NotEmpty(txtQuestion.Text.Trim(), rfvQuestion.ErrorMessage).Result;

        // Check CodeName for identificator format
        if (!ValidationHelper.IsCodeName(codeName))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentificatorFormat");
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            bool isnew = false;

            // Create new
            PollInfo pollObj = new PollInfo();
            pollObj.PollAllowMultipleAnswers = false;
            pollObj.PollAccess = SecurityAccessEnum.AllUsers;

            // Check if codename already exists on a group or is a global
            PollInfo pi = null;
            if (this.CreateGlobal)
            {
                pi = PollInfoProvider.GetPollInfo("." + codeName, 0);
                if ((pi != null) && (pi.PollSiteID <= 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }
            else
            {
                pi = PollInfoProvider.GetPollInfo(codeName, this.SiteID, this.GroupID);
                if ((pi != null) && (pi.PollSiteID > 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                // Set the fields
                pollObj.PollCodeName    = codeName;
                pollObj.PollDisplayName = txtDisplayName.Text.Trim();
                pollObj.PollTitle       = txtTitle.Text.Trim();
                pollObj.PollQuestion    = txtQuestion.Text.Trim();
                pollObj.PollLogActivity = true;
                if (this.GroupID > 0)
                {
                    if (this.SiteID <= 0)
                    {
                        lblError.Text    = GetString("polls.nositeid");
                        lblError.Visible = true;
                        return;
                    }

                    pollObj.PollGroupID = this.GroupID;
                    pollObj.PollSiteID  = this.SiteID;
                }
                else
                {
                    // Assigned poll to particular site if it is not global poll
                    if (!this.CreateGlobal)
                    {
                        if (!PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert))
                        {
                            this.LicenseError = GetString("LicenseVersion.Polls");
                        }
                        else
                        {
                            pollObj.PollSiteID = this.SiteID;
                        }
                    }
                }

                // Save the object
                PollInfoProvider.SetPollInfo(pollObj);
                this.ItemID = pollObj.PollID;
                isnew       = true;

                // Add global poll to current site
                if ((CMSContext.CurrentSite != null) && this.CreateGlobal)
                {
                    if (PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert))
                    {
                        if ((pollObj.PollGroupID == 0) && (pollObj.PollSiteID == 0))
                        {
                            // Bind only global polls to current site
                            PollInfoProvider.AddPollToSite(pollObj.PollID, CMSContext.CurrentSiteID);
                        }
                    }
                    else
                    {
                        this.LicenseError = GetString("LicenseVersion.Polls");
                    }
                }

                // Redirect to edit mode
                if ((isnew) && (!lblError.Visible))
                {
                    RaiseOnSaved();
                }
            }
            else
            {
                // Error message - code name already exists
                lblError.Visible = true;
                lblError.Text    = GetString("polls.codenameexists");
            }
        }


        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error message - validation
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }