/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Do not process control by default StopProcessing = true; // Keep frequent objects cui = MembershipContext.AuthenticatedUser; PageInfo pi = DocumentContext.CurrentPageInfo; if (pi == null) { IsPageNotFound = true; pi = DocumentContext.CurrentCultureInvariantPageInfo ?? new PageInfo(); checkChanges = string.Empty; } ucUIToolbar.StopProcessing = true; // Get main UI element var element = UIElementInfoProvider.GetUIElementInfo(MODULE_NAME, ELEMENT_NAME); if (element == null) { return; } // Check whether user is authorized to edit page if ((pi != null) && AuthenticationHelper.IsAuthenticated() && cui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName) && ((IsPageNotFound && pi.NodeID == 0) || cui.IsAuthorizedPerTreeNode(pi.NodeID, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed) && CMSPage.CheckUIElementAccessHierarchical(element, redirectToAccessDenied: false)) { // Enable processing StopProcessing = false; // Check whether the preferred culture is RTL isRTL = CultureHelper.IsUICultureRTL(); // Add link to CSS file CSSHelper.RegisterCSSLink(Page, "Design", "OnSiteEdit.css"); CSSHelper.RegisterBootstrap(Page); // Filter UI element buttons ucUIToolbar.OnButtonFiltered += ucUIToolbar_OnButtonFiltered; ucUIToolbar.OnButtonCreated += ucUIToolbar_OnButtonCreated; ucUIToolbar.OnGroupsCreated += ucUIToolbar_OnGroupsCreated; ucUIToolbar.IsRTL = isRTL; // Register edit script file RegisterEditScripts(pi); if (ViewMode.IsEditLive()) { popupHandler.Visible = true; IsLiveSite = false; MessagesPlaceHolder.IsLiveSite = false; MessagesPlaceHolder.Opacity = 100; // Keep content of editable web parts when saving the document changes if (!IsPageNotFound) { PortalManager.PreserveContent = true; } // Display warning in the Safe mode if (PortalHelper.SafeMode) { string safeModeText = GetString("onsiteedit.safemode") + "<br/><a href=\"" + RequestContext.RawURL.Replace("safemode=1", "safemode=0") + "\">" + GetString("general.close") + "</a> " + GetString("contentedit.safemode2"); string safeModeDescription = GetString("onsiteedit.safemode") + "<br/>" + GetString("general.seeeventlog"); // Display the warning message ShowWarning(safeModeText, safeModeDescription, ""); } ucUIToolbar.StopProcessing = false; // Ensure document redirection var redirectUrl = TreePathUtils.GetRedirectionUrl(pi); if (!String.IsNullOrEmpty(redirectUrl)) { redirectUrl = URLHelper.ResolveUrl(redirectUrl); ShowInformation(GetString("onsiteedit.redirectinfo") + " <a href=\"" + redirectUrl + "\">" + redirectUrl + "</a>"); } pnlUpdateProgress.Visible = true; } // Mode menu on live site else if (ViewMode.IsLiveSite()) { // Hide the edit panel, show only slider button pnlToolbarSpace.Visible = false; pnlToolbar.Visible = false; pnlSlider.Visible = true; icon.CssClass = "cms-icon-80 icon-edit"; icon.ToolTip = GetString("onsitedit.editmode"); pnlButton.Attributes.Add("onclick", "OnSiteEdit_ChangeEditMode();"); // Hide the OnSite edit button when displayed in CMSDesk pnlSlider.Style.Add("display", "none"); } } // Hide control actions for unauthorized users else { plcEdit.Visible = false; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Do not process control by default StopProcessing = true; // Keep frequent objects cui = CMSContext.CurrentUser; PageInfo pi = CMSContext.CurrentPageInfo; if (pi == null) { IsPageNotFound = true; pi = OnSiteEditHelper.PageInfoForPageNotFound; } ucUIToolbar.StopProcessing = true; largeCMSDeskButton = !cui.UserSiteManagerAdmin; // Check whether user is authorized to edit page if ((pi != null) && cui.IsAuthenticated() && cui.IsEditor && ((IsPageNotFound && pi.NodeID == 0) || cui.IsAuthorizedPerTreeNode(pi.NodeID, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed)) { // Enable processing StopProcessing = false; // Check whether the preferred culture is RTL isRTL = CultureHelper.IsUICultureRTL(); // Add link to CSS file CSSHelper.RegisterCSSLink(Page, "Design", "OnSiteEdit.css"); // Filter UI element buttons ucUIToolbar.OnButtonFiltered += ucUIToolbar_OnButtonFiltered; ucUIToolbar.OnButtonCreated += ucUIToolbar_OnButtonCreated; ucUIToolbar.OnButtonCreating += ucUIToolbar_OnButtonCreating; ucUIToolbar.OnGroupsCreated += ucUIToolbar_OnGroupsCreated; ucUIToolbar.IsRTL = isRTL; // Register edit script file RegisterEditScripts(pi); if (ViewMode == ViewModeEnum.EditLive) { popupHandler.Visible = true; IsLiveSite = false; MessagesPlaceHolder.IsLiveSite = false; MessagesPlaceHolder.Opacity = 100; // Display warning in the Safe mode if (PortalHelper.SafeMode) { string safeModeText = GetString("onsiteedit.safemode") + "<br/><a href=\"" + URLHelper.RawUrl.Replace("safemode=1", "safemode=0") + "\">" + GetString("general.close") + "</a> " + GetString("contentedit.safemode2"); string safeModeDescription = GetString("onsiteedit.safemode") + "<br/>" + GetString("general.seeeventlog"); // Display the warning message ShowWarning(safeModeText, safeModeDescription, ""); } ucUIToolbar.StopProcessing = false; // Ensure document redirection if (!String.IsNullOrEmpty(pi.DocumentMenuRedirectUrl)) { string redirectUrl = CMSContext.ResolveMacros(pi.DocumentMenuRedirectUrl); redirectUrl = URLHelper.ResolveUrl(redirectUrl); ShowInformation(GetString("onsiteedit.redirectinfo") + " <a href=\"" + redirectUrl + "\">" + redirectUrl + "</a>"); } } // Mode menu on live site else if (ViewMode == ViewModeEnum.LiveSite) { // Hide the edit panel, show only slider button pnlToolbarSpace.Visible = false; pnlToolbar.Visible = false; pnlSlider.Visible = true; imgSliderButton.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/edit.png"); imgSliderButton.ToolTip = GetString("onsiteedit.editmode"); imgSliderButton.AlternateText = GetString("onsitedit.editmode"); pnlButton.Attributes.Add("onclick", "OnSiteEdit_ChangeEditMode();"); imgMaximize.Style.Add("display", "none"); imgMaximize.AlternateText = GetString("general.maximize"); imgMaximize.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/ArrowDown.png"); imgMinimize.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/ArrowUp.png"); imgMinimize.AlternateText = GetString("general.minimize"); pnlMinimize.Attributes.Add("onclick", "OESlideSideToolbar();"); // Hide the OnSite edit button when displayed in CMSDesk pnlSlider.Style.Add("display", "none"); } } // Hide control actions for unauthorized users else { plcEdit.Visible = false; } }
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> /// Reloads control. /// </summary> /// <param name="forceReload">Forces nested CMSForm to reload if true</param> public void ReloadData(bool forceReload) { if (!mFormLoaded || forceReload) { // Check License LicenseHelper.CheckFeatureAndRedirect(URLHelper.GetCurrentDomain(), FeatureEnum.UserContributions); if (StopProcessing) { formElem.StopProcessing = true; } else { // Set document manager mode if (NewDocument) { DocumentManager.Mode = FormModeEnum.Insert; DocumentManager.ParentNodeID = NodeID; DocumentManager.NewNodeClassID = ClassID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; } else if (NewCulture) { DocumentManager.Mode = FormModeEnum.InsertNewCultureVersion; DocumentManager.NodeID = NodeID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; DocumentManager.SourceDocumentID = CopyDefaultDataFromDocumentID; } else { DocumentManager.Mode = FormModeEnum.Update; DocumentManager.NodeID = NodeID; DocumentManager.SiteName = SiteName; DocumentManager.CultureCode = CultureCode; } ScriptHelper.RegisterDialogScript(Page); formElem.StopProcessing = false; titleElem.TitleImage = String.Empty; titleElem.TitleText = String.Empty; pnlSelectClass.Visible = false; pnlEdit.Visible = false; pnlInfo.Visible = false; pnlNewCulture.Visible = false; pnlDelete.Visible = false; // If node found, init the form if (NewDocument || (Node != null)) { // Delete action if (Delete) { // Delete document pnlDelete.Visible = true; titleElem.TitleText = GetString("Content.DeleteTitle"); titleElem.TitleImage = GetImageUrl("CMSModules/CMS_Content/Menu/delete.png"); chkAllCultures.Text = GetString("ContentDelete.AllCultures"); chkDestroy.Text = GetString("ContentDelete.Destroy"); lblQuestion.Text = GetString("ContentDelete.Question"); btnYes.Text = GetString("general.yes"); // Prevent button double-click btnYes.Attributes.Add("onclick", string.Format("document.getElementById('{0}').disabled=true;this.disabled=true;{1};", btnNo.ClientID, ControlsHelper.GetPostBackEventReference(btnYes, string.Empty, true, false))); btnNo.Text = GetString("general.no"); DataSet culturesDS = CultureInfoProvider.GetSiteCultures(SiteName); if ((DataHelper.DataSourceIsEmpty(culturesDS)) || (culturesDS.Tables[0].Rows.Count <= 1)) { chkAllCultures.Visible = false; chkAllCultures.Checked = true; } if (Node.IsLink) { titleElem.TitleText = GetString("Content.DeleteTitleLink") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\""; lblQuestion.Text = GetString("ContentDelete.QuestionLink"); chkAllCultures.Checked = true; plcCheck.Visible = false; } else { titleElem.TitleText = GetString("Content.DeleteTitle") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\""; } } // New document or edit action else { if (NewDocument) { titleElem.TitleImage = GetImageUrl("CMSModules/CMS_Content/Menu/new.png"); titleElem.TitleText = GetString("Content.NewTitle"); } // Document type selection if (NewDocument && (ClassID <= 0)) { // Use parent node TreeNode parentNode = DocumentManager.ParentNode; if (parentNode != null) { // Select document type pnlSelectClass.Visible = true; // Get the allowed child classes DataSet ds = DataClassInfoProvider.GetAllowedChildClasses(ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0), ValidationHelper.GetInteger(SiteInfoProvider.GetSiteInfo(SiteName).SiteID, 0), "ClassName, ClassDisplayName, ClassID", -1); ArrayList deleteRows = new ArrayList(); if (!DataHelper.DataSourceIsEmpty(ds)) { // Get the unwanted classes string allowed = AllowedChildClasses.Trim().ToLowerCSafe(); if (!string.IsNullOrEmpty(allowed)) { allowed = String.Format(";{0};", allowed); } CurrentUserInfo userInfo = CMSContext.CurrentUser; string className = null; // Check if the user has 'Create' permission per Content bool isAuthorizedToCreateInContent = userInfo.IsAuthorizedPerResource("CMS.Content", "Create"); bool hasNodeAllowCreate = (userInfo.IsAuthorizedPerTreeNode(parentNode, NodePermissionsEnum.Create) != AuthorizationResultEnum.Allowed); foreach (DataRow dr in ds.Tables[0].Rows) { className = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), String.Empty).ToLowerCSafe(); // Document type is not allowed or user hasn't got permission, remove it from the data set if ((!string.IsNullOrEmpty(allowed) && (!allowed.Contains(";" + className + ";"))) || (CheckPermissions && CheckDocPermissionsForInsert && !isAuthorizedToCreateInContent && !userInfo.IsAuthorizedPerClassName(className, "Create") && (!userInfo.IsAuthorizedPerClassName(className, "CreateSpecific") || !hasNodeAllowCreate))) { deleteRows.Add(dr); } } // Remove the rows foreach (DataRow dr in deleteRows) { ds.Tables[0].Rows.Remove(dr); } } // Check if some classes are available if (!DataHelper.DataSourceIsEmpty(ds)) { // If number of classes is more than 1 display them in grid if (ds.Tables[0].Rows.Count > 1) { ds.Tables[0].DefaultView.Sort = "ClassDisplayName"; lblError.Visible = false; lblInfo.Visible = true; lblInfo.Text = GetString("Content.NewInfo"); DataSet sortedResult = new DataSet(); sortedResult.Tables.Add(ds.Tables[0].DefaultView.ToTable()); gridClass.DataSource = sortedResult; gridClass.ReloadData(); } // else show form of the only class else { ClassID = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "ClassID"), 0); ReloadData(true); return; } } else { // Display error message lblError.Visible = true; lblError.Text = GetString("Content.NoAllowedChildDocuments"); lblInfo.Visible = false; gridClass.Visible = false; } } else { pnlInfo.Visible = true; lblFormInfo.Text = GetString("EditForm.DocumentNotFound"); formElem.StopProcessing = true; } } // Insert or update of a document else { // Display the form pnlEdit.Visible = true; // Try to get GroupID if group context exists int currentGroupId = ModuleCommands.CommunityGetCurrentGroupID(); btnDelete.Attributes.Add("style", "display: none;"); btnRefresh.Attributes.Add("style", "display: none;"); // CMSForm initialization formElem.NodeID = Node.NodeID; formElem.SiteName = SiteName; formElem.CultureCode = CultureCode; formElem.ValidationErrorMessage = ValidationErrorMessage; formElem.IsLiveSite = IsLiveSite; // Set group ID if group context exists formElem.GroupID = currentGroupId; // WebDAV is allowed for live site only if the permissions are checked or user is global administrator or for group context - user is group administrator formElem.AllowWebDAV = !IsLiveSite || CheckPermissions || CMSContext.CurrentUser.IsGlobalAdministrator || CMSContext.CurrentUser.IsGroupAdministrator(currentGroupId); // Set the form mode if (NewDocument) { ci = DataClassInfoProvider.GetDataClass(ClassID); if (ci == null) { throw new Exception(String.Format("[CMSAdminControls/EditForm.aspx]: Class ID '{0}' not found.", ClassID)); } string classDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ci.ClassDisplayName)); titleElem.TitleText = GetString("Content.NewTitle") + ": " + classDisplayName; // Set default template ID formElem.DefaultPageTemplateID = TemplateID > 0 ? TemplateID : ci.ClassDefaultPageTemplateID; // Set document owner formElem.OwnerID = OwnerID; formElem.FormMode = FormModeEnum.Insert; string newClassName = ci.ClassName; string newFormName = newClassName + ".default"; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } if (newFormName.ToLowerCSafe() != formElem.FormName.ToLowerCSafe()) { formElem.FormName = newFormName; } } else if (NewCulture) { formElem.FormMode = FormModeEnum.InsertNewCultureVersion; // Default data document ID formElem.CopyDefaultDataFromDocumentId = CopyDefaultDataFromDocumentID; ci = DataClassInfoProvider.GetDataClass(Node.NodeClassName); formElem.FormName = Node.NodeClassName + ".default"; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } } else { formElem.FormMode = FormModeEnum.Update; ci = DataClassInfoProvider.GetDataClass(Node.NodeClassName); formElem.FormName = String.Empty; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } // Initialize the CMSForm formElem.LoadForm(forceReload); } // Display the CMSForm formElem.Visible = true; ReloadForm(); } } } // New culture version else { // Switch to new culture version mode DocumentManager.Mode = FormModeEnum.InsertNewCultureVersion; DocumentManager.NodeID = NodeID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; if (Node != null) { // Offer a new culture creation pnlNewCulture.Visible = true; titleElem.TitleText = GetString("Content.NewCultureVersionTitle") + " (" + HTMLHelper.HTMLEncode(CMSContext.CurrentUser.PreferredCultureCode) + ")"; titleElem.TitleImage = GetImageUrl("CMSModules/CMS_Content/Menu/new.png"); lblNewCultureInfo.Text = GetString("ContentNewCultureVersion.Info"); radCopy.Text = GetString("ContentNewCultureVersion.Copy"); radEmpty.Text = GetString("ContentNewCultureVersion.Empty"); radCopy.Attributes.Add("onclick", "ShowSelection();"); radEmpty.Attributes.Add("onclick", "ShowSelection()"); AddScript( "function ShowSelection() { \n" + " if (document.getElementById('" + radCopy.ClientID + "').checked) { document.getElementById('divCultures').style.display = 'block'; } \n" + " else { document.getElementById('divCultures').style.display = 'none'; } \n" + "} \n" ); btnOk.Text = GetString("ContentNewCultureVersion.Create"); // Load culture versions SiteInfo si = SiteInfoProvider.GetSiteInfo(Node.NodeSiteID); if (si != null) { lstCultures.Items.Clear(); DataSet nodes = TreeProvider.SelectNodes(si.SiteName, Node.NodeAliasPath, TreeProvider.ALL_CULTURES, false, null, null, null, 1, false); foreach (DataRow nodeCulture in nodes.Tables[0].Rows) { ListItem li = new ListItem(); li.Text = CultureInfoProvider.GetCultureInfo(nodeCulture["DocumentCulture"].ToString()).CultureName; li.Value = nodeCulture["DocumentID"].ToString(); lstCultures.Items.Add(li); } if (lstCultures.Items.Count > 0) { lstCultures.SelectedIndex = 0; } } } else { pnlInfo.Visible = true; lblFormInfo.Text = GetString("EditForm.DocumentNotFound"); formElem.StopProcessing = true; } } } // Set flag that the form is loaded mFormLoaded = true; } }
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"); } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Do not process control by default StopProcessing = true; // Keep frequent objects cui = CMSContext.CurrentUser; PageInfo pi = CMSContext.CurrentPageInfo; if (pi == null) { IsPageNotFound = true; pi = OnSiteEditHelper.PageInfoForPageNotFound; } ucUIToolbar.StopProcessing = true; largeCMSDeskButton = !cui.UserSiteManagerAdmin; // Check whether user is authorized to edit page if ((pi != null) && cui.IsAuthenticated() && cui.IsEditor && ((IsPageNotFound && pi.NodeID == 0) || cui.IsAuthorizedPerTreeNode(pi.NodeID, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed)) { // Enable processing StopProcessing = false; // Check whether the preferred culture is RTL isRTL = CultureHelper.IsUICultureRTL(); // Add link to CSS file CSSHelper.RegisterCSSLink(Page, "Design", "OnSiteEdit.css"); // Filter UI element buttons ucUIToolbar.OnButtonFiltered += ucUIToolbar_OnButtonFiltered; ucUIToolbar.OnButtonCreated += ucUIToolbar_OnButtonCreated; ucUIToolbar.OnButtonCreating += ucUIToolbar_OnButtonCreating; ucUIToolbar.OnGroupsCreated += ucUIToolbar_OnGroupsCreated; ucUIToolbar.IsRTL = isRTL; // Register edit script file RegisterEditScripts(pi); if (ViewMode == ViewModeEnum.EditLive) { popupHandler.Visible = true; IsLiveSite = false; MessagesPlaceHolder.IsLiveSite = false; MessagesPlaceHolder.Opacity = 100; // Display warning in the Safe mode if (PortalHelper.SafeMode) { string safeModeText = GetString("onsiteedit.safemode") + "<br/><a href=\"" + URLHelper.RawUrl.Replace("safemode=1", "safemode=0") + "\">" + GetString("general.close") + "</a> " + GetString("contentedit.safemode2"); string safeModeDescription = GetString("onsiteedit.safemode") + "<br/>" + GetString("general.seeeventlog"); // Display the warning message ShowWarning(safeModeText, safeModeDescription, ""); } ucUIToolbar.StopProcessing = false; // Ensure document redirection if (!String.IsNullOrEmpty(pi.DocumentMenuRedirectUrl)) { string redirectUrl = CMSContext.ResolveMacros(pi.DocumentMenuRedirectUrl); redirectUrl = URLHelper.ResolveUrl(redirectUrl); ShowInformation(GetString("onsiteedit.redirectinfo") + " <a href=\"" + redirectUrl + "\">" + redirectUrl + "</a>"); } } // Mode menu on live site else if (ViewMode == ViewModeEnum.LiveSite) { // Hide the edit panel, show only slider button pnlToolbarSpace.Visible = false; pnlToolbar.Visible = false; pnlSlider.Visible = true; imgSliderButton.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/edit.png"); imgSliderButton.ToolTip = GetString("onsiteedit.editmode"); imgSliderButton.AlternateText = GetString("onsitedit.editmode"); pnlButton.Attributes.Add("onclick", "OnSiteEdit_ChangeEditMode();"); imgMaximize.Style.Add("display", "none"); imgMaximize.AlternateText = GetString("general.maximize"); imgMaximize.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/ArrowDown.png"); imgMinimize.ImageUrl = GetImageUrl("CMSModules/CMS_PortalEngine/OnSiteEdit/ArrowUp.png"); imgMinimize.AlternateText = GetString("general.minimize"); pnlMinimize.Attributes.Add("onclick", "OESlideSideToolbar();"); // Hide the OnSite edit button when displayed in CMSDesk pnlSlider.Style.Add("display", "none"); } } // Hide control actions for unauthorized users else { plcEdit.Visible = false; } }
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; }