/// <summary>
    /// Provides operations necessary to create and store new content file.
    /// </summary>
    private void HandleContentUpload()
    {
        string message            = string.Empty;
        bool   newDocumentCreated = false;

        try
        {
            if (NodeParentNodeID == 0)
            {
                throw new Exception(GetString("dialogs.document.parentmissing"));
            }

            // Check license limitations
            if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
            {
                throw new Exception(GetString("cmsdesk.documentslicenselimits"));
            }

            // Check if class exists
            DataClassInfo ci = DataClassInfoProvider.GetDataClass("CMS.File");
            if (ci == null)
            {
                throw new Exception(string.Format(GetString("dialogs.newfile.classnotfound"), "CMS.File"));
            }

            #region "Check permissions"

            // Get the node
            TreeNode parentNode = TreeProvider.SelectSingleNode(NodeParentNodeID, CMSContext.PreferredCultureCode, true);
            if (parentNode != null)
            {
                if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0), ci.ClassID))
                {
                    throw new Exception(GetString("Content.ChildClassNotAllowed"));
                }
            }

            // Check user permissions
            if (!RaiseOnCheckPermissions("Create", this))
            {
                if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parentNode, "CMS.File"))
                {
                    throw new Exception(string.Format(GetString("dialogs.newfile.notallowed"), NodeClassName));
                }
            }

            #endregion

            // Check the allowed extensions
            CheckAllowedExtensions();

            // Create new document
            string fileName = Path.GetFileNameWithoutExtension(ucFileUpload.FileName);
            string ext      = Path.GetExtension(ucFileUpload.FileName);

            if (IncludeExtension)
            {
                fileName += ext;
            }

            // Make sure the file name with extension respects maximum file name
            fileName = TextHelper.LimitFileNameLength(fileName, TreePathUtils.MaxNameLength);

            node = TreeNode.New("CMS.File", TreeProvider);
            node.DocumentCulture = CMSContext.PreferredCultureCode;
            node.DocumentName    = fileName;
            if (NodeGroupID > 0)
            {
                node.SetValue("NodeGroupID", NodeGroupID);
            }

            // Load default values
            FormHelper.LoadDefaultValues(node);
            node.SetValue("FileDescription", "");
            node.SetValue("FileName", fileName);
            node.SetValue("FileAttachment", Guid.Empty);

            // Set default template ID
            node.DocumentPageTemplateID = ci.ClassDefaultPageTemplateID;

            // Insert the document
            DocumentHelper.InsertDocument(node, parentNode, TreeProvider);

            newDocumentCreated = true;

            // Add the file
            DocumentHelper.AddAttachment(node, "FileAttachment", ucFileUpload.PostedFile, TreeProvider, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize);

            // Create default SKU if configured
            if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
            {
                node.CreateDefaultSKU();
            }

            // Update the document
            DocumentHelper.UpdateDocument(node, TreeProvider);

            // Get workflow info
            wi = WorkflowManager.GetNodeWorkflow(node);

            // Check if auto publish changes is allowed
            if ((wi != null) && wi.WorkflowAutoPublishChanges && !wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))
            {
                // Automatically publish document
                WorkflowManager.AutomaticallyPublish(node, wi, null);
            }
        }
        catch (Exception ex)
        {
            // Delete the document if something failed
            if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
            {
                DocumentHelper.DeleteDocument(node, TreeProvider, false, true, true);
            }

            message = ex.Message;
        }
        finally
        {
            // Create node info string
            string nodeInfo = "";
            if ((node != null) && (node.NodeID > 0) && (IncludeNewItemInfo))
            {
                nodeInfo = node.NodeID.ToString();
            }

            // Ensure message text
            message = HTMLHelper.EnsureLineEnding(message, " ");

            // Call function to refresh parent window
            string afterSaveScript = null;
            if (!string.IsNullOrEmpty(AfterSaveJavascript))
            {
                afterSaveScript = String.Format(@"
if (window.{0} != null){{
    window.{0}();
}} else if ((window.parent != null) && (window.parent.{0} != null)){{
    window.parent.{0}();
}}", AfterSaveJavascript);
            }

            afterSaveScript += String.Format(@"
if (typeof(parent.DFU) !== 'undefined') {{ 
    parent.DFU.OnUploadCompleted('{0}'); 
}} 
if ((window.parent != null) && (/parentelemid={1}/i.test(window.location.href)) && (window.parent.InitRefresh_{1} != null)){{
    window.parent.InitRefresh_{1}({2}, false, false{3}{4});
}}", QueryHelper.GetString("containerid", ""), ParentElemID, ScriptHelper.GetString(message.Trim()), ((nodeInfo != "") ? ", '" + nodeInfo + "'" : ""), (InsertMode ? ", 'insert'" : ", 'update'"));

            ScriptHelper.RegisterStartupScript(this, typeof(string), "afterSaveScript_" + ClientID, ScriptHelper.GetScript(afterSaveScript));
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates new page(CMS.MenuItem) and assignes selected template.
    /// </summary>
    protected void Save(bool createAnother)
    {
        // Check security
        CheckSecurity(true);

        string newPageName = txtPageName.Text.Trim();

        string errorMessage = null;

        if (!String.IsNullOrEmpty(newPageName))
        {
            // Limit length to 100 characters
            newPageName = TextHelper.LimitLength(newPageName, TreePathUtils.MaxNameLength, String.Empty);
        }
        else
        {
            errorMessage = GetString("newpage.nameempty");
        }

        if (parentNodeId == 0)
        {
            errorMessage = GetString("newpage.invalidparentnode");
        }

        // If error, show error message and return
        if (String.IsNullOrEmpty(errorMessage))
        {
            TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
            TreeNode node = TreeNode.New("CMS.MenuItem", tree);

            // Load default data
            FormHelper.LoadDefaultValues(node);

            node.DocumentName = newPageName;
            node.SetValue("MenuItemName", newPageName);
            lblError.Style.Remove("display");

            node.DocumentPageTemplateID = selTemplate.EnsureTemplate(node.DocumentName, ref errorMessage);

            // Switch to design mode (the template is empty at this moment)
            if (selTemplate.NewTemplateIsEmpty && !createAnother)
            {
                CMSContext.ViewMode = ViewModeEnum.Design;
            }

            // Insert node if no error
            if (String.IsNullOrEmpty(errorMessage))
            {
                node.DocumentCulture = CMSContext.PreferredCultureCode;

                // Insert the document
                DocumentHelper.InsertDocument(node, parentNodeId, tree);
                //node.Insert(parentNodeId);

                // Create default SKU if configured
                if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
                {
                    bool? skuCreated = node.CreateDefaultSKU();
                    if (skuCreated.HasValue && !skuCreated.Value)
                    {
                        lblError.Text = GetString("com.CreateDefaultSKU.Error");
                    }
                }

                if (node.NodeSKUID > 0)
                {
                    DocumentHelper.UpdateDocument(node, tree);
                }

                // Automatically publish
                // Check if allowed 'Automatically publish changes'
                WorkflowManager wm = new WorkflowManager(tree);
                WorkflowInfo wi = wm.GetNodeWorkflow(node);
                if ((wi != null) && wi.WorkflowAutoPublishChanges && !wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))
                {
                    wm.AutomaticallyPublish(node, wi, null);
                }

                // Process create another flag
                string script = null;
                if (createAnother)
                {
                    script = ScriptHelper.GetScript("parent.PassiveRefresh(" + node.NodeParentID + ", " + node.NodeParentID + "); parent.CreateAnother();");
                }
                else
                {
                    script = ScriptHelper.GetScript("parent.RefreshTree(" + node.NodeID + ", " + node.NodeID + ");");
                    script += ScriptHelper.GetScript("parent.SelectNode(" + node.NodeID + ");");
                }

                ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "Refresh", script);
            }
        }

        // Insert node if no error
        if (!String.IsNullOrEmpty(errorMessage))
        {
            lblError.Text = errorMessage;
            lblError.Visible = true;
            return;
        }
    }
Ejemplo n.º 3
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check allowed cultures
        if (!CMSContext.CurrentUser.IsCultureAllowed(CMSContext.PreferredCultureCode, CMSContext.CurrentSiteName))
        {
            lblError.Text   = GetString("Content.NotAuthorizedFile");
            pnlForm.Visible = false;
            return;
        }

        TreeNode     node = null;
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        if ((UseFileUploader && !FileUpload.HasFile) || (!UseFileUploader && !ucDirectUploader.HasData()))
        {
            lblError.Text = GetString("NewFile.ErrorEmpty");
        }
        else
        {
            // Get file extension
            string fileExtension = UseFileUploader ? FileUpload.FileName : ucDirectUploader.AttachmentName;
            fileExtension = Path.GetExtension(fileExtension).TrimStart('.');

            // Check file extension
            if (IsExtensionAllowed(fileExtension))
            {
                bool newDocumentCreated = false;

                try
                {
                    if (UseFileUploader)
                    {
                        // Process file using file upload
                        node = ProcessFileUploader(tree);
                    }
                    else
                    {
                        // Process file using direct uploader
                        node = ProcessDirectUploader(tree);

                        // Save temporary attachments
                        DocumentHelper.SaveTemporaryAttachments(node, Guid, CMSContext.CurrentSiteName, tree);
                    }

                    newDocumentCreated = true;

                    // Create default SKU if configured
                    if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
                    {
                        bool?skuCreated = node.CreateDefaultSKU();
                        if (skuCreated.HasValue && !skuCreated.Value)
                        {
                            lblError.Text = GetString("com.CreateDefaultSKU.Error");
                        }
                    }

                    // Set additional values
                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        // Update document extensions if no custom are used
                        if (!node.DocumentUseCustomExtensions)
                        {
                            node.DocumentExtensions = "." + fileExtension;
                        }
                        node.SetValue("DocumentType", "." + fileExtension);
                    }

                    // Update the document
                    DocumentHelper.UpdateDocument(node, tree);

                    WorkflowManager workflowManager = new WorkflowManager(tree);
                    // Get workflow info
                    WorkflowInfo workflowInfo = workflowManager.GetNodeWorkflow(node);

                    // Check if auto publish changes is allowed
                    if ((workflowInfo != null) && workflowInfo.WorkflowAutoPublishChanges && !workflowInfo.UseCheckInCheckOut(CMSContext.CurrentSiteName))
                    {
                        // Automatically publish document
                        workflowManager.AutomaticallyPublish(node, workflowInfo, null);
                    }

                    bool createAnother = ValidationHelper.GetBoolean(Request.Params["hidAnother"], false);

                    // Added from CMSDesk->Content
                    if (!isDialog)
                    {
                        if (createAnother)
                        {
                            ltlScript.Text += ScriptHelper.GetScript("PassiveRefresh(" + node.NodeParentID + ", " + node.NodeParentID + "); CreateAnother();");
                        }
                        else
                        {
                            ltlScript.Text += ScriptHelper.GetScript(
                                "   RefreshTree(" + node.NodeID + ", " + node.NodeID + "); SelectNode(" + node.NodeID + "); \n"
                                );
                        }
                    }
                    // Added from dialog window
                    else
                    {
                        if (createAnother)
                        {
                            txtFileDescription.Text = "";
                            ltlScript.Text         += ScriptHelper.GetScript("FileCreated(" + node.NodeID + ", " + node.NodeParentID + ", false);");
                        }
                        else
                        {
                            ltlScript.Text += ScriptHelper.GetScript("FileCreated(" + node.NodeID + ", " + node.NodeParentID + ", true);");
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Delete the document if something failed
                    if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
                    {
                        DocumentHelper.DeleteDocument(node, tree, false, true, true);
                    }
                    lblError.Text = GetString("NewFile.Failed") + ": " + ex.Message;
                }
            }
            else
            {
                lblError.Text = String.Format(GetString("NewFile.ExtensionNotAllowed"), fileExtension);
            }
        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Provides operations necessary to create and store new cms file.
        /// </summary>
        /// <param name="args">Upload arguments.</param>
        /// <param name="context">HttpContext instance.</param>
        private void HandleContentUpload(UploaderHelper args, HttpContext context)
        {
            bool   newDocumentCreated = false;
            string name = args.Name;

            try
            {
                if (args.FileArgs.NodeID == 0)
                {
                    throw new Exception(ResHelper.GetString("dialogs.document.parentmissing"));
                }
                // Check license limitations
                if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
                {
                    throw new Exception(ResHelper.GetString("cmsdesk.documentslicenselimits"));
                }

                // Check user permissions
                if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(args.FileArgs.NodeID, "CMS.File"))
                {
                    throw new Exception(string.Format(ResHelper.GetString("dialogs.newfile.notallowed"), "CMS.File"));
                }

                // Check if class exists
                DataClassInfo ci = DataClassInfoProvider.GetDataClass("CMS.File");
                if (ci == null)
                {
                    throw new Exception(string.Format(ResHelper.GetString("dialogs.newfile.classnotfound"), "CMS.File"));
                }


                #region "Check permissions"

                // Get the node
                using (TreeNode parentNode = TreeProvider.SelectSingleNode(args.FileArgs.NodeID, args.FileArgs.Culture, true))
                {
                    if (parentNode != null)
                    {
                        if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0), ci.ClassID))
                        {
                            throw new Exception(ResHelper.GetString("Content.ChildClassNotAllowed"));
                        }
                    }
                    // Check user permissions
                    if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parentNode, "CMS.File"))
                    {
                        throw new Exception(string.Format(ResHelper.GetString("dialogs.newfile.notallowed"), args.AttachmentArgs.NodeClassName));
                    }
                }

                #endregion

                args.IsExtensionAllowed();

                if (args.FileArgs.IncludeExtension)
                {
                    name += args.Extension;
                }

                // Make sure the file name with extension respects maximum file name
                name = TextHelper.LimitFileNameLength(name, TreePathUtils.MaxNameLength);

                node = TreeNode.New("CMS.File", TreeProvider);
                node.DocumentCulture = args.FileArgs.Culture;
                node.DocumentName    = name;
                if (args.FileArgs.NodeGroupID > 0)
                {
                    node.SetValue("NodeGroupID", args.FileArgs.NodeGroupID);
                }

                // Load default values
                FormHelper.LoadDefaultValues(node);
                node.SetValue("FileDescription", "");
                node.SetValue("FileName", name);
                node.SetValue("FileAttachment", Guid.Empty);
                node.SetValue("DocumentType", args.Extension);
                node.DocumentPageTemplateID = ci.ClassDefaultPageTemplateID;

                // Insert the document
                DocumentHelper.InsertDocument(node, args.FileArgs.NodeID, TreeProvider);
                newDocumentCreated = true;

                // Add the attachment data
                DocumentHelper.AddAttachment(node, "FileAttachment", args.FilePath, TreeProvider, args.ResizeToWidth, args.ResizeToHeight, args.ResizeToMaxSide);

                // Create default SKU if configured
                if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
                {
                    node.CreateDefaultSKU();
                }

                DocumentHelper.UpdateDocument(node, TreeProvider);

                // Get workflow info
                wi = WorkflowManager.GetNodeWorkflow(node);

                // Check if auto publish changes is allowed
                if ((wi != null) && wi.WorkflowAutoPublishChanges && !wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))
                {
                    // Automatically publish document
                    WorkflowManager.AutomaticallyPublish(node, wi, null);
                }
            }
            catch (Exception ex)
            {
                // Delete the document if something failed
                if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
                {
                    DocumentHelper.DeleteDocument(node, TreeProvider, false, true, true);
                }
                args.Message = ex.Message;
            }
            finally
            {
                // Create node info string
                string nodeInfo = ((node != null) && (node.NodeID > 0) && args.IncludeNewItemInfo) ? String.Format("'{0}', ", node.NodeID) : "";

                // Ensure message text
                args.Message = HTMLHelper.EnsureLineEnding(args.Message, " ");

                // Call function to refresh parent window
                if (!string.IsNullOrEmpty(args.AfterSaveJavascript))
                {
                    // Calling javascript function with parameters attachments url, name, width, height
                    args.AfterScript += string.Format(@"
                    if (window.{0} != null)
                    {{
                        window.{0}();
                    }}
                    else if((window.parent != null) && (window.parent.{0} != null))
                    {{
                        window.parent.{0}();
                    }}", args.AfterSaveJavascript);
                }

                // Create after script and return it to the silverlight application, this script will be evaluated by the SL application in the end
                args.AfterScript += string.Format(@"
                if (window.InitRefresh_{0} != null)
                {{
                    window.InitRefresh_{0}('{1}', false, false, {2});
                }}
                else {{ 
                    if ('{1}' != '') {{
                        alert('{1}');
                    }}
                }}",
                                                  args.ParentElementID,
                                                  ScriptHelper.GetString(args.Message.Trim(), false),
                                                  nodeInfo + (args.IsInsertMode ? "'insert'" : "'update'"));

                args.AddEventTargetPostbackReference();
                context.Response.Write(args.AfterScript);
                context.Response.Flush();
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Save new or existing document.
    /// </summary>
    /// <param name="forceRefreshTree">Indicates if content tree should be refreshed</param>
    private void SaveDocument(bool forceRefreshTree)
    {
        if (nodeId > 0)
        {
            // Validate the form first
            if (formElem.BasicForm.ValidateData())
            {
                bool createAnother = newdocument && ValidationHelper.GetBoolean(Request.Params["hidAnother"], false);

                if (!newdocument && !newculture)
                {
                    // Get the document
                    node = DocumentHelper.GetDocument(nodeId, CMSContext.PreferredCultureCode, TreeProvider);

                    // Check modify permissions
                    if (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
                    {
                        formElem.Enabled     = false;
                        lblWorkflowInfo.Text = String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), node.NodeAliasPath);
                        PassiveRefresh(nodeId, node.NodeParentID, node.DocumentName);
                        return;
                    }
                }

                try
                {
                    // Backup original document's values - before saving
                    string   originalDocumentName = node.DocumentName;
                    DateTime originalPublishFrom  = node.DocumentPublishFrom;
                    DateTime originalPublishTo    = node.DocumentPublishTo;
                    bool     wasArchived          = node.IsArchived;
                    bool     wasInPublishedStep   = node.IsInPublishStep;

                    // If not using check-in/check-out, check out automatically (not for new document and new culture version)
                    if (!newdocument && !newculture && AutoCheck)
                    {
                        if (node != null)
                        {
                            // Check out
                            VersionManager.CheckOut(node, node.IsPublished, true);
                        }
                    }

                    // Tree node is returned from CMSForm.Save method
                    if ((node != null) && !newdocument && !newculture)
                    {
                        formElem.Save(node);
                    }
                    else
                    {
                        // Document was not saved yet
                        node = null;

                        // Product should be created -> save document only when product data are valid
                        if ((chkCreateProduct.Checked) && (ucNewProduct != null))
                        {
                            if (ucNewProduct.ValidateData())
                            {
                                node = formElem.Save();
                            }
                        }
                        // Product should not be created -> save document
                        else
                        {
                            node = formElem.Save();
                        }
                    }

                    if (node != null)
                    {
                        // Create product only if the doc. type can be product
                        if ((newdocument) && (chkCreateProduct.Checked) && (ucNewProduct != null) && (ucNewProduct.ClassObj.ClassIsProduct))
                        {
                            // Create product
                            ucNewProduct.Node = node;

                            GeneralizedInfo skuObj = ucNewProduct.SaveData();
                            if (skuObj != null)
                            {
                                // Asssign new product to the document
                                node.NodeSKUID = skuObj.ObjectID;
                                DocumentHelper.UpdateDocument(node, TreeProvider, true);
                            }
                        }

                        // If not using check-in/check-out
                        if (AutoCheck)
                        {
                            // Check in the document (not for new document and new culture version)
                            if (!newdocument && !newculture)
                            {
                                VersionManager.CheckIn(node, null, null);
                            }
                            else
                            {
                                // Automatically publish
                                // Check if allowed 'Automatically publish changes'
                                WorkflowInfo wi = WorkflowManager.GetNodeWorkflow(node);
                                if (wi.WorkflowAutoPublishChanges)
                                {
                                    WorkflowManager.AutomaticallyPublish(node, wi, null);
                                }
                            }
                        }

                        int newNodeId = node.NodeID;
                        if (newdocument || newculture)
                        {
                            // Store error text
                            if (!string.IsNullOrEmpty(formElem.lblError.Text))
                            {
                                SessionHelper.SetValue("FormErrorText|" + newNodeId, formElem.lblError.Text);
                            }

                            if (createAnother)
                            {
                                PassiveRefresh(node.NodeParentID, node.NodeParentID, "");
                                AddScript("CreateAnother();");
                            }
                            else
                            {
                                // Refresh frame in split mode
                                if (newculture && displaySplitMode && (CultureHelper.GetOriginalPreferredCulture() != node.DocumentCulture))
                                {
                                    AddScript("SplitModeRefreshFrame();");
                                }
                                else
                                {
                                    // Document tree is refreshed and new document is displayed
                                    AddScript("RefreshTree(" + newNodeId + "," + newNodeId + "); SelectNode(" + newNodeId + ");");
                                }
                            }
                        }
                        else
                        {
                            // Refresh content tree and frames if 'forceRefreshTree' is True or document was changed
                            if (forceRefreshTree || ((originalDocumentName != node.DocumentName) || (wasInPublishedStep != node.IsInPublishStep) || (wasArchived != node.IsArchived) ||
                                                     (((originalPublishFrom != node.DocumentPublishFrom) || (originalPublishTo != node.DocumentPublishTo)) &&
                                                      (AutoCheck || (WorkflowManager.GetNodeWorkflow(node) == null)))))
                            {
                                // Refresh content tree and frames
                                PassiveRefresh(nodeId, node.NodeParentID, node.DocumentName);
                            }
                            else
                            {
                                // Refresh frames
                                FramesRefresh(false, nodeId);
                            }

                            // Reload the form
                            ReloadForm();
                            string oldInfo = formElem.lblInfo.Text;
                            formElem.LoadForm(false);
                            formElem.lblInfo.Text  = oldInfo;
                            formElem.lblInfo.Text += "<br />";
                        }

                        // If not menuitem type, switch to form mode to keep editing the form
                        if (!TreePathUtils.IsMenuItemType(node.NodeClassName))
                        {
                            CMSContext.ViewMode = ViewModeEnum.EditForm;
                        }
                    }
                }
                catch (Exception ex)
                {
                    AddAlert(GetString("ContentRequest.SaveFailed") + " : " + ex.Message);
                }
            }
        }
    }
Ejemplo n.º 6
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check allowed cultures
        if (!CMSContext.CurrentUser.IsCultureAllowed(CMSContext.PreferredCultureCode, CMSContext.CurrentSiteName))
        {
            lblError.Text = GetString("Content.NotAuthorizedFile");
            pnlForm.Visible = false;
            return;
        }

        TreeNode node = null;
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        if ((UseFileUploader && !FileUpload.HasFile) || (!UseFileUploader && !ucDirectUploader.HasData()))
        {
            lblError.Text = GetString("NewFile.ErrorEmpty");
        }
        else
        {
            // Get file extension
            string fileExtension = UseFileUploader ? FileUpload.FileName : ucDirectUploader.AttachmentName;
            fileExtension = Path.GetExtension(fileExtension).TrimStart('.');

            // Check file extension
            if (IsExtensionAllowed(fileExtension))
            {
                bool newDocumentCreated = false;

                try
                {
                    if (UseFileUploader)
                    {
                        // Process file using file upload
                        node = ProcessFileUploader(tree);
                    }
                    else
                    {
                        // Process file using direct uploader
                        node = ProcessDirectUploader(tree);

                        // Save temporary attachments
                        DocumentHelper.SaveTemporaryAttachments(node, Guid, CMSContext.CurrentSiteName, tree);
                    }

                    newDocumentCreated = true;

                    // Create default SKU if configured
                    if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
                    {
                        bool? skuCreated = node.CreateDefaultSKU();
                        if (skuCreated.HasValue && !skuCreated.Value)
                        {
                            lblError.Text = GetString("com.CreateDefaultSKU.Error");
                        }
                    }

                    // Set additional values
                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        // Update document extensions if no custom are used
                        if (!node.DocumentUseCustomExtensions)
                        {
                            node.DocumentExtensions = "." + fileExtension;
                        }
                        node.SetValue("DocumentType", "." + fileExtension);
                    }

                    // Update the document
                    DocumentHelper.UpdateDocument(node, tree);

                    WorkflowManager workflowManager = new WorkflowManager(tree);
                    // Get workflow info
                    WorkflowInfo workflowInfo = workflowManager.GetNodeWorkflow(node);

                    // Check if auto publish changes is allowed
                    if ((workflowInfo != null) && workflowInfo.WorkflowAutoPublishChanges && !workflowInfo.UseCheckInCheckOut(CMSContext.CurrentSiteName))
                    {
                        // Automatically publish document
                        workflowManager.AutomaticallyPublish(node, workflowInfo, null);
                    }

                    bool createAnother = ValidationHelper.GetBoolean(Request.Params["hidAnother"], false);

                    // Added from CMSDesk->Content
                    if (!isDialog)
                    {
                        if (createAnother)
                        {
                            ltlScript.Text += ScriptHelper.GetScript("PassiveRefresh(" + node.NodeParentID + ", " + node.NodeParentID + "); CreateAnother();");
                        }
                        else
                        {
                            ltlScript.Text += ScriptHelper.GetScript(
                                "   RefreshTree(" + node.NodeID + ", " + node.NodeID + "); SelectNode(" + node.NodeID + "); \n"
                            );
                        }
                    }
                    // Added from dialog window
                    else
                    {
                        if (createAnother)
                        {
                            txtFileDescription.Text = "";
                            ltlScript.Text += ScriptHelper.GetScript("FileCreated(" + node.NodeID + ", " + node.NodeParentID + ", false);");
                        }
                        else
                        {
                            ltlScript.Text += ScriptHelper.GetScript("FileCreated(" + node.NodeID + ", " + node.NodeParentID + ", true);");
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Delete the document if something failed
                    if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
                    {
                        DocumentHelper.DeleteDocument(node, tree, false, true, true);
                    }
                    lblError.Text = GetString("NewFile.Failed") + ": " + ex.Message;
                }
            }
            else
            {
                lblError.Text = String.Format(GetString("NewFile.ExtensionNotAllowed"), fileExtension);
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Provides operations necessary to create and store new content file.
    /// </summary>
    private void HandleContentUpload()
    {
        TreeNode     node = null;
        TreeProvider tree = null;

        string message            = string.Empty;
        bool   newDocumentCreated = false;

        try
        {
            if (this.NodeParentNodeID == 0)
            {
                throw new Exception(GetString("dialogs.document.parentmissing"));
            }

            // Check license limitations
            if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
            {
                throw new Exception(GetString("cmsdesk.documentslicenselimits"));
            }

            // Check if class exists
            DataClassInfo ci = DataClassInfoProvider.GetDataClass("CMS.File");
            if (ci == null)
            {
                throw new Exception("Class 'CMS.File' not found.");
            }

            #region "Check permissions"

            // Get the node
            tree = new TreeProvider(CMSContext.CurrentUser);
            TreeNode parentNode = tree.SelectSingleNode(this.NodeParentNodeID, TreeProvider.ALL_CULTURES);
            if (parentNode != null)
            {
                if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0), ci.ClassID))
                {
                    throw new Exception(GetString("Content.ChildClassNotAllowed"));
                }
            }

            // Check user permissions
            if (!RaiseOnCheckPermissions("Create", this))
            {
                if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(NodeParentNodeID, NodeClassName))
                {
                    throw new Exception("You aren not allowed to create document of type '" + NodeClassName + "' in required location.");
                }
            }

            #endregion

            // Check the allowed extensions
            CheckAllowedExtensions();

            // Create new document
            string fileName = Path.GetFileNameWithoutExtension(ucFileUpload.FileName);

            node = TreeNode.New("CMS.File", tree);
            node.DocumentCulture = CMSContext.PreferredCultureCode;
            node.DocumentName    = fileName;

            // Load default values
            FormHelper.LoadDefaultValues(node);

            node.SetValue("FileDescription", "");
            node.SetValue("FileName", fileName);
            node.SetValue("FileAttachment", Guid.Empty);

            // Set default template ID
            node.DocumentPageTemplateID = ci.ClassDefaultPageTemplateID;

            // Insert the document
            DocumentHelper.InsertDocument(node, parentNode, tree);

            newDocumentCreated = true;

            // Add the file
            DocumentHelper.AddAttachment(node, "FileAttachment", ucFileUpload.PostedFile, tree, this.ResizeToWidth, this.ResizeToHeight, this.ResizeToMaxSideSize);

            // Create default SKU if configured
            if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
            {
                node.CreateDefaultSKU();
            }

            // Update the document
            DocumentHelper.UpdateDocument(node, tree);

            WorkflowManager workflowManager = new WorkflowManager(tree);
            // Get workflow info
            WorkflowInfo workflowInfo = workflowManager.GetNodeWorkflow(node);

            // Check if auto publish changes is allowed
            if ((workflowInfo != null) && workflowInfo.WorkflowAutoPublishChanges && !workflowInfo.UseCheckInCheckOut(CMSContext.CurrentSiteName))
            {
                // Automatically publish document
                workflowManager.AutomaticallyPublish(node, workflowInfo, null);
            }
        }
        catch (Exception ex)
        {
            // Delete the document if something failed
            if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
            {
                DocumentHelper.DeleteDocument(node, tree, false, true, true);
            }

            message       = ex.Message;
            lblError.Text = message;
        }
        finally
        {
            if (string.IsNullOrEmpty(message))
            {
                // Create node info string
                string nodeInfo = "";
                if ((node != null) && (node.NodeID > 0) && (this.IncludeNewItemInfo))
                {
                    nodeInfo = node.NodeID.ToString();
                }

                // Ensure message text
                message = HTMLHelper.EnsureLineEnding(message, " ");

                // Register wopener script
                ScriptHelper.RegisterWOpenerScript(Page);

                // Call function to refresh parent window
                ScriptHelper.RegisterStartupScript(this.Page, typeof(Page), "refresh", ScriptHelper.GetScript("if ((wopener.parent != null) && (wopener.parent.InitRefresh_" + ParentElemID + " != null)){wopener.parent.InitRefresh_" + ParentElemID + "(" + ScriptHelper.GetString(message.Trim()) + ", false, false" + ((nodeInfo != "") ? ", '" + nodeInfo + "'" : "") + (InsertMode ? ", 'insert'" : ", 'update'") + ");}window.close();"));
            }
        }
    }
    /// <summary>
    /// Provides operations necessary to create and store new content file.
    /// </summary>
    private void HandleContentUpload()
    {
        TreeNode node = null;
        TreeProvider tree = null;

        string message = string.Empty;
        bool newDocumentCreated = false;

        try
        {
            if (this.NodeParentNodeID == 0)
            {
                throw new Exception(GetString("dialogs.document.parentmissing"));
            }

            // Check license limitations
            if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
            {
                throw new Exception(GetString("cmsdesk.documentslicenselimits"));
            }

            // Check if class exists
            DataClassInfo ci = DataClassInfoProvider.GetDataClass("CMS.File");
            if (ci == null)
            {
                throw new Exception("Class 'CMS.File' not found.");
            }

            #region "Check permissions"

            // Get the node
            tree = new TreeProvider(CMSContext.CurrentUser);
            TreeNode parentNode = tree.SelectSingleNode(this.NodeParentNodeID, TreeProvider.ALL_CULTURES);
            if (parentNode != null)
            {
                if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0), ci.ClassID))
                {
                    throw new Exception(GetString("Content.ChildClassNotAllowed"));
                }
            }

            // Check user permissions
            if (!RaiseOnCheckPermissions("Create", this))
            {
                if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(NodeParentNodeID, NodeClassName))
                {
                    throw new Exception("You aren not allowed to create document of type '" + NodeClassName + "' in required location.");
                }
            }

            #endregion

            // Check the allowed extensions
            CheckAllowedExtensions();

            // Create new document
            string fileName = Path.GetFileNameWithoutExtension(ucFileUpload.FileName);

            node = TreeNode.New("CMS.File", tree);
            node.DocumentCulture = CMSContext.PreferredCultureCode;
            node.DocumentName = fileName;

            // Load default values
            FormHelper.LoadDefaultValues(node);

            node.SetValue("FileDescription", "");
            node.SetValue("FileName", fileName);
            node.SetValue("FileAttachment", Guid.Empty);

            // Set default template ID
            node.DocumentPageTemplateID = ci.ClassDefaultPageTemplateID;

            // Insert the document
            DocumentHelper.InsertDocument(node, parentNode, tree);

            newDocumentCreated = true;

            // Add the file
            DocumentHelper.AddAttachment(node, "FileAttachment", ucFileUpload.PostedFile, tree, this.ResizeToWidth, this.ResizeToHeight, this.ResizeToMaxSideSize);

            // Create default SKU if configured
            if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
            {
                node.CreateDefaultSKU();
            }

            // Update the document
            DocumentHelper.UpdateDocument(node, tree);

            WorkflowManager workflowManager = new WorkflowManager(tree);
            // Get workflow info
            WorkflowInfo workflowInfo = workflowManager.GetNodeWorkflow(node);

            // Check if auto publish changes is allowed
            if ((workflowInfo != null) && workflowInfo.WorkflowAutoPublishChanges && !workflowInfo.UseCheckInCheckOut(CMSContext.CurrentSiteName))
            {
                // Automatically publish document
                workflowManager.AutomaticallyPublish(node, workflowInfo, null);
            }
        }
        catch (Exception ex)
        {
            // Delete the document if something failed
            if (newDocumentCreated && (node != null) && (node.DocumentID > 0))
            {
                DocumentHelper.DeleteDocument(node, tree, false, true, true);
            }

            message = ex.Message;
            lblError.Text = message;
        }
        finally
        {
            if (string.IsNullOrEmpty(message))
            {
                // Create node info string
                string nodeInfo = "";
                if ((node != null) && (node.NodeID > 0) && (this.IncludeNewItemInfo))
                {
                    nodeInfo = node.NodeID.ToString();
                }

                // Ensure message text
                message = HTMLHelper.EnsureLineEnding(message, " ");

                // Register wopener script
                ScriptHelper.RegisterWOpenerScript(Page);

                // Call function to refresh parent window
                ScriptHelper.RegisterStartupScript(this.Page, typeof(Page), "refresh", ScriptHelper.GetScript("if ((wopener.parent != null) && (wopener.parent.InitRefresh_" + ParentElemID + " != null)){wopener.parent.InitRefresh_" + ParentElemID + "(" + ScriptHelper.GetString(message.Trim()) + ", false, false" + ((nodeInfo != "") ? ", '" + nodeInfo + "'" : "") + (InsertMode ? ", 'insert'" : ", 'update'") + ");}window.close();"));
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Creates new page(CMS.MenuItem) and assignes selected template.
    /// </summary>
    protected void Save(bool createAnother)
    {
        // Check security
        CheckSecurity(true);

        string newPageName = txtPageName.Text.Trim();

        string errorMessage = null;

        if (!String.IsNullOrEmpty(newPageName))
        {
            // Limit length to 100 characters
            newPageName = TextHelper.LimitLength(newPageName, TreePathUtils.MaxNameLength, String.Empty);
        }
        else
        {
            errorMessage = GetString("newpage.nameempty");
        }

        if (parentNodeId == 0)
        {
            errorMessage = GetString("newpage.invalidparentnode");
        }

        // If error, show error message and return
        if (String.IsNullOrEmpty(errorMessage))
        {
            TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
            TreeNode     node = TreeNode.New("CMS.MenuItem", tree);

            // Load default data
            FormHelper.LoadDefaultValues(node);

            node.DocumentName = newPageName;
            lblError.Style.Remove("display");

            node.DocumentPageTemplateID = selTemplate.EnsureTemplate(node.DocumentName, ref errorMessage);

            // Switch to design mode (the template is empty at this moment)
            if (selTemplate.NewTemplateIsEmpty && !createAnother)
            {
                CMSContext.ViewMode = ViewModeEnum.Design;
            }

            // Insert node if no error
            if (String.IsNullOrEmpty(errorMessage))
            {
                node.DocumentCulture = CMSContext.PreferredCultureCode;

                // Insert the document
                DocumentHelper.InsertDocument(node, parentNodeId, tree);
                //node.Insert(parentNodeId);

                // Create default SKU if configured
                if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
                {
                    bool?skuCreated = node.CreateDefaultSKU();
                    if (skuCreated.HasValue && !skuCreated.Value)
                    {
                        lblError.Text = GetString("com.CreateDefaultSKU.Error");
                    }
                }

                if (node.NodeSKUID > 0)
                {
                    DocumentHelper.UpdateDocument(node, tree);
                }

                // Automatically publish
                // Check if allowed 'Automatically publish changes'
                WorkflowManager wm = new WorkflowManager(tree);
                WorkflowInfo    wi = wm.GetNodeWorkflow(node);
                if ((wi != null) && wi.WorkflowAutoPublishChanges && !wi.UseCheckInCheckOut(CMSContext.CurrentSiteName))
                {
                    wm.AutomaticallyPublish(node, wi, null);
                }

                // Process create another flag
                string script = null;
                if (createAnother)
                {
                    script = ScriptHelper.GetScript("parent.PassiveRefresh(" + node.NodeParentID + ", " + node.NodeParentID + "); parent.CreateAnother();");
                }
                else
                {
                    script  = ScriptHelper.GetScript("parent.RefreshTree(" + node.NodeID + ", " + node.NodeID + ");");
                    script += ScriptHelper.GetScript("parent.SelectNode(" + node.NodeID + ");");
                }

                ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "Refresh", script);
            }
        }

        // Insert node if no error
        if (!String.IsNullOrEmpty(errorMessage))
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }
    }