protected void gridClasses_OnBeforeDataReload() { if (node != null) { CurrentUserInfo curUser = CMSContext.CurrentUser; // Check permission to create new document if (curUser.IsAuthorizedToCreateNewDocument(node, null)) { // Prepare where condition string where = "ClassID IN (SELECT ChildClassID FROM CMS_AllowedChildClasses WHERE ParentClassID=" + ValidationHelper.GetInteger(node.GetValue("NodeClassID"), 0) + ") " + "AND ClassID IN (SELECT ClassID FROM CMS_ClassSite WHERE SiteID = " + CMSContext.CurrentSiteID + ")"; if (!String.IsNullOrEmpty(gridClasses.CompleteWhereCondition)) { where += " AND (" + gridClasses.CompleteWhereCondition + ")"; } // Get the allowed child classes DataSet ds = DataClassInfoProvider.GetClasses("ClassID, ClassName, ClassDisplayName", where, null, gridClasses.TopN); DataRow menuItemRow = null; DataTable resultTable = new DataTable(); // Check user permissions for "Create" permission bool hasNodeAllowCreate = (curUser.IsAuthorizedPerTreeNode(node, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed); bool isAuthorizedToCreateInContent = curUser.IsAuthorizedPerResource("CMS.Content", "Create"); // If dataSet is not empty if (!DataHelper.DataSourceIsEmpty(ds)) { ArrayList rows = new ArrayList(); DataTable table = ds.Tables[0]; table.DefaultView.Sort = "ClassDisplayName"; resultTable = table.DefaultView.ToTable(); for (int i = 0; i < resultTable.Rows.Count; ++i) { DataRow dr = resultTable.Rows[i]; string doc = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), ""); // Document type is not allowed, remove it from the data set if (!isAuthorizedToCreateInContent && !curUser.IsAuthorizedPerClassName(doc, "Create") && (!curUser.IsAuthorizedPerClassName(doc, "CreateSpecific") || !hasNodeAllowCreate)) { rows.Add(dr); } else { if (doc.ToLower() == "cms.menuitem") { menuItemRow = dr; } } } // Remove the document types foreach (DataRow dr in rows) { resultTable.Rows.Remove(dr); } if (!DataHelper.DataSourceIsEmpty(resultTable)) { // Put Menu item to first position if (menuItemRow != null) { DataRow dr = resultTable.NewRow(); dr.ItemArray = menuItemRow.ItemArray; resultTable.Rows.Remove(menuItemRow); resultTable.Rows.InsertAt(dr, 0); } } else { // Show error message lblError.Visible = true; lblError.Text = GetString("Content.NoPermissions"); lblInfo.Visible = false; pnlFooter.Visible = false; pnlABVariant.Visible = false; } } else { // Show error message lblError.Visible = true; lblError.Text = GetString("Content.NoAllowedChildDocuments"); lblInfo.Visible = false; pnlFooter.Visible = false; pnlABVariant.Visible = false; } dsClasses = new DataSet(); dsClasses.Tables.Add(resultTable); gridClasses.DataSource = dsClasses; } else { // Show error message lblError.Visible = true; lblError.Text = GetString("Content.NoPermissions"); lblInfo.Visible = false; pnlFooter.Visible = false; pnlABVariant.Visible = false; } lblInfo.Text = GetString("Content.NewInfo"); } gridClasses.DataSource = dsClasses; }
/// <summary> /// Import files. /// </summary> private void Import(object parameter) { try { object[] parameters = (object[])parameter; string[] items = (string[])parameters[0]; CurrentUserInfo currentUser = (CurrentUserInfo)parameters[3]; if ((items.Length > 0) && (currentUser != null)) { resultListValues.Clear(); errorFiles.Clear(); hdnValue.Value = null; hdnSelected.Value = null; string siteName = CMSContext.CurrentSiteName; string targetAliasPath = ValidationHelper.GetString(parameters[1], null); bool imported = false; // Flag - true if one file was imported at least bool importError = false; // Flag - true when import failed TreeProvider tree = new TreeProvider(currentUser); TreeNode tn = tree.SelectSingleNode(siteName, targetAliasPath, TreeProvider.ALL_CULTURES, true, null, false); if (tn != null) { // Check if CMS.File document type exist and check if document contains required columns (FileName, FileAttachment) DataClassInfo fileClassInfo = DataClassInfoProvider.GetDataClass("CMS.File"); if (fileClassInfo == null) { AddError(GetString("newfile.classcmsfileismissing")); return; } else { FormInfo fi = new FormInfo(fileClassInfo.ClassFormDefinition); FormFieldInfo fileFfi = null; FormFieldInfo attachFfi = null; if (fi != null) { fileFfi = fi.GetFormField("FileName"); attachFfi = fi.GetFormField("FileAttachment"); } if ((fi == null) || (fileFfi == null) || (attachFfi == null)) { AddError(GetString("newfile.someofrequiredfieldsmissing")); return; } } DataClassInfo dci = DataClassInfoProvider.GetDataClass(tn.NodeClassName); if (dci != null) { // Check if "file" and "folder" are allowed as a child document under selected document type bool fileAllowed = false; bool folderAllowed = false; DataClassInfo folderClassInfo = DataClassInfoProvider.GetDataClass("CMS.Folder"); if ((fileClassInfo != null) || (folderClassInfo != null)) { string[] paths; foreach (string fullFileName in items) { paths = fullFileName.Substring(rootPath.Length).Split('\\'); // Check file if (paths.Length == 1) { if (!fileAllowed && (fileClassInfo != null) && !DataClassInfoProvider.IsChildClassAllowed(dci.ClassID, fileClassInfo.ClassID)) { AddError(GetString("Tools.FileImport.NotAllowedChildClass")); return; } else { fileAllowed = true; } } // Check folder if (paths.Length > 1) { if (!folderAllowed && (folderClassInfo != null) && !DataClassInfoProvider.IsChildClassAllowed(dci.ClassID, folderClassInfo.ClassID)) { AddError(GetString("Tools.FileImport.FolderNotAllowedChildClass")); return; } else { folderAllowed = true; } } if (fileAllowed && folderAllowed) { break; } } } // Check if user is allowed to create new file document if (fileAllowed && !currentUser.IsAuthorizedToCreateNewDocument(tn, "CMS.File")) { AddError(GetString("accessdenied.notallowedtocreatedocument")); return; } // Check if user is allowed to create new folder document if (folderAllowed && !currentUser.IsAuthorizedToCreateNewDocument(tn, "CMS.Folder")) { AddError(GetString("accessdenied.notallowedtocreatedocument")); return; } } string cultureCode = ValidationHelper.GetString(parameters[2], ""); string[] fileList = new string[1]; string[] relativePathList = new string[1]; // Begin log AddLog(GetString("tools.fileimport.importingprogress")); string msgImported = GetString("Tools.FileImport.Imported"); string msgFailed = GetString("Tools.FileImport.Failed"); // Insert files selected in datagrid to list of files to import foreach (string fullFileName in items) { // Import selected files only fileList[0] = fullFileName; relativePathList[0] = fullFileName.Substring(rootPath.Length); // Remove extension if needed if (!chkIncludeExtension.Checked) { relativePathList[0] = Regex.Replace(relativePathList[0], "(.*)\\..*", "$1"); } try { FileImport.ImportFiles(siteName, targetAliasPath, cultureCode, fileList, relativePathList, currentUser.UserID, chkDeleteImported.Checked); // Import of a file succeeded, fill the output lists resultListValues.Add(new string[] { fullFileName, msgImported, true.ToString() }); imported = true; // One file was imported AddLog(HTMLHelper.HTMLEncode(fullFileName)); } catch (Exception ex) { // File import failed errorFiles.Add(fullFileName); importError = true; // Fill the output lists resultListValues.Add(new string[] { fullFileName, msgFailed + " (" + HTMLHelper.HTMLEncode(ex.Message) + ")", false.ToString() }); AddError(msgFailed + " (" + HTMLHelper.HTMLEncode(ex.Message) + ")"); // Abort importing the rest of files for serious exceptions if (!(ex is UnauthorizedAccessException)) { return; } } } } // Specified alias path not found else { AddError(GetString("Tools.FileImport.AliasPathNotFound")); return; } if (filesList.Count > 0) { if (!importError) { if (imported) { AddError(GetString("Tools.FileImport.FilesWereImported")); return; } } else { AddError(GetString("Tools.FileImport.FilesNotImported")); return; } } } // No items selected to import else { AddError(GetString("Tools.FileImport.FilesNotImported")); return; } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled } else { // Log error LogExceptionToEventLog(ex); } } catch (Exception ex) { // Log error LogExceptionToEventLog(ex); } }
private void btnOk_Click(object sender, EventArgs e) { // Validate all required data for new blog string errorMessage = ValidateData(); if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert)) { errorMessage = GetString("cmsdesk.bloglicenselimits"); } // Get current user CurrentUserInfo user = CMSContext.CurrentUser; if (errorMessage == "") { // Get parent node for new blog TreeProvider tree = new TreeProvider(user); TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, BlogParentPath.TrimEnd('%'), TreeProvider.ALL_CULTURES); if (parent != null) { if (!CheckPermissions || user.IsAuthorizedToCreateNewDocument(parent, "cms.blog")) { bool useParentNodeGroupID = tree.UseParentNodeGroupID; TreeNode blogNode = null; try { // Reflect group document tree.UseParentNodeGroupID = true; // Initialize and create new blog node blogNode = TreeNode.New("cms.blog", tree); blogNode.SetValue("BlogName", txtName.Text.Trim()); blogNode.SetValue("BlogDescription", txtDescription.Text.Trim()); blogNode.SetValue("BlogAllowAnonymousComments", BlogAllowAnonymousComments); blogNode.SetValue("BlogModerateComments", BlogModerateComments); blogNode.SetValue("BlogOpenCommentsFor", BlogOpenCommentsFor); blogNode.SetValue("BlogSendCommentsToEmail", BlogSendCommentsToEmail); blogNode.SetValue("BlogSideColumnText", BlogSideColumnText); blogNode.SetValue("BlogUseCAPTCHAForComments", BlogUseCAPTCHAForComments); blogNode.SetValue("BlogModerators", BlogModerators); if (BlogTeaser == Guid.Empty) { blogNode.SetValue("BlogTeaser", null); } else { blogNode.SetValue("BlogTeaser", BlogTeaser); } blogNode.SetValue("NodeOwner", user.UserID); if (NewBlogTemplate != null) { // Get the BlogMonth class to set the default page template if (NewBlogTemplate == "") { DataClassInfo blogClass = DataClassInfoProvider.GetDataClass("CMS.Blog"); if (blogClass != null) { blogNode.SetDefaultPageTemplateID(blogClass.ClassDefaultPageTemplateID); } } else { // Set the selected template PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(NewBlogTemplate); if (pti != null) { blogNode.NodeTemplateForAllCultures = true; blogNode.NodeTemplateID = pti.PageTemplateId; } } } // Trackbacks are denied by default blogNode.SetValue("BlogEnableTrackbacks", false); blogNode.DocumentName = txtName.Text.Trim(); blogNode.DocumentCulture = CMSContext.CurrentUser.PreferredCultureCode; DocumentHelper.InsertDocument(blogNode, parent, tree); } finally { tree.UseParentNodeGroupID = useParentNodeGroupID; } if (RedirectToNewBlog) { // Redirect to the new blog URLHelper.Redirect(CMSContext.GetUrl(blogNode.NodeAliasPath)); } else { // Display info message lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } } else { // Not authorized to create blog errorMessage = GetString("blogs.notallowedtocreate"); } } else { // Parent node was not found errorMessage = GetString("Blogs.NewBlog.PathNotFound"); } } if (errorMessage != "") { // Display error message lblError.Visible = true; lblError.Text = errorMessage; } }
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" : "") ); }
protected override void OnInit(EventArgs e) { CurrentUserInfo currentUser = CMSContext.CurrentUser; // Check UIProfile if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", "EditForm")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "EditForm"); } base.OnInit(e); DocumentManager.OnAfterAction += DocumentManager_OnAfterAction; DocumentManager.OnLoadData += DocumentManager_OnLoadData; // 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); 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.GetDataClass(ClassID); if (ci == null) { throw new Exception("[Content/Edit.aspx]: Class ID '" + ClassID + "' not found."); } if (ci.ClassName.ToLowerCSafe() == "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 int templateId = TemplateID; if (!ProductSection && ci.ClassShowTemplateSelection && (templateId < 0) && (ci.ClassName.ToLowerCSafe() != "cms.menuitem")) { URLHelper.Redirect("~/CMSModules/Content/CMSDesk/TemplateSelection.aspx" + URLHelper.Url.Query); } // 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) || !DataClassInfoProvider.IsChildClassAllowed(parentNode.GetIntegerValue("NodeClassID", 0), ClassID)) { AddNotAllowedScript("child"); } if (!currentUser.IsAuthorizedToCreateNewDocument(DocumentManager.ParentNode, DocumentManager.NewNodeClassName)) { AddNotAllowedScript("new"); } } if (RequiresDialog) { SetTitle("CMSModules/CMS_Content/Menu/New.png", GetString("Content.NewTitle"), null, null); } } 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; authorized = currentUser.IsAuthorizedToCreateNewDocument(treeNode.NodeParentID, treeNode.NodeClassName); if (authorized) { string className = DocumentManager.NewNodeClassName; if (className.ToLowerCSafe() == "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"), "")); } // Default data document ID formElem.CopyDefaultDataFromDocumentId = ValidationHelper.GetInteger(Request.QueryString["sourcedocumentid"], 0); ci = DataClassInfoProvider.GetDataClass(className); formElem.FormName = className + ".default"; } } } if (!authorized) { AddNotAllowedScript("newculture"); } if (RequiresDialog) { SetTitle("CMSModules/CMS_Content/Menu/New.png", GetString("content.newcultureversiontitle"), null, null); } } break; default: { TreeNode node = Node; if (node == null) { RedirectToNewCultureVersionPage(); } else { // Update view mode if (!RequiresDialog) { CMSContext.ViewMode = ViewModeEnum.EditForm; } EnableSplitMode = true; DocumentManager.Mode = FormModeEnum.Update; ci = DataClassInfoProvider.GetDataClass(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 = CMSContext.CurrentSite.DisplayName; } SetTitle("CMSModules/CMS_Content/Menu/New.png", GetString("Content.EditTitle") + " \"" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nodeName)) + "\"", null, null); } } } 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"; } if (RequiresDialog) { plcCKFooter.Visible = false; } }
protected void menuNew_OnReloadData(object sender, EventArgs e) { int nodeId = ValidationHelper.GetInteger(menuNew.Parameter, 0); // Get the node TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); TreeNode node = tree.SelectSingleNode(nodeId); pnlNewVariant.Visible = false; if (node != null) { CurrentUserInfo curUser = CMSContext.CurrentUser; if (!curUser.IsAuthorizedPerUIElement("CMS.Content", "New")) { DisplayErrorMessage(String.Format(GetString("CMSSiteManager.AccessDeniedOnUIElementName"), "New")); return; } if (curUser.IsAuthorizedToCreateNewDocument(node, null)) { // Check user permissions for "Create" permission bool hasNodeAllowCreate = (curUser.IsAuthorizedPerTreeNode(node, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed); bool isAuthorizedToCreateInContent = curUser.IsAuthorizedPerResource("CMS.Content", "Create"); // AB test variant settings if (SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSABTestingEnabled") && curUser.IsAuthorizedPerResource("cms.ABTest", "Read") && ModuleEntry.IsModuleLoaded("cms.onlinemarketing") && (node.NodeAliasPath != "/")) { if (isAuthorizedToCreateInContent || curUser.IsAuthorizedPerClassName(node.NodeClassName, "Create") || (curUser.IsAuthorizedPerClassName(node.NodeClassName, "CreateSpecific") && hasNodeAllowCreate)) { pnlNewVariant.Visible = true; imgNewVariant.ImageUrl = GetImageUrl("objects/cms_variant/object_small.png"); lblNewVariant.Text = GetString("abtesting.abtestvariant"); lblNewVariant.Attributes.Add("onclick", "NewVariant(GetContextMenuParameter('nodeMenu'), true);"); if (!imgNewLinked.Visible) { pnlNewVariantSeparator.Visible = true; } } } string where = "ClassID IN (SELECT ChildClassID FROM CMS_AllowedChildClasses WHERE ParentClassID=" + ValidationHelper.GetInteger(node.GetValue("NodeClassID"), 0) + ") " + "AND ClassID IN (SELECT ClassID FROM CMS_ClassSite WHERE SiteID = " + CMSContext.CurrentSiteID + ")"; // Get the allowed child classes DataSet ds = DataClassInfoProvider.GetClasses("ClassID, ClassName, ClassDisplayName, (CASE ClassName WHEN 'CMS.MenuItem' THEN 0 ELSE 1 END) AS MenuItemOrder", where, null, 50); DataTable resultTable = null; ArrayList rows = new ArrayList(); if (!DataHelper.DataSourceIsEmpty(ds)) { DataTable table = ds.Tables[0]; table.DefaultView.Sort = "MenuItemOrder, ClassDisplayName"; resultTable = table.DefaultView.ToTable(); for (int i = 0; i < resultTable.Rows.Count; ++i) { DataRow dr = resultTable.Rows[i]; string doc = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), ""); // Document type is not allowed, remove it from the data set if (!isAuthorizedToCreateInContent && !curUser.IsAuthorizedPerClassName(doc, "Create") && (!curUser.IsAuthorizedPerClassName(doc, "CreateSpecific") || !hasNodeAllowCreate)) { rows.Add(dr); } } // Remove the document types foreach (DataRow dr in rows) { resultTable.Rows.Remove(dr); } bool classesRemoved = false; // Leave only first 15 rows while (resultTable.Rows.Count > 15) { resultTable.Rows.RemoveAt(resultTable.Rows.Count - 1); classesRemoved = true; } if (!DataHelper.DataSourceIsEmpty(resultTable)) { // Add show more item if (classesRemoved) { DataRow dr = resultTable.NewRow(); dr["ClassID"] = 0; dr["ClassName"] = "more"; dr["ClassDisplayName"] = GetString("class.showmore"); resultTable.Rows.InsertAt(dr, resultTable.Rows.Count); } // Create temp column int rowCount = resultTable.Rows.Count; DataColumn tmpColumn = new DataColumn("Count"); tmpColumn.DefaultValue = rowCount; resultTable.Columns.Add(tmpColumn); } else { DisplayErrorMessage("Content.NoPermissions"); } } else { pnlNewVariantSeparator.Visible = true; DisplayErrorMessage("NewMenu.NoChildAllowed"); } repNew.DataSource = resultTable; repNew.DataBind(); if (DataHelper.DataSourceIsEmpty(ds)) { DisplayErrorMessage("NewMenu.NoChildAllowed"); } } else { DisplayErrorMessage("Content.NoPermissions"); } } }
protected void gridClasses_OnBeforeDataReload() { if (ParentNode != null) { CurrentUserInfo currentUser = CMSContext.CurrentUser; // Check permission to create new document if (currentUser.IsAuthorizedToCreateNewDocument(ParentNode, null)) { // Prepare where condition string where = "ClassID IN (SELECT ChildClassID FROM CMS_AllowedChildClasses WHERE ParentClassID=" + ValidationHelper.GetInteger(ParentNode.GetValue("NodeClassID"), 0) + ") " + "AND ClassID IN (SELECT ClassID FROM CMS_ClassSite WHERE SiteID = " + CMSContext.CurrentSiteID + ")"; if (!String.IsNullOrEmpty(gridClasses.CompleteWhereCondition)) { where += " AND (" + gridClasses.CompleteWhereCondition + ")"; } if ((ConvertDocumentID > 0) || !PortalHelper.IsWireframingEnabled(CMSContext.CurrentSiteName)) { where += " AND ClassName <> 'CMS.Wireframe'"; } // Add extra where condition where = SqlHelperClass.AddWhereCondition(where, Where); // Get the allowed child classes DataSet ds = DataClassInfoProvider.GetClasses("ClassID, ClassName, ClassDisplayName", where, null, gridClasses.TopN); List <DataRow> priorityRows = new List <DataRow>(); DataTable resultTable = new DataTable(); // Check user permissions for "Create" permission bool hasNodeAllowCreate = (currentUser.IsAuthorizedPerTreeNode(ParentNode, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed); bool isAuthorizedToCreateInContent = currentUser.IsAuthorizedPerResource("CMS.Content", "Create"); // No data loaded yet ClassesCount = 0; // If dataSet is not empty if (!DataHelper.DataSourceIsEmpty(ds)) { List <DataRow> rows = new List <DataRow>(); DataTable table = ds.Tables[0]; table.DefaultView.Sort = "ClassDisplayName"; resultTable = table.DefaultView.ToTable(); for (int i = 0; i < resultTable.Rows.Count; ++i) { DataRow dr = resultTable.Rows[i]; string doc = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), string.Empty); // Document type is not allowed, remove it from the data set if (!isAuthorizedToCreateInContent && !currentUser.IsAuthorizedPerClassName(doc, "Create") && (!currentUser.IsAuthorizedPerClassName(doc, "CreateSpecific") || !hasNodeAllowCreate)) { rows.Add(dr); } else { // Priority document types switch (doc.ToLowerCSafe()) { case "cms.menuitem": // Page (Menu item) { priorityRows.Add(dr); lastPriorityClassName = doc; } break; case "cms.wireframe": // Wireframe document if (currentUser.IsAuthorizedPerResource("CMS.Design", "Wireframing")) { priorityRows.Add(dr); lastPriorityClassName = doc; } else { rows.Add(dr); } break; } } } // Remove the document types foreach (DataRow dr in rows) { resultTable.Rows.Remove(dr); } if (!DataHelper.DataSourceIsEmpty(resultTable)) { int index = 0; // Put priority rows to first position foreach (DataRow priorityRow in priorityRows) { DataRow dr = resultTable.NewRow(); dr.ItemArray = priorityRow.ItemArray; resultTable.Rows.Remove(priorityRow); resultTable.Rows.InsertAt(dr, index); index++; } ClassesCount = resultTable.Rows.Count; } else { // Show error message SetErrorMessage(GetString("Content.NoPermissions")); gridClasses.Visible = false; ClassesCount = -1; } } else { if (!gridClasses.FilterIsSet && NoDataAsError) { // Show error message SetErrorMessage(NoDataMessage); } else { gridClasses.ZeroRowsText = NoDataMessage; } } dsClasses = new DataSet(); dsClasses.Tables.Add(resultTable); gridClasses.DataSource = dsClasses; } else { // Show error message SetErrorMessage(GetString("Content.NoPermissions")); } } gridClasses.DataSource = dsClasses; }