private bool Save(bool closeOnSave)
    {
        // Validate user input
        string errorMessage = new Validator()
                              .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                              .IsCodeName(txtContainerName.Text, GetString("General.InvalidCodeName"))
                              .Result;

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return(false);
        }

        // Parse the container text
        string text  = txtContainerText.Text;
        string after = "";

        int wpIndex = text.IndexOf(WebPartContainerInfoProvider.WP_CHAR);

        if (wpIndex >= 0)
        {
            after = text.Substring(wpIndex + 1).Replace(WebPartContainerInfoProvider.WP_CHAR, "");
            text  = text.Substring(0, wpIndex);
        }

        WebPartContainerInfo webPartContainerObj = new WebPartContainerInfo()
        {
            ContainerTextBefore  = text,
            ContainerTextAfter   = after,
            ContainerCSS         = txtContainerCSS.Text,
            ContainerName        = txtContainerName.Text.Trim(),
            ContainerDisplayName = txtContainerDisplayName.Text.Trim()
        };

        // Check for duplicity
        if (WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName) != null)
        {
            ShowError(GetString("Container_Edit.UniqueError"));
            return(false);
        }

        WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);
        CMSContext.EditedObject = webPartContainerObj;
        CMSObjectManager.CheckOutNewObject(Page);

        if (mDialogMode)
        {
            ProcessDialog(webPartContainerObj, closeOnSave);
        }
        else
        {
            ProcessPage(webPartContainerObj);
        }

        return(true);
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Limit text length
        txtTemplateCodeName.Text    = TextHelper.LimitLength(txtTemplateCodeName.Text.Trim(), 100, "");
        txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

        // finds whether required fields are not empty
        string result = new Validator().NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName")).NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                        .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                        .Result;

        if (result == "")
        {
            if (parentCategoryId > 0)
            {
                if (!PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
                {
                    //Insert page template info
                    PageTemplateInfo pi = new PageTemplateInfo();

                    pi.PageTemplateType = PageTemplateTypeEnum.Portal;
                    pi.DisplayName      = txtTemplateDisplayName.Text;
                    pi.CodeName         = txtTemplateCodeName.Text;
                    pi.IsPortal         = true;
                    pi.FileName         = "";
                    pi.WebParts         = "";
                    pi.Description      = txtTemplateDescription.Text;
                    pi.CategoryID       = parentCategoryId;
                    pi.IsReusable       = true; //set default value for isReusable

                    PageTemplateInfoProvider.SetPageTemplateInfo(pi);

                    EditedObject = pi;
                    CMSObjectManager.CheckOutNewObject(this.Page);

                    string script = "parent.frames['pt_tree'].location.href = 'PageTemplate_Tree.aspx?templateid=" + pi.PageTemplateId + "';";
                    script         += "this.location.href = 'PageTemplate_Edit.aspx?templateid=" + pi.PageTemplateId + "';";
                    ltlScript.Text += ScriptHelper.GetScript(script);
                }
                else
                {
                    ShowError(GetString("Administration-PageTemplate_New.TemplateExistsAlready"));
                }
            }
            else
            {
                ShowError(GetString("Administration-PageTemplate_New.NoParentIdGiven"));
            }
        }
        else
        {
            rfvTemplateDisplayName.Visible = false;
            rfvTemplateCodeName.Visible    = false;
            ShowError(result);
        }
    }
Esempio n. 3
0
    protected int SaveNewCssStylesheet()
    {
        CssStylesheetInfo cs = new CssStylesheetInfo
        {
            StylesheetDisplayName = txtDisplayName.Text,
            StylesheetName        = txtName.Text,
            StylesheetText        = txtText.Text
        };

        CssStylesheetInfoProvider.SetCssStylesheetInfo(cs);
        CMSContext.EditedObject = cs;

        // Stylesheet is assigned to site if checkbox is showed and checked or in dialog mode(stylesheet is assigned to specified or current site)
        if (((chkAssign.Visible && chkAssign.Checked) || dialogMode) && (CurrentSite != null) && (cs.StylesheetID > 0))
        {
            // Add new stylesheet to the actual site
            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(cs.StylesheetID, CurrentSite.SiteID);
        }

        CMSObjectManager.CheckOutNewObject(Page);

        return(cs.StylesheetID);
    }
    /// <summary>
    /// Save button is clicked.
    /// </summary>
    protected void SaveAction(object sender, EventArgs e)
    {
        // Check permissions
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "Design.EditLayout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "Design.EditLayout");
        }

        // New device profile
        int newDeviceProfileId = deviceProfileId;

        if (newDeviceProfileId == 0)
        {
            newDeviceProfileId = ValidationHelper.GetInteger(ucNewDeviceProfile.Value, 0);
        }

        if (newDeviceProfileId == 0)
        {
            // Show error - select device profile first
            ShowError(GetString("devicelayout.selectdeviceprofile.error"));
            rbtnDevice.Checked = true;
            return;
        }

        PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);

        if ((pti != null) && (newDeviceProfileId > 0))
        {
            string         layoutCode = null;
            string         layoutCSS  = null;
            int            layoutId   = 0;
            LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx;

            if (rbtnDevice.Checked)
            {
                // Copy from device
                int selectedDeviceProfileId = ValidationHelper.GetInteger(ucDeviceProfile.Value, 0);
                if (selectedDeviceProfileId > 0)
                {
                    // Existing device profile
                    PageTemplateDeviceLayoutInfo selectedDeviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, selectedDeviceProfileId);
                    if (selectedDeviceLayout != null)
                    {
                        layoutId   = selectedDeviceLayout.LayoutID;
                        layoutCode = selectedDeviceLayout.LayoutCode;
                        layoutCSS  = selectedDeviceLayout.LayoutCSS;
                        layoutType = selectedDeviceLayout.LayoutType;
                    }
                }
                else
                {
                    // Default device
                    layoutType = pti.PageTemplateLayoutType;

                    if (pti.LayoutID > 0)
                    {
                        layoutId = pti.LayoutID;
                    }
                    else
                    {
                        layoutCode = pti.PageTemplateLayout;
                        layoutCSS  = pti.PageTemplateCSS;
                    }
                }
            }
            else if (rbtnLayout.Checked)
            {
                // Use existing layout
                int        selectedLayoutId = ValidationHelper.GetInteger(ucLayout.Value, 0);
                LayoutInfo selectedLayout   = LayoutInfoProvider.GetLayoutInfo(selectedLayoutId);
                if (selectedLayout != null)
                {
                    layoutType = selectedLayout.LayoutType;

                    if (chkCopy.Checked)
                    {
                        // Copy layout code
                        layoutCode = selectedLayout.LayoutCode;
                        layoutCSS  = selectedLayout.LayoutCSS;
                    }
                    else
                    {
                        // Copy layout id
                        layoutId = selectedLayoutId;
                    }
                }
            }
            else if (rbtnEmptyLayout.Checked)
            {
                layoutCode = "<cms:CMSWebPartZone ZoneID=\"zoneA\" runat=\"server\" />";
            }

            PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, newDeviceProfileId);

            if (deviceLayout == null)
            {
                // Create a new device profile layout object
                deviceLayout = new PageTemplateDeviceLayoutInfo();
                deviceLayout.PageTemplateID = templateId;
                deviceLayout.ProfileID      = newDeviceProfileId;
            }

            // Modify the device profile layout object with updated values
            deviceLayout.LayoutID   = layoutId;
            deviceLayout.LayoutType = layoutType;
            deviceLayout.LayoutCode = layoutCode;
            deviceLayout.LayoutCSS  = layoutCSS;

            // Save the device profile layout object
            PageTemplateDeviceLayoutInfoProvider.SetTemplateDeviceLayoutInfo(deviceLayout);
            UIContext.EditedObject = deviceLayout;
            CMSObjectManager.CheckOutNewObject(Page);

            // Register refresh page scripts
            ScriptHelper.RegisterStartupScript(this, typeof(string), "deviceLayoutSaved", "if (wopener) { wopener.location.replace(wopener.location); } CloseDialog();", true);
        }
    }
    private void SaveContainer()
    {
        try
        {
            // Validate user input
            string errorMessage = new Validator()
                                  .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                                  .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                                  .IsCodeName(txtContainerName.Text, GetString("General.InvalidCodeName"))
                                  .Result;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                ShowError(errorMessage);
                return;
            }

            // Parse the container text
            string text  = txtContainerText.Text;
            string after = "";

            int wpIndex = text.IndexOf(WebPartContainerInfoProvider.WP_CHAR);
            if (wpIndex >= 0)
            {
                after = text.Substring(wpIndex + 1).Replace(WebPartContainerInfoProvider.WP_CHAR, "");
                text  = text.Substring(0, wpIndex);
            }

            WebPartContainerInfo webPartContainerObj = new WebPartContainerInfo()
            {
                ContainerTextBefore  = text,
                ContainerTextAfter   = after,
                ContainerCSS         = txtContainerCSS.Text,
                ContainerName        = txtContainerName.Text.Trim(),
                ContainerDisplayName = txtContainerDisplayName.Text.Trim()
            };

            // Check for duplicity
            if (WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName) != null)
            {
                ShowError(GetString("Container_Edit.UniqueError"));
                return;
            }

            WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);
            UIContext.EditedObject = webPartContainerObj;
            CMSObjectManager.CheckOutNewObject(Page);

            if (mDialogMode)
            {
                ProcessDialog(webPartContainerObj, true);
            }
            else
            {
                ProcessPage(webPartContainerObj);
            }
        }
        catch (SecurityException ex)
        {
            ShowError(!SystemContext.IsFullTrustLevel ? ResHelper.GetStringFormat("general.fulltrustrequired", ex.Message) : ex.Message);
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
Esempio n. 6
0
    public void Save(bool closeOnSave)
    {
        // Check modify permission
        RaiseOnCheckPermissions(PERMISSION_MODIFY, this);

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtCodeName.Text    = txtCodeName.Text.Trim();
        txtSubject.Text     = txtSubject.Text.Trim();

        // Find whether required fields are not empty
        string result = new Validator().NotEmpty(txtDisplayName.Text, GetString("EmailTemplate_Edit.FillDisplayNameField"))
                        .NotEmpty(txtCodeName.Text, GetString("EmailTemplate_Edit.FillCodeNameField"))
                        .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
                        .Result;

        // Check validity of entered e-mails
        if (!String.IsNullOrEmpty(txtFrom.Text) && !ValidationHelper.AreEmails(txtFrom.Text))
        {
            result = GetString("EmailTemplate_Edit.InvalidFrom");
        }
        else if (!String.IsNullOrEmpty(txtBcc.Text) && !ValidationHelper.AreEmails(txtBcc.Text))
        {
            result = GetString("EmailTemplate_Edit.InvalidBcc");
        }
        else if (!String.IsNullOrEmpty(txtCc.Text) && !ValidationHelper.AreEmails(txtCc.Text))
        {
            result = GetString("EmailTemplate_Edit.InvalidCc");
        }

        if (String.IsNullOrEmpty(result))
        {
            string siteName = null;
            if (SiteID != 0)
            {
                // Get site name for non-global templates
                SiteInfo site = SiteInfoProvider.GetSiteInfo(SiteID);
                if (site != null)
                {
                    siteName = site.SiteName;
                }
            }
            // Try to get template by template name and site name
            EmailTemplateInfo templateInfo = EmailTemplateProvider.GetEmailTemplate(txtCodeName.Text, siteName);

            // Find if codename of the email template is unique for the site
            if ((templateInfo == null) || (templateInfo.TemplateID == EmailTemplateID) || ((templateInfo.TemplateSiteID == 0) && (SiteID > 0)))
            {
                bool isInsert = false;

                // Get object
                if (templateInfo == null)
                {
                    templateInfo = EmailTemplateProvider.GetEmailTemplate(EmailTemplateID);
                    if (templateInfo == null)
                    {
                        templateInfo = new EmailTemplateInfo();
                        isInsert     = true;
                    }
                }

                templateInfo.TemplateID          = EmailTemplateID;
                templateInfo.TemplateDisplayName = txtDisplayName.Text;
                templateInfo.TemplateName        = txtCodeName.Text;
                templateInfo.TemplateSubject     = txtSubject.Text;
                templateInfo.TemplateFrom        = txtFrom.Text;
                templateInfo.TemplateBcc         = txtBcc.Text;
                templateInfo.TemplateCc          = txtCc.Text;
                templateInfo.TemplateText        = txtText.Text;
                templateInfo.TemplatePlainText   = txtPlainText.Text;
                templateInfo.TemplateSiteID      = SiteID;
                templateInfo.TemplateType        = ValidationHelper.GetString(drpEmailType.Value, null);

                // Save (insert/update) EmailTemplateInfo object
                EmailTemplateProvider.SetEmailTemplate(templateInfo);

                CMSContext.EditedObject = templateInfo;

                if (isInsert)
                {
                    pnlObjectLocking.ObjectManager.ObjectType = null;
                    CMSObjectManager.CheckOutNewObject(this.Page);
                }

                // Handle redirection
                RedirectOnSave(templateInfo, closeOnSave);
            }
            else
            {
                ShowError(GetString("EmailTemplate_Edit.UniqueCodeName"));
            }
        }
        else
        {
            ShowError(result);
        }
    }