示例#1
0
    protected void ValidateValues(object sender, EventArgs e)
    {
        // Validate unsubscription template
        if (ValidationHelper.GetInteger(NewForm.GetFieldValue("NewsletterUnsubscriptionTemplateID"), 0) == 0)
        {
            ShowError(GetString("Newsletter_Edit.NoUnsubscriptionTemplateSelected"));
            NewForm.StopProcessing = true;
        }

        // Validate subscription template
        if (ValidationHelper.GetInteger(NewForm.GetFieldValue("NewsletterSubscriptionTemplateID"), 0) == 0)
        {
            ShowError(GetString("Newsletter_Edit.NoSubscriptionTemplateSelected"));
            NewForm.StopProcessing = true;
        }

        // If Template based, validate template
        if (GetUpperNewsletterType() == NewsletterType.TemplateBased && ValidationHelper.GetInteger(NewForm.GetFieldValue("NewsletterTemplateID"), 0) == 0)
        {
            ShowError(GetString("Newsletter_Edit.NoEmailTemplateSelected"));
            NewForm.StopProcessing = true;
        }

        // If Dynamic, validate schedule interval and Source page URL
        if (GetUpperNewsletterType() == NewsletterType.Dynamic)
        {
            if (ValidationHelper.GetString(NewForm.GetFieldValue("NewsletterDynamicURL"), string.Empty) == string.Empty)
            {
                // Source page URL can not be empty
                ShowError(GetString("newsletter_edit.sourcepageurlempty"));
                NewForm.StopProcessing = true;
            }

            if (chkSchedule.Checked)
            {
                if (!ScheduleInterval.CheckOneDayMinimum())
                {
                    // Problem occurred while setting schedule interval for dynamic newsletter
                    ShowError(GetString("Newsletter_Edit.NoDaySelected"));
                    NewForm.StopProcessing = true;
                }

                if (SchedulingHelper.DecodeInterval(ScheduleInterval.ScheduleInterval).StartTime == DateTime.MinValue)
                {
                    ShowError(GetString("Newsletter.IncorrectDate"));
                    NewForm.StopProcessing = true;
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check 'configure' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "configure");
        }

        // Validate base inputs (newsletter display name, code name, sender name, sender e-mail)
        string errorMessage = new Validator().NotEmpty(txtNewsletterDisplayName.Text.Trim(), GetString("general.requiresdisplayname")).NotEmpty(txtNewsletterName.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptyName")).NotEmpty(txtNewsletterSenderName.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptySenderName")).NotEmpty(txtNewsletterSenderEmail.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptySenderEmail")).IsEmail(txtNewsletterSenderEmail.Text.Trim(), GetString("Newsletter_Edit.ErrorEmailFormat")).IsCodeName(txtNewsletterName.Text.Trim(), GetString("general.invalidcodename")).Result;

        if (String.IsNullOrEmpty(errorMessage))
        {
            if (String.IsNullOrEmpty((string)subscriptionTemplate.Value))
            {
                // No subscription template selected
                lblSubscriptionError.Visible = true;
                return;
            }

            if (String.IsNullOrEmpty((string)unsubscriptionTemplate.Value))
            {
                // No unsubscription template selected
                lblUnsubscriptionError.Visible = true;
                return;
            }

            if ((radTemplateBased.Checked) && (String.IsNullOrEmpty((string)issueTemplate.Value)))
            {
                // No issue template selected for template based newsletter
                lblIssueError.Visible = true;
                return;
            }

            if ((radDynamic.Checked) && (String.IsNullOrEmpty(txtNewsletterDynamicURL.Text.Trim())))
            {
                // Dynamic URL cannot be empty
                ShowError(GetString("menuitem_edit.errorpageurlempty"));
                return;
            }

            if ((radDynamic.Checked) && (chkSchedule.Checked) && (!ScheduleInterval.CheckOneDayMinimum()))
            {
                // Problem occurred while setting schedule interval for dynamic newsletter
                ShowError(GetString("Newsletter_Edit.NoDaySelected"));
                return;
            }

            if ((radDynamic.Checked) && (chkSchedule.Checked) && (SchedulingHelper.DecodeInterval(ScheduleInterval.ScheduleInterval).StartTime == DateTime.MinValue))
            {
                ShowError(GetString("Newsletter.IncorrectDate"));
                return;
            }

            // Newsletter code name must to be unique per site...
            NewsletterInfo newsletterObj = NewsletterInfoProvider.GetNewsletterInfo(txtNewsletterName.Text.Trim(), CMSContext.CurrentSiteID);

            // If newsletter code name is unique...
            if (newsletterObj == null)
            {
                // Create new item -> insert
                newsletterObj = new NewsletterInfo();

                newsletterObj.NewsletterDisplayName = txtNewsletterDisplayName.Text.Trim();
                newsletterObj.NewsletterName        = txtNewsletterName.Text.Trim();

                int selectedValue = ValidationHelper.GetInteger(subscriptionTemplate.Value, 0);
                if (selectedValue != 0)
                {
                    newsletterObj.NewsletterSubscriptionTemplateID = selectedValue;
                }
                else
                {
                    ShowError(GetString("Newsletter_Edit.NoSubscriptionTemplateSelected"));
                    return;
                }

                selectedValue = ValidationHelper.GetInteger(unsubscriptionTemplate.Value, 0);
                if (selectedValue != 0)
                {
                    newsletterObj.NewsletterUnsubscriptionTemplateID = selectedValue;
                }
                else
                {
                    ShowError(GetString("Newsletter_Edit.NoUnsubscriptionTemplateSelected"));
                    return;
                }
                newsletterObj.NewsletterSenderName  = txtNewsletterSenderName.Text.Trim();
                newsletterObj.NewsletterSenderEmail = txtNewsletterSenderEmail.Text.Trim();
                if (radDynamic.Checked)
                {
                    newsletterObj.NewsletterDynamicURL = txtNewsletterDynamicURL.Text.Trim();
                    newsletterObj.NewsletterType       = NewsletterType.Dynamic;
                }
                else
                {
                    selectedValue = ValidationHelper.GetInteger(issueTemplate.Value, 0);
                    if (selectedValue != 0)
                    {
                        newsletterObj.NewsletterTemplateID = selectedValue;
                    }
                    else
                    {
                        ShowError(GetString("Newsletter_Edit.NoEmailTemplateSelected"));
                        return;
                    }
                    newsletterObj.NewsletterType = NewsletterType.TemplateBased;
                }
                newsletterObj.NewsletterSiteID          = CMSContext.CurrentSiteID;
                newsletterObj.NewsletterGUID            = Guid.NewGuid();
                newsletterObj.NewsletterLogActivity     = true;
                newsletterObj.NewsletterEnableResending = true;

                try
                {
                    // Create new newsletter
                    NewsletterInfoProvider.SetNewsletterInfo(newsletterObj);

                    if (radDynamic.Checked)
                    {
                        if (chkSchedule.Checked)
                        {
                            // Create new task to schedule the dynamic newsletter
                            TaskInfo task = new TaskInfo();
                            task.TaskAssemblyName = "CMS.Newsletter";
                            task.TaskClass        = "CMS.Newsletter.DynamicNewsletterSender";
                            task.TaskDisplayName  = GetString("DynamicNewsletter.TaskName") + newsletterObj.NewsletterDisplayName;
                            task.TaskEnabled      = true;
                            task.TaskInterval     = ScheduleInterval.ScheduleInterval;
                            task.TaskLastResult   = string.Empty;
                            task.TaskName         = "DynamicNewsletter." + ValidationHelper.GetCodeName(newsletterObj.NewsletterName, "_");
                            task.TaskSiteID       = CMSContext.CurrentSiteID;
                            task.TaskNextRunTime  = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime());
                            task.TaskData         = newsletterObj.NewsletterGUID.ToString();
                            // Set task for processing in external service
                            task.TaskAllowExternalService = true;
                            task.TaskUseExternalService   = (SchedulingHelper.UseExternalService && NewsletterHelper.UseExternalServiceForDynamicNewsletters(CMSContext.CurrentSiteName));
                            task.TaskType = ScheduledTaskTypeEnum.System;

                            TaskInfoProvider.SetTaskInfo(task);

                            newsletterObj.NewsletterDynamicScheduledTaskID = task.TaskID;
                            NewsletterInfoProvider.SetNewsletterInfo(newsletterObj);
                        }
                    }
                    URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + ValidationHelper.GetString(newsletterObj.NewsletterID, null) + "&saved=1");
                }
                catch (Exception ex)
                {
                    ShowError(GetString(ex.Message));
                }
            }
            else
            {
                ShowError(GetString("Newsletter_Edit.NewsletterNameExists"));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }