/// <summary> /// Processes all panes and modules in the template file /// </summary> /// <param name="nodePanes">Template file node for the panes is current tab</param> /// <param name="PortalId">PortalId of the new portal</param> /// <param name="TabId">Tab being processed</param> /// <remarks> /// </remarks> /// <history> /// [VMasanas] 03/09/2004 Created /// [VMasanas] 15/10/2004 Modified for new skin structure /// [cnurse] 15/10/2004 Modified to allow for merging template /// with existing pages /// </history> public void ParsePanes( XmlNode nodePanes, int PortalId, int TabId, PortalTemplateModuleAction mergeTabs, Hashtable hModules ) { XmlNode nodePane = null; XmlNode nodeModule = null; ModuleDefinitionController objModuleDefinitions = new ModuleDefinitionController(); ModuleDefinitionInfo objModuleDefinition = null; ModuleController objModules = new ModuleController(); Dictionary<int, ModuleInfo> dicModules = objModules.GetTabModules( TabId ); ModuleInfo objModule = null; int intModuleId = 0; string modTitle = null; bool moduleFound = false; PortalInfo objportal = null; objportal = GetPortal( PortalId ); //If Mode is Replace remove all the modules already on this Tab if( mergeTabs == PortalTemplateModuleAction.Replace ) { foreach( KeyValuePair<int, ModuleInfo> kvp in dicModules ) { objModule = kvp.Value; objModules.DeleteTabModule( TabId, objModule.ModuleID ); } } // iterate through the panes foreach( XmlNode nodePaneWithinLoop in nodePanes.ChildNodes ) { nodePane = nodePaneWithinLoop; // iterate through the modules if( nodePaneWithinLoop.SelectSingleNode( "modules" ) != null ) { foreach( XmlNode nodeModuleWithinLoop in nodePaneWithinLoop.SelectSingleNode( "modules" ) ) { nodeModule = nodeModuleWithinLoop; // will be instance or module? int templateModuleID = XmlUtils.GetNodeValueInt( nodeModule, "moduleID", 0 ); bool IsInstance = false; if( templateModuleID > 0 ) { if( hModules[templateModuleID] != null ) { // this module has already been processed -> process as instance IsInstance = true; } } // Templates prior to v4.3.5 only have the <definition> node to define the Module Type // This <definition> node was populated with the DesktopModuleInfo.ModuleName property // Thus there is no mechanism to determine to which module definition the module belongs. // // Template from v4.3.5 on also have the <moduledefinition> element that is populated // with the ModuleDefinitionInfo.FriendlyName. Therefore the module Instance identifies // which Module Definition it belongs to. //Get the DesktopModule defined by the <definition> element DesktopModuleInfo objDesktopModule = Globals.GetDesktopModuleByName( XmlUtils.GetNodeValue( nodeModule, "definition", "" ) ); if( objDesktopModule != null ) { //Get the moduleDefinition from the <moduledefinition> element string friendlyName = XmlUtils.GetNodeValue( nodeModule, "moduledefinition", "" ); if( string.IsNullOrEmpty( friendlyName ) ) { //Module is pre 4.3.5 so get the first Module Definition (at least it won't throw an error then) ArrayList arrModuleDefinitions = objModuleDefinitions.GetModuleDefinitions( objDesktopModule.DesktopModuleID ); objModuleDefinition = (ModuleDefinitionInfo)( arrModuleDefinitions[0] ); } else { //Module is 4.3.5 or later so get the Module Defeinition by its friendly name objModuleDefinition = objModuleDefinitions.GetModuleDefinitionByName( objDesktopModule.DesktopModuleID, friendlyName ); } if( objModuleDefinition != null ) { //If Mode is Merge Check if Module exists moduleFound = false; modTitle = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "title", "" ); if( mergeTabs == PortalTemplateModuleAction.Merge ) { foreach( KeyValuePair<int, ModuleInfo> kvp in dicModules ) { objModule = kvp.Value; if( modTitle == objModule.ModuleTitle ) { moduleFound = true; break; } } } if( moduleFound == false ) { //Create New Module objModule = new ModuleInfo(); objModule.PortalID = PortalId; objModule.TabID = TabId; objModule.ModuleOrder = -1; objModule.ModuleTitle = modTitle; objModule.PaneName = XmlUtils.GetNodeValue( nodePaneWithinLoop, "name", "" ); objModule.ModuleDefID = objModuleDefinition.ModuleDefID; objModule.CacheTime = XmlUtils.GetNodeValueInt( nodeModuleWithinLoop, "cachetime", 0 ); objModule.Alignment = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "alignment", "" ); objModule.IconFile = ImportFile( PortalId, XmlUtils.GetNodeValue( nodeModuleWithinLoop, "iconfile", "" ) ); objModule.AllTabs = XmlUtils.GetNodeValueBoolean( nodeModuleWithinLoop, "alltabs", false ); switch( XmlUtils.GetNodeValue( nodeModuleWithinLoop, "visibility", "" ) ) { case "Maximized": objModule.Visibility = VisibilityState.Maximized; break; case "Minimized": objModule.Visibility = VisibilityState.Minimized; break; case "None": objModule.Visibility = VisibilityState.None; break; } objModule.Color = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "color", "" ); objModule.Border = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "border", "" ); objModule.Header = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "header", "" ); objModule.Footer = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "footer", "" ); objModule.InheritViewPermissions = XmlUtils.GetNodeValueBoolean( nodeModuleWithinLoop, "inheritviewpermissions", false ); objModule.ModulePermissions = new ModulePermissionCollection(); objModule.StartDate = XmlUtils.GetNodeValueDate( nodeModuleWithinLoop, "startdate", Null.NullDate ); objModule.EndDate = XmlUtils.GetNodeValueDate( nodeModuleWithinLoop, "enddate", Null.NullDate ); if( XmlUtils.GetNodeValue( nodeModuleWithinLoop, "containersrc", "" ) != "" ) { objModule.ContainerSrc = XmlUtils.GetNodeValue( nodeModuleWithinLoop, "containersrc", "" ); } objModule.DisplayTitle = XmlUtils.GetNodeValueBoolean( nodeModuleWithinLoop, "displaytitle", true ); objModule.DisplayPrint = XmlUtils.GetNodeValueBoolean( nodeModuleWithinLoop, "displayprint", true ); objModule.DisplaySyndicate = XmlUtils.GetNodeValueBoolean( nodeModuleWithinLoop, "displaysyndicate", false ); if( !IsInstance ) { //Add new module intModuleId = objModules.AddModule( objModule ); if( templateModuleID > 0 ) { hModules.Add( templateModuleID, intModuleId ); } } else { //Add instance objModule.ModuleID = Convert.ToInt32( hModules[templateModuleID] ); intModuleId = objModules.AddModule( objModule ); } if( XmlUtils.GetNodeValue( nodeModuleWithinLoop, "content", "" ) != "" & !IsInstance ) { objModule = objModules.GetModule( intModuleId, TabId, true ); string strVersion = nodeModule.SelectSingleNode( "content" ).Attributes["version"].Value; string strType = nodeModule.SelectSingleNode( "content" ).Attributes["type"].Value; string strcontent = nodeModule.SelectSingleNode( "content" ).InnerXml; strcontent = strcontent.Substring( 9, strcontent.Length - 12 ); strcontent = HttpContext.Current.Server.HtmlDecode( strcontent ); if( objModule.BusinessControllerClass != "" & objModule.IsPortable ) { try { object objObject = Reflection.CreateObject( objModule.BusinessControllerClass, objModule.BusinessControllerClass ); if( objObject is IPortable ) { ( (IPortable)objObject ).ImportModule( objModule.ModuleID, strcontent, strVersion, objportal.AdministratorId ); } } catch { //ignore errors } } } // Process permissions only once if( !IsInstance ) { XmlNodeList nodeModulePermissions = nodeModule.SelectNodes( "modulepermissions/permission" ); ParseModulePermissions( nodeModulePermissions, PortalId, intModuleId ); } } } } } } } }
protected void AddNewModule(string title, int desktopModuleId, string paneName, int position, ViewPermissionType permissionType, string align) { TabPermissionCollection objTabPermissions = PortalSettings.ActiveTab.TabPermissions; PermissionController objPermissionController = new PermissionController(); ModuleController objModules = new ModuleController(); ModuleDefinitionController objModuleDefinitions = new ModuleDefinitionController(); Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController(); int intIndex; try { DesktopModuleController objDesktopModules = new DesktopModuleController(); ArrayList arrDM = objDesktopModules.GetDesktopModulesByPortal(PortalSettings.PortalId); bool isSelectable = false; for (int intloop = 0; intloop < arrDM.Count; intloop++) { if (((DesktopModuleInfo)(arrDM[intloop])).DesktopModuleID == desktopModuleId) { isSelectable = true; break; } } if (isSelectable == false) { throw new Exception(); } } catch (Exception ex) { throw new Exception(ex.Message); } int UserId = -1; if (Request.IsAuthenticated) { UserInfo objUserInfo = UserController.GetCurrentUserInfo(); UserId = objUserInfo.UserID; } ArrayList arrModuleDefinitions = objModuleDefinitions.GetModuleDefinitions(desktopModuleId); for (intIndex = 0; intIndex < arrModuleDefinitions.Count; intIndex++) { ModuleDefinitionInfo objModuleDefinition = (ModuleDefinitionInfo)(arrModuleDefinitions[intIndex]); ModuleInfo objModule = new ModuleInfo(); objModule.Initialize(PortalSettings.PortalId); objModule.PortalID = PortalSettings.PortalId; objModule.TabID = PortalSettings.ActiveTab.TabID; objModule.ModuleOrder = position; if (String.IsNullOrEmpty(title)) { objModule.ModuleTitle = objModuleDefinition.FriendlyName; } else { objModule.ModuleTitle = title; } objModule.ModuleTitle = title; objModule.PaneName = paneName; objModule.ModuleDefID = objModuleDefinition.ModuleDefID; objModule.CacheTime = objModuleDefinition.DefaultCacheTime; // initialize module permissions ModulePermissionCollection objModulePermissions = new ModulePermissionCollection(); objModule.ModulePermissions = objModulePermissions; objModule.InheritViewPermissions = false; // get the default module view permissions ArrayList arrSystemModuleViewPermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW"); // get the permissions from the page foreach (TabPermissionInfo objTabPermission in objTabPermissions) { // get the system module permissions for the permissionkey ArrayList arrSystemModulePermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", objTabPermission.PermissionKey); // loop through the system module permissions int j; for (j = 0; j < arrSystemModulePermissions.Count; j++) { // create the module permission PermissionInfo objSystemModulePermission = (PermissionInfo)(arrSystemModulePermissions[j]); ModulePermissionInfo objModulePermission = AddModulePermission(objModule.ModuleID, objSystemModulePermission, objTabPermission.RoleID); // add the permission to the collection if (!(objModulePermissions.Contains(objModulePermission)) & objModulePermission.AllowAccess) { objModulePermissions.Add(objModulePermission); } // ensure that every EDIT permission which allows access also provides VIEW permission if (objModulePermission.PermissionKey == "EDIT" & objModulePermission.AllowAccess) { ModulePermissionInfo objModuleViewperm = new ModulePermissionInfo(); objModuleViewperm.ModuleID = objModulePermission.ModuleID; objModuleViewperm.PermissionID = ((PermissionInfo)(arrSystemModuleViewPermissions[0])).PermissionID; objModuleViewperm.RoleID = objModulePermission.RoleID; objModuleViewperm.PermissionKey = "VIEW"; objModuleViewperm.AllowAccess = true; if (!(objModulePermissions.Contains(objModuleViewperm))) { objModulePermissions.Add(objModuleViewperm); } } } //Get the custom Module Permissions, Assume that roles with Edit Tab Permissions //are automatically assigned to the Custom Module Permissions if (objTabPermission.PermissionKey == "EDIT") { ArrayList arrCustomModulePermissions = objPermissionController.GetPermissionsByModuleDefID(objModule.ModuleDefID); // loop through the custom module permissions for (j = 0; j < arrCustomModulePermissions.Count; j++) { // create the module permission PermissionInfo objCustomModulePermission = (PermissionInfo)(arrCustomModulePermissions[j]); ModulePermissionInfo objModulePermission = AddModulePermission(objModule.ModuleID, objCustomModulePermission, objTabPermission.RoleID); // add the permission to the collection if (!(objModulePermissions.Contains(objModulePermission)) & objModulePermission.AllowAccess) { objModulePermissions.Add(objModulePermission); } } } } switch (permissionType) { case ViewPermissionType.View: objModule.InheritViewPermissions = true; break; case ViewPermissionType.Edit: objModule.ModulePermissions = objModulePermissions; break; } objModule.AllTabs = false; objModule.Visibility = VisibilityState.Maximized; objModule.Alignment = align; objModules.AddModule(objModule); objEventLog.AddLog(objModule, PortalSettings, UserId, "", Services.Log.EventLog.EventLogController.EventLogType.MODULE_CREATED); } }
private int AddNewModule(TabInfo tab, string title, int desktopModuleId, string paneName, int permissionType, string align) { TabPermissionCollection objTabPermissions = tab.TabPermissions; var objPermissionController = new PermissionController(); var objModules = new ModuleController(); int j; var mdc = new ModuleDefinitionController(); foreach (ModuleDefinitionInfo objModuleDefinition in mdc.GetModuleDefinitions(desktopModuleId)) { var objModule = new ModuleInfo(); objModule.Initialize(tab.PortalID); objModule.PortalID = tab.PortalID; objModule.TabID = tab.TabID; if (string.IsNullOrEmpty(title)) { objModule.ModuleTitle = objModuleDefinition.FriendlyName; } else { objModule.ModuleTitle = title; } objModule.PaneName = paneName; objModule.ModuleDefID = objModuleDefinition.ModuleDefID; objModule.CacheTime = 0; objModule.InheritViewPermissions = true; objModule.DisplayTitle = false; // get the default module view permissions ArrayList arrSystemModuleViewPermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW"); // get the permissions from the page foreach (TabPermissionInfo objTabPermission in objTabPermissions) { if (objTabPermission.PermissionKey == "VIEW" && permissionType == 0) { //Don't need to explicitly add View permisisons if "Same As Page" continue; } // get the system module permissions for the permissionkey ArrayList arrSystemModulePermissions = objPermissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", objTabPermission.PermissionKey); // loop through the system module permissions for (j = 0; j <= arrSystemModulePermissions.Count - 1; j++) { // create the module permission PermissionInfo objSystemModulePermission = default(PermissionInfo); objSystemModulePermission = (PermissionInfo) arrSystemModulePermissions[j]; if (objSystemModulePermission.PermissionKey == "VIEW" && permissionType == 1 && objTabPermission.PermissionKey != "EDIT") { //Only Page Editors get View permissions if "Page Editors Only" continue; } ModulePermissionInfo objModulePermission = AddModulePermission(objModule, objSystemModulePermission, objTabPermission.RoleID, objTabPermission.UserID, objTabPermission.AllowAccess); // ensure that every EDIT permission which allows access also provides VIEW permission if (objModulePermission.PermissionKey == "EDIT" & objModulePermission.AllowAccess) { ModulePermissionInfo objModuleViewperm = AddModulePermission(objModule, (PermissionInfo) arrSystemModuleViewPermissions[0], objModulePermission.RoleID, objModulePermission.UserID, true); } } } objModule.AllTabs = false; objModule.Alignment = align; return objModules.AddModule(objModule); } return -1; }
/// <summary> /// Creates the DNN manifest. /// </summary> /// <param name="objDesktopModule">The obj desktop module.</param> private void CreateDnnManifest(DesktopModuleInfo objDesktopModule) { string filename = ""; _Name = objDesktopModule.ModuleName; //Create Manifest Document XmlDocument xmlManifest = new XmlDocument(); //Root Element XmlNode nodeRoot = xmlManifest.CreateElement("dotnetnuke"); nodeRoot.Attributes.Append(XmlUtils.CreateAttribute(xmlManifest, "version", "3.0")); nodeRoot.Attributes.Append(XmlUtils.CreateAttribute(xmlManifest, "type", "Module")); //Folders Element XmlNode nodeFolders = xmlManifest.CreateElement("folders"); nodeRoot.AppendChild(nodeFolders); //Folder Element XmlNode nodeFolder = xmlManifest.CreateElement("folder"); nodeFolders.AppendChild(nodeFolder); //Desktop Module Info nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "name", _Name)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "friendlyname", objDesktopModule.FriendlyName)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "foldername", objDesktopModule.FolderName)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "modulename", _Name)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "description", objDesktopModule.Description)); if (objDesktopModule.Version == Null.NullString) { objDesktopModule.Version = "01.00.00"; } nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "version", objDesktopModule.Version)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "businesscontrollerclass", objDesktopModule.BusinessControllerClass)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "version", objDesktopModule.Version)); nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "businesscontrollerclass", objDesktopModule.BusinessControllerClass)); if (objDesktopModule.CompatibleVersions != "") { nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "compatibleversions", objDesktopModule.CompatibleVersions)); } if (SupportsProbingPrivatePath) { nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "supportsprobingprivatepath", SupportsProbingPrivatePath.ToString())); } //Add Source files if (IncludeSource) { nodeFolder.AppendChild(XmlUtils.CreateElement(xmlManifest, "resourcefile", ResourceFileName)); } //Modules Element XmlNode nodeModules = xmlManifest.CreateElement("modules"); nodeFolder.AppendChild(nodeModules); //Get the Module Definitions for this Module ModuleDefinitionController objModuleDefinitionController = new ModuleDefinitionController(); ArrayList arrModuleDefinitions = objModuleDefinitionController.GetModuleDefinitions(objDesktopModule.DesktopModuleID); //Iterate through Module Definitions foreach (ModuleDefinitionInfo objModuleInfo in arrModuleDefinitions) { XmlNode nodeModule = xmlManifest.CreateElement("module"); //Add module definition properties nodeModule.AppendChild(XmlUtils.CreateElement(xmlManifest, "friendlyname", objModuleInfo.FriendlyName)); //Add Cache properties nodeModule.AppendChild(XmlUtils.CreateElement(xmlManifest, "cachetime", objModuleInfo.DefaultCacheTime.ToString())); //Get the Module Controls for this Module Definition ModuleControlController objModuleControlController = new ModuleControlController(); ArrayList arrModuleControls = objModuleControlController.GetModuleControls(objModuleInfo.ModuleDefID); //Controls Element XmlNode nodeControls = xmlManifest.CreateElement("controls"); nodeModule.AppendChild(nodeControls); //Iterate through Module Controls foreach (ModuleControlInfo objModuleControl in arrModuleControls) { XmlNode nodeControl = xmlManifest.CreateElement("control"); //Add module control properties XmlUtils.AppendElement(ref xmlManifest, nodeControl, "key", objModuleControl.ControlKey, false); XmlUtils.AppendElement(ref xmlManifest, nodeControl, "title", objModuleControl.ControlTitle, false); XmlUtils.AppendElement(ref xmlManifest, nodeControl, "src", objModuleControl.ControlSrc, true); XmlUtils.AppendElement(ref xmlManifest, nodeControl, "iconfile", objModuleControl.IconFile, false); XmlUtils.AppendElement(ref xmlManifest, nodeControl, "type", objModuleControl.ControlType.ToString(), true); XmlUtils.AppendElement(ref xmlManifest, nodeControl, "helpurl", objModuleControl.HelpURL, false); //Add control Node to controls nodeControls.AppendChild(nodeControl); //Determine the filename for the Manifest file (It should be saved with the other Module files) if (filename == "") { filename = Folder + "\\" + objDesktopModule.ModuleName + ".dnn"; } } //Add module Node to modules nodeModules.AppendChild(nodeModule); } //Files Element XmlNode nodeFiles = xmlManifest.CreateElement("files"); nodeFolder.AppendChild(nodeFiles); //Add the files foreach (PaFileInfo file in _Files) { XmlNode nodeFile = xmlManifest.CreateElement("file"); //Add file properties XmlUtils.AppendElement(ref xmlManifest, nodeFile, "path", file.Path, false); XmlUtils.AppendElement(ref xmlManifest, nodeFile, "name", file.Name, false); //Add file Node to files nodeFiles.AppendChild(nodeFile); } //Add Root element to document xmlManifest.AppendChild(nodeRoot); //Save Manifest file xmlManifest.Save(filename); }
/// <summary> /// LoadDefinitions fetches the definitions from the database and updates the controls /// </summary> /// <history> /// [cnurse] 9/28/2004 Updated to reflect design changes for Help, 508 support /// and localisation /// </history> private void LoadDefinitions() { ModuleDefinitionController objModuleDefinitions = new ModuleDefinitionController(); cboDefinitions.DataSource = objModuleDefinitions.GetModuleDefinitions( DesktopModuleId ); cboDefinitions.DataBind(); if( cboDefinitions.Items.Count != 0 ) { cboDefinitions.SelectedIndex = 0; int ModuleDefId = int.Parse( cboDefinitions.SelectedItem.Value ); LoadCacheProperties( ModuleDefId ); LoadControls( ModuleDefId ); tabCache.Visible = true; } else { cmdAddControl.Visible = false; grdControls.Visible = false; txtCacheTime.Text = "0"; tabCache.Visible = false; } }