示例#1
0
    /// <summary>
    /// Check out.
    /// </summary>
    protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        // Ensure version before check-out
        using (CMSActionContext context = new CMSActionContext())
        {
            context.AllowAsyncActions = false;

            SetCurrentLayout(false, true);
        }

        try
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (wpi != null)
            {
                WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                if (wpli != null)
                {
                    SiteManagerFunctions.CheckOutWebPartLayout(wpli.WebPartLayoutID);
                }
            }
        }
        catch (Exception ex)
        {
            this.lblError.Text    = GetString("WebPartLayout.ErrorCheckout") + ": " + ex.Message;
            this.lblError.Visible = true;
            return;
        }

        SetCheckPanel(null);
    }
示例#2
0
    /// <summary>
    /// Gets and bulk updates web part layouts. Called when the "Get and bulk update layouts" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebPartLayouts()
    {
        // Prepare the parameters
        string where = "WebPartLayoutCodeName LIKE N'MyNewLayout%'";

        // Get the data
        DataSet layouts = WebPartLayoutInfoProvider.GetWebPartLayouts().Where(where);

        if (!DataHelper.DataSourceIsEmpty(layouts))
        {
            // Loop through the individual items
            foreach (DataRow layoutDr in layouts.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartLayoutInfo modifyLayout = new WebPartLayoutInfo(layoutDr);

                // Update the properties
                modifyLayout.WebPartLayoutDisplayName = modifyLayout.WebPartLayoutDisplayName.ToUpper();

                // Save the changes
                WebPartLayoutInfoProvider.SetWebPartLayoutInfo(modifyLayout);
            }

            return(true);
        }

        return(false);
    }
 /// <summary>
 /// Handles only delete action.
 /// </summary>
 protected void UniGrid_OnAction(string actionName, object actionArgument)
 {
     if (actionName == "delete")
     {
         WebPartLayoutInfoProvider.DeleteWebPartLayoutInfo(ValidationHelper.GetInteger(actionArgument, 0));
         UniGrid.ReloadData();
     }
 }
示例#4
0
    /// <summary>
    /// Saves the form data.
    /// </summary>
    private void Save()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

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

        string errorMessage = new Validator()
                              .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
                              .Result;

        if (errorMessage != String.Empty)
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }

        // Check web part id
        int         webPartId = QueryHelper.GetInteger("webpartId", 0);
        WebPartInfo wpi       = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wpi == null)
        {
            lblError.Text    = GetString("WebPartEditLayoutNew.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Check web part layout code name
        WebPartLayoutInfo tempwpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, txtCodeName.Text);

        if (tempwpli != null)
        {
            lblError.Text    = GetString("WebPartEditLayoutNew.CodeNameAlreadyExist");
            lblError.Visible = true;
            return;
        }


        // Create and fill info structure
        WebPartLayoutInfo wpli = new WebPartLayoutInfo();

        wpli.WebPartLayoutID          = 0;
        wpli.WebPartLayoutCodeName    = txtCodeName.Text;
        wpli.WebPartLayoutDisplayName = txtDisplayName.Text;
        wpli.WebPartLayoutCode        = tbCode.Text;
        wpli.WebPartLayoutCSS         = tbCSS.Text;
        wpli.WebPartLayoutDescription = txtDescription.Text;
        wpli.WebPartLayoutWebPartID   = webPartId;

        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

        URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartId);
    }
示例#5
0
    /// <summary>
    /// Deletes web part layout. Called when the "Delete layout" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool DeleteWebPartLayout()
    {
        // Get the web part layout
        WebPartLayoutInfo deleteLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout");

        // Delete the web part layout
        WebPartLayoutInfoProvider.DeleteWebPartLayoutInfo(deleteLayout);

        return(deleteLayout != null);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "WebPartProperties.Layout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
            }
        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|") && !QueryHelper.GetBoolean("tabmode", false))
                    {
                        string url = UIContextHelper.GetElementUrl("CMS.Design", "Design.WebPartProperties.LayoutEdit", false, wpli.WebPartLayoutID);
                        url = URLHelper.AppendQuery(url, RequestContext.CurrentQueryString);
                        url = URLHelper.AddParameterToUrl(url, "tabmode", "1");
                        URLHelper.Redirect(url);
                    }
                }
            }
        }
        base.OnPreInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for web part properties UI
        var currentUser = MembershipContext.AuthenticatedUser;

        if (!currentUser.IsAuthorizedPerUIElement("CMS.Design", "WebPartProperties.Layout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "WebPartProperties.Layout");
        }

        WebPartInstance webPart = null;

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi != null)
            {
                // Get page template
                PageTemplateInfo pti = pi.UsedPageTemplateInfo;

                // Get web part
                if ((pti != null) && ((pti.TemplateInstance != null)))
                {
                    webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
                }
            }
        }

        // If the web part is not found, do not continue
        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (wpi != null)
            {
                // Get the current layout name
                if (String.IsNullOrEmpty(LayoutCodeName))
                {
                    // Get the current layout name
                    LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
                }

                // Load the web part information
                if (LayoutCodeName != "")
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    SetEditedObject(wpli, null);
                }
            }
        }

        // Set page tabs
        InitTabs("webpartlayoutcontent");
        SetTab(0, GetString("general.general"), "webpartproperties_layout.aspx" + RequestContext.CurrentQueryString, null);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "WebPartProperties.Layout"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|"))
                    {
                        SetEditedObject(wpli, "WebPartProperties_layout_frameset_frameset.aspx");
                    }
                }
            }
        }

        base.OnPreInit(e);
    }
示例#9
0
    /// <summary>
    /// Gets and updates web part layout. Called when the "Get and update layout" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool GetAndUpdateWebPartLayout()
    {
        // Get the web part layout
        WebPartLayoutInfo updateLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout");

        if (updateLayout != null)
        {
            // Update the properties
            updateLayout.WebPartLayoutDisplayName = updateLayout.WebPartLayoutDisplayName.ToLower();

            // Save the changes
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(updateLayout);

            return(true);
        }

        return(false);
    }
示例#10
0
    /// <summary>
    /// Retrieves the stylesheets of the web part layout from the database.
    /// </summary>
    /// <param name="layoutFullName">Layout full name</param>
    /// <returns>The stylesheet data (plain version only)</returns>
    private static CMSOutputResource GetWebPartLayout(string layoutFullName)
    {
        WebPartLayoutInfo layoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutFullName);

        if (layoutInfo == null)
        {
            return(null);
        }

        // Build the result
        CMSOutputResource resource = new CMSOutputResource()
        {
            Data         = HTMLHelper.ResolveCSSUrls(layoutInfo.WebPartLayoutCSS, URLHelper.ApplicationPath),
            LastModified = layoutInfo.WebPartLayoutLastModified,
            Etag         = layoutInfo.WebPartLayoutFullName
        };

        return(resource);
    }
    protected override void CreateChildControls()
    {
        ucHierarchy.DialogMode = RequiresDialog;

        int layoutId           = QueryHelper.GetInteger("layoutid", 0);
        WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);

        if (wpli != null)
        {
            ucHierarchy.PreviewObjectName = wpli.WebPartLayoutCodeName;
            ucHierarchy.PreviewURLSuffix  = "&previewobjectidentifier=" + wpli.WebPartLayoutCodeName;
        }

        if (layoutId != 0)
        {
            EditedObject = wpli;
        }

        base.CreateChildControls();
    }
示例#12
0
    /// <summary>
    /// Creates web part layout. Called when the "Create layout" button is pressed.
    /// </summary>
    private bool CreateWebPartLayout()
    {
        // Get the web part
        WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart");

        if (webpart != null)
        {
            // Create new web part layout object
            WebPartLayoutInfo newLayout = new WebPartLayoutInfo();

            // Set the properties
            newLayout.WebPartLayoutDisplayName = "My new layout";
            newLayout.WebPartLayoutCodeName    = "MyNewLayout";
            newLayout.WebPartLayoutWebPartID   = webpart.WebPartID;
            newLayout.WebPartLayoutCode        = "This is the new layout of MyNewWebpart webpart.";

            // Save the web part layout
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(newLayout);

            return(true);
        }
        return(false);
    }
示例#13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Setup the filesystem browser
        int layoutId  = QueryHelper.GetInteger("layoutid", 0);
        int webPartId = QueryHelper.GetInteger("webpartid", 0);

        if ((webPartId > 0) && (layoutId > 0))
        {
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
            EditedObject = wpli;

            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPartId);

            if ((wpli != null) && (wpi != null))
            {
                // Ensure the theme folder
                themeElem.Path = "~/App_Themes/Components/WebParts/" + ValidationHelper.GetSafeFileName(wpi.WebPartName) + "/Layouts/" + ValidationHelper.GetSafeFileName(wpli.WebPartLayoutCodeName);
            }
        }
        else
        {
            EditedObject = null;
        }
    }
示例#14
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Setup the file system browser
        int layoutId  = QueryHelper.GetInteger("layoutid", 0);
        int webPartId = QueryHelper.GetInteger("webpartid", 0);

        if ((webPartId > 0) && (layoutId > 0))
        {
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
            EditedObject = wpli;

            if (wpli != null)
            {
                // Ensure the theme folder
                themeElem.Path = wpli.GetThemePath();
            }
        }
        else
        {
            EditedObject = null;
        }
    }
示例#15
0
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public bool Save()
    {
        // Check MVT/CP security
        if (VariantID > 0)
        {
            // Check OnlineMarketing permissions.
            if (!CheckPermissions("Manage"))
            {
                ShowError(GetString("general.modifynotallowed"));
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form))
        {
            if (SynchronizationHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                ShowError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName));
                return(false);
            }

            // Add web part if new
            if (IsNewWebPart)
            {
                int webpartId = ValidationHelper.GetInteger(WebPartID, 0);

                // Ensure layout zone flag
                if (QueryHelper.GetBoolean("layoutzone", false))
                {
                    WebPartZoneInstance zone = pti.TemplateInstance.EnsureZone(ZoneID);
                    zone.LayoutZone = true;
                }

                webPartInstance = PortalHelper.AddNewWebPart(webpartId, ZoneID, false, ZoneVariantID, Position, templateInstance);

                // Set default layout
                if (wpi.WebPartParentID > 0)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetDefaultLayout(wpi.WebPartID);
                    if (wpli != null)
                    {
                        webPartInstance.SetValue("WebPartLayout", wpli.WebPartLayoutCodeName);
                    }
                }
            }

            webPartInstance.XMLVersion = 1;
            if (IsNewVariant)
            {
                webPartInstance             = webPartInstance.Clone();
                webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLowerInvariant());
            }

            // Get basic form's data row and update web part
            SaveFormToWebPart(form);

            // Set new position if set
            if (PositionLeft > 0)
            {
                webPartInstance.SetValue("PositionLeft", PositionLeft);
            }
            if (PositionTop > 0)
            {
                webPartInstance.SetValue("PositionTop", PositionTop);
            }

            bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant;
            if (!isWebPartVariant)
            {
                // Save the changes
                CMSPortalManager.SaveTemplateChanges(pi, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
            }
            else
            {
                Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable;
                // Save changes to the web part variant
                VariantHelper.SaveWebPartVariantChanges(webPartInstance, VariantID, ZoneVariantID, VariantMode, varProperties);
            }

            // Reload the form (because of macro values set only by JS)
            form.ReloadData();

            // Clear the cached web part
            CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerInvariant());

            ShowChangesSaved();

            return(true);
        }

        if (webPartInstance?.ParentZone?.ParentTemplateInstance != null)
        {
            // Reload the zone/web part variants when saving of the form fails
            webPartInstance.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None);
        }

        return(false);
    }
示例#16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>();

        foreach (DictionaryEntry param in Properties)
        {
            // Decode special CK editor char
            String str = String.Empty;
            if (param.Value != null)
            {
                str = param.Value.ToString().Replace("%25", "%");
            }

            decodedProperties[(string)param.Key] = HttpUtility.UrlDecode(str);
        }
        Properties = decodedProperties;

        string widgetName = ValidationHelper.GetString(Properties["name"], String.Empty);

        // Widget name must be specified
        if (String.IsNullOrEmpty(widgetName))
        {
            AddErrorWebPart("widgets.invalidname", null);
            return;
        }

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName);

        if (wi == null)
        {
            AddErrorWebPart("widget.failedtoload", null);
            return;
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

        if (wpi == null)
        {
            return;
        }

        //no widgets can be used as inline
        if (!wi.WidgetForInline)
        {
            AddErrorWebPart("widgets.cantbeusedasinline", null);
            return;
        }

        try
        {
            FormInfo fi = null;
            DataRow  dr = null;

            using (var cs = new CachedSection <FormInfo>(ref fi, 1440, (PortalContext.ViewMode == ViewModeEnum.LiveSite), null, "inlinewidgetcontrol", wi.WidgetID, wpi.WebPartID))
            {
                if (cs.LoadData)
                {
                    // Merge widget and it's parent webpart properties
                    string props = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

                    // Prepare form
                    const WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor;
                    fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, props, true, wi.WidgetDefaultValues);

                    // Apply changed values
                    dr = fi.GetDataRow();
                    fi.LoadDefaultValues(dr);

                    if (cs.Cached)
                    {
                        cs.CacheDependency = CacheHelper.GetCacheDependency("cms.webpart|byid|" + wpi.WebPartID + "\n" + "cms.widget|byid|" + wi.WidgetID);
                    }

                    cs.Data = fi;
                }
            }

            // Get datarow
            if (dr == null)
            {
                dr = fi.GetDataRow();
                fi.LoadDefaultValues(dr);
            }

            // Incorporate inline parameters to datarow
            string publicFields = ";containertitle;container;";
            if (wi.WidgetPublicFileds != null)
            {
                publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";";
            }

            // Load the widget control
            string url = null;

            // Set widget layout
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID);

            if (wpli != null)
            {
                // Load specific layout through virtual path
                url = wpli.Generalized.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID);
            }
            else
            {
                // Load regularly
                url = WebPartInfoProvider.GetWebPartUrl(wpi, false);
            }

            CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url);
            control.PartInstance = new WebPartInstance();

            // Use current page placeholder
            control.PagePlaceholder = PortalHelper.FindParentPlaceholder(this);

            // Set all form values to webpart
            foreach (DataColumn column in dr.Table.Columns)
            {
                object value      = dr[column];
                string columnName = column.ColumnName.ToLowerCSafe();

                //Resolve set values by user
                if (Properties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && ((ffi.DisplayIn == null) || !ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = Properties[columnName];
                    }
                }

                // Resolve macros in defined in default values
                if (!String.IsNullOrEmpty(value as string))
                {
                    // Do not resolve macros for public fields
                    if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0)
                    {
                        // Check whether current column
                        bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";");

                        // Resolve macros
                        MacroSettings settings = new MacroSettings()
                        {
                            AvoidInjection = avoidInjection,
                        };
                        value = control.ContextResolver.ResolveMacros(value.ToString(), settings);
                    }
                }

                control.PartInstance.SetValue(column.ColumnName, value);
            }

            control.PartInstance.IsWidget = true;

            // Load webpart content
            control.OnContentLoaded();

            // Add webpart to controls collection
            Controls.Add(control);

            // Handle DisableViewstate setting
            control.EnableViewState = !control.DisableViewState;
        }

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }
示例#17
0
    /// <summary>
    /// Sets current layout.
    /// </summary>
    protected void SetCurrentLayout(bool saveToWebPartInstance, bool updateLayout)
    {
        if ((webPart != null) && (LayoutCodeName != "|new|"))
        {
            if (saveToWebPartInstance)
            {
                if (LayoutCodeName == "|default|")
                {
                    webPart.SetValue("WebPartLayout", "");
                }
                else
                {
                    webPart.SetValue("WebPartLayout", LayoutCodeName);
                }

                bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;
                if (!isWebPartVariant)
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save the variant properties
                    if ((webPart != null) &&
                        (webPart.ParentZone != null) &&
                        (webPart.ParentZone.ParentTemplateInstance != null) &&
                        (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        XmlDocument doc         = new XmlDocument();
                        XmlNode     xmlWebParts = null;

                        if (zoneVariantId > 0)
                        {
                            // This webpart is in a zone variant therefore save the whole variant webparts
                            xmlWebParts = webPart.ParentZone.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                        }
                        else if (variantId > 0)
                        {
                            // This webpart is a web part variant
                            xmlWebParts = webPart.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts);
                            }
                        }
                    }
                }
            }

            string parameters = this.aliasPath + "/" + this.zoneId + "/" + this.webpartId;
            string cacheName  = "CMSVirtualWebParts|" + parameters.ToLower().TrimStart('/');

            CacheHelper.Remove(cacheName);

            if (updateLayout)
            {
                WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                if (wpi != null)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    if (wpli != null)
                    {
                        if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                        {
                            wpli.WebPartLayoutCode = etaCode.Text;
                        }
                        wpli.WebPartLayoutCSS = etaCSS.Text;

                        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                    }
                }
            }
        }
    }
示例#18
0
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWebPartName.Text        = txtWebPartName.Text.Trim();
        txtWebPartDisplayName.Text = txtWebPartDisplayName.Text.Trim();
        txtWebPartFileName.Text    = txtWebPartFileName.Text.Trim();

        // Validate the text box fields
        string errorMessage = new Validator()
                              .NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage)
                              .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage)
                              .IsCodeName(txtWebPartName.Text, GetString("WebPart_Clone.InvalidCodeName"))
                              .Result;

        // Validate file name
        if (string.IsNullOrEmpty(errorMessage) && chckCloneWebPartFiles.Checked)
        {
            errorMessage = new Validator()
                           .NotEmpty(txtWebPartFileName.Text, rfvWebPartFileName.ErrorMessage)
                           .IsFileName(Path.GetFileName(txtWebPartFileName.Text.Trim('~')), GetString("WebPart_Clone.InvalidFileName")).Result;
        }

        // Check if webpart with same name exists
        if (WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text) != null)
        {
            errorMessage = GetString(String.Format("Development-WebPart_Clone.WebPartExists", txtWebPartName.Text));
        }

        // Check if webpart is not cloned to the root category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (wci.CategoryID == ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1))
        {
            errorMessage = GetString("Development-WebPart_Clone.cannotclonetoroot");
        }

        if (errorMessage != "")
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }

        // get web part info object
        WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wi == null)
        {
            lblError.Text    = GetString("WebPart_Clone.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Create new webpart with all properties from source webpart
        WebPartInfo nwpi = new WebPartInfo(wi, false);

        nwpi.WebPartID   = 0;
        nwpi.WebPartGUID = Guid.NewGuid();

        // Modify clone info
        nwpi.WebPartName        = txtWebPartName.Text;
        nwpi.WebPartDisplayName = txtWebPartDisplayName.Text;
        nwpi.WebPartCategoryID  = ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1);

        if (nwpi.WebPartParentID <= 0)
        {
            nwpi.WebPartFileName = txtWebPartFileName.Text;
        }

        string path     = String.Empty;
        string filename = String.Empty;
        string inher    = String.Empty;

        try
        {
            // Copy file if needed and webpart is not ihnerited
            if (chckCloneWebPartFiles.Checked && (wi.WebPartParentID == 0))
            {
                // Get source file path
                string srcFile = GetWebPartPhysicalPath(wi.WebPartFileName);

                // Get destination file path
                string dstFile = GetWebPartPhysicalPath(nwpi.WebPartFileName);

                // Ensure directory
                DirectoryHelper.EnsureDiskPath(Path.GetDirectoryName(DirectoryHelper.EnsurePathBackSlash(dstFile)), URLHelper.WebApplicationPhysicalPath);

                // Check if source and target file path are different
                if (File.Exists(dstFile))
                {
                    throw new Exception(GetString("general.fileexists"));
                }

                // Get file name
                filename = Path.GetFileName(dstFile);
                // Get path to the partial class name replace
                string wpPath = nwpi.WebPartFileName;

                if (!wpPath.StartsWith("~/"))
                {
                    wpPath = WebPartInfoProvider.WebPartsDirectory + "/" + wpPath.TrimStart('/');
                }
                path = Path.GetDirectoryName(wpPath);

                inher = path.Replace('\\', '_').Replace('/', '_') + "_" + Path.GetFileNameWithoutExtension(filename).Replace('.', '_');
                inher = inher.Trim('~');
                inher = inher.Trim('_');

                // Read .aspx file, replace classname and save as new file
                string text = File.ReadAllText(srcFile);
                File.WriteAllText(dstFile, ReplaceASCX(text, DirectoryHelper.CombinePath(path, filename), inher));

                // Read .aspx file, replace classname and save as new file
                if (File.Exists(srcFile + ".cs"))
                {
                    text = File.ReadAllText(srcFile + ".cs");
                    File.WriteAllText(dstFile + ".cs", ReplaceASCXCS(text, inher));
                }

                if (File.Exists(srcFile + ".vb"))
                {
                    text = File.ReadAllText(srcFile + ".vb");
                    File.WriteAllText(dstFile + ".vb", ReplaceASCXVB(text, inher));
                }

                // Copy web part subfolder
                string srcDirectory = srcFile.Remove(srcFile.Length - Path.GetFileName(srcFile).Length) + Path.GetFileNameWithoutExtension(srcFile) + "_files";
                if (Directory.Exists(srcDirectory))
                {
                    string dstDirectory = dstFile.Remove(dstFile.Length - Path.GetFileName(dstFile).Length) + Path.GetFileNameWithoutExtension(dstFile) + "_files";
                    if (srcDirectory.ToLower() != dstDirectory.ToLower())
                    {
                        DirectoryHelper.EnsureDiskPath(srcDirectory, URLHelper.WebApplicationPhysicalPath);
                        DirectoryHelper.CopyDirectory(srcDirectory, dstDirectory);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Add new web part to database
        WebPartInfoProvider.SetWebPartInfo(nwpi);

        try
        {
            // Get and duplicate all webpart layouts associated to webpart
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts(webPartId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo(dr);
                    wpli.WebPartLayoutID                    = 0;              // Create new record
                    wpli.WebPartLayoutWebPartID             = nwpi.WebPartID; // Associate layout to new webpart
                    wpli.WebPartLayoutGUID                  = Guid.NewGuid();
                    wpli.WebPartLayoutCheckedOutByUserID    = 0;
                    wpli.WebPartLayoutCheckedOutFilename    = "";
                    wpli.WebPartLayoutCheckedOutMachineName = "";

                    // Replace classname and inherits attribut
                    wpli.WebPartLayoutCode = ReplaceASCX(wpli.WebPartLayoutCode, DirectoryHelper.CombinePath(path, filename), inher);
                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                }
            }

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(webPartId, nwpi.WebPartID, PortalObjectType.WEBPART, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Close clone window
        // Refresh web part tree and select/edit new widget
        string script      = String.Empty;
        string refreshLink = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?webpartid=" + nwpi.WebPartID + "&reload=true");

        if (QueryHelper.Contains("reloadAll"))
        {
            script += "wopener.parent.parent.frames['webparttree'].location.href ='" + refreshLink + "';";
        }
        else
        {
            script = "wopener.location = '" + refreshLink + "';";
        }
        script += "window.close();";

        ltlScript.Text = ScriptHelper.GetScript(script);
    }
示例#19
0
    protected void btnSaveAll_Click(object sender, EventArgs e)
    {
        try
        {
            // Save all the document transformations
            DataSet ds = DataClassInfoProvider.GetAllDataClass();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    classId        = ValidationHelper.GetInteger(dr["ClassID"], 0);
                    string className      = ValidationHelper.GetString(dr["ClassName"], "");
                    bool   isDocumentType = ValidationHelper.GetBoolean(dr["ClassIsDocumentType"], false);

                    if (isDocumentType)
                    {
                        ProcessTransformations(classId, className);
                    }
                }
            }

            // Save all the custom table transformations
            ds = DataClassInfoProvider.GetCustomTableClasses(null, null, 0, "ClassID,ClassName,ClassIsCustomTable");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    classId       = ValidationHelper.GetInteger(dr["ClassID"], 0);
                    string className     = ValidationHelper.GetString(dr["ClassName"], "");
                    bool   isCustomTable = ValidationHelper.GetBoolean(dr["ClassIsCustomTable"], false);

                    if (isCustomTable)
                    {
                        ProcessTransformations(classId, className);
                    }
                }
            }

            // Save all the layouts
            ds = LayoutInfoProvider.GetAllLayouts();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string layoutName = ValidationHelper.GetString(dr["LayoutCodeName"], "");
                    string layoutCode = ValidationHelper.GetString(dr["LayoutCode"], "");

                    int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["LayoutCheckedOutByUserID"], 0);
                    string checkedOutMachineName = ValidationHelper.GetString(dr["LayoutCheckedOutMachineName"], "");

                    if ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower()))
                    {
                        string filename = LayoutInfoProvider.GetLayoutUrl(layoutName, null);

                        // Prepare the code
                        string code = layoutCode;
                        code = LayoutInfoProvider.AddLayoutDirectives(code);

                        SiteManagerFunctions.SaveCodeFile(filename, code);
                    }
                }
            }

            // Save all the page template layouts
            ds = PageTemplateInfoProvider.GetAllTemplates();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string templateName   = ValidationHelper.GetString(dr["PageTemplateCodeName"], "");
                    string templateLayout = ValidationHelper.GetString(dr["PageTemplateLayout"], "");
                    bool   isReusable     = ValidationHelper.GetBoolean(dr["PageTemplateIsReusable"], false);

                    int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["PageTemplateLayoutCheckedOutByUserID"], 0);
                    string checkedOutMachineName = ValidationHelper.GetString(dr["PageTemplateLayoutCheckedOutMachineName"], "");
                    bool   isPortalTemplate      = ValidationHelper.GetBoolean(dr["PageTemplateIsPortal"], false);
                    string pageTemplateType      = ValidationHelper.GetString(dr["PageTemplateType"], "");
                    bool   isDashboard           = pageTemplateType.Equals(PageTemplateInfoProvider.GetPageTemplateTypeCode(PageTemplateTypeEnum.Dashboard));

                    if ((isPortalTemplate || isDashboard) && !String.IsNullOrEmpty(templateLayout) && ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower())))
                    {
                        string filename = null;
                        if (isReusable)
                        {
                            filename = PageTemplateInfoProvider.GetLayoutUrl(templateName, null);
                        }
                        else
                        {
                            filename = PageTemplateInfoProvider.GetAdhocLayoutUrl(templateName, null);
                        }

                        // Prepare the code
                        string code = templateLayout;
                        code = LayoutInfoProvider.AddLayoutDirectives(code);

                        SiteManagerFunctions.SaveCodeFile(filename, code);
                    }
                }
            }

            // Save all the web part layouts
            ds = WebPartLayoutInfoProvider.GetWebPartLayouts(null, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string webPartLayoutCodeName = ValidationHelper.GetString(dr["WebPartLayoutCodeName"], "");
                    string webPartLayoutCode     = ValidationHelper.GetString(dr["WebPartLayoutCode"], "");

                    WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(dr["WebPartLayoutWebPartID"], 0));

                    if (wpi != null)
                    {
                        int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["WebPartLayoutCheckedOutByUserID"], 0);
                        string checkedOutMachineName = ValidationHelper.GetString(dr["WebPartLayoutCheckedOutMachineName"], "");

                        if (!String.IsNullOrEmpty(webPartLayoutCode) && ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower())))
                        {
                            // Get layout filename
                            string filename = WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, webPartLayoutCodeName, "");
                            // Get path to the code file
                            string codeFilePath = URLHelper.GetVirtualPath(filename) + ".cs";

                            // Get path to the original code behind file
                            string originalCodeFilePath = String.Empty;
                            if (codeFileRegex.IsMatch(webPartLayoutCode, 0))
                            {
                                originalCodeFilePath = codeFileRegex.Match(webPartLayoutCode).Result("$1");
                            }

                            // Get original class name
                            string originalClassName = String.Empty;
                            if (inheritsRegex.IsMatch(webPartLayoutCode))
                            {
                                originalClassName = inheritsRegex.Match(webPartLayoutCode).Result("$1");
                            }

                            if (codeFileRegex.IsMatch(webPartLayoutCode))
                            {
                                webPartLayoutCode = codeFileRegex.Replace(webPartLayoutCode, "CodeFile=\"" + codeFilePath + "\"");
                            }

                            if (inheritsRegex.IsMatch(webPartLayoutCode))
                            {
                                webPartLayoutCode = inheritsRegex.Replace(webPartLayoutCode, "Inherits=\"$1_Web_Deployment\"");
                            }

                            // Read original codefile and change classname
                            string codeFileCode = String.Empty;
                            if (!String.IsNullOrEmpty(originalCodeFilePath) && FileHelper.FileExists(originalCodeFilePath))
                            {
                                codeFileCode = File.ReadAllText(Server.MapPath(originalCodeFilePath));
                                codeFileCode = codeFileCode.Replace(originalClassName, originalClassName + "_Web_Deployment");

                                // Save code file
                                SiteManagerFunctions.SaveCodeFile(filename, webPartLayoutCode);

                                // Save code behind file
                                SiteManagerFunctions.SaveCodeFile(codeFilePath, codeFileCode);
                            }
                        }
                    }
                }
            }

            lblResult.Text = GetString("Deployment.ObjectsSaved");
        }
        catch (Exception ex)
        {
            CMS.EventLog.EventLogProvider ep = new CMS.EventLog.EventLogProvider();
            ep.LogEvent("System deployment", "E", ex);

            lblError.Visible = true;
            lblError.Text    = ex.Message;
        }
    }
示例#20
0
    /// <summary>
    /// Save new layout.
    /// </summary>
    protected bool Save()
    {
        if (webPartInfo != null)
        {
            // Remove "." due to virtual path provider replacement
            txtLayoutName.Text = txtLayoutName.Text.Replace(".", "");

            string result = new Validator().NotEmpty(txtLayoutName.Text, GetString("WebPartPropertise.errCodeName")).NotEmpty(txtLayoutDisplayName.Text, GetString("WebPartPropertise.errDisplayName")).IsCodeName(txtLayoutName.Text, GetString("WebPartPropertise.errCodeNameFormat")).Result;

            if (result == "")
            {
                WebPartLayoutInfo tmpLayInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(webPartInfo.WebPartName, txtLayoutName.Text.Trim());
                if (tmpLayInfo == null)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo();

                    wpli.WebPartLayoutCodeName = txtLayoutName.Text.Trim();

                    wpli.WebPartLayoutDescription = txtDescription.Text;
                    wpli.WebPartLayoutDisplayName = txtLayoutDisplayName.Text;

                    if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                    {
                        wpli.WebPartLayoutCode = etaCode.Text;
                    }
                    else
                    {
                        wpli.WebPartLayoutCode = GetDefaultCode();
                    }

                    wpli.WebPartLayoutCSS       = etaCSS.Text;
                    wpli.WebPartLayoutWebPartID = webPartInfo.WebPartID;

                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

                    LayoutCodeName = wpli.WebPartLayoutCodeName;

                    txtDescription.Text       = "";
                    txtLayoutDisplayName.Text = "";
                    txtLayoutName.Text        = "";

                    plcDescription.Visible = false;
                    plcValues.Visible      = false;
                    etaCode.Rows           = 17;

                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("General.ChangesSaved");

                    pnlMenu.Visible         = true;
                    pnlCheckOutInfo.Visible = true;
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("WebPartPropertise.CodeNameAllreadyExists");
                    etaCode.Rows     = 17;
                    return(false);
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = result;
                etaCode.Rows     = 17;
                return(false);
            }
        }

        return(true);
    }
示例#21
0
    /// <summary>
    /// Sets check out/in/undo panel
    /// </summary>
    protected void SetCheckPanel(WebPartLayoutInfo mwpli)
    {
        WebPartInfo       wpi  = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
        WebPartLayoutInfo wpli = mwpli;

        if (wpi != null)
        {
            if (wpli == null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
            }
        }

        if (wpli != null)
        {
            this.pnlCheckOutInfo.Visible = true;

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.ReadOnly = true;
                etaCSS.ReadOnly  = true;

                string   username = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(wpli.WebPartLayoutCheckedOutByUserID);
                if (ui != null)
                {
                    username = HTMLHelper.HTMLEncode(ui.FullName);
                }

                plcCheckOut.Visible = false;

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    this.plcCheckIn.Visible = true;

                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    this.plcUndoCheckOut.Visible = true;
                }
            }
            else
            {
                wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
                if (wpi != null)
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

                    this.plcCheckOut.Visible     = true;
                    this.plcCheckIn.Visible      = false;
                    this.plcUndoCheckOut.Visible = false;
                }
            }
        }
    }
    /// <summary>
    /// Loads data of edited layout from DB into TextBoxes.
    /// </summary>
    protected void LoadData()
    {
        // Initialize default flag values
        bool displayCheckIn      = false;
        bool displayUndoCheckOut = false;
        bool displayCheckOut     = false;

        if (wpli != null)
        {
            pnlCheckOutInfo.Visible = true;

            string codeNameOnly = wpli.WebPartLayoutCodeName;
            int    pos          = codeNameOnly.IndexOf('.');
            if (pos >= 0)
            {
                codeNameOnly = codeNameOnly.Substring(pos + 1, codeNameOnly.Length - pos - 1);
            }

            if (!RequestHelper.IsPostBack())
            {
                txtDisplayName.Text = wpli.WebPartLayoutDisplayName;
                txtCodeName.Text    = codeNameOnly;
                txtDescription.Text = wpli.WebPartLayoutDescription;
                etaCode.Text        = wpli.WebPartLayoutCode;
                tbCSS.Text          = wpli.WebPartLayoutCSS;
            }

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.Enabled = false;
                tbCSS.Enabled   = false;

                string   username = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(wpli.WebPartLayoutCheckedOutByUserID);
                if (ui != null)
                {
                    username = HTMLHelper.HTMLEncode(ui.FullName);
                }

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    displayCheckIn = true;

                    lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    displayUndoCheckOut = true;
                }
            }
            else if (wpi != null)
            {
                lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

                displayCheckOut = true;
            }
        }
        else
        {
            lblError.Text    = GetString("WebPartEditLayoutEdit.InvalidLayoutID");
            lblError.Visible = true;
        }

        InitializeMasterPage(displayCheckIn, displayCheckOut, displayUndoCheckOut);

        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            lblInfo.Text    = GetString("general.changessaved");
            lblInfo.Visible = true;

            // Reload header if changes were saved
            ScriptHelper.RefreshTabHeader(Page, null);
        }
    }
示例#23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>();

        foreach (DictionaryEntry param in mProperties)
        {
            // Decode special CK editor char
            String str = String.Empty;
            if (param.Value != null)
            {
                str = param.Value.ToString().Replace("%25", "%");
            }

            decodedProperties[param.Key] = HttpUtility.UrlDecode(str);
        }
        mProperties = decodedProperties;

        string widgetName = ValidationHelper.GetString(mProperties["name"], String.Empty);

        // Widget name must be specified
        if (String.IsNullOrEmpty(widgetName))
        {
            AddErrorWebPart("widgets.invalidname", null);
            return;
        }

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName);

        if (wi == null)
        {
            AddErrorWebPart("widget.failedtoload", null);
            return;
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

        if (wpi == null)
        {
            return;
        }

        //no widgets can be used as inline
        if (!wi.WidgetForInline)
        {
            AddErrorWebPart("widgets.cantbeusedasinline", null);
            return;
        }

        try
        {
            // Merge widget and it's parent webpart properties
            string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

            // Prepare form
            WidgetZoneTypeEnum zoneType           = WidgetZoneTypeEnum.Editor;
            FormInfo           zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType);
            FormInfo           fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true);

            // Apply changed values
            DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi);
            fi.LoadDefaultValues(dr);

            // Incorporate inline parameters to datarow
            string publicFields = ";containertitle;container;";
            if (wi.WidgetPublicFileds != null)
            {
                publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";";
            }

            // Load the widget control
            string url = null;

            // Set widget layout
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID);

            if (wpli != null)
            {
                // Load specific layout through virtual path
                url = wpli.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID);
            }
            else
            {
                // Load regularly
                url = WebPartInfoProvider.GetWebPartUrl(wpi, false);
            }

            CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url);
            control.PartInstance = new WebPartInstance();

            // Set all form values to webpart
            foreach (DataColumn column in dr.Table.Columns)
            {
                object value      = dr[column];
                string columnName = column.ColumnName.ToLowerCSafe();

                //Resolve set values by user
                if (mProperties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = mProperties[columnName];
                    }
                }

                // Resolve macros in defined in default values
                if (!String.IsNullOrEmpty(value as string))
                {
                    // Do not resolve macros for public fields
                    if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0)
                    {
                        // Check whether current column
                        bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";");

                        // Resolve macros
                        value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection);
                    }
                }

                control.PartInstance.SetValue(column.ColumnName, value);
            }

            control.PartInstance.IsWidget = true;

            // Load webpart content
            control.OnContentLoaded();

            // Add webpart to controls collection
            Controls.Add(control);
        }

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }
    /// <summary>
    /// Save layout code.
    /// </summary>
    protected bool SaveData()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

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

        string errorMessage = new Validator()
                              .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result;

        int         webPartId   = ValidationHelper.GetInteger(Request.QueryString["webpartId"], 0);
        WebPartInfo webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (webPartInfo == null)
        {
            errorMessage = GetString("WebPartEditLayoutEdit.InvalidWebPartID");
        }

        if (errorMessage != String.Empty)
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return(false);
        }

        // Get layout info
        WebPartLayoutInfo webPartLayoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);

        if (webPartLayoutInfo != null)
        {
            // Get layout info using its code name - layout code name must be unique
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts("WebPartLayoutCodeName = '" + WebPartLayoutInfoProvider.GetWebPartLayoutFullCodeName(webPartInfo.WebPartName, txtCodeName.Text) + "'", null);

            // Find anything?
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                WebPartLayoutInfo temp = new WebPartLayoutInfo(ds.Tables[0].Rows[0]);
                // Is it the same layout?
                if ((ds.Tables[0].Rows.Count > 1) || (temp.WebPartLayoutID != webPartLayoutInfo.WebPartLayoutID))
                {
                    lblError.Text    = String.Format(GetString("WebPartEditLayoutEdit.CodeNameAlreadyExist"), txtCodeName.Text);
                    lblError.Visible = true;
                    return(false);
                }
            }

            webPartLayoutInfo.WebPartLayoutCodeName    = txtCodeName.Text;
            webPartLayoutInfo.WebPartLayoutDisplayName = txtDisplayName.Text;
            webPartLayoutInfo.WebPartLayoutDescription = txtDescription.Text;

            if (!webPartLayoutInfo.Generalized.IsCheckedOut)
            {
                webPartLayoutInfo.WebPartLayoutCode = etaCode.Text;
                webPartLayoutInfo.WebPartLayoutCSS  = tbCSS.Text;
            }

            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(webPartLayoutInfo);

            // Reload header if changes were saved
            if (TabMode)
            {
                ScriptHelper.RefreshTabHeader(Page, null);
            }
        }
        return(true);
    }
示例#25
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for web part properties UI
        CurrentUserInfo currentUser = CMSContext.CurrentUser;

        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", "WebPartProperties.Layout"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "WebPartProperties.Layout");
        }

        // Check saved
        bool saved = false;

        if (QueryHelper.GetBoolean("saved", false))
        {
            saved           = true;
            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }

        // Init GUI
        mCheckOut     = GetString("WebPartLayout.CheckOut");
        mCheckIn      = GetString("WebPartLayout.CheckIn");
        mUndoCheckOut = GetString("WebPartLayout.DiscardCheckOut");
        mSave         = GetString("General.Save");

        this.imgSave.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/Save.png");

        this.imgCheckIn.ImageUrl  = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkin.png");
        this.imgCheckOut.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkout.png");

        this.imgUndoCheckOut.ImageUrl      = GetImageUrl("CMSModules/CMS_Content/EditMenu/undocheckout.png");
        this.btnUndoCheckOut.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("General.ConfirmUndoCheckOut")) + ");";

        if (webpartId != "")
        {
            // Get pageinfo
            pi = GetPageInfo(aliasPath, templateId);
            if (pi == null)
            {
                this.lblInfo.Text        = GetString("WebPartProperties.WebPartNotFound");
                this.pnlFormArea.Visible = false;
                return;
            }

            // Get page template
            pti = pi.PageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        // If the web part is not found, do not continue
        if (webPart == null)
        {
            this.lblInfo.Text        = GetString("WebPartProperties.WebPartNotFound");
            this.pnlFormArea.Visible = false;

            return;
        }
        else
        {
            if (String.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);

        if (wpi != null)
        {
            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                pnlMenu.Visible         = false;
                pnlCheckOutInfo.Visible = false;

                if (LayoutCodeName != "")
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    if (wpli != null)
                    {
                        if ((LayoutCodeName != "|default|") && (LayoutCodeName != "|new|"))
                        {
                            SetEditedObject(wpli, "WebPartProperties_layout_frameset_frameset.aspx");
                        }

                        pnlMenu.Visible         = true;
                        pnlCheckOutInfo.Visible = true;

                        // Read-only code text area
                        etaCode.ReadOnly = false;
                        etaCSS.ReadOnly  = false;

                        // Set checkout panel
                        SetCheckPanel(wpli);

                        etaCode.Text = wpli.WebPartLayoutCode;
                        etaCSS.Text  = wpli.WebPartLayoutCSS;
                        loaded       = true;
                    }
                }

                if (!loaded)
                {
                    string fileName = webPartInfo.WebPartFileName;

                    if (webPartInfo.WebPartParentID > 0)
                    {
                        WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);
                        if (pwpi != null)
                        {
                            fileName = pwpi.WebPartFileName;
                        }
                    }

                    if (!fileName.StartsWith("~"))
                    {
                        fileName = "~/CMSWebparts/" + fileName;
                    }

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        lblError.Text      = GetString("WebPartProperties.FileNotExist");
                        lblError.Visible   = true;
                        plcContent.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        etaCSS.Text = wpi.WebPartCSS;
                    }
                }
            }
        }

        btnOnOK.Click += new EventHandler(btnOnOK_Click);

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
                                                   "function SetRefresh(refreshpage) { document.getElementById('" + this.hidRefresh.ClientID + "').value = refreshpage; } \n" +
                                                   "function OnApplyButton(refreshpage) { SetRefresh(refreshpage); " + Page.ClientScript.GetPostBackEventReference(lnkSave, "") + "} \n" +
                                                   "function OnOKButton(refreshpage) { SetRefresh(refreshpage); " + Page.ClientScript.GetPostBackEventReference(btnOnOK, "") + "} \n"
                                                   ));

        if (saved && (LayoutCodeName == "|new|"))
        {
            // Refresh menu
            string query = URLHelper.Url.Query;
            query = URLHelper.AddParameterToUrl(query, "layoutcodename", webPart.GetValue("WebPartLayout").ToString());
            query = URLHelper.AddParameterToUrl(query, "reload", "true");

            string scriptText = ScriptHelper.GetScript(@"parent.frames['webpartpropertiesmenu'].location = 'webpartproperties_layout_menu.aspx" + query + "';");
            ScriptHelper.RegisterStartupScript(this, typeof(string), "ReloadAfterNewLayout", scriptText);
        }

        if (!RequestHelper.IsPostBack())
        {
            InitLayoutForm();
        }

        this.plcCssLink.Visible = String.IsNullOrEmpty(etaCSS.Text.Trim());
        this.lnkStyles.Visible  = !String.IsNullOrEmpty(LayoutCodeName) && (LayoutCodeName != "|default|");
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        // Disable items when virtual path provider is disabled
        if (!SettingsKeyProvider.UsingVirtualPathProvider && (wpli != null) && (wpi != null))
        {
            lblVirtualInfo.Text     = String.Format(GetString("WebPartLayout.VirtualPathProviderNotRunning"), WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null));
            plcVirtualInfo.Visible  = true;
            pnlCheckOutInfo.Visible = false;
            etaCode.Enabled         = false;
            tbCSS.Enabled           = false;
        }
    }
示例#27
0
    /// <summary>
    /// Selected index changed.
    /// </summary>
    private void InitLayoutForm()
    {
        if (webPartInfo != null)
        {
            if (!String.IsNullOrEmpty(LayoutCodeName))
            {
                if (LayoutCodeName == "|new|")
                {
                    // New layout
                    plcDescription.Visible  = true;
                    plcValues.Visible       = true;
                    etaCode.ReadOnly        = false;
                    etaCSS.ReadOnly         = false;
                    etaCode.Rows            = 19;
                    pnlMenu.Visible         = false;
                    pnlCheckOutInfo.Visible = false;

                    // Prefill with default layout
                    etaCode.Text = GetDefaultCode();
                }
                else
                {
                    etaCode.Rows           = 24;
                    plcDescription.Visible = false;
                    plcValues.Visible      = false;
                    etaCode.ReadOnly       = false;

                    if (LayoutCodeName == "|default|")
                    {
                        // Get default code and disable editing
                        etaCode.Text = GetDefaultCode();

                        etaCode.ReadOnly = true;
                        etaCSS.ReadOnly  = true;
                        etaCSS.Text      = webPartInfo.WebPartCSS;

                        pnlMenu.Visible         = false;
                        pnlCheckOutInfo.Visible = false;
                    }
                    else
                    {
                        // Other layouts
                        etaCode.Rows = 18;

                        pnlMenu.Visible         = true;
                        pnlCheckOutInfo.Visible = true;
                        etaCode.Text            = "Loading...";

                        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                        if (wpi != null)
                        {
                            // Get the layout code from layout info
                            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                            if (wpli != null)
                            {
                                SetCheckPanel(null);

                                etaCode.Text    = wpli.WebPartLayoutCode;
                                etaCSS.ReadOnly = false;
                                etaCSS.Text     = wpli.WebPartLayoutCSS;
                            }
                        }
                    }
                }
            }
        }
        else
        {
        }
    }