Exemple #1
0
    /// <summary>
    /// Creates versioned css stylesheet. Called when the "Create versioned object" button is pressed.
    /// </summary>
    private bool CreateVersionedObject()
    {
        // Create new css stylesheet object
        CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

        // Check if object versioning of stylesheet objects is allowed on current site
        if (ObjectVersionManager.AllowObjectVersioning(newStylesheet, CMSContext.CurrentSiteName))
        {
            // Set the properties
            newStylesheet.StylesheetDisplayName = "My new versioned stylesheet";
            newStylesheet.StylesheetName        = "MyNewVersionedStylesheet";
            newStylesheet.StylesheetText        = "Some versioned CSS code";

            // Save the css stylesheet
            CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

            // Add css stylesheet to site
            int stylesheetId = newStylesheet.StylesheetID;
            int siteId       = CMSContext.CurrentSiteID;

            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheetId, siteId);

            return(true);
        }

        return(false);
    }
Exemple #2
0
    private void SetDialogMode(CssStylesheetInfo si)
    {
        // Check if stylesheet is under curent site
        int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;

        string where = SqlHelperClass.AddWhereCondition("SiteID = " + siteId, "StylesheetID = " + si.StylesheetID);
        DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("StylesheetID", where, null, 1);

        if (DataHelper.DataSourceIsEmpty(ds))
        {
            URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
        }

        // Set CSS classes
        CurrentMaster.PanelContent.CssClass = "PageContent";
        CurrentMaster.PanelFooter.CssClass  = "FloatRight";

        // Add save and close button
        LocalizedButton btnSaveAndCancel = new LocalizedButton
        {
            ID              = "btnSaveCancel",
            ResourceString  = "general.saveandclose",
            EnableViewState = false,
            CssClass        = "LongSubmitButton"
        };

        btnSaveAndCancel.Click += (sender, e) =>
        {
            if (Save())
            {
                ScriptHelper.RegisterStartupScript(this, GetType(), "SaveAndClose", "window.top.close();", true);
            }
        };

        CurrentMaster.PanelFooter.Controls.Add(btnSaveAndCancel);

        // Add close button
        CurrentMaster.PanelFooter.Controls.Add(new LocalizedButton
        {
            ID              = "btnClose",
            ResourceString  = "general.close",
            EnableViewState = false,
            OnClientClick   = "window.top.close(); return false;",
            CssClass        = "SubmitButton"
        });

        // Set CMS master page title
        CurrentMaster.Title.TitleText  = GetString("CssStylesheet.EditCssStylesheet");
        CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_CSSStylesheet/object.png");

        // Disable display and code name editing
        //txtCssStylesheetDisplayName.ReadOnly = txtCssStylesheetName.ReadOnly = true;
    }
Exemple #3
0
    /// <summary>
    /// Adds css stylesheet to site. Called when the "Add stylesheet to site" button is pressed.
    /// Expects the CreateCssStylesheet method to be run first.
    /// </summary>
    private bool AddCssStylesheetToSite()
    {
        // Get the css stylesheet
        CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        if (stylesheet != null)
        {
            int stylesheetId = stylesheet.StylesheetID;
            int siteId       = SiteContext.CurrentSiteID;

            // Save the binding
            CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheetId, siteId);

            return(true);
        }

        return(false);
    }
Exemple #4
0
    /// <summary>
    /// Removes css stylesheet from site. Called when the "Remove stylesheet from site" button is pressed.
    /// Expects the AddCssStylesheetToSite method to be run first.
    /// </summary>
    private bool RemoveCssStylesheetFromSite()
    {
        // Get the css stylesheet
        CssStylesheetInfo removeStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewStylesheet");

        if (removeStylesheet != null)
        {
            int siteId = SiteContext.CurrentSiteID;

            // Get the binding
            CssStylesheetSiteInfo stylesheetSite = CssStylesheetSiteInfoProvider.GetCssStylesheetSiteInfo(removeStylesheet.StylesheetID, siteId);

            // Delete the binding
            CssStylesheetSiteInfoProvider.DeleteCssStylesheetSiteInfo(stylesheetSite);

            return(true);
        }

        return(false);
    }
Exemple #5
0
    protected int SaveNewCssStylesheet()
    {
        CssStylesheetInfo cs = new CssStylesheetInfo
        {
            StylesheetDisplayName = txtDisplayName.Text,
            StylesheetName        = txtName.Text,
            StylesheetText        = txtText.Text
        };

        CssStylesheetInfoProvider.SetCssStylesheetInfo(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);
        }

        return(cs.StylesheetID);
    }
Exemple #6
0
    protected void SaveSites()
    {
        // Remove old items
        string newValues = ValidationHelper.GetString(usSites.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        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);
                    CssStylesheetSiteInfoProvider.RemoveCssStylesheetFromSite(cssStylesheetId, 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);
                    CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(cssStylesheetId, siteId);
                }
            }
        }

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("General.ChangesSaved");
    }
Exemple #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        lblAvialable.Text = GetString("CssStylesheet_Sites.Available");
        cssStylesheetId   = QueryHelper.GetInteger("cssstylesheetid", 0);
        if (cssStylesheetId > 0)
        {
            // Get the active sites
            DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("SiteID", "StylesheetID = " + cssStylesheetId, null, 0);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                currentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "SiteID"));
            }

            if (!RequestHelper.IsPostBack())
            {
                usSites.Value = currentValues;
            }
        }

        usSites.IconPath            = GetImageUrl("Objects/CMS_Site/object.png");
        usSites.OnSelectionChanged += usSites_OnSelectionChanged;
    }
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        // Check for UI permissions
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "Properties", "Properties.General", "General.Design", "Design.EditCSSStylesheets" }, CMSContext.CurrentSiteName))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "Properties;Properties.General;General.Design;Design.EditCSSStylesheets");
        }

        // Page has been opened in CMSDesk and only stylesheet style editing is allowed
        requiresDialog = QueryHelper.GetBoolean("editonlycode", false);

        if (requiresDialog)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash", "saved;cssstylesheetid;selectorid;tabmode;siteid;aliaspath;line", true, true, true))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("dialogs.badhashtitle"), ResHelper.GetString("dialogs.badhashtext"))));
            }

            // Check 'Design Web site' permission if opened from CMS Desk
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Design", "Design"))
            {
                RedirectToCMSDeskAccessDenied("CMS.Design", "Design");
            }
        }
        else
        {
            CheckAccessToSiteManager();
        }

        string stylesheet = QueryHelper.GetString("cssstylesheetid", "0");

        // If default stylesheet defined and selected, choose it
        if (stylesheet == "default")
        {
            si = CMSContext.CurrentSiteStylesheet;
        }

        // Default stylesheet not selected try to find stylesheet selected
        if (si != null)
        {
            cssStylesheetId = si.StylesheetID;
        }
        else
        {
            cssStylesheetId = ValidationHelper.GetInteger(stylesheet, 0);
            if (cssStylesheetId > 0)
            {
                // Get the stylesheet
                si = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssStylesheetId);
            }
        }

        SetEditedObject(si, "CssStylesheet_Edit.aspx");

        var checkSiteAssociation = QueryHelper.GetBoolean("checksiteassociation", true);

        if ((si != null) && requiresDialog && checkSiteAssociation)
        {
            // Check if stylesheet is under current site
            int siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;
            string where = SqlHelperClass.AddWhereCondition("SiteID = " + siteId, "StylesheetID = " + si.StylesheetID);
            DataSet ds = CssStylesheetSiteInfoProvider.GetCssStylesheetSites("StylesheetID", where, null, 1);
            if (DataHelper.DataSourceIsEmpty(ds))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
            }
        }

        base.OnPreInit(e);
    }
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser;

        // Check for UI permissions
        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "Properties", "Properties.General", "General.Design", "Design.EditCSSStylesheets" }, SiteContext.CurrentSiteName))
        {
            RedirectToUIElementAccessDenied("CMS.Content", "Properties;Properties.General;General.Design;Design.EditCSSStylesheets");
        }

        // Page has been opened in CMSDesk and only stylesheet style editing is allowed
        isDialog = (QueryHelper.GetBoolean("dialog", false) || QueryHelper.GetBoolean("isindialog", false));

        // Prevent replacing of the master page with dialog master page
        RequiresDialog = false;

        if (isDialog)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash", "objectid", true, true, true))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("dialogs.badhashtitle"), ResHelper.GetString("dialogs.badhashtext"))));
            }

            // Check 'Design Web site' permission
            if (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))
            {
                RedirectToAccessDenied("CMS.Design", "Design");
            }
        }
        else
        {
            CheckGlobalAdministrator();
        }

        string stylesheet = QueryHelper.GetString("objectid", "0");

        // If default stylesheet defined and selected, choose it
        if (stylesheet == "default")
        {
            si = PortalContext.CurrentSiteStylesheet;
        }

        // Default stylesheet not selected try to find stylesheet selected
        if (si != null)
        {
            cssStylesheetId = si.StylesheetID;
        }
        else
        {
            cssStylesheetId = ValidationHelper.GetInteger(stylesheet, 0);
            if (cssStylesheetId > 0)
            {
                // Get the stylesheet
                si = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssStylesheetId);
            }
        }

        SetEditedObject(si, null);

        // Check site association in case that user is not admin
        var checkSiteAssociation = !currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin);

        if ((si != null) && isDialog && checkSiteAssociation)
        {
            // Check if stylesheet is under current site
            int     siteId = (CurrentSite != null) ? CurrentSite.SiteID : 0;
            DataSet ds     = CssStylesheetSiteInfoProvider.GetCssStylesheetSites()
                             .WhereEquals("SiteID", siteId)
                             .WhereEquals("StylesheetID", si.StylesheetID)
                             .TopN(1);

            if (DataHelper.DataSourceIsEmpty(ds))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("cssstylesheet.errorediting"), ResHelper.GetString("cssstylesheet.notallowedtoedit"))));
            }
        }

        base.OnPreInit(e);
    }