예제 #1
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) && (!ScheduleInterval.CheckOneDayMinimum()))
            {
                // Problem occurred while setting schedule interval for dynamic newsletter
                lblError.Visible = true;
                lblError.Text    = GetString("Newsletter_Edit.NoDaySelected");
                return;
            }

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

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

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

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

                selectedValue = ValidationHelper.GetInteger(unsubscriptionTemplate.Value, 0);
                if (selectedValue != 0)
                {
                    newsletterObj.NewsletterUnsubscriptionTemplateID = selectedValue;
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = 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
                    {
                        lblError.Visible = true;
                        lblError.Text    = GetString("Newsletter_Edit.NoEmailTemplateSelected");
                        return;
                    }
                    newsletterObj.NewsletterType = NewsletterType.TemplateBased;
                }
                newsletterObj.NewsletterSiteID      = CMSContext.CurrentSiteID;
                newsletterObj.NewsletterGUID        = Guid.NewGuid();
                newsletterObj.NewsletterLogActivity = true;

                if (NewsletterProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Newsletters, VersionActionEnum.Insert))
                {
                    // Create new newsletter
                    NewsletterProvider.SetNewsletter(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 && NewsletterProvider.UseExternalServiceForDynamicNewsletters(CMSContext.CurrentSiteName));

                            TaskInfoProvider.SetTaskInfo(task);

                            newsletterObj.NewsletterDynamicScheduledTaskID = task.TaskID;
                            NewsletterProvider.SetNewsletter(newsletterObj);
                        }
                    }
                    URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + ValidationHelper.GetString(newsletterObj.NewsletterID, null) + "&saved=1");
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("LicenseVersionCheck.Newsletter");
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = GetString("Newsletter_Edit.NewsletterNameExists");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
예제 #2
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLower())
        {
        case "edit":
            URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + Convert.ToString(actionArgument));
            break;

        case "delete":
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "configure");
            }
            // delete Newsletter object from database
            NewsletterProvider.DeleteNewsletter(ValidationHelper.GetInteger(actionArgument, 0));
            break;

        case "clone":
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "configure");
            }

            Newsletter oldnl = NewsletterProvider.GetNewsletter(ValidationHelper.GetInteger(actionArgument, 0));
            if (oldnl != null)
            {
                // Create new newsletter
                Newsletter nl = oldnl.Clone(true);

                // Find unique newsletter code name
                string newsletterDisplayName = nl.NewsletterDisplayName;
                string newsletterName        = nl.NewsletterName;

                while (NewsletterProvider.GetNewsletter(newsletterName, nl.NewsletterSiteID) != null)
                {
                    newsletterName        = Increment(newsletterName, "_", "");
                    newsletterDisplayName = Increment(newsletterDisplayName, "(", ")");
                }

                nl.NewsletterName        = newsletterName;
                nl.NewsletterDisplayName = newsletterDisplayName;

                if (NewsletterProvider.LicenseVersionCheck(CMSContext.CurrentSite.DomainName, FeatureEnum.Newsletters, VersionActionEnum.Insert))
                {
                    // Clone scheduled task
                    if (oldnl.NewsletterDynamicScheduledTaskID > 0)
                    {
                        TaskInfo oldti = TaskInfoProvider.GetTaskInfo(oldnl.NewsletterDynamicScheduledTaskID);
                        if (oldti != null)
                        {
                            // Create new task
                            TaskInfo ti = oldti.Clone(true);

                            ti.TaskDisplayName = GetString("DynamicNewsletter.TaskName") + nl.NewsletterDisplayName;

                            // Save the task
                            TaskInfoProvider.SetTaskInfo(ti);

                            nl.NewsletterDynamicScheduledTaskID = ti.TaskID;
                        }
                    }

                    NewsletterProvider.SetNewsletter(nl);
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("licenseversioncheck.newsletterclone");
                }
            }
            break;
        }
    }