Exemple #1
0
    protected void SaveSites()
    {
        // Check 'GlobalModify' permission
        CheckPollsModifyPermission(0);

        // Remove old items
        string newValues   = ValidationHelper.GetString(usSites.Value, null);
        string items       = DataHelper.GetNewItemsInList(newValues, currentValues);
        bool   falseValues = false;

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Remove poll from site
                    PollInfoProvider.RemovePollFromSite(pollId, siteId);
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int      siteId = ValidationHelper.GetInteger(item, 0);
                    SiteInfo si     = SiteInfoProvider.GetSiteInfo(siteId);

                    if (si != null)
                    {
                        // Check if site has license permission to assign poll to the site
                        if (!PollInfoProvider.LicenseVersionCheck(si.DomainName, FeatureEnum.Polls, ObjectActionEnum.Insert))
                        {
                            ShowError(GetString("LicenseVersion.Polls"));
                            falseValues = true;
                            continue;
                        }
                        else
                        {
                            // If poll is not in site, add it to the site
                            PollInfoProvider.AddPollToSite(pollId, si.SiteID);
                        }
                    }
                }
            }
        }

        // If there were some errors, reload uniselector
        if (falseValues)
        {
            usSites.Value = GetPollSites();
            usSites.Reload(true);
        }

        ShowChangesSaved();
    }
Exemple #2
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);
        }
    }
Exemple #3
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;
        }
    }