protected TabItem tabElem_OnTabCreated(UIElementInfo element, TabItem tab, int tabIndex)
    {
        bool   splitViewSupported = true;
        string elementName        = element.ElementName.ToLowerCSafe();

        switch (elementName)
        {
        case "properties.languages":
            splitViewSupported = false;
            if (!CultureInfoProvider.IsSiteMultilignual(CMSContext.CurrentSiteName) || !CultureInfoProvider.LicenseVersionCheck())
            {
                return(null);
            }
            break;

        case "properties.security":
        case "properties.relateddocs":
        case "properties.linkeddocs":
            splitViewSupported = false;
            break;

        case "properties.wireframe":
        {
            // Hide wireframe tab if wireframe is not present
            if ((DocumentManager.Node == null) || (DocumentManager.Node.NodeWireframeTemplateID <= 0))
            {
                return(null);
            }

            splitViewSupported = false;
        }
        break;

        case "properties.variants":

            if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), "") != "")
            {
                // Check license and whether content personalization is enabled and whether exists at least one variant for current template
                if ((DocumentManager.Node == null) ||
                    !LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.ContentPersonalization, ModuleEntry.ONLINEMARKETING) ||
                    !ResourceSiteInfoProvider.IsResourceOnSite("CMS.ContentPersonalization", CMSContext.CurrentSiteName) ||
                    !PortalContext.ContentPersonalizationEnabled ||
                    (ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(DocumentManager.Node.GetUsedPageTemplateId(), String.Empty) <= 0))
                {
                    return(null);
                }
            }


            break;

        case "properties.workflow":
        case "properties.versions":
            if (DocumentManager.Workflow == null)
            {
                return(null);
            }
            break;
        }

        // Ensure tab pre-selection
        if (elementName.StartsWithCSafe("properties.") && (elementName.Substring("properties.".Length) == selected))
        {
            CurrentMaster.Tabs.SelectedTab = tabIndex;
        }

        // Ensure split view mode
        if (splitViewSupported && CMSContext.DisplaySplitMode)
        {
            tab.RedirectUrl = GetSplitViewUrl(tab.RedirectUrl);
        }

        return(tab);
    }
Example #2
0
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // Setup basic form on live site
        formCustom.AllowMacroEditing = false;
        formCustom.IsLiveSite        = IsLiveSite;

        // Load settings
        if (!String.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWidget = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!String.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Try to find the widget variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (properties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(properties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = 0;
                if (VariantMode == VariantModeEnum.MVT)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName);
                }
                else if (VariantMode == VariantModeEnum.ContentPersonalization)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName);
                }

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    VariantID    = variantIdFromDB;
                    IsNewVariant = false;
                }
            }
        }

        EnsureDashboard();

        if (!String.IsNullOrEmpty(WidgetId) && !IsInline)
        {
            // Get page info
            try
            {
                pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode);
            }
            catch (PageNotFoundException)
            {
                // Do not throw exception if page info not found (e.g. bad alias path)
            }

            if (pi == null)
            {
                lblInfo.Text        = GetString("Widgets.Properties.aliasnotfound");
                lblInfo.Visible     = true;
                pnlFormArea.Visible = false;
                return;
            }

            // Get template instance
            templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi);

            if (!IsNewWidget)
            {
                // Get the instance of widget
                widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId);
                if (widgetInstance == null)
                {
                    lblInfo.Text        = GetString("Widgets.Properties.WidgetNotFound");
                    lblInfo.Visible     = true;
                    pnlFormArea.Visible = false;
                    return;
                }

                if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null))
                {
                    // Check OnlineMarketing permissions.
                    if (CheckPermissions("Read"))
                    {
                        widgetInstance = pi.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId);
                        widgetInstance = widgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID));
                        // Set the widget variant mode
                        if (widgetInstance != null)
                        {
                            VariantMode = widgetInstance.VariantMode;
                        }
                    }
                    else
                    {
                        // Not authorized for OnlineMarketing - Manage.
                        RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                    }
                }

                // Get widget info by widget name(widget type)
                wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType);
            }
            // Widget instance hasn't created yet
            else
            {
                wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0));
            }

            // Keep xml version
            if (widgetInstance != null)
            {
                xmlVersion = widgetInstance.XMLVersion;
            }

            CMSPage.EditedObject = wi;
            zoneType             = ZoneType;

            // Get the zone to which it inserts
            WebPartZoneInstance zone = templateInstance.GetZone(ZoneId);
            if ((zoneType == WidgetZoneTypeEnum.None) && (zone != null))
            {
                zoneType = zone.WidgetZoneType;
            }

            // Check security
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            switch (zoneType)
            {
            // Group zone => Only group widgets and group admin
            case WidgetZoneTypeEnum.Group:
                // Should always be, only group widget are allowed in group zone
                if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupID) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design"))))))
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for editor zones
            case WidgetZoneTypeEnum.Editor:
                if (!wi.WidgetForEditor)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for user zones
            case WidgetZoneTypeEnum.User:
                if (!wi.WidgetForUser)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;

            // Widget must be allowed for dashboard zones
            case WidgetZoneTypeEnum.Dashboard:
                if (!wi.WidgetForDashboard)
                {
                    if (OnNotAllowed != null)
                    {
                        OnNotAllowed(this, null);
                    }
                }
                break;
            }

            // Check security
            if ((zoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated()))
            {
                if (OnNotAllowed != null)
                {
                    OnNotAllowed(this, null);
                }
            }

            // Get form schemas
            wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);
            FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType);
            string   widgetProperties   = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);
            FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true);

            if (fi != null)
            {
                // Check if there are some editable properties
                var ffi = fi.GetFields(true, false).ToList <FormFieldInfo>();
                if ((ffi == null) || (ffi.Count == 0))
                {
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("widgets.emptyproperties");
                }

                // Get datarows with required columns
                DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi);

                // Load default values for new widget
                if (IsNewWidget || (xmlVersion > 0))
                {
                    fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible);
                }

                if (IsNewWidget)
                {
                    // Override default value and set title as widget display name
                    DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(wi.WidgetDisplayName));
                }

                // Load values from existing widget
                LoadDataRowFromWidget(dr, fi);

                // Init HTML toolbar if exists
                InitHTMLToobar(fi);

                // Init the form
                InitForm(formCustom, dr, fi);

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES;
            }
        }

        if (IsInline)
        {
            // Load text definition from session
            string definition = ValidationHelper.GetString(SessionHelper.GetValue("WidgetDefinition"), string.Empty);
            if (String.IsNullOrEmpty(definition))
            {
                definition = Request.Form[hdnWidgetDefinition.UniqueID];
            }
            else
            {
                hdnWidgetDefinition.Value = definition;
            }

            Hashtable parameters = null;

            if (IsNewWidget)
            {
                // New widget - load widget info by id
                if (!String.IsNullOrEmpty(WidgetId))
                {
                    wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0));
                }
                else
                {
                    // Try to get widget from codename
                    mName = QueryHelper.GetString("WidgetName", String.Empty);
                    wi    = WidgetInfoProvider.GetWidgetInfo(mName);
                }
            }
            else
            {
                if (definition == null)
                {
                    DisplayError("widget.failedtoload");
                    return;
                }

                // Parse definition
                parameters = CMSDialogHelper.GetHashTableFromString(definition);

                // Trim control name
                if (parameters["name"] != null)
                {
                    mName = parameters["name"].ToString();
                }

                wi = WidgetInfoProvider.GetWidgetInfo(mName);
            }
            if (wi == null)
            {
                DisplayError("widget.failedtoload");
                return;
            }

            // If widget cant be used as inline
            if (!wi.WidgetForInline)
            {
                DisplayError("widget.cantbeusedasinline");
                return;
            }


            // Test permission for user
            CurrentUserInfo currentUser = CMSContext.CurrentUser;
            if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated()))
            {
                mIsValidWidget = false;
                OnNotAllowed(this, null);
            }

            // If user is editor, more properties are shown
            WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User;
            if (currentUser.IsEditor)
            {
                zoneType = WidgetZoneTypeEnum.Editor;
            }

            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);
            string      widgetProperties   = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);
            FormInfo    zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType);
            FormInfo    fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true);

            if (fi != null)
            {
                // Check if there are some editable properties
                mFields = fi.GetFields(true, true);
                if ((mFields == null) || !mFields.Any())
                {
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("widgets.emptyproperties");
                }

                // Get datarows with required columns
                DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi);

                if (IsNewWidget)
                {
                    // Load default values for new widget
                    fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible);
                }
                else
                {
                    foreach (string key in parameters.Keys)
                    {
                        object value = parameters[key];
                        // Test if given property exists
                        if (dr.Table.Columns.Contains(key) && (value != null))
                        {
                            try
                            {
                                dr[key] = DataHelper.ConvertValue(value, dr.Table.Columns[key].DataType);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                // Override default value and set title as widget display name
                DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName);

                // Init HTML toolbar if exists
                InitHTMLToobar(fi);

                // Init the form
                InitForm(formCustom, dr, fi);

                // Set the context name
                formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES;
            }
        }
    }
Example #3
0
    /// <summary>
    /// Loads the web part form.
    /// </summary>
    protected void LoadForm()
    {
        // Load settings
        if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Indicates whether the new variant should be chosen when closing this dialog
        selectNewVariant = IsNewVariant;

        // Try to find the web part variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (properties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(properties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = 0;
                if (VariantMode == VariantModeEnum.MVT)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName);
                }
                else if (VariantMode == VariantModeEnum.ContentPersonalization)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName);
                }

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    VariantID    = variantIdFromDB;
                    IsNewVariant = false;
                }
            }
        }

        if (!String.IsNullOrEmpty(WebpartId))
        {
            // Get the page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode);
            if (pi != null)
            {
                // Get template
                pti = pi.UsedPageTemplateInfo;

                // Get template instance
                templateInstance = pti.TemplateInstance;

                if (!IsNewWebPart)
                {
                    // Standard zone
                    webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebpartId);

                    // If the web part not found, try to find it among the MVT/CP variants
                    if (webPartInstance == null)
                    {
                        // MVT/CP variant
                        templateInstance.LoadVariants(false, VariantModeEnum.None);
                        webPartInstance = templateInstance.GetWebPart(InstanceGUID, true);

                        // Set the VariantMode according to the selected web part/zone variant
                        if ((webPartInstance != null) && (webPartInstance.ParentZone != null))
                        {
                            VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode;
                        }
                        else
                        {
                            VariantMode = VariantModeEnum.None;
                        }
                    }
                    else
                    {
                        // Ensure that the ZoneVarianID is not set when the web part was found in a regular zone
                        ZoneVariantID = 0;
                    }

                    if ((VariantID > 0) && (webPartInstance != null) && (webPartInstance.PartInstanceVariants != null))
                    {
                        // Check OnlineMarketing permissions.
                        if (CheckPermissions("Read"))
                        {
                            webPartInstance = webPartInstance.FindVariant(VariantID);
                        }
                        else
                        {
                            // Not authorized for OnlineMarketing - Manage.
                            RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                        }
                    }

                    if (webPartInstance == null)
                    {
                        CMSPage.EditedObject = null;
                        return;
                    }
                }

                // Keep xml version
                if (webPartInstance != null)
                {
                    xmlVersion = webPartInstance.XMLVersion;
                }

                // Get the form info
                FormInfo fi = GetWebPartFormInfo();

                // Get the form definition
                if (fi != null)
                {
                    form.AllowMacroEditing = ((WebPartTypeEnum)wpi.WebPartType != WebPartTypeEnum.Wireframe);

                    // Get data row with required columns
                    DataRow dr = fi.GetDataRow(true, wpi.WebPartDefaultValues);

                    if (IsNewWebPart || (xmlVersion > 0))
                    {
                        fi.LoadDefaultValues(dr);

                        // Load overridden system values
                        fi.LoadDefaultValues(dr, wpi.WebPartDefaultValues);
                    }

                    if (IsNewWebPart)
                    {
                        // Set control ID
                        FormFieldInfo ffi = fi.GetFormField("WebPartControlID");
                        if (ffi != null)
                        {
                            ffi.DefaultValue = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance);
                            fi.UpdateFormField("WebPartControlID", ffi);
                        }
                    }

                    // Load values from existing web part
                    LoadDataRowFromWebPart(dr, webPartInstance, fi);

                    // Set a unique WebPartControlID for the new variant
                    if (IsNewVariant)
                    {
                        // Set control ID
                        dr["WebPartControlID"] = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance);
                    }

                    // Init the form
                    InitForm(form, dr, fi);

                    AddExportLink();
                }
                else
                {
                    CMSPage.EditedObject = null;
                }
            }
        }
    }
    /// <summary>
    /// OnInit event (BasicForm initialization).
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        string zoneId     = QueryHelper.GetString("zoneid", "");
        string aliasPath  = QueryHelper.GetString("aliaspath", "");
        int    templateId = QueryHelper.GetInteger("templateid", 0);
        string culture    = QueryHelper.GetString("culture", CMSContext.PreferredCultureCode);

        mZoneVariantID = QueryHelper.GetInteger("variantid", 0);
        mIsNewVariant  = QueryHelper.GetBoolean("isnewvariant", false);
        variantMode    = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", string.Empty));

        // When displaying an existing variant of a web part, get the variant mode for its original web part
        if (ZoneVariantID > 0)
        {
            PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                // Get the original webpart and retrieve its variant mode
                WebPartZoneInstance zoneInstance = pti.TemplateInstance.GetZone(zoneId);
                if ((zoneInstance != null) && (zoneInstance.VariantMode != VariantModeEnum.None))
                {
                    variantMode = zoneInstance.VariantMode;
                }
            }
        }

        // Try to find the zone variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (properties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(properties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = 0;
                if (variantMode == VariantModeEnum.MVT)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(templateId, variantName);
                }
                else if (variantMode == VariantModeEnum.ContentPersonalization)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(templateId, variantName);
                }

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    mZoneVariantID = variantIdFromDB;
                    mIsNewVariant  = false;
                }
            }
        }

        if (!String.IsNullOrEmpty(zoneId))
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("webpartzone.notfound"));
                pnlFormArea.Visible = false;
                return;
            }

            // Get template
            pti = pi.UsedPageTemplateInfo;
            if (pti != null)
            {
                // Get web part zone
                pti.EnsureZone(zoneId);
                webPartZone = pti.GetZone(zoneId);

                if ((ZoneVariantID > 0) && (webPartZone != null) && (webPartZone.ZoneInstanceVariants != null))
                {
                    // Check OnlineMarketing permissions
                    if (CheckPermissions("Read"))
                    {
                        webPartZone = webPartZone.ZoneInstanceVariants.Find(v => v.VariantID.Equals(ZoneVariantID));
                    }
                    else
                    {
                        // Not authorized for OnlineMarketing - Manage.
                        RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (variantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                    }
                }
                if (webPartZone == null)
                {
                    ShowInformation(GetString("webpartzone.notfound"));
                    pnlFormArea.Visible = false;
                    return;
                }

                FormInfo fi = BuildFormInfo(webPartZone);

                // Get the DataRow and fill the data row with values
                DataRow dr = fi.GetDataRow();
                foreach (DataColumn column in dr.Table.Columns)
                {
                    try
                    {
                        DataHelper.SetDataRowValue(dr, column.ColumnName, webPartZone.GetValue(column.ColumnName));
                    }
                    catch
                    {
                    }
                }

                // Initialize Form
                formElem.DataRow              = dr;
                formElem.MacroTable           = webPartZone.MacroTable;
                formElem.SubmitButton.Visible = false;
                formElem.SiteName             = CMSContext.CurrentSiteName;
                formElem.FormInformation      = fi;
                formElem.ShowPrivateFields    = true;
                formElem.OnAfterDataLoad     += formElem_OnAfterDataLoad;

                // HTML editor toolbar
                if (fi.UsesHtmlArea())
                {
                    plcToolbarPadding.Visible = true;
                    plcToolbar.Visible        = true;
                    pnlFormArea.Height        = 285;
                }
            }
        }
    }
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // Load settings
        if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Try to find the web part variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (properties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(properties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = 0;
                if (VariantMode == VariantModeEnum.MVT)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName);
                }
                else if (VariantMode == VariantModeEnum.ContentPersonalization)
                {
                    variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName);
                }

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    VariantID    = variantIdFromDB;
                    IsNewVariant = false;
                }
            }
        }

        if (!String.IsNullOrEmpty(WebpartId))
        {
            // Get the page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(this.AliasPath, this.PageTemplateId);
            if (pi != null)
            {
                // Get template
                pti = pi.PageTemplateInfo;

                // Get template instance
                templateInstance = pti.TemplateInstance;

                // Parent webpart
                WebPartInfo parentWpi = null;

                //Before FormInfo
                FormInfo beforeFI = null;

                //After FormInfo
                FormInfo afterFI = null;

                // Webpart form info
                FormInfo fi = null;

                if (!IsNewWebPart)
                {
                    // Standard zone
                    webPartInstance = pti.GetWebPart(InstanceGUID, WebpartId);

                    // If the web part not found, try to find it among the MVT/CP variants
                    if (webPartInstance == null)
                    {
                        // MVT/CP variant
                        templateInstance.LoadVariants(false, VariantModeEnum.None);
                        webPartInstance = templateInstance.GetWebPart(InstanceGUID, true);

                        // Set the VariantMode according to the selected web part/zone variant
                        if ((webPartInstance != null) && (webPartInstance.ParentZone != null))
                        {
                            VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode;
                        }
                        else
                        {
                            VariantMode = VariantModeEnum.None;
                        }
                    }
                    else
                    {
                        // Ensure that the ZoneVarianID is not set when the web part was found in a regural zone.
                        ZoneVariantID = 0;
                    }

                    if ((VariantID > 0) && (webPartInstance != null) && (webPartInstance.PartInstanceVariants != null))
                    {
                        // Check OnlineMarketing permissions.
                        if (CheckPermissions("Read"))
                        {
                            webPartInstance = webPartInstance.FindVariant(VariantID);
                        }
                        else
                        {
                            // Not authorised for OnlineMarketing - Manage.
                            RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                        }
                    }

                    if (webPartInstance == null)
                    {
                        lblInfo.Text        = GetString("WebPartProperties.WebPartNotFound");
                        pnlFormArea.Visible = false;
                        return;
                    }

                    wpi       = WebPartInfoProvider.GetWebPartInfo(webPartInstance.WebPartType);
                    form.Mode = FormModeEnum.Update;
                }
                // Webpart instance hasn't created yet
                else
                {
                    wpi       = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(WebpartId, 0));
                    form.Mode = FormModeEnum.Insert;
                }

                // Load parent
                if (wpi != null)
                {
                    if (wpi.WebPartParentID > 0)
                    {
                        parentWpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    }
                }

                // Get the form definition
                string wpProperties = "<form></form>";
                if (wpi != null)
                {
                    wpProperties = wpi.WebPartProperties;

                    // Use parent webpart if is defined
                    if (parentWpi != null)
                    {
                        wpProperties = parentWpi.WebPartProperties;
                    }

                    // Get before FormInfo
                    if (BeforeFormDefinition == null)
                    {
                        beforeFI = PortalHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before);
                    }
                    else
                    {
                        beforeFI = new FormInfo(BeforeFormDefinition);
                    }

                    // Get after FormInfo
                    if (AfterFormDefinition == null)
                    {
                        afterFI = PortalHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After);
                    }
                    else
                    {
                        afterFI = new FormInfo(AfterFormDefinition);
                    }
                }

                // Add 'General' category at the beginning if no one is specified
                if (!string.IsNullOrEmpty(wpProperties) && (!wpProperties.StartsWith("<form><category", StringComparison.InvariantCultureIgnoreCase)))
                {
                    wpProperties = wpProperties.Insert(6, "<category name=\"" + GetString("general.general") + "\" />");
                }

                // Get merged web part FormInfo
                fi = FormHelper.GetWebPartFormInfo(wpi.WebPartName, wpProperties, beforeFI, afterFI, true);

                // Get datarow with required columns
                DataRow dr = fi.GetDataRow();

                if (IsNewWebPart)
                {
                    // Load default properties values
                    fi.LoadDefaultValues(dr);

                    // Load overriden system values
                    fi.LoadDefaultValues(dr, wpi.WebPartDefaultValues);

                    // Set control ID
                    FormFieldInfo ffi = fi.GetFormField("WebPartControlID");
                    if (ffi != null)
                    {
                        ffi.DefaultValue = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance);
                        fi.UpdateFormField("WebPartControlID", ffi);
                    }
                }

                // Load values from existing webpart
                LoadDataRowFromWebPart(dr, webPartInstance);

                // Set a unique WebPartControlID for athe new variant
                if (IsNewVariant)
                {
                    // Set control ID
                    dr["WebPartControlID"] = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance);
                }

                // Init the form
                InitForm(form, dr, fi);

                AddExportLink();
            }
        }
    }
Example #6
0
    protected void ContextMenu_OnReloadData(object sender, EventArgs e)
    {
        int nodeId = ValidationHelper.GetInteger(ContextMenu.Parameter, 0);

        // Get the node
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
        TreeNode     node = tree.SelectSingleNode(nodeId);

        if (node != null)
        {
            // Hide Properties menu item with separator
            plcProperties.Visible = !HidePropertiesItem && !node.IsWireframe();
            if (plcProperties.Visible)
            {
                iProperties.ImageUrl = GetImageUrl("CMSModules/CMS_Content/ContextMenu/Properties.png");
                iProperties.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'general');");

                // Properties menu
                iGeneral.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'general');");
                iUrls.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'urls');");
                iTemplate.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'template');");
                iMetadata.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'metadata');");
                iCategories.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'categories');");
                iMenu.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'menu');");
                iWorkflow.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'workflow');");
                iVersions.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'versions');");
                iRelated.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'relateddocs');");
                iLinked.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'linkeddocs');");
                iSecurity.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'security');");
                iAttachments.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'attachments');");
                iLanguages.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'languages');");
                iWireframe.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'wireframe');");
                iVariants.Attributes.Add("onclick", "Properties(GetContextMenuParameter('nodeMenu'), 'variants');");

                // Hide language item
                if (!CultureInfoProvider.IsSiteMultilignual(CMSContext.CurrentSiteName) || !CultureInfoProvider.LicenseVersionCheck())
                {
                    pnlUILanguages.Visible = false;
                }

                // Hide wireframe tab if wireframe is not present
                if (node.NodeWireframeTemplateID <= 0)
                {
                    pnlUIWireframe.Visible = false;
                }

                if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), "") != "")
                {
                    // Check license and whether content personalization is enabled and whether exists at least one variant for current template
                    if (!LicenseHelper.IsFeatureAvailableInUI(FeatureEnum.ContentPersonalization, ModuleEntry.ONLINEMARKETING) ||
                        !ResourceSiteInfoProvider.IsResourceOnSite("CMS.ContentPersonalization", CMSContext.CurrentSiteName) ||
                        !PortalContext.ContentPersonalizationEnabled ||
                        (ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(node.GetUsedPageTemplateId(), String.Empty) <= 0))
                    {
                        pnlUICPVariants.Visible = false;
                    }
                }

                // No workflow
                if (node.GetWorkflow() == null)
                {
                    // Hide menu items
                    pnlUIWorkflow.Visible = false;
                    pnlUIVersions.Visible = false;
                }
            }
        }
        else
        {
            iNoNode.Visible = true;
            plcFirstLevelContainer.Visible = false;
        }
    }