/// <summary>
    /// Loads content from specific newsletter template.
    /// </summary>
    private void LoadContent()
    {
        EmailTemplateInfo emailTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo(mTemplateID);

        if ((emailTemplate == null) || string.IsNullOrEmpty(emailTemplate.TemplateBody))
        {
            return;
        }

        // Remove security parameters from macros
        string templateText = MacroResolver.RemoveSecurityParameters(emailTemplate.TemplateBody, true, null);

        if (!RequestHelper.IsPostBack() && (issue != null))
        {
            // Load content of editable regions
            IssueHelper.LoadRegionsContents(ref regionsContents, issue.IssueText);
        }

        CMSEditableRegion editableRegion = null;
        LiteralControl    before         = null;
        int    count     = 0;
        int    textStart = 0;
        string region    = null;

        string[] parts           = null;
        string   name            = null;
        int      width           = 0;
        int      height          = 0;
        string   toolbarLocation = "Out:CKEditorToolbar";
        string   toolbarSetName  = "Newsletter";

        int editRegStart = templateText.IndexOfCSafe("$$", textStart);
        int editRegEnd   = 0;

        // Apply CSS e-mail template style
        HTMLHelper.AddToHeader(Page, CSSHelper.GetCSSFileLink(EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName)));

        while (editRegStart >= 0)
        {
            count++;

            before = new LiteralControl();
            // Get template text surrounding editable regions - make links absolute
            before.Text = URLHelper.MakeLinksAbsolute(templateText.Substring(textStart, (editRegStart - textStart)));
            plcContent.Controls.Add(before);

            // End of region
            editRegStart += 2;
            textStart     = editRegStart;
            if (editRegStart < templateText.Length - 1)
            {
                editRegEnd = templateText.IndexOfCSafe("$$", editRegStart);
                if (editRegEnd >= 0)
                {
                    region = templateText.Substring(editRegStart, editRegEnd - editRegStart);
                    parts  = (region + ":" + ":").Split(':');

                    try
                    {
                        name = parts[0];
                        if (!string.IsNullOrEmpty(name.Trim()))
                        {
                            width  = ValidationHelper.GetInteger(parts[1], 0);
                            height = ValidationHelper.GetInteger(parts[2], 0);

                            editableRegion            = new CMSEditableRegion();
                            editableRegion.ID         = name;
                            editableRegion.RegionType = CMSEditableRegionTypeEnum.HtmlEditor;
                            editableRegion.ViewMode   = ViewModeEnum.Edit;

                            editableRegion.DialogHeight = height;
                            editableRegion.DialogWidth  = width;

                            editableRegion.WordWrap = false;
                            editableRegion.HtmlAreaToolbarLocation = toolbarLocation;
                            editableRegion.RegionTitle             = name;
                            editableRegion.UseStylesheet           = false;
                            editableRegion.HTMLEditorCssStylesheet = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName);

                            if (!mReadOnly)
                            {
                                editableRegion.HtmlAreaToolbar = toolbarSetName;
                            }
                            else
                            {
                                editableRegion.HtmlAreaToolbar = "Disabled";
                            }

                            CMSHtmlEditor editor = editableRegion.HtmlEditor;
                            editor.AddExtraPlugin("CMSPlugins");
                            editor.AddExtraPlugin("autogrow");
                            editor.AutoGrowMinHeight            = height;
                            editor.LinkDialogConfig.UseFullURL  = true;
                            editor.QuickInsertConfig.UseFullURL = true;
                            editor.ResolverName = "NewsletterResolver";

                            DialogConfiguration dialogConfig = editor.MediaDialogConfig;
                            dialogConfig.UseFullURL         = true;
                            dialogConfig.MetaFileObjectID   = (issue != null) ? issue.IssueID : 0;
                            dialogConfig.MetaFileObjectType = (issue != null) && issue.IssueIsVariant ? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE;
                            dialogConfig.MetaFileCategory   = MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE;
                            dialogConfig.HideAttachments    = false;

                            editableRegion.LoadContent(ValidationHelper.GetString(regionsContents[name.ToLowerCSafe()], string.Empty));

                            plcContent.Controls.Add(editableRegion);

                            textStart = editRegEnd + 2;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            editRegStart = templateText.IndexOfCSafe("$$", textStart);
        }

        before      = new LiteralControl();
        before.Text = URLHelper.MakeLinksAbsolute(templateText.Substring(textStart));

        plcContent.Controls.Add(before);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        rfvTemplateDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvTemplateName.ErrorMessage        = GetString("NewsletterTemplate_Edit.ErrorEmptyName");

        ScriptHelper.RegisterSpellChecker(this);

        // Control initializations
        string varsScript = string.Format("var emptyNameMsg = '{0}'; \nvar emptyWidthMsg = '{1}'; \nvar emptyHeightMsg = '{2}'; \nvar spellURL = '{3}'; \n",
                                          GetString("NewsletterTemplate_Edit.EmptyNameMsg"),
                                          GetString("NewsletterTemplate_Edit.EmptyWidthMsg"),
                                          GetString("NewsletterTemplate_Edit.EmptyHeightMsg"),
                                          CMSContext.ResolveDialogUrl("~/CMSModules/Content/CMSDesk/Edit/SpellCheck.aspx"));

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Script_" + ClientID, ScriptHelper.GetScript(varsScript));

        // Set fields to be checked by Spell Checker
        string spellCheckScript = string.Format("if (typeof(spellCheckFields)==='undefined') {{var spellCheckFields = new Array();}} spellCheckFields.push('{0}');",
                                                htmlTemplateBody.ClientID);

        ScriptHelper.RegisterStartupScript(this, typeof(string), ClientID, ScriptHelper.GetScript(spellCheckScript));

        string currentEmailTemplate = GetString("NewsletterTemplate_Edit.NewItemCaption");

        // Get edited object and its existence
        EmailTemplateInfo emailTemplateObj = (EmailTemplateInfo)EditedObject;

        templateid = emailTemplateObj.TemplateID;

        currentEmailTemplate = emailTemplateObj.TemplateDisplayName;

        // Display editable region section only for e-mail templates of type "Issue template"
        if (emailTemplateObj.TemplateType == EmailTemplateType.Issue)
        {
            pnlEditableRegion.Visible = true;
            plcThumb.Visible          = true;
            ucThumbnail.Visible       = true;
            ucThumbnail.ObjectID      = emailTemplateObj.TemplateID;
            ucThumbnail.ObjectType    = NewsletterObjectType.NEWSLETTERTEMPLATE;
            ucThumbnail.Category      = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL;
            ucThumbnail.SiteID        = emailTemplateObj.TemplateSiteID;
        }
        else
        {
            plcSubject.Visible = true;
        }

        // Init CSS styles every time during page load
        htmlTemplateBody.EditorAreaCSS = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplateObj.TemplateName) + "&timestamp=" + DateTime.Now.Millisecond;

        // Initialize header actions
        InitHeaderActions(emailTemplateObj.TemplateID);

        // Initialize HTML editor
        InitHTMLEditor(emailTemplateObj);

        if (!RequestHelper.IsPostBack())
        {
            // Initialize dialog
            LoadData(emailTemplateObj);

            // Show that the emailTemplate was created successfully
            if (QueryHelper.GetBoolean("saved", false))
            {
                ShowChangesSaved();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get subscriber by its ID and check its existence
        var template = EditedObject as EmailTemplateInfo;

        if (template == null)
        {
            RedirectToAccessDenied(GetString("general.invalidparameters"));
        }

        if (!template.CheckPermissions(PermissionsEnum.Read, CurrentSiteName, CurrentUser))
        {
            RedirectToAccessDenied(template.TypeInfo.ModuleName, "ManageTemplates");
        }

        rfvTemplateDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvTemplateName.ErrorMessage        = GetString("NewsletterTemplate_Edit.ErrorEmptyName");

        ScriptHelper.RegisterSpellChecker(this);

        // Control initializations
        string varsScript = string.Format("var emptyNameMsg = '{0}'; \nvar emptyWidthMsg = '{1}'; \nvar emptyHeightMsg = '{2}'; \nvar spellURL = '{3}'; \n",
                                          GetString("NewsletterTemplate_Edit.EmptyNameMsg"),
                                          GetString("NewsletterTemplate_Edit.EmptyWidthMsg"),
                                          GetString("NewsletterTemplate_Edit.EmptyHeightMsg"),
                                          AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Content/CMSDesk/Edit/SpellCheck.aspx"));

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Script_" + ClientID, ScriptHelper.GetScript(varsScript));

        // Set fields to be checked by Spell Checker
        string spellCheckScript = string.Format("if (typeof(spellCheckFields)==='undefined') {{var spellCheckFields = new Array();}} spellCheckFields.push('{0}');",
                                                htmlTemplateBody.ClientID);

        ScriptHelper.RegisterStartupScript(this, typeof(string), ClientID, ScriptHelper.GetScript(spellCheckScript));

        // Get edited object and its existence
        EmailTemplateInfo emailTemplateObj = (EmailTemplateInfo)EditedObject;

        templateid = emailTemplateObj.TemplateID;

        // Display editable region section only for e-mail templates of type "Issue template"
        if (emailTemplateObj.TemplateType == EmailTemplateType.Issue)
        {
            pnlEditableRegion.Visible = true;
            plcThumb.Visible          = true;
            ucThumbnail.Visible       = true;
            ucThumbnail.ObjectID      = emailTemplateObj.TemplateID;
            ucThumbnail.ObjectType    = EmailTemplateInfo.OBJECT_TYPE;
            ucThumbnail.Category      = ObjectAttachmentsCategories.THUMBNAIL;
            ucThumbnail.SiteID        = emailTemplateObj.TemplateSiteID;
        }
        else
        {
            plcSubject.Visible = true;
        }

        // Init CSS styles every time during page load
        htmlTemplateBody.EditorAreaCSS = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplateObj.TemplateName) + "&timestamp=" + DateTime.Now.Millisecond;

        // Initialize header actions
        InitHeaderActions(emailTemplateObj.TemplateID);

        // Initialize HTML editor
        InitHTMLEditor(emailTemplateObj);

        if (!RequestHelper.IsPostBack())
        {
            // Initialize dialog
            LoadData(emailTemplateObj);

            // Show that the emailTemplate was created successfully
            if (QueryHelper.GetBoolean("saved", false))
            {
                ShowChangesSaved();
            }
        }
    }
    /// <summary>
    /// Loads content from specific newsletter template.
    /// </summary>
    private void LoadContent()
    {
        var urlHelper = new URLHelper();

        EmailTemplateInfo emailTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo(mTemplateID);

        if ((emailTemplate == null) || string.IsNullOrEmpty(emailTemplate.TemplateBody))
        {
            return;
        }

        // Remove security parameters from macros
        string templateText = MacroSecurityProcessor.RemoveSecurityParameters(emailTemplate.TemplateBody, true, null);

        if (!RequestHelper.IsPostBack() && (issue != null))
        {
            // Load content of editable regions
            IssueHelper.LoadRegionsContents(ref regionsContents, issue.IssueText);
        }

        LiteralControl before;
        int            count           = 0;
        int            textStart       = 0;
        string         toolbarLocation = "Out:CKToolbar";
        string         toolbarSetName  = "Newsletter";

        int editRegStart = templateText.IndexOfCSafe("$$", textStart);

        // Apply CSS e-mail template style
        Page.AddToHeader(CssLinkHelper.GetCssFileLink(EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName)));

        string domainName = SiteContext.CurrentSite.SiteIsContentOnly ? SiteContext.CurrentSite.SitePresentationURL : SiteContext.CurrentSite.DomainName;

        while (editRegStart >= 0)
        {
            count++;
            before = new LiteralControl();
            // Get template text surrounding editable regions - make links absolute
            before.Text = urlHelper.MakeLinksAbsolute(templateText.Substring(textStart, (editRegStart - textStart)), domainName);
            plcContent.Controls.Add(before);

            // End of region
            editRegStart += 2;
            textStart     = editRegStart;
            if (editRegStart < templateText.Length - 1)
            {
                int editRegEnd = templateText.IndexOfCSafe("$$", editRegStart);
                if (editRegEnd >= 0)
                {
                    string   region = templateText.Substring(editRegStart, editRegEnd - editRegStart);
                    string[] parts  = (region + ":" + ":").Split(':');

                    try
                    {
                        string name = parts[0];
                        if (!string.IsNullOrEmpty(name.Trim()))
                        {
                            Regex intNumber = RegexHelper.GetRegex("^[0-9]+");
                            int   width     = ValidationHelper.GetInteger(intNumber.Match(parts[1]).Value, 0);
                            int   height    = ValidationHelper.GetInteger(intNumber.Match(parts[2]).Value, 0);

                            CMSEditableRegion editableRegion = new CMSEditableRegion();
                            editableRegion.ID         = name;
                            editableRegion.RegionType = CMSEditableRegionTypeEnum.HtmlEditor;
                            editableRegion.ViewMode   = ViewModeEnum.Edit;

                            editableRegion.DialogHeight = height;
                            editableRegion.DialogWidth  = width;

                            editableRegion.WordWrap = false;
                            editableRegion.HtmlAreaToolbarLocation = toolbarLocation;
                            editableRegion.RegionTitle             = name;
                            editableRegion.UseStylesheet           = false;
                            editableRegion.HTMLEditorCssStylesheet = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName);

                            if (!mReadOnly)
                            {
                                editableRegion.HtmlAreaToolbar = toolbarSetName;
                            }
                            else
                            {
                                editableRegion.HtmlAreaToolbar = "Disabled";
                            }

                            CMSHtmlEditor editor = editableRegion.HtmlEditor;
                            editor.ExtraPlugins.Add("autogrow");
                            editor.AutoGrowMinHeight = height;
                            editor.ResolverName      = "NewsletterResolver";

                            DialogConfiguration dialogConfig = editor.MediaDialogConfig;
                            dialogConfig.MetaFileObjectID   = (issue != null) ? issue.IssueID : 0;
                            dialogConfig.MetaFileObjectType = (issue != null) && issue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE;
                            dialogConfig.MetaFileCategory   = ObjectAttachmentsCategories.ISSUE;
                            dialogConfig.HideAttachments    = false;

                            editableRegion.LoadContent(ValidationHelper.GetString(regionsContents[name.ToLowerCSafe()], string.Empty));

                            plcContent.Controls.Add(editableRegion);

                            textStart = editRegEnd + 2;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            editRegStart = templateText.IndexOfCSafe("$$", textStart);
        }

        before      = new LiteralControl();
        before.Text = urlHelper.MakeLinksAbsolute(templateText.Substring(textStart), domainName);

        plcContent.Controls.Add(before);
    }