private void BindMenu(MenuItemCollection items, XmlNodeList nodes) { foreach (XmlNode node in nodes) { string pageId = null; if (node.Attributes["pageID"] != null) { pageId = node.Attributes["pageID"].Value; } if (!PortalUtils.PageExists(pageId)) { continue; } string url = null; if (node.Attributes["url"] != null) { url = node.Attributes["url"].Value; } string title = null; if (node.Attributes["title"] != null) { title = node.Attributes["title"].Value; } string target = null; if (node.Attributes["target"] != null) { target = node.Attributes["target"].Value; } string resourceGroup = null; if (node.Attributes["resourceGroup"] != null) { resourceGroup = node.Attributes["resourceGroup"].Value; } string quota = null; if (node.Attributes["quota"] != null) { quota = node.Attributes["quota"].Value; } bool disabled = false; if (node.Attributes["disabled"] != null) { disabled = Utils.ParseBool(node.Attributes["disabled"].Value, false); } // get custom page parameters XmlNodeList xmlParameters = node.SelectNodes("Parameters/Add"); List <string> parameters = new List <string>(); foreach (XmlNode xmlParameter in xmlParameters) { parameters.Add(xmlParameter.Attributes["name"].Value + "=" + xmlParameter.Attributes["value"].Value); } // add menu item string pageUrl = !String.IsNullOrEmpty(url) ? url : PortalUtils.NavigatePageURL( pageId, PortalUtils.SPACE_ID_PARAM, currentPackage.ToString(), parameters.ToArray()); string pageName = !String.IsNullOrEmpty(title) ? title : PortalUtils.GetLocalizedPageName(pageId); MenuItem item = new MenuItem(pageName, pageId, "", disabled ? null : pageUrl); if (!String.IsNullOrEmpty(target)) { item.Target = target; } item.Selectable = !disabled; // check groups/quotas bool display = true; String displayValue = String.Empty; if (cntx != null) { display = (String.IsNullOrEmpty(resourceGroup) || cntx.Groups.ContainsKey(resourceGroup)) && (String.IsNullOrEmpty(quota) || (cntx.Quotas.ContainsKey(quota) && cntx.Quotas[quota].QuotaAllocatedValue != 0)); if (!String.IsNullOrEmpty(resourceGroup)) { displayValue = "String.IsNullOrEmpty(resourceGroup): " + String.IsNullOrEmpty(resourceGroup).ToString(); displayValue += "| cntx.Groups.ContainsKey(resourceGroup): " + cntx.Groups.ContainsKey(resourceGroup).ToString(); displayValue += "| resourceGroup: " + resourceGroup; } if (!String.IsNullOrEmpty(quota)) { displayValue += "| String.IsNullOrEmpty(quota): " + String.IsNullOrEmpty(quota).ToString(); displayValue += "| cntx.Quotas.ContainsKey(quota): " + cntx.Quotas.ContainsKey(quota).ToString(); if (cntx.Quotas.ContainsKey(quota)) { displayValue += "| cntx.Quotas[quota].QuotaAllocatedValue: " + cntx.Quotas[quota].QuotaAllocatedValue.ToString(); } displayValue += "| quota: " + quota; } } if (display) { // process nested menu items XmlNodeList xmlNestedNodes = node.SelectNodes("MenuItems/MenuItem"); BindMenu(item.ChildItems, xmlNestedNodes); } //item.Text += displayValue; //Response.Write("DisplayValue :[" + displayValue + "] "); //for Selected == added kuldeep if (Request.QueryString.Get("pid") != null) { string pid = Request.QueryString.Get("pid").ToString(); if (item.NavigateUrl.IndexOf(pid) >= 0) { item.Selected = true; } } if (display && !(disabled && item.ChildItems.Count == 0)) { items.Add(item); } } }
private MenuItem CreateMenuItem(PackageContext cntx, XmlNode xmlNode) { string pageId = GetXmlAttribute(xmlNode, "pageID"); if (!PortalUtils.PageExists(pageId)) { return(null); } string url = GetXmlAttribute(xmlNode, "url"); string title = GetXmlAttribute(xmlNode, "title"); string imageUrl = GetXmlAttribute(xmlNode, "imageUrl"); string target = GetXmlAttribute(xmlNode, "target"); string resourceGroup = GetXmlAttribute(xmlNode, "resourceGroup"); string quota = GetXmlAttribute(xmlNode, "quota"); bool disabled = Utils.ParseBool(GetXmlAttribute(xmlNode, "disabled"), false); string titleresourcekey = GetXmlAttribute(xmlNode, "titleresourcekey"); if (!String.IsNullOrEmpty(titleresourcekey)) { title = GetLocalizedString(titleresourcekey + ".Text"); } // get custom page parameters XmlNodeList xmlParameters = xmlNode.SelectNodes("Parameters/Add"); List <string> parameters = new List <string>(); foreach (XmlNode xmlParameter in xmlParameters) { parameters.Add(xmlParameter.Attributes["name"].Value + "=" + xmlParameter.Attributes["value"].Value); } // add menu item string pageUrl = !String.IsNullOrEmpty(url) ? url : PortalUtils.NavigatePageURL( pageId, PortalUtils.SPACE_ID_PARAM, cntx.Package.PackageId.ToString(), parameters.ToArray()); string pageName = !String.IsNullOrEmpty(title) ? title : PortalUtils.GetLocalizedPageName(pageId); MenuItem item = new MenuItem(pageName, pageId, "", disabled ? null : pageUrl); item.ImageUrl = PortalUtils.GetThemedIcon(imageUrl); if (!String.IsNullOrEmpty(target)) { item.Target = target; } item.Selectable = !disabled; // check groups/quotas bool display = true; if (cntx != null) { display = (String.IsNullOrEmpty(resourceGroup) || cntx.Groups.ContainsKey(resourceGroup)) && (String.IsNullOrEmpty(quota) || (cntx.Quotas.ContainsKey(quota) && cntx.Quotas[quota].QuotaAllocatedValue != 0)); } // process nested menu items XmlNodeList xmlMenuNodes = xmlNode.SelectNodes("Icon"); if (xmlMenuNodes.Count == 0) { xmlMenuNodes = xmlNode.SelectNodes("MenuItems/MenuItem"); } foreach (XmlNode xmlMenuNode in xmlMenuNodes) { MenuItem menuItem = CreateMenuItem(cntx, xmlMenuNode); if (menuItem != null) { item.ChildItems.Add(menuItem); } } // test //return item; if (display && !(disabled && item.ChildItems.Count == 0)) { return(item); } return(null); }
private void BindMenu(MenuItemCollection items, XmlNodeList nodes) { foreach (XmlNode node in nodes) { string pageId = null; if (node.Attributes["pageID"] != null) { pageId = node.Attributes["pageID"].Value; } if (!PortalUtils.PageExists(pageId)) { continue; } string url = null; if (node.Attributes["url"] != null) { url = node.Attributes["url"].Value; } string title = null; if (node.Attributes["title"] != null) { title = node.Attributes["title"].Value; } string target = null; if (node.Attributes["target"] != null) { target = node.Attributes["target"].Value; } string roles = null; if (node.Attributes["roles"] != null) { roles = node.Attributes["roles"].Value; } string selectedUserContext = null; if (node.Attributes["selectedUserContext"] != null) { selectedUserContext = node.Attributes["selectedUserContext"].Value; } // get custom page parameters XmlNodeList xmlParameters = node.SelectNodes("Parameters/Add"); List <string> parameters = new List <string>(); foreach (XmlNode xmlParameter in xmlParameters) { parameters.Add(xmlParameter.Attributes["name"].Value + "=" + xmlParameter.Attributes["value"].Value); } bool display = true; // set user role visibility second if (!String.IsNullOrEmpty(selectedUserContext)) { display = false; string[] arrRoles = selectedUserContext.Split(','); string userRole = PanelSecurity.SelectedUser.Role.ToString(); foreach (string role in arrRoles) { if (String.Compare(userRole, role, true) == 0) { display = true; break; } } } if ((!String.IsNullOrEmpty(roles)) & display) { display = false; string[] arrRoles = roles.Split(','); string userRole = PanelSecurity.LoggedUser.Role.ToString(); foreach (string role in arrRoles) { if (String.Compare(userRole, role, true) == 0) { display = true; break; } } } //Audit Log functionality is disabled when user is in Demo mode if ((pageId == "AuditLog") && (PanelSecurity.SelectedUser.IsDemo)) { display = false; } // add menu item if (display) { string pageUrl = !String.IsNullOrEmpty(url) ? url : PortalUtils.NavigatePageURL( pageId, PortalUtils.USER_ID_PARAM, PanelSecurity.SelectedUserId.ToString(), parameters.ToArray()); string pageName = !String.IsNullOrEmpty(title) ? title : PortalUtils.GetLocalizedPageName(pageId); MenuItem item = new MenuItem(pageName, "", "", pageUrl); if (!String.IsNullOrEmpty(target)) { item.Target = target; } //for Selected == added kuldeep if (Request.QueryString.Get("pid") != null) { string pid = Request.QueryString.Get("pid").ToString(); //Parent Menu Replacement if (pid.Equals("SpaceHome", StringComparison.CurrentCultureIgnoreCase)) { pid = "UserSpaces"; } if (item.NavigateUrl.IndexOf(pid) >= 0) { item.Selected = true; } } items.Add(item); // process nested menu items XmlNodeList xmlNestedNodes = node.SelectNodes("MenuItems/MenuItem"); BindMenu(item.ChildItems, xmlNestedNodes); } } }