using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.SettingsProvider; using CMS.SiteProvider; using CMS.UIControls; public partial class CMSAdminControls_UI_UIProfiles_UIPanelMenu : CMSUserControl { #region "Properties" /// /// Module name. /// public string ModuleName { get; set; } /// /// Number of columns in which categories will be displayed. /// public int ColumnsCount { get; set; } #endregion #region "Events" /// /// Category creation delegate. /// public delegate void CategoryCreatedEventHandler(object sender, CategoryCreatedEventArgs e); /// /// Category creation event. /// public event CategoryCreatedEventHandler CategoryCreated; #endregion #region "Page events" protected void Page_Load(object sender, EventArgs e) { CurrentUserInfo currentUser = CMSContext.CurrentUser; // Fill the menu with UIElement data for specified module if (!String.IsNullOrEmpty(ModuleName) & (currentUser != null)) { DataSet dsModules = UIElementInfoProvider.GetUIMenuElements(ModuleName); List categoriesTmp = new List(); if (!DataHelper.DataSourceIsEmpty(dsModules)) { foreach (DataRow drModule in dsModules.Tables[0].Rows) { UIElementInfo moduleElement = new UIElementInfo(drModule); // Proceed if user has permissions for this UI element if (currentUser.IsAuthorizedPerUIElement(ModuleName, moduleElement.ElementName)) { // Category title string categoryTitle = ResHelper.LocalizeString(moduleElement.ElementDisplayName); // Category name string categoryName = ResHelper.LocalizeString(moduleElement.ElementName); // Category URL string categoryUrl = CMSContext.ResolveMacros(URLHelper.EnsureHashToQueryParameters(moduleElement.ElementTargetURL)); // Category image URL string categoryImageUrl = GetImagePath(moduleElement.ElementIconPath.Replace("list.png", "module.png")); if (!FileHelper.FileExists(categoryImageUrl)) { categoryImageUrl = GetImagePath("CMSModules/module.png"); } categoryImageUrl = UIHelper.ResolveImageUrl(categoryImageUrl); // Category tooltip string categoryTooltip = ResHelper.LocalizeString(moduleElement.ElementDescription); // Category actions DataSet dsActions = UIElementInfoProvider.GetChildUIElements(moduleElement.ElementID); List actionsTmp = new List(); foreach (DataRow drAction in dsActions.Tables[0].Rows) { UIElementInfo actionElement = new UIElementInfo(drAction); // Proceed if user has permissions for this UI element if (currentUser.IsAuthorizedPerUIElement(ModuleName, actionElement.ElementName)) { actionsTmp.Add(new string[] { ResHelper.LocalizeString(actionElement.ElementDisplayName), CMSContext.ResolveMacros(URLHelper.EnsureHashToQueryParameters(actionElement.ElementTargetURL)) }); } } int actionsCount = actionsTmp.Count; string[,] categoryActions = new string[actionsCount,2]; for (int i = 0; i < actionsCount; i++) { categoryActions[i, 0] = actionsTmp[i][0]; categoryActions[i, 1] = actionsTmp[i][1]; } CategoryCreatedEventArgs args = new CategoryCreatedEventArgs(moduleElement, categoryName, categoryTitle, categoryUrl, categoryImageUrl, categoryTooltip, categoryActions); // Raise additional initialization events for this category if (CategoryCreated != null) { CategoryCreated(this, args); } // Add to categories, if further processing of this category was not cancelled if (!args.Cancel) { categoriesTmp.Add(new object[] { args.CategoryTitle, args.CategoryName, args.CategoryURL, args.CategoryImageURL, args.CategoryTooltip, args.CategoryActions }); } } } } int categoriesCount = categoriesTmp.Count; object[,] categories = new object[categoriesCount,6]; for (int i = 0; i < categoriesCount; i++) { categories[i, 0] = categoriesTmp[i][0]; categories[i, 1] = categoriesTmp[i][1]; categories[i, 2] = categoriesTmp[i][2]; categories[i, 3] = categoriesTmp[i][3]; categories[i, 4] = categoriesTmp[i][4]; categories[i, 5] = categoriesTmp[i][5]; } if (categoriesCount > 0) { panelMenu.Categories = categories; panelMenu.ColumnsCount = ColumnsCount; } else { RedirectToUINotAvailable(); } // Add editing icon in development mode if (SettingsKeyProvider.DevelopmentMode && currentUser.IsGlobalAdministrator) { ResourceInfo ri = ResourceInfoProvider.GetResourceInfo(ModuleName); if (ri != null) { ltlAfter.Text += "
" + UIHelper.GetResourceUIElementsLink(Page, ri.ResourceId) + "
"; } } } } #endregion #region "Classes" /// /// Event arguments class for UIPanelMenu OnCategoryCreated event. /// public class CategoryCreatedEventArgs : CMSEventArgs { #region "Properties" /// /// Base UI element for this category. /// public UIElementInfo UIElement { get; protected set; } /// /// Category name. /// public string CategoryName { get; set; } /// /// Category title. /// public string CategoryTitle { get; set; } /// /// Category URL. /// public string CategoryURL { get; set; } /// /// Category image url. /// public string CategoryImageURL { get; set; } /// /// Category tooltip. /// public string CategoryTooltip { get; set; } /// /// Category actions. /// public string[,] CategoryActions { get; protected set; } /// /// Indicates if further processing of this category will be done or not. /// public bool Cancel { get; set; } #endregion #region "Constructors" /// /// Initiliazes new instance of class. /// /// Category title /// Category URL /// Category image URL /// Category tooltip /// Category actions public CategoryCreatedEventArgs(UIElementInfo element, string categoryName, string categoryTitle, string categoryUrl, string categoryImageUrl, string categoryTooltip, string[,] categoryActions) { UIElement = element; CategoryName = categoryName; CategoryTitle = categoryTitle; CategoryURL = categoryUrl; CategoryImageURL = categoryImageUrl; CategoryTooltip = categoryTooltip; CategoryActions = categoryActions; Cancel = false; } #endregion } #endregion }