/// <summary>
 /// Initializes the HTML toolbar.
 /// </summary>
 /// <param name="form">Form information</param>
 private void InitHTMLToobar(FormInfo form)
 {
     // Display / hide the HTML editor toolbar area
     if (form.UsesHtmlArea())
     {
         plcToolbar.Visible = true;
     }
 }
 /// <summary>
 /// Initializes the HTML toolbar.
 /// </summary>
 /// <param name="form">Form information</param>
 private void InitHTMLToobar(FormInfo form)
 {
     // Display / hide the HTML editor toolbar area
     if (form.UsesHtmlArea())
     {
         plcToolbar.Visible = true;
     }
 }
Esempio n. 3
0
    /// <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", LocalizationContext.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 = VariantHelper.GetVariantID(variantMode, templateId, variantName, true);

                // 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 = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);
            if (pti != null)
            {
                // Get web part zone
                pti.TemplateInstance.EnsureZone(zoneId);
                webPartZone = pti.TemplateInstance.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             = SiteContext.CurrentSiteName;
                formElem.FormInformation      = fi;
                formElem.OnAfterDataLoad     += formElem_OnAfterDataLoad;

                // HTML editor toolbar
                if (fi.UsesHtmlArea())
                {
                    plcToolbarPadding.Visible = true;
                    plcToolbar.Visible        = true;
                    pnlFormArea.Height        = 285;
                }
            }
        }
    }
Esempio n. 4
0
    protected override void OnInit(EventArgs e)
    {
        var currentUser = MembershipContext.AuthenticatedUser;

        // Check UIProfile
        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "EditForm", "Edit" }, SiteContext.CurrentSiteName))
        {
            RedirectToUIElementAccessDenied("CMS.Content", "EditForm");
        }

        base.OnInit(e);

        DocumentManager.OnAfterAction  += DocumentManager_OnAfterAction;
        DocumentManager.OnLoadData     += DocumentManager_OnLoadData;
        DocumentManager.OnBeforeAction += DocumentManager_OnBeforeAction;

        // Register scripts
        string script = "function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }";

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), formElem.ClientID + "_RefreshForm", ScriptHelper.GetScript(script));

        ScriptHelper.RegisterCompletePageScript(this);
        ScriptHelper.RegisterLoader(this);
        ScriptHelper.RegisterDialogScript(this);

        formElem.OnBeforeDataLoad += formElem_OnBeforeDataLoad;
        formElem.OnAfterDataLoad  += formElem_OnAfterDataLoad;

        // Analyze the action parameter
        switch (Action)
        {
        case "new":
        case "convert":
        {
            newdocument = true;

            // Check if document type is allowed under parent node
            if ((ParentNodeID > 0) && (ClassID > 0))
            {
                // Check class
                ci = DataClassInfoProvider.GetDataClassInfo(ClassID);
                if (ci == null)
                {
                    throw new Exception("[Content/Edit.aspx]: Class ID '" + ClassID + "' not found.");
                }

                if (ci.ClassName.ToLowerCSafe() == "cms.blog")
                {
                    if (!LicenseHelper.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Blogs, ObjectActionEnum.Insert))
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                    }
                }

                if (!LicenseHelper.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Documents, ObjectActionEnum.Insert))
                {
                    RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                }

                // Check if need template selection, if so, then redirect to template selection page
                int templateId = TemplateID;
                if (!ProductSection && ci.ClassShowTemplateSelection && (templateId < 0) && (ci.ClassName.ToLowerCSafe() != "cms.menuitem"))
                {
                    URLHelper.Redirect("~/CMSModules/Content/CMSDesk/TemplateSelection.aspx" + RequestContext.CurrentQueryString);
                }

                // Set default template ID
                formElem.DefaultPageTemplateID = (templateId > 0) ? templateId : ci.ClassDefaultPageTemplateID;

                string newClassName = ci.ClassName;
                formElem.FormName = newClassName + ".default";

                DocumentManager.Mode               = FormModeEnum.Insert;
                DocumentManager.ParentNodeID       = ParentNodeID;
                DocumentManager.NewNodeCultureCode = ParentCulture;

                // Set up the document conversion
                int convertDocumentId = QueryHelper.GetInteger("convertdocumentid", 0);
                if (convertDocumentId > 0)
                {
                    DocumentManager.SourceDocumentID = convertDocumentId;
                    DocumentManager.Mode             = FormModeEnum.Convert;
                }

                DocumentManager.NewNodeClassID = ClassID;

                // Check allowed document type
                TreeNode parentNode = DocumentManager.ParentNode;
                if ((parentNode == null) || !DocumentHelper.IsDocumentTypeAllowed(parentNode, ClassID))
                {
                    AddNotAllowedScript("child");
                }

                if (!currentUser.IsAuthorizedToCreateNewDocument(DocumentManager.ParentNode, DocumentManager.NewNodeClassName))
                {
                    AddNotAllowedScript("new");
                }
            }

            if (RequiresDialog)
            {
                SetTitle(GetString("Content.NewTitle"));
            }
            else
            {
                EnsureDocumentBreadcrumbs(PageBreadcrumbs, action: String.Format(GetString("content.newdocument"), ci.ClassDisplayName));
            }
        }
        break;

        case "newculture":
        {
            newculture = true;
            int nodeId = QueryHelper.GetInteger("nodeid", 0);
            DocumentManager.Mode = FormModeEnum.InsertNewCultureVersion;
            formElem.NodeID      = nodeId;

            // Check permissions
            bool authorized = false;
            if (nodeId > 0)
            {
                // Get the node
                TreeNode treeNode = DocumentManager.Tree.SelectSingleNode(nodeId);
                if (treeNode != null)
                {
                    DocumentManager.NewNodeClassID     = treeNode.GetIntegerValue("NodeClassID", 0);
                    DocumentManager.ParentNodeID       = ParentNodeID;
                    DocumentManager.NewNodeCultureCode = ParentCulture;
                    DocumentManager.SourceDocumentID   = QueryHelper.GetInteger("sourcedocumentid", 0);
                    authorized = currentUser.IsAuthorizedToCreateNewDocument(treeNode.NodeParentID, treeNode.NodeClassName);

                    if (authorized)
                    {
                        string className = DocumentManager.NewNodeClassName;
                        if (className.ToLowerCSafe() == "cms.blog")
                        {
                            if (!LicenseHelper.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Blogs, ObjectActionEnum.Insert))
                            {
                                RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                            }
                        }

                        if (!LicenseHelper.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Documents, ObjectActionEnum.Insert))
                        {
                            RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                        }

                        ci = DataClassInfoProvider.GetDataClassInfo(className);
                        formElem.FormName = className + ".default";
                    }

                    // Setup page title
                    PageTitle.TitleText = GetString("Content.NewCultureVersionTitle");
                }
            }

            if (!authorized)
            {
                AddNotAllowedScript("newculture");
            }

            if (RequiresDialog)
            {
                SetTitle(GetString("content.newcultureversiontitle"));
            }
            else
            {
                if (!IsProductsUI)
                {
                    EnsureDocumentBreadcrumbs(PageBreadcrumbs, action: GetString("content.newcultureversiontitle"));
                }
            }
        }
        break;

        default:
        {
            TreeNode node = Node;
            if (node == null)
            {
                RedirectToNewCultureVersionPage();
            }
            else
            {
                // Update view mode
                if (!RequiresDialog)
                {
                    PortalContext.ViewMode = ViewModeEnum.EditForm;
                }

                EnableSplitMode      = true;
                DocumentManager.Mode = FormModeEnum.Update;
                ci = DataClassInfoProvider.GetDataClassInfo(node.NodeClassName);
                if (RequiresDialog)
                {
                    menuElem.ShowSaveAndClose = true;

                    // Add the document name to the properties header title
                    string nodeName = node.GetDocumentName();
                    // Get name for root document
                    if (node.NodeClassName.ToLowerCSafe() == "cms.root")
                    {
                        nodeName = SiteContext.CurrentSite.DisplayName;
                    }

                    SetTitle(GetString("Content.EditTitle") + " \"" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nodeName)) + "\"");
                }
            }
        }
        break;
        }

        formElem.Visible = true;

        // Display / hide the CK editor toolbar area
        FormInfo fi = FormHelper.GetFormInfo(ci.ClassName, false);

        if (fi.UsesHtmlArea())
        {
            // Add script to display toolbar
            if (formElem.HtmlAreaToolbarLocation.ToLowerCSafe() == "out:cktoolbar")
            {
                mShowToolbar = true;
            }
        }

        // Init form for product section edit
        if (ProductSection)
        {
            // Form prefix
            formElem.FormPrefix = "ecommerce";

            // Hide Apply workflow action
            menuElem.ShowApplyWorkflow = false;
        }

        if (RequiresDialog)
        {
            plcCKFooter.Visible = false;
        }
    }
Esempio n. 5
0
    protected override void OnInit(EventArgs e)
    {
        ManagersContainer = plcManagers;

        CurrentUserInfo currentUser = CMSContext.CurrentUser;

        // Check UIProfile
        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", "EditForm"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "EditForm");
        }

        base.OnInit(e);

        ScriptHelper.RegisterStartupScript(this, typeof(string), "spellCheckDialog", GetSpellCheckDialog());

        // Register scripts
        string script = "function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }";

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), formElem.ClientID + "_RefreshForm", ScriptHelper.GetScript(script));

        ScriptHelper.RegisterCompletePageScript(this);
        ScriptHelper.RegisterProgress(this);
        ScriptHelper.RegisterDialogScript(this);

        confirmChanges = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSConfirmChanges");

        formElem.TreeProvider     = TreeProvider;
        formElem.OnAfterDataLoad += formElem_OnAfterDataLoad;

        // Current nodeID
        nodeId = QueryHelper.GetInteger("nodeid", 0);

        // ClassID, used when creating new document
        classId = QueryHelper.GetInteger("classid", 0);

        // TemplateID, used when Use template selection is enabled in actual class
        templateId = QueryHelper.GetInteger("templateid", 0);


        // Analyze the action parameter
        switch (QueryHelper.GetString("action", "").ToLower())
        {
        case "new":
            // Check if document type is allowed under parent node
            if ((nodeId > 0) && (classId > 0))
            {
                // Get the node
                TreeNode      treeNode = TreeProvider.SelectSingleNode(nodeId);
                DataClassInfo dci      = DataClassInfoProvider.GetDataClass(classId);
                if ((treeNode == null) || (dci == null))
                {
                    throw new Exception("[Content.Edit]: Given node or document class cannot be found!");
                }

                // Check allowed document type
                if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(treeNode.GetValue("NodeClassID"), 0), classId))
                {
                    AddNotAllowedScript("child");
                }

                if (!currentUser.IsAuthorizedToCreateNewDocument(treeNode, dci.ClassName))
                {
                    AddNotAllowedScript("new");
                }
            }

            newdocument = true;
            break;

        case "newculture":
            // Check permissions
            bool authorized = false;
            if (nodeId > 0)
            {
                // Get the node
                TreeNode treeNode = TreeProvider.SelectSingleNode(nodeId);
                if (treeNode != null)
                {
                    authorized = currentUser.IsAuthorizedToCreateNewDocument(treeNode.NodeParentID, treeNode.NodeClassName);
                }
            }

            if (!authorized)
            {
                AddNotAllowedScript("newculture");
            }

            newculture = true;
            break;
        }

        // Get the node
        if (newculture || newdocument)
        {
            node = DocumentHelper.GetDocument(nodeId, TreeProvider.ALL_CULTURES, TreeProvider);
            if (newculture)
            {
                DocumentHelper.ClearWorkflowInformation(node);
            }
        }
        else
        {
            node = DocumentHelper.GetDocument(nodeId, CMSContext.PreferredCultureCode, TreeProvider);
            if ((node == null) && displaySplitMode)
            {
                URLHelper.Redirect("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx" + URLHelper.Url.Query);
            }
        }

        // Set edited document
        EditedDocument = node;

        if (!confirmChanges)
        {
            AddScript("confirmChanges = false;");
        }

        // If node found, init the form
        if (node != null)
        {
            // CMSForm initialization
            formElem.NodeId      = node.NodeID;
            formElem.CultureCode = CMSContext.PreferredCultureCode;

            // Set the form mode
            if (newdocument)
            {
                ci = DataClassInfoProvider.GetDataClass(classId);
                if (ci == null)
                {
                    throw new Exception("[Content/Edit.aspx]: Class ID '" + classId + "' not found.");
                }

                if (ci.ClassName.ToLower() == "cms.blog")
                {
                    if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert))
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                    }
                }

                if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
                {
                    RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                }

                // Check if need template selection, if so, then redirect to template selection page
                if ((ci.ClassShowTemplateSelection) && (templateId == 0) && (ci.ClassName.ToLower() != "cms.menuitem"))
                {
                    URLHelper.Redirect("~/CMSModules/Content/CMSDesk/TemplateSelection.aspx" + URLHelper.Url.Query);
                }

                // Set default template ID
                formElem.DefaultPageTemplateID = templateId > 0 ? templateId : ci.ClassDefaultPageTemplateID;

                formElem.FormMode = FormModeEnum.Insert;
                string newClassName = ci.ClassName;
                formElem.FormName = newClassName + ".default";
            }
            else if (newculture)
            {
                if (node.NodeClassName.ToLower() == "cms.blog")
                {
                    if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert))
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                    }
                }

                if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
                {
                    RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                }

                formElem.FormMode = FormModeEnum.InsertNewCultureVersion;
                // Default data document ID
                formElem.CopyDefaultDataFromDocumentId = ValidationHelper.GetInteger(Request.QueryString["sourcedocumentid"], 0);

                ci = DataClassInfoProvider.GetDataClass(node.NodeClassName);
                formElem.FormName = node.NodeClassName + ".default";
            }
            else
            {
                formElem.FormMode = FormModeEnum.Update;
                ci = DataClassInfoProvider.GetDataClass(node.NodeClassName);
            }
            formElem.Visible = true;

            // Display / hide the CK editor toolbar area
            FormInfo fi = FormHelper.GetFormInfo(ci.ClassName, false);

            if (fi.UsesHtmlArea())
            {
                // Add script to display toolbar
                if (formElem.HtmlAreaToolbarLocation.ToLower() == "out:cktoolbar")
                {
                    mShowToolbar = true;
                }
            }

            ReloadForm();
        }

        AddScript(
            "function SaveDocument(nodeId, createAnother) { document.getElementById('hidAnother').value = createAnother; " + (confirmChanges ? "AllowSubmit(); " : "") + ClientScript.GetPostBackEventReference(btnSave, null) + "; } \n" +
            "function Approve(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnApprove, null) + "; } \n" +
            "function Reject(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnReject, null) + "; } \n" +
            "function CheckIn(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnCheckIn, null) + "; } \n" +
            (confirmChanges ? "var confirmLeave='" + GetString("Content.ConfirmLeave") + "'; \n" : "")
            );
    }