예제 #1
0
        ///-----------------------------------------------------------------------------
        ///<summary>
        ///  AddModuleToPage adds a module to a Page
        ///</summary>
        ///<remarks>
        ///</remarks>
        ///<param name = "page">The Page to add the Module to</param>
        ///<param name = "moduleDefId">The Module Deinition Id for the module to be aded to this tab</param>
        ///<param name = "moduleTitle">The Module's title</param>
        ///<param name = "moduleIconFile">The Module's icon</param>
        ///<param name = "inheritPermissions">Inherit the Pages View Permisions</param>
        ///<history>
        ///  [cnurse]	11/16/2004	created
        ///</history>
        ///-----------------------------------------------------------------------------
        public static int AddModuleToPage(TabInfo page, int moduleDefId, string moduleTitle, string moduleIconFile, bool inheritPermissions)
        {
            var moduleController = new ModuleController();
            ModuleInfo moduleInfo;
            int moduleId = Null.NullInteger;

            if ((page != null))
            {
                bool isDuplicate = false;
                foreach (var kvp in moduleController.GetTabModules(page.TabID))
                {
                    moduleInfo = kvp.Value;
                    if (moduleInfo.ModuleDefID == moduleDefId)
                    {
                        isDuplicate = true;
                        moduleId = moduleInfo.ModuleID;
                    }
                }

                if (!isDuplicate)
                {
                    moduleInfo = new ModuleInfo
                    {
                        ModuleID = Null.NullInteger,
                        PortalID = page.PortalID,
                        TabID = page.TabID,
                        ModuleOrder = -1,
                        ModuleTitle = moduleTitle,
                        PaneName = Globals.glbDefaultPane,
                        ModuleDefID = moduleDefId,
                        CacheTime = 0,
                        IconFile = moduleIconFile,
                        AllTabs = false,
                        Visibility = VisibilityState.None,
                        InheritViewPermissions = inheritPermissions
                    };
                    moduleId = moduleController.AddModule(moduleInfo);
                }
            }

            return moduleId;
        }
예제 #2
0
        public int AddModuleToPage(TabInfo t, ModuleType type)
        {
            string DesktopModuleFriendlyName="";
            string ModuleDefFriendlyName="";

            ModuleDefinitionInfo moduleDefinitionInfo = new ModuleDefinitionInfo();
            ModuleInfo moduleInfo = new ModuleInfo();
            moduleInfo.PortalID = t.PortalID;
            moduleInfo.TabID = t.TabID;
            moduleInfo.ModuleOrder = 1;
            moduleInfo.ModuleTitle = "";
            moduleInfo.DisplayPrint = false;
            moduleInfo.IsShareable = true;
            moduleInfo.IsShareableViewOnly = true;

            switch (type)
            {
                case ModuleType.DisplayPlugg:
                    moduleInfo.PaneName = "RowTwo_Grid8_Pane";
                    DesktopModuleFriendlyName = "DisplayPlugg";
                    ModuleDefFriendlyName = "DisplayPlugg";
                    break;
                case ModuleType.DisplayCourse:
                    moduleInfo.PaneName = "RowTwo_Grid8_Pane";
                    DesktopModuleFriendlyName = "DisplayCourse";
                    ModuleDefFriendlyName = "DisplayCourse";
                    break;
                case ModuleType.CourseMenu:
                    moduleInfo.PaneName = "RowTwo_Grid4_Pane";
                    DesktopModuleFriendlyName = "CourseMenu";
                    ModuleDefFriendlyName = "CourseMenu";
                    break;
                case ModuleType.Rating:
                    moduleInfo.PaneName = "RowTwo_Grid4_Pane";
                    DesktopModuleFriendlyName = "DNNCentric RnC";
                    ModuleDefFriendlyName = "DNNCentric.RatingAndComments";
                    break;
                case ModuleType.Comments:
                    moduleInfo.PaneName = "RowTwo_Grid8_Pane";
                    DesktopModuleFriendlyName = "DNNCentric RnC";
                    ModuleDefFriendlyName = "DNNCentric.RatingAndComments";
                    break;
                case ModuleType.DisplayPluggeTitle:
                    moduleInfo.PaneName = "RowTwo_Grid4_Pane";
                    DesktopModuleFriendlyName = "DisplayPluggeTitle";
                    ModuleDefFriendlyName = "DisplayPluggeTitle";
                    break;

               }

            DesktopModuleInfo myModule = null;
            foreach (KeyValuePair<int, DesktopModuleInfo> kvp in DesktopModuleController.GetDesktopModules(t.PortalID))
            {
                DesktopModuleInfo mod = kvp.Value;
                if (mod != null)
                    if (mod.FriendlyName == DesktopModuleFriendlyName)
                    {
                        myModule = mod;
                        break;
                    }
            }

            int moduleId=0;
            if (myModule != null)
            {
                var mc = new ModuleDefinitionController();
                var mInfo = new ModuleDefinitionInfo();
                mInfo = ModuleDefinitionController.GetModuleDefinitionByFriendlyName(ModuleDefFriendlyName,
                    myModule.DesktopModuleID);
                moduleInfo.ModuleDefID = mInfo.ModuleDefID;
                moduleInfo.CacheTime = moduleDefinitionInfo.DefaultCacheTime;//Default Cache Time is 0
                moduleInfo.InheritViewPermissions = true;  //Inherit View Permissions from Tab
                moduleInfo.AllTabs = false;
                moduleInfo.Alignment = "Top";

                ModuleController moduleController = new ModuleController();
                moduleId = moduleController.AddModule(moduleInfo);
            }

            DotNetNuke.Common.Utilities.DataCache.ClearModuleCache(t.TabID);
            DotNetNuke.Common.Utilities.DataCache.ClearTabsCache(t.PortalID);
            DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(t.PortalID, false);

            //Add settings for RnC
            ModuleController m = new ModuleController();
            if (type == ModuleType.Rating)
            {
                AddModuleSettingsRnCCommon(moduleId);
                m.UpdateModuleSetting(moduleId, "PRC_settingCommentObject", "tabid:" + t.TabID);
                m.UpdateModuleSetting(moduleId, "PRC_settingShow", "OnlyRatings");
                m.UpdateModuleSetting(moduleId, "PRC_settingRncWidth", "357");
            }
            if (type == ModuleType.Comments)
            {
                AddModuleSettingsRnCCommon(moduleId);
                m.UpdateModuleSetting(moduleId, "PRC_settingCommentObject", "tabid:" + t.TabID);
                m.UpdateModuleSetting(moduleId, "PRC_settingShow", "OnlyComments");
                m.UpdateModuleSetting(moduleId, "PRC_settingRncWidth", "744");
            }

            if (type == ModuleType.Rating || type == ModuleType.Comments)
            {
                RnCController c = new RnCController();
                DCC_PRC_CommentObject myCO = new DCC_PRC_CommentObject();
                myCO.CommentObject = "tabid:" + t.TabID;
                myCO.CommentObjectViewCount = 0;
                myCO.PortalID = t.PortalID;
                c.CreateCommentObject(myCO);
            }
            return moduleId;
        }
예제 #3
0
        /// <summary>
        /// Deserializes the module.
        /// </summary>
        /// <param name="nodeModule">The node module.</param>
        /// <param name="nodePane">The node pane.</param>
        /// <param name="portalId">The portal id.</param>
        /// <param name="tabId">The tab id.</param>
        /// <param name="mergeTabs">The merge tabs.</param>
        /// <param name="hModules">The modules.</param>
        public static void DeserializeModule(XmlNode nodeModule, XmlNode nodePane, int portalId, int tabId, PortalTemplateModuleAction mergeTabs, Hashtable hModules)
        {
            var moduleController = new ModuleController();
            var moduleDefinition = GetModuleDefinition(nodeModule);
            ModuleInfo module;
            //will be instance or module?
            int templateModuleID = XmlUtils.GetNodeValueInt(nodeModule, "moduleID");
            bool isInstance = CheckIsInstance(templateModuleID, hModules);
            if (moduleDefinition != null)
            {
                //If Mode is Merge Check if Module exists
                if (!FindModule(nodeModule, tabId, mergeTabs))
                {
                    module = DeserializeModule(nodeModule, nodePane, portalId, tabId, moduleDefinition.ModuleDefID);

                    //deserialize Module's settings
                    XmlNodeList nodeModuleSettings = nodeModule.SelectNodes("modulesettings/modulesetting");
                    DeserializeModuleSettings(nodeModuleSettings, module);
                    XmlNodeList nodeTabModuleSettings = nodeModule.SelectNodes("tabmodulesettings/tabmodulesetting");
                    DeserializeTabModuleSettings(nodeTabModuleSettings, module);
                    int intModuleId;
                    if (!isInstance)
                    {
                        //Add new module
                        intModuleId = moduleController.AddModule(module);
                        if (templateModuleID > 0)
                        {
                            hModules.Add(templateModuleID, intModuleId);
                        }
                    }
                    else
                    {
                        //Add instance
                        module.ModuleID = Convert.ToInt32(hModules[templateModuleID]);
                        intModuleId = moduleController.AddModule(module);
                    }
                    if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(nodeModule.CreateNavigator(), "content")) && !isInstance)
                    {
                        GetModuleContent(nodeModule, intModuleId, tabId, portalId);
                    }
                    //Process permissions only once
                    if (!isInstance && portalId != Null.NullInteger)
                    {
                        XmlNodeList nodeModulePermissions = nodeModule.SelectNodes("modulepermissions/permission");
                        DeserializeModulePermissions(nodeModulePermissions, portalId, module);

                        //Persist the permissions to the Data base
                        ModulePermissionController.SaveModulePermissions(module);
                    }
                }
            }
        }
        /// <summary>
        ///   SaveTabData saves the Tab to the Database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name = "strAction">The action to perform "edit" or "add"</param>
        /// <history>
        ///   [cnurse]	9/10/2004	Updated to reflect design changes for Help, 508 support
        ///   and localisation
        ///   [jlucarino]	2/26/2009	Added CreatedByUserID and LastModifiedByUserID
        /// </history>
        private int SaveTabData(string strAction)
        {
            string strIcon;
            string strIconLarge;
            strIcon = ctlIcon.Url;
            strIconLarge = ctlIconLarge.Url;

            var objTabs = new TabController();

            Tab.TabName = txtTabName.Text;
            Tab.Title = txtTitle.Text;
            Tab.Description = txtDescription.Text;
            Tab.KeyWords = txtKeyWords.Text;
            Tab.IsVisible = chkMenu.Checked;
            Tab.DisableLink = chkDisableLink.Checked;

            TabInfo parentTab = null;
            if (cboParentTab.SelectedItem != null)
            {
                var parentTabID = Int32.Parse(cboParentTab.SelectedItem.Value);
                var controller = new TabController();
                parentTab = controller.GetTab(parentTabID, -1, false);
            }

            if (parentTab != null)
            {
                Tab.PortalID = parentTab.PortalID;
                Tab.ParentId = parentTab.TabID;
            }
            else
            {
                Tab.ParentId = Null.NullInteger;
            }
            Tab.IconFile = strIcon;
            Tab.IconFileLarge = strIconLarge;
            Tab.IsDeleted = false;
            Tab.Url = ctlURL.Url;

            Tab.TabPermissions.Clear();
            if (Tab.PortalID != Null.NullInteger)
            {
                Tab.TabPermissions.AddRange(dgPermissions.Permissions);
            }

            Tab.Terms.Clear();
            Tab.Terms.AddRange(termsSelector.Terms);

            Tab.SkinSrc = pageSkinCombo.SelectedValue;
            Tab.ContainerSrc = pageContainerCombo.SelectedValue;
            Tab.TabPath = Globals.GenerateTabPath(Tab.ParentId, Tab.TabName);

            //Check for invalid
            if (!IsValidTabName(Tab.TabName))
            {
                return Null.NullInteger;
            }

            //Validate Tab Path
            if (!IsValidTabPath(Tab, Tab.TabPath))
            {
                return Null.NullInteger;
            }

            //Set Culture Code
            var positionTabID = Null.NullInteger;
            if (cboPositionTab.SelectedItem != null)
            {
                positionTabID = Int32.Parse(cboPositionTab.SelectedItem.Value);
            }

            if (strAction != "edit")
            {
                if (PortalSettings.ContentLocalizationEnabled)
                {
                    switch (cultureTypeList.SelectedValue)
                    {
                        case "Localized":
                            var defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalId);
                            Tab.CultureCode = defaultLocale.Code;
                            break;
                        case "Culture":
                            Tab.CultureCode = PortalSettings.CultureCode;
                            break;
                        default:
                            Tab.CultureCode = Null.NullString;
                            break;
                    }

                    var tabLocale = LocaleController.Instance.GetLocale(Tab.CultureCode) ?? LocaleController.Instance.GetDefaultLocale(PortalId);

                    //Fix parent
                    if (Tab.ParentId > Null.NullInteger)
                    {
                        parentTab = objTabs.GetTab(Tab.ParentId, PortalId, false);
                        if (parentTab.CultureCode != Tab.CultureCode)
                        {
                            parentTab = objTabs.GetTabByCulture(Tab.ParentId, PortalId, tabLocale);
                        }
                        Tab.ParentId = parentTab.TabID;
                    }

                    //Fix position TabId
                    if (positionTabID > Null.NullInteger)
                    {
                        var positionTab = objTabs.GetTab(positionTabID, PortalId, false);
                        if (positionTab.CultureCode != Tab.CultureCode)
                        {
                            positionTab = objTabs.GetTabByCulture(positionTabID, PortalId, tabLocale);
                        }
                        positionTabID = positionTab.TabID;
                    }
                }
                else
                {
                    Tab.CultureCode = Null.NullString;
                }
            }

            //Validate Tab Path
            if (string.IsNullOrEmpty(strAction))
            {
                var tabID = TabController.GetTabByTabPath(Tab.PortalID, Tab.TabPath, Tab.CultureCode);

                if (tabID != Null.NullInteger)
                {
                    var existingTab = objTabs.GetTab(tabID, PortalId, false);
                    if (existingTab != null && existingTab.IsDeleted)
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabRecycled", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
                    }
                    else
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    }
                    return Null.NullInteger;
                }
            }

            Tab.StartDate = datepickerStartDate.SelectedDate != null ? datepickerStartDate.SelectedDate.Value : Null.NullDate;
            Tab.EndDate = datepickerEndDate.SelectedDate != null ? datepickerEndDate.SelectedDate.Value : Null.NullDate;

            if (Tab.StartDate > Null.NullDate && Tab.EndDate > Null.NullDate && Tab.StartDate.AddDays(1) >= Tab.EndDate)
            {
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("InvalidTabDates", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return Null.NullInteger;
            }
            if (txtRefreshInterval.Text.Length > 0 && Regex.IsMatch(txtRefreshInterval.Text, "^\\d+$"))
            {
                Tab.RefreshInterval = Convert.ToInt32(txtRefreshInterval.Text);
            }

            Tab.SiteMapPriority = float.Parse(txtPriority.Text);
            Tab.PageHeadText = txtPageHeadText.Text;
            Tab.IsSecure = chkSecure.Checked;
            Tab.PermanentRedirect = chkPermanentRedirect.Checked;

            if (strAction == "edit")
            {
                // trap circular tab reference
                if (cboParentTab.SelectedItem != null && Tab.TabID != Int32.Parse(cboParentTab.SelectedItem.Value) && !IsCircularReference(Int32.Parse(cboParentTab.SelectedItem.Value), Tab.PortalID))
                {
                    objTabs.UpdateTab(Tab);
                    if (IsHostMenu && Tab.PortalID != Null.NullInteger)
                    {
                        //Host Tab moved to Portal so clear Host cache
                        objTabs.ClearCache(Null.NullInteger);
                    }
                    if (!IsHostMenu && Tab.PortalID == Null.NullInteger)
                    {
                        //Portal Tab moved to Host so clear portal cache
                        objTabs.ClearCache(PortalId);
                    }
                    UpdateTabSettings(Tab.TabID);
                }
                // add or copy
            }
            else
            {
                if (positionTabID == Null.NullInteger)
                {
                    Tab.TabID = objTabs.AddTab(Tab);
                }
                else
                {
                    if (rbInsertPosition.SelectedValue == "After" && positionTabID > Null.NullInteger)
                    {
                        Tab.TabID = objTabs.AddTabAfter(Tab, positionTabID);
                    }
                    else if (rbInsertPosition.SelectedValue == "Before" && positionTabID > Null.NullInteger)
                    {
                        Tab.TabID = objTabs.AddTabBefore(Tab, positionTabID);
                    }
                    else
                    {
                        Tab.TabID = objTabs.AddTab(Tab);
                    }
                }

                UpdateTabSettings(Tab.TabID);

                //Create Localized versions
                if (PortalSettings.ContentLocalizationEnabled && cultureTypeList.SelectedValue == "Localized")
                {
                    objTabs.CreateLocalizedCopies(Tab);
                    //Refresh tab
                    _tab = objTabs.GetTab(Tab.TabID, Tab.PortalID, true);
                }

                var copyTabId = Int32.Parse(cboCopyPage.SelectedItem.Value);
                if (copyTabId != -1)
                {
                    var objModules = new ModuleController();
                    ModuleInfo objModule;
                    CheckBox chkModule;
                    RadioButton optCopy;
                    RadioButton optReference;
                    TextBox txtCopyTitle;

                    foreach (DataGridItem objDataGridItem in grdModules.Items)
                    {
                        chkModule = (CheckBox)objDataGridItem.FindControl("chkModule");
                        if (chkModule.Checked)
                        {
                            var intModuleID = Convert.ToInt32(grdModules.DataKeys[objDataGridItem.ItemIndex]);
                            optCopy = (RadioButton)objDataGridItem.FindControl("optCopy");
                            optReference = (RadioButton)objDataGridItem.FindControl("optReference");
                            txtCopyTitle = (TextBox)objDataGridItem.FindControl("txtCopyTitle");

                            objModule = objModules.GetModule(intModuleID, copyTabId, false);
                            ModuleInfo newModule = null;
                            if ((objModule != null))
                            {
                                //Clone module as it exists in the cache and changes we make will update the cached object
                                newModule = objModule.Clone();

                                if (!optReference.Checked)
                                {
                                    newModule.ModuleID = Null.NullInteger;
                                }

                                newModule.TabID = Tab.TabID;
                                newModule.DefaultLanguageGuid = Null.NullGuid;
                                newModule.CultureCode = Tab.CultureCode;
                                newModule.ModuleTitle = txtCopyTitle.Text;
                                newModule.ModuleID = objModules.AddModule(newModule);

                                if (optCopy.Checked)
                                {
                                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                                    {
                                        var objObject = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                                        if (objObject is IPortable)
                                        {
                                            var content = Convert.ToString(((IPortable)objObject).ExportModule(intModuleID));
                                            if (!string.IsNullOrEmpty(content))
                                            {
                                                ((IPortable)objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, UserInfo.UserID);
                                            }
                                        }
                                    }
                                }
                            }

                            if (optReference.Checked)
                            {
                                //Make reference copies on secondary language
                                foreach (var m in objModule.LocalizedModules.Values)
                                {
                                    var newLocalizedModule = m.Clone();
                                    var localizedTab = Tab.LocalizedTabs[m.CultureCode];
                                    newLocalizedModule.TabID = localizedTab.TabID;
                                    newLocalizedModule.CultureCode = localizedTab.CultureCode;
                                    newLocalizedModule.ModuleTitle = txtCopyTitle.Text;
                                    newLocalizedModule.DefaultLanguageGuid = newModule.UniqueId;
                                    newLocalizedModule.ModuleID = objModules.AddModule(newLocalizedModule);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // create the page from a template
                    if (cboTemplate.SelectedItem != null && cboTemplate.SelectedItem.Value != Null.NullInteger.ToString())
                    {
                        var xmlDoc = new XmlDocument();
                        try
                        {
                            // open the XML file
                            xmlDoc.Load(PortalSettings.HomeDirectoryMapPath + cboFolders.SelectedValue + cboTemplate.SelectedValue);
                        }
                        catch (Exception ex)
                        {
                            Exceptions.LogException(ex);

                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("BadTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return Null.NullInteger;
                        }
                        TabController.DeserializePanes(xmlDoc.SelectSingleNode("//portal/tabs/tab/panes"), Tab.PortalID, Tab.TabID, PortalTemplateModuleAction.Ignore, new Hashtable());
                        //save tab permissions
                        RibbonBarManager.DeserializeTabPermissions(xmlDoc.SelectNodes("//portal/tabs/tab/tabpermissions/permission"), Tab);

                        var tabIndex = 0;
                        var exceptions = string.Empty;
                        foreach (XmlNode tabNode in xmlDoc.SelectSingleNode("//portal/tabs").ChildNodes)
                        {
                            //Create second tab onward tabs. Note first tab is already created above.
                            if(tabIndex > 0)
                            {
                                try
                                {
                                    TabController.DeserializeTab(tabNode, null, PortalId, PortalTemplateModuleAction.Replace);
                                }
                                catch (Exception ex)
                                {
                                    Exceptions.LogException(ex);
                                    exceptions += string.Format("Template Tab # {0}. Error {1}<br/>", tabIndex + 1, ex.Message);
                                }
                            }
                            tabIndex++;
                        }

                        if (!string.IsNullOrEmpty(exceptions))
                        {
                            UI.Skins.Skin.AddModuleMessage(this, exceptions, ModuleMessage.ModuleMessageType.RedError);
                            return Null.NullInteger;
                        }
                    }
                }
            }

            // url tracking
            var objUrls = new UrlController();
            objUrls.UpdateUrl(PortalId, ctlURL.Url, ctlURL.UrlType, 0, Null.NullDate, Null.NullDate, ctlURL.Log, ctlURL.Track, Null.NullInteger, ctlURL.NewWindow);

            //Clear the Tab's Cached modules
            DataCache.ClearModuleCache(TabId);

            //Update Cached Tabs as TabPath may be needed before cache is cleared
            TabInfo tempTab;
            if (new TabController().GetTabsByPortal(PortalId).TryGetValue(Tab.TabID, out tempTab))
            {
                tempTab.TabPath = Tab.TabPath;
            }

            //Update Translation Status
            objTabs.UpdateTranslationStatus(Tab, translatedCheckbox.Checked);

            return Tab.TabID;
        }
예제 #5
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Adds an Existing Module to a Pane
        /// </summary>
        /// <param name="align">The alignment for the Modue</param>
        /// <param name="moduleId">The Id of the existing module</param>
        /// <param name="tabId">The id of the tab</param>
        /// <param name="paneName">The pane to add the module to</param>
        /// <param name="position">The relative position within the pane for the module</param>
        /// <history>
        /// 	[cnurse]	01/11/2008  documented
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void AddExistingModule(int moduleId, int tabId, string paneName, int position, string align)
        {
            var objModules = new ModuleController();
            ModuleInfo objModule;
            var objEventLog = new EventLogController();

            int UserId = -1;
            if (Request.IsAuthenticated)
            {
                UserInfo objUserInfo = UserController.GetCurrentUserInfo();
                UserId = objUserInfo.UserID;
            }
            objModule = objModules.GetModule(moduleId, tabId, false);
            if (objModule != null)
            {
                //clone the module object ( to avoid creating an object reference to the data cache )
                ModuleInfo objClone = objModule.Clone();
                objClone.TabID = PortalSettings.ActiveTab.TabID;
                objClone.ModuleOrder = position;
                objClone.PaneName = paneName;
                objClone.Alignment = align;
                objModules.AddModule(objClone);
                objEventLog.AddLog(objClone, PortalSettings, UserId, "", EventLogController.EventLogType.MODULE_CREATED);
            }
        }
        private int DoAddNewModule(string title, int desktopModuleId, string paneName, int position, int permissionType, string align)
        {
            var objModules = new ModuleController();
            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(PortalSettings.Current.PortalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

	        var tabModuleId = Null.NullInteger;
            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.Initialize(PortalSettings.Current.ActiveTab.PortalID);

                objModule.PortalID = PortalSettings.Current.ActiveTab.PortalID;
                objModule.TabID = PortalSettings.Current.ActiveTab.TabID;
                objModule.ModuleOrder = position;
                objModule.ModuleTitle = string.IsNullOrEmpty(title) ? objModuleDefinition.FriendlyName : title;
                objModule.PaneName = paneName;
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                if (objModuleDefinition.DefaultCacheTime > 0)
                {
                    objModule.CacheTime = objModuleDefinition.DefaultCacheTime;
                    if (PortalSettings.Current.DefaultModuleId > Null.NullInteger && PortalSettings.Current.DefaultTabId > Null.NullInteger)
                    {
                        ModuleInfo defaultModule = objModules.GetModule(PortalSettings.Current.DefaultModuleId, PortalSettings.Current.DefaultTabId, true);
                        if ((defaultModule != null))
                        {
                            objModule.CacheTime = defaultModule.CacheTime;
                        }
                    }
                }

				objModules.InitialModulePermission(objModule, objModule.TabID, permissionType);

                if (PortalSettings.Current.ContentLocalizationEnabled)
                {
                    Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalSettings.Current.PortalId);
                    //set the culture of the module to that of the tab
                    var tabInfo = new TabController().GetTab(objModule.TabID, PortalSettings.Current.PortalId, false);
                    objModule.CultureCode = tabInfo != null ? tabInfo.CultureCode : defaultLocale.Code;
                }
                else
                {
                    objModule.CultureCode = Null.NullString;
                }
                objModule.AllTabs = false;
                objModule.Alignment = align;

                objModules.AddModule(objModule);

				if (tabModuleId == Null.NullInteger)
				{
					tabModuleId = objModule.ModuleID;
				}
				//update the position to let later modules with add after previous one.
	            position = objModules.GetTabModule(objModule.TabModuleID).ModuleOrder + 1;
            }

			return tabModuleId;
        }
예제 #7
0
        /// <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 );
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// SaveTabData saves the Tab to the Database
        /// </summary>
        /// <param name="action">The action to perform "edit" or "add"</param>
        /// <history>
        /// 	[cnurse]	9/10/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        public int SaveTabData( string action )
        {
            EventLogController objEventLog = new EventLogController();

            string strIcon = ctlIcon.Url;

            TabController objTabs = new TabController();

            TabInfo objTab = new TabInfo();

            objTab.TabID = TabId;
            objTab.PortalID = PortalId;
            objTab.TabName = txtTabName.Text;
            objTab.Title = txtTitle.Text;
            objTab.Description = txtDescription.Text;
            objTab.KeyWords = txtKeyWords.Text;
            objTab.IsVisible = ! chkHidden.Checked;
            objTab.DisableLink = chkDisableLink.Checked;
            objTab.ParentId = int.Parse( cboTab.SelectedItem.Value );
            objTab.IconFile = strIcon;
            objTab.IsDeleted = false;
            objTab.Url = ctlURL.Url;
            objTab.TabPermissions = dgPermissions.Permissions;
            objTab.SkinSrc = ctlSkin.SkinSrc;
            objTab.ContainerSrc = ctlContainer.SkinSrc;
            objTab.TabPath = Globals.GenerateTabPath(objTab.ParentId, objTab.TabName);
            if( !String.IsNullOrEmpty(txtStartDate.Text) )
            {
                objTab.StartDate = Convert.ToDateTime( txtStartDate.Text );
            }
            else
            {
                objTab.StartDate = Null.NullDate;
            }
            if( !String.IsNullOrEmpty(txtEndDate.Text) )
            {
                objTab.EndDate = Convert.ToDateTime( txtEndDate.Text );
            }
            else
            {
                objTab.EndDate = Null.NullDate;
            }
            int refreshInt;
            if( txtRefreshInterval.Text.Length > 0 && Int32.TryParse(txtRefreshInterval.Text, out refreshInt ) )
            {
                objTab.RefreshInterval = Convert.ToInt32( txtRefreshInterval.Text );
            }
            objTab.PageHeadText = txtPageHeadText.Text;

            if( action == "edit" )
            {
                // trap circular tab reference
                if( objTab.TabID != int.Parse( cboTab.SelectedItem.Value ) && ! IsCircularReference( int.Parse( cboTab.SelectedItem.Value ) ) )
                {
                    objTabs.UpdateTab( objTab );
                    objEventLog.AddLog( objTab, PortalSettings, UserId, "", EventLogController.EventLogType.TAB_UPDATED );
                }
            }
            else // add or copy
            {
                objTab.TabID = objTabs.AddTab( objTab );
                objEventLog.AddLog( objTab, PortalSettings, UserId, "", EventLogController.EventLogType.TAB_CREATED );

                if( int.Parse( cboCopyPage.SelectedItem.Value ) != - 1 )
                {
                    ModuleController objModules = new ModuleController();

                    foreach( DataGridItem objDataGridItem in grdModules.Items )
                    {
                        CheckBox chkModule = (CheckBox)objDataGridItem.FindControl( "chkModule" );
                        if( chkModule.Checked )
                        {
                            int intModuleID = Convert.ToInt32( grdModules.DataKeys[ objDataGridItem.ItemIndex ] );
                            //RadioButton optNew = (RadioButton)objDataGridItem.FindControl( "optNew" );
                            RadioButton optCopy = (RadioButton)objDataGridItem.FindControl( "optCopy" );
                            RadioButton optReference = (RadioButton)objDataGridItem.FindControl( "optReference" );
                            TextBox txtCopyTitle = (TextBox)objDataGridItem.FindControl( "txtCopyTitle" );
                            
                            ModuleInfo objModule = objModules.GetModule( intModuleID, Int32.Parse( cboCopyPage.SelectedItem.Value ), false );
                            if( objModule != null )
                            {
                                if( ! optReference.Checked )
                                {
                                    objModule.ModuleID = Null.NullInteger;
                                }

                                objModule.TabID = objTab.TabID;
                                objModule.ModuleTitle = txtCopyTitle.Text;
                                objModule.ModuleID = objModules.AddModule( objModule );

                                if( optCopy.Checked )
                                {
                                    if( !String.IsNullOrEmpty(objModule.BusinessControllerClass) )
                                    {
                                        object objObject = Reflection.CreateObject( objModule.BusinessControllerClass, objModule.BusinessControllerClass );
                                        if( objObject is IPortable )
                                        {
                                            try
                                            {
                                                string Content = Convert.ToString( ( (IPortable)objObject ).ExportModule( intModuleID ) );
                                                if( !String.IsNullOrEmpty(Content) )
                                                {
                                                    ( (IPortable)objObject ).ImportModule( objModule.ModuleID, Content, objModule.Version, UserInfo.UserID );
                                                }
                                            }
                                            catch( Exception exc )
                                            {
                                                // the export/import operation failed
                                                Exceptions.ProcessModuleLoadException( this, exc );
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // create the page from a template
                    if( cboTemplate.SelectedItem != null )
                    {
                        if( !String.IsNullOrEmpty(cboTemplate.SelectedItem.Value) )
                        {
                            // open the XML file
                            try
                            {
                                XmlDocument xmlDoc = new XmlDocument();
                                xmlDoc.Load( cboTemplate.SelectedItem.Value );
                                PortalController objPortals = new PortalController();
                                objPortals.ParsePanes( xmlDoc.SelectSingleNode( "//portal/tabs/tab/panes" ), objTab.PortalID, objTab.TabID, PortalTemplateModuleAction.Ignore, new Hashtable() );
                            }
                            catch
                            {
                                // error opening page template
                            }
                        }
                    }
                }
            }

            // url tracking
            UrlController objUrls = new UrlController();
            objUrls.UpdateUrl( PortalId, ctlURL.Url, ctlURL.UrlType, 0, Null.NullDate, Null.NullDate, ctlURL.Log, ctlURL.Track, Null.NullInteger, ctlURL.NewWindow );

            return objTab.TabID;
        }
        /// <summary>
        /// Copies the module to page.
        /// </summary>
        /// <param name="moduleToCopy">The module to copy.</param>
        /// <param name="destinationTabID">The destination tab ID.</param>
        private static void CopyModuleToPage(ModuleInfo moduleToCopy, int destinationTabID)
        {
            var  moduleController = new ModuleController();

            // duplicate the module and assign it the new page
            ModuleInfo newModule = moduleToCopy.Clone();
            newModule.ModuleID = -1;
            newModule.TabID = destinationTabID;

            // add it to the system - this takes care of adding the 
            // module and the tab module
            newModule.ModuleID = moduleController.AddModule(newModule);

            // duplicate the settings for the module
            DuplicateModuleSettings(moduleToCopy, newModule.ModuleID);

            // duplicate the settings for the tabmodule
            moduleController.CopyTabModuleSettings(moduleToCopy, newModule);
        }
예제 #10
0
        /// <summary>
        /// AddModuleToPage adds a module to a Page
        /// </summary>
        /// <remarks>
        /// </remarks>
        ///	<param name="page">The Page to add the Module to</param>
        ///	<param name="ModuleDefId">The Module Deinition Id for the module to be aded to this tab</param>
        ///	<param name="ModuleTitle">The Module's title</param>
        ///	<param name="ModuleIconFile">The Module's icon</param>
        ///	<param name="InheritPermissions">Inherit the Pages View Permisions</param>
        private static void AddModuleToPage(TabInfo page, int ModuleDefId, string ModuleTitle, string ModuleIconFile, bool InheritPermissions)
        {
            ModuleController objModules = new ModuleController();
            ModuleInfo objModule;

            bool blnDuplicate = false;
            foreach (KeyValuePair<int, ModuleInfo> kvp in objModules.GetTabModules(page.TabID))
            {
                objModule = kvp.Value;
                if (objModule.ModuleDefID == ModuleDefId)
                {
                    blnDuplicate = true;
                }
            }

            if (!blnDuplicate)
            {
                objModule = new ModuleInfo();
                objModule.ModuleID = Null.NullInteger;
                objModule.PortalID = page.PortalID;
                objModule.TabID = page.TabID;
                objModule.ModuleOrder = -1;
                objModule.ModuleTitle = ModuleTitle;
                objModule.PaneName = Globals.glbDefaultPane;
                objModule.ModuleDefID = ModuleDefId;
                objModule.CacheTime = 0;
                objModule.IconFile = ModuleIconFile;
                objModule.AllTabs = false;
                objModule.Visibility = VisibilityState.Maximized;
                objModule.InheritViewPermissions = InheritPermissions;

                try
                {
                    objModules.AddModule(objModule);
                }
                catch
                {
                    // error adding module
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Adds the module to page.
        /// </summary>
        /// <param name="portalId">The portal id.</param>
        /// <param name="tabId">The tab id.</param>
        /// <exception cref="System.ArgumentException">desktopModuleId</exception>
        private void AddModuleToPage(int portalId, int tabId)
        {
            TabPermissionCollection objTabPermissions = new TabController().GetTab(tabId, portalId, false).TabPermissions;
            var objPermissionController = new PermissionController();
            var objModules = new ModuleController();
            new EventLogController();

            int desktopModuleId =
                DesktopModuleController.GetDesktopModuleByFriendlyName("VanityURLs").DesktopModuleID;

            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(portalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.PortalID = portalId;
                objModule.TabID = tabId;
                objModule.ModuleOrder = 0;
                objModule.ModuleTitle = objModuleDefinition.FriendlyName;
                objModule.PaneName = "ContentPane";
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                objModule.InheritViewPermissions = true;
                objModule.CultureCode = Null.NullString;
                objModule.AllTabs = false;
                objModules.AddModule(objModule);
            }
        }
예제 #12
0
        protected void btnAddModule_Click(object sender, EventArgs e)
        {
            string DesktopModuleFriendlyName = "DNNDal2";
            ModuleDefinitionInfo moduleDefinitionInfo = new ModuleDefinitionInfo();
            ModuleInfo moduleInfo = new ModuleInfo();
            moduleInfo.PortalID = 0;
            moduleInfo.TabID = 150;
            moduleInfo.PaneName = "TopPane";
            moduleInfo.ModuleDefID = 160;
            moduleInfo.CacheTime = moduleDefinitionInfo.DefaultCacheTime;//Default Cache Time is 0
            moduleInfo.InheritViewPermissions = true;  //Inherit View Permissions from Tab
            moduleInfo.AllTabs = false;
            moduleInfo.Alignment = "Top";

            ModuleController moduleController = new ModuleController();
            int moduleId = moduleController.AddModule(moduleInfo);
        }
        public static void DeserializeModule(XmlNode nodeModule, XmlNode nodePane, int portalId, int tabId,
                                             PortalTemplateModuleAction mergeTabs, Hashtable hModules)
        {
            var moduleController = new ModuleController();
            var objModuleDefinition = GetModuleDefinition(nodeModule);

            // will be instance or module
            var templateModuleId = XmlUtils.GetNodeValueInt(nodeModule, "moduleID");
            var isInstance = CheckIsInstance(templateModuleId, hModules);

            //remove containersrc node if container is missing
            var containerNode = nodeModule.SelectSingleNode("containersrc");
            if (containerNode != null)
            {
                var container = containerNode.Value;
                if (! File.Exists(HttpContext.Current.Server.MapPath(container)))
                {
                    nodeModule.RemoveChild(containerNode);
                }
            }

            if (objModuleDefinition != null)
            {
                //If Mode is Merge Check if Module exists
                if (! FindModule(nodeModule, tabId, mergeTabs))
                {
                    var module = DeserializeModule(nodeModule, nodePane, portalId, tabId,
                                                   objModuleDefinition.ModuleDefID);

                    int intModuleId;
                    if (! isInstance)
                    {
                        //Add new module
                        intModuleId = moduleController.AddModule(module);
                        if (templateModuleId > 0)
                        {
                            hModules.Add(templateModuleId, intModuleId);
                        }
                    }
                    else
                    {
                        //Add instance
                        module.ModuleID = Convert.ToInt32(hModules[templateModuleId]);
                        intModuleId = moduleController.AddModule(module);
                    }

                    if (XmlUtils.GetNodeValue(nodeModule, "content", "") != "")
                    {
                        GetModuleContent(nodeModule, intModuleId, tabId, portalId, isInstance);
                    }

                    // Process permissions and moduleSettings only once
                    if (! isInstance)
                    {
                        var nodeModulePermissions = nodeModule.SelectNodes("modulepermissions/permission");
                        DeserializeModulePermissions(nodeModulePermissions, portalId, module);

                        //Persist the permissions to the Data base
                        ModulePermissionController.SaveModulePermissions(module);

                        var nodeModuleSettings = nodeModule.SelectNodes("modulesettings/setting");
                        DeserializeModuleSettings(nodeModuleSettings, intModuleId);
                    }

                    //apply TabModuleSettings
                    var nodeTabModuleSettings = nodeModule.SelectNodes("tabmodulesettings/setting");
                    DeserializeTabModuleSettings(nodeTabModuleSettings, intModuleId, tabId);
                }
            }
        }
        private static void GenerateAdminTab(int PortalId)
        {
            var tabID = TabController.GetTabByTabPath(PortalId, @"//Admin//OpenUrlRewriter", Null.NullString);
            if (tabID == Null.NullInteger)
            {
                var adminTabID = TabController.GetTabByTabPath(PortalId, @"//Admin", Null.NullString);

                /* dont work on dnn 7 -  generate new section "SEO Features" in admin menu

                var tabName = "SEO Features";
                var tabPath = Globals.GenerateTabPath(adminTabID, tabName);
                tabID = TabController.GetTabByTabPath(PortalId, tabPath, Null.NullString);
                if (tabID == Null.NullInteger)
                {
                    //Create a new page
                    var newParentTab = new TabInfo();
                    newParentTab.TabName = tabName;
                    newParentTab.ParentId = adminTabID;
                    newParentTab.PortalID = PortalId;
                    newParentTab.IsVisible = true;
                    newParentTab.DisableLink = true;
                    newParentTab.TabID = new TabController().AddTab(newParentTab);
                    tabID = newParentTab.TabID;
                }
                 */

                // create new page "Url Rules Cache"
                int parentTabID = adminTabID;
                var tabName = "Open Url Rewriter";
                var tabPath = Globals.GenerateTabPath(parentTabID, tabName);
                tabID = TabController.GetTabByTabPath(PortalId, tabPath, Null.NullString);
                if (tabID == Null.NullInteger)
                {
                    //Create a new page
                    var newTab = new TabInfo();
                    newTab.TabName = tabName;
                    newTab.ParentId = parentTabID;
                    newTab.PortalID = PortalId;
                    newTab.IsVisible = true;
            #if DNN71
                    newTab.IconFile = "~/Icons/Sigma/AdvancedUrlMngmt_16x16.png";
                    newTab.IconFileLarge = "~/Icons/Sigma/AdvancedUrlMngmt_32x32.png";
            #else
                    newTab.IconFile = "~/Images/icon_search_16px.gif";
                    newTab.IconFileLarge = "~/Images/icon_search_32px.gif";
            #endif
                    newTab.TabID = new TabController().AddTab(newTab, false);
                    tabID = newTab.TabID;

                }
            }
            // create new module "OpenUrlRewriter"
            var moduleCtl = new ModuleController();
            if (moduleCtl.GetTabModules(tabID).Count == 0)
            {
                var dmc = new DesktopModuleController();
                var dm = dmc.GetDesktopModuleByModuleName("OpenUrlRewriter");
                var mdc = new ModuleDefinitionController();
                var md = mdc.GetModuleDefinitionByName(dm.DesktopModuleID, "OpenUrlRewriter");

                var objModule = new ModuleInfo();
                //objModule.Initialize(PortalId);
                objModule.PortalID = PortalId;
                objModule.TabID = tabID;
                objModule.ModuleOrder = Null.NullInteger;
                objModule.ModuleTitle = "Open Url Rewriter";
                objModule.PaneName = Globals.glbDefaultPane;
                objModule.ModuleDefID = md.ModuleDefID;
                objModule.InheritViewPermissions = true;
                objModule.AllTabs = false;
            #if DNN71
                objModule.IconFile = "~/Icons/Sigma/AdvancedUrlMngmt_16x16.png";
            #else
                objModule.IconFile = "~/Images/icon_search_32px.gif";
            #endif
                moduleCtl.AddModule(objModule);
            }
        }
예제 #15
0
        //this has an overload of whether or not to create a cloned module
        private void DoAddExistingModule(int moduleId, int tabId, string paneName, int position, string align, bool cloneModule)
        {
            var moduleCtrl = new ModuleController();
            ModuleInfo moduleInfo = moduleCtrl.GetModule(moduleId, tabId, false);

            int userID = -1;
            if (Request.IsAuthenticated)
            {
                UserInfo user = UserController.GetCurrentUserInfo();
                if (((user != null)))
                {
                    userID = user.UserID;
                }
            }

            if ((moduleInfo != null))
            {
                // clone the module object ( to avoid creating an object reference to the data cache )
                ModuleInfo newModule = moduleInfo.Clone();

                newModule.UniqueId = Guid.NewGuid(); // Cloned Module requires a different uniqueID

                newModule.TabID = PortalSettings.Current.ActiveTab.TabID;
                newModule.ModuleOrder = position;
                newModule.PaneName = paneName;
                newModule.Alignment = align;

                if ((cloneModule))
                {
                    newModule.ModuleID = Null.NullInteger;
                    //reset the module id
                    newModule.ModuleID = moduleCtrl.AddModule(newModule);

                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                    {
                        object objObject = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                        if (objObject is IPortable)
                        {
                            string content = Convert.ToString(((IPortable) objObject).ExportModule(moduleId));
                            if (!string.IsNullOrEmpty(content))
                            {
                                ((IPortable) objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, userID);
                            }
                        }
                    }
                }
                else
                {
                    moduleCtrl.AddModule(newModule);
                }

                //Add Event Log
                var objEventLog = new EventLogController();
                objEventLog.AddLog(newModule, PortalSettings.Current, userID, "", EventLogController.EventLogType.MODULE_CREATED);
            }
        }
        private static void DoAddNewModule(string title, int desktopModuleId, string paneName, int position, int permissionType, string align)
        {
            var objModules = new ModuleController();

            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(PortalSettings.Current.PortalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var objModule = new ModuleInfo();
                objModule.Initialize(PortalSettings.Current.ActiveTab.PortalID);

                objModule.PortalID = PortalSettings.Current.ActiveTab.PortalID;
                objModule.TabID = PortalSettings.Current.ActiveTab.TabID;
                objModule.ModuleOrder = position;
                objModule.ModuleTitle = string.IsNullOrEmpty(title) ? objModuleDefinition.FriendlyName : title;
                objModule.PaneName = paneName;
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                if (objModuleDefinition.DefaultCacheTime > 0)
                {
                    objModule.CacheTime = objModuleDefinition.DefaultCacheTime;
                    if (PortalSettings.Current.DefaultModuleId > Null.NullInteger && PortalSettings.Current.DefaultTabId > Null.NullInteger)
                    {
                        ModuleInfo defaultModule = objModules.GetModule(PortalSettings.Current.DefaultModuleId, PortalSettings.Current.DefaultTabId, true);
                        if ((defaultModule != null))
                        {
                            objModule.CacheTime = defaultModule.CacheTime;
                        }
                    }
                }

                objModules.InitialModulePermission(objModule, objModule.TabID, permissionType);

                if (PortalSettings.Current.ContentLocalizationEnabled)
                {
                    Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalSettings.Current.PortalId);
                    //check whether original tab is exists, if true then set culture code to default language,
                    //otherwise set culture code to current.
                    if (new TabController().GetTabByCulture(objModule.TabID, PortalSettings.Current.PortalId, defaultLocale) != null)
                    {
                        objModule.CultureCode = defaultLocale.Code;
                    }
                    else
                    {
                        objModule.CultureCode = PortalSettings.Current.CultureCode;
                    }
                }
                else
                {
                    objModule.CultureCode = Null.NullString;
                }
                objModule.AllTabs = false;
                objModule.Alignment = align;

                objModules.AddModule(objModule);
            }
        }
예제 #17
0
        private int DoAddExistingModule(int moduleId, int tabId, string paneName, int position, string align, bool cloneModule)
        {
            var moduleCtrl = new ModuleController();
            ModuleInfo moduleInfo = moduleCtrl.GetModule(moduleId, tabId, false);

            int userID = -1;
          
            UserInfo user = UserController.GetCurrentUserInfo();
            if (user != null)
            {
                userID = user.UserID;
            }
            

            if ((moduleInfo != null))
            {
                // Is this from a site other than our own? (i.e., is the user requesting "module sharing"?)
                var remote = moduleInfo.PortalID != PortalSettings.Current.PortalId;
                if (remote)
                {
                    switch (moduleInfo.DesktopModule.Shareable)
                    {
                        case ModuleSharing.Unsupported:
                            // Should never happen since the module should not be listed in the first place.
                            throw new ApplicationException(string.Format("Module '{0}' does not support Shareable and should not be listed in Add Existing Module from a different source site",
                                                                         moduleInfo.DesktopModule.FriendlyName));
                        case ModuleSharing.Supported:
                            break;
                        case ModuleSharing.Unknown:
                            break;
                    }
                }

                // clone the module object ( to avoid creating an object reference to the data cache )
                ModuleInfo newModule = moduleInfo.Clone();

                newModule.UniqueId = Guid.NewGuid(); // Cloned Module requires a different uniqueID

                newModule.TabID = PortalSettings.Current.ActiveTab.TabID;
                newModule.ModuleOrder = position;
                newModule.PaneName = paneName;
                newModule.Alignment = align;

                if ((cloneModule))
                {
                    newModule.ModuleID = Null.NullInteger;
                    //reset the module id
                    newModule.ModuleID = moduleCtrl.AddModule(newModule);

                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                    {
                        object objObject = DotNetNuke.Framework.Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                        if (objObject is IPortable)
                        {
                            string content = Convert.ToString(((IPortable)objObject).ExportModule(moduleId));
                            if (!string.IsNullOrEmpty(content))
                            {
                                ((IPortable)objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, userID);
                            }
                        }
                    }
                }
                else
                {
                    moduleCtrl.AddModule(newModule);
                }

                if (remote)
                {
                    //Ensure the Portal Admin has View rights
                    var permissionController = new PermissionController();
                    ArrayList arrSystemModuleViewPermissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");
                    AddModulePermission(newModule,
                                    (PermissionInfo)arrSystemModuleViewPermissions[0],
                                    PortalSettings.Current.AdministratorRoleId,
                                    Null.NullInteger,
                                    true);

                    //Set PortalID correctly
                    newModule.OwnerPortalID = newModule.PortalID;
                    newModule.PortalID = PortalSettings.Current.PortalId;
                    ModulePermissionController.SaveModulePermissions(newModule);
                }

                //Add Event Log
                var objEventLog = new EventLogController();
                objEventLog.AddLog(newModule, PortalSettings.Current, userID, "", EventLogController.EventLogType.MODULE_CREATED);

                return newModule.ModuleID;
            }

            return -1;
        }
        protected void AddExistingModule(int moduleId, int tabId, string paneName, int position, string align)
        {

            ModuleController objModules = new ModuleController();
            Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();

            int UserId = -1;
            if (Request.IsAuthenticated)
            {
                UserInfo objUserInfo = UserController.GetCurrentUserInfo();
                UserId = objUserInfo.UserID;
            }

            ModuleInfo objModule = objModules.GetModule(moduleId, tabId, false);
            if (objModule != null)
            {
                objModule.TabID = PortalSettings.ActiveTab.TabID;
                objModule.ModuleOrder = position;
                objModule.PaneName = paneName;
                objModule.Alignment = align;
                objModules.AddModule(objModule);
                objEventLog.AddLog(objModule, PortalSettings, UserId, "", Services.Log.EventLog.EventLogController.EventLogType.MODULE_CREATED);
            }


        }
		protected void cmdCreate_Click(object sender, EventArgs e)
		{
			try
			{
				ModuleDefinitionInfo moduleDefinition = null;
				string strMessage = Null.NullString;
				switch (cboCreate.SelectedValue)
				{
					case "":
						break;
					case "New":
						if (String.IsNullOrEmpty(cboModule.SelectedValue))
						{
							strMessage = Localization.GetString("ModuleFolder", LocalResourceFile);
							break;
						}

						if (String.IsNullOrEmpty(rblLanguage.SelectedValue))
						{
							strMessage = Localization.GetString("LanguageError", LocalResourceFile);
							break;
						}

						//remove spaces so file is created correctly
						var controlSrc = txtFile.Text.Replace(" ", "");
						if (InvalidFilename(controlSrc))
						{
							strMessage = Localization.GetString("InvalidFilename", LocalResourceFile);
							break;
						}

						if (String.IsNullOrEmpty(controlSrc))
						{
							strMessage = Localization.GetString("MissingControl", LocalResourceFile);
							break;
						}
						if (String.IsNullOrEmpty(txtName.Text))
						{
							strMessage = Localization.GetString("MissingFriendlyname", LocalResourceFile);
							break;
						}
						if (!controlSrc.EndsWith(".ascx"))
						{
							controlSrc += ".ascx";
						}

						var uniqueName = true;
						var packages = new List<PackageInfo>();
						foreach (var package in PackageController.GetPackages())
						{
							if (package.Name == txtName.Text || package.FriendlyName == txtName.Text)
							{
								uniqueName = false;
								break;
							}
						}

						if (!uniqueName)
						{
							strMessage = Localization.GetString("NonuniqueName", LocalResourceFile);
							break;
						}
						//First create the control
						strMessage = CreateControl(controlSrc);
						if (String.IsNullOrEmpty(strMessage))
						{
							//Next import the control
							moduleDefinition = ImportControl(controlSrc);
						}
						break;
					case "Control":
						if (!String.IsNullOrEmpty(cboFile.SelectedValue))
						{
							moduleDefinition = ImportControl(cboFile.SelectedValue);
						}
						else
						{
							strMessage = Localization.GetString("NoControl", LocalResourceFile);
						}
						break;
					case "Template":
						break;
					case "Manifest":
						if (String.IsNullOrEmpty(cboFile.SelectedValue))
						{
							strMessage = Localization.GetString("MissingManifest", LocalResourceFile);
						}
						else
						{
							moduleDefinition = ImportManifest();
						}
						break;
				}
				if (moduleDefinition == null)
				{
					UI.Skins.Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.RedError);
				}
				else
				{
					if (!string.IsNullOrEmpty(cboCreate.SelectedValue) && chkAddPage.Checked)
					{
						var tabName = "Test " + txtName.Text + " Page";
						var tabPath = Globals.GenerateTabPath(Null.NullInteger, tabName);
						var tabID = TabController.GetTabByTabPath(ModuleContext.PortalId, tabPath, Null.NullString);
						if (tabID == Null.NullInteger)
						{
							//Create a new page
							var newTab = new TabInfo();
							newTab.TabName = "Test " + txtName.Text + " Page";
							newTab.ParentId = Null.NullInteger;
							newTab.PortalID = ModuleContext.PortalId;
							newTab.IsVisible = true;
							newTab.TabID = new TabController().AddTabBefore(newTab, ModuleContext.PortalSettings.AdminTabId);
							var objModule = new ModuleInfo();
							objModule.Initialize(ModuleContext.PortalId);
							objModule.PortalID = ModuleContext.PortalId;
							objModule.TabID = newTab.TabID;
							objModule.ModuleOrder = Null.NullInteger;
							objModule.ModuleTitle = moduleDefinition.FriendlyName;
							objModule.PaneName = Globals.glbDefaultPane;
							objModule.ModuleDefID = moduleDefinition.ModuleDefID;
							objModule.InheritViewPermissions = true;
							objModule.AllTabs = false;
							var moduleCtl = new ModuleController();
							moduleCtl.AddModule(objModule);
							Response.Redirect(Globals.NavigateURL(newTab.TabID), true);
						}
						else
						{
							UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
						}
					}
					else
					{
						//Redirect to main extensions page
						Response.Redirect(Globals.NavigateURL(), true);
					}
				}
			}
			catch (Exception ex)
			{
				Exceptions.ProcessModuleLoadException(this, ex);
			}
		}
        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);
            }

        }
예제 #21
0
        ///-----------------------------------------------------------------------------
        ///<summary>
        ///  AddModuleToPage adds a module to a Page
        ///</summary>
        ///<remarks>
        ///</remarks>
        ///<param name = "page">The Page to add the Module to</param>
        ///<param name = "moduleDefId">The Module Deinition Id for the module to be aded to this tab</param>
        ///<param name = "moduleTitle">The Module's title</param>
        ///<param name = "moduleIconFile">The Module's icon</param>
        ///<param name = "inheritPermissions">Inherit the Pages View Permisions</param>
        ///<history>
        ///  [cnurse]	11/16/2004	created
        ///</history>
        ///-----------------------------------------------------------------------------
        public static int AddModuleToPage(TabInfo page, int moduleDefId, string moduleTitle, string moduleIconFile, bool inheritPermissions)
        {
            DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddModuleToPage:" + moduleDefId);
            var moduleController = new ModuleController();
            ModuleInfo moduleInfo;
            int moduleId = Null.NullInteger;

            if ((page != null))
            {
                bool isDuplicate = false;
                foreach (var kvp in moduleController.GetTabModules(page.TabID))
                {
                    moduleInfo = kvp.Value;
                    if (moduleInfo.ModuleDefID == moduleDefId)
                    {
                        isDuplicate = true;
                        moduleId = moduleInfo.ModuleID;
                    }
                }

                if (!isDuplicate)
                {
                    moduleInfo = new ModuleInfo
                                     {
                                         ModuleID = Null.NullInteger,
                                         PortalID = page.PortalID,
                                         TabID = page.TabID,
                                         ModuleOrder = -1,
                                         ModuleTitle = moduleTitle,
                                         PaneName = Globals.glbDefaultPane,
                                         ModuleDefID = moduleDefId,
                                         CacheTime = 0,
                                         IconFile = moduleIconFile,
                                         AllTabs = false,
                                         Visibility = VisibilityState.None,
                                         InheritViewPermissions = inheritPermissions
                                     };

                    try
                    {
                        moduleId = moduleController.AddModule(moduleInfo);
                    }
                    catch (Exception exc)
                    {
                        Logger.Error(exc);
						DnnInstallLogger.InstallLogError(exc);
                    }
                }
            }
            DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogEnd", Localization.Localization.GlobalResourceFile) + "AddModuleToPage:" + moduleDefId);
            return moduleId;
        }
예제 #22
0
        public void CopyTab( int PortalId, int FromTabId, int ToTabId, bool IncludeContent )
        {
            ModuleController objModules = new ModuleController();

            foreach( KeyValuePair<int, ModuleInfo> kvp in objModules.GetTabModules( FromTabId ) )
            {
                ModuleInfo objModule = kvp.Value;

                // if the module shows on all pages does not need to be copied since it will
                // be already added to this page
                if( !objModule.AllTabs )
                {
                    if( IncludeContent == false )
                    {
                        objModule.ModuleID = Null.NullInteger;
                    }

                    objModule.TabID = ToTabId;
                    objModules.AddModule( objModule );
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Deserializes the module.
        /// </summary>
        /// <param name="nodeModule">The node module.</param>
        /// <param name="nodePane">The node pane.</param>
        /// <param name="portalId">The portal id.</param>
        /// <param name="tabId">The tab id.</param>
        /// <param name="mergeTabs">The merge tabs.</param>
        /// <param name="hModules">The modules.</param>
        public static void DeserializeModule(XmlNode nodeModule, XmlNode nodePane, int portalId, int tabId, PortalTemplateModuleAction mergeTabs, Hashtable hModules)
        {
            var moduleController = new ModuleController();
            var moduleDefinition = GetModuleDefinition(nodeModule);
            //will be instance or module?
            int templateModuleID = XmlUtils.GetNodeValueInt(nodeModule, "moduleID");
            bool isInstance = CheckIsInstance(templateModuleID, hModules);
            if (moduleDefinition != null)
            {
                //If Mode is Merge Check if Module exists
                if (!FindModule(nodeModule, tabId, mergeTabs))
                {
                    ModuleInfo module = DeserializeModule(nodeModule, nodePane, portalId, tabId, moduleDefinition.ModuleDefID);
					//if the module is marked as show on all tabs, then check whether the module is exist in current website and it also
					//still marked as shown on all tabs, this action will make sure there is no duplicate modules created on new tab.
					if (module.AllTabs)
					{
						var existModule = moduleController.GetModule(templateModuleID);
						if (existModule != null && !existModule.IsDeleted && existModule.AllTabs)
						{
							return;
						}
					}
                    //deserialize Module's settings
                    XmlNodeList nodeModuleSettings = nodeModule.SelectNodes("modulesettings/modulesetting");
                    DeserializeModuleSettings(nodeModuleSettings, module);
                    XmlNodeList nodeTabModuleSettings = nodeModule.SelectNodes("tabmodulesettings/tabmodulesetting");
                    DeserializeTabModuleSettings(nodeTabModuleSettings, module);

                    // DNN-24983 get culture from page
                    var tabInfo = new TabController().GetTab(tabId, portalId, false);
                    if (tabInfo != null)
                    {
                        module.CultureCode = tabInfo.CultureCode;
                    }

                    int intModuleId;
                    if (!isInstance)
                    {
                        //Add new module
                        intModuleId = moduleController.AddModule(module);
                        if (templateModuleID > 0)
                        {
                            hModules.Add(templateModuleID, intModuleId);
                        }
                    }
                    else
                    {
                        //Add instance
                        module.ModuleID = Convert.ToInt32(hModules[templateModuleID]);
                        intModuleId = moduleController.AddModule(module);
                    }

                    // save localization info
                    string oldGuid = XmlUtils.GetNodeValue(nodeModule, "uniqueId");
                    if (!ParsedLocalizedModuleGuid.ContainsKey(oldGuid))
                        ParsedLocalizedModuleGuid.Add(oldGuid, module.UniqueId.ToString());

                    if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(nodeModule.CreateNavigator(), "content")) && !isInstance)
                    {
                        GetModuleContent(nodeModule, intModuleId, tabId, portalId);
                    }
                    //Process permissions only once
                    if (!isInstance && portalId != Null.NullInteger)
                    {
                        XmlNodeList nodeModulePermissions = nodeModule.SelectNodes("modulepermissions/permission");
                        DeserializeModulePermissions(nodeModulePermissions, portalId, module);

                        //Persist the permissions to the Data base
                        ModulePermissionController.SaveModulePermissions(module);
                    }
                }
            }
        }
예제 #24
0
        private void Create()
        {
            //Create new Folder
            string folderMapPath = Server.MapPath(string.Format("~/DesktopModules/RazorModules/{0}", txtFolder.Text));
            if (Directory.Exists(folderMapPath))
            {
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("FolderExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }
            else
            {
                //Create folder
                Directory.CreateDirectory(folderMapPath);
            }

            //Create new Module Control
            string moduleControlMapPath = folderMapPath + "/" + ModuleControl;
            try
            {
                using (var moduleControlWriter = new StreamWriter(moduleControlMapPath))
                {
                    moduleControlWriter.Write(Localization.GetString("ModuleControlText.Text", LocalResourceFile));
                    moduleControlWriter.Flush();
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("ModuleControlCreationError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            //Copy Script to new Folder
            string scriptSourceFile = Server.MapPath(string.Format(razorScriptFileFormatString, scriptList.SelectedValue));
            string scriptTargetFile = folderMapPath + "/" + scriptList.SelectedValue;
            try
            {
                File.Copy(scriptSourceFile, scriptTargetFile);
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("ScriptCopyError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            //Create new Manifest in target folder
            string manifestMapPath = folderMapPath + "/" + ModuleControl.Replace(".ascx", ".dnn");
            try
            {
                using (var manifestWriter = new StreamWriter(manifestMapPath))
                {
                    string manifestTemplate = Localization.GetString("ManifestText.Text", LocalResourceFile);
                    string manifest = string.Format(manifestTemplate, txtName.Text, txtDescription.Text, txtFolder.Text, ModuleControl, scriptList.SelectedValue);
                    manifestWriter.Write(manifest);
                    manifestWriter.Flush();
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("ManifestCreationError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            //Register Module
            ModuleDefinitionInfo moduleDefinition = ImportManifest(manifestMapPath);

            //Optionally goto new Page
            if (chkAddPage.Checked)
            {
                string tabName = "Test " + txtName.Text + " Page";
                string tabPath = Globals.GenerateTabPath(Null.NullInteger, tabName);
                int tabID = TabController.GetTabByTabPath(ModuleContext.PortalId, tabPath, ModuleContext.PortalSettings.CultureCode);

                if (tabID == Null.NullInteger)
                {
                    //Create a new page
                    var newTab = new TabInfo();
                    newTab.TabName = "Test " + txtName.Text + " Page";
                    newTab.ParentId = Null.NullInteger;
                    newTab.PortalID = ModuleContext.PortalId;
                    newTab.IsVisible = true;
                    newTab.TabID = new TabController().AddTabBefore(newTab, ModuleContext.PortalSettings.AdminTabId);

                    var objModule = new ModuleInfo();
                    objModule.Initialize(ModuleContext.PortalId);

                    objModule.PortalID = ModuleContext.PortalId;
                    objModule.TabID = newTab.TabID;
                    objModule.ModuleOrder = Null.NullInteger;
                    objModule.ModuleTitle = moduleDefinition.FriendlyName;
                    objModule.PaneName = Globals.glbDefaultPane;
                    objModule.ModuleDefID = moduleDefinition.ModuleDefID;
                    objModule.InheritViewPermissions = true;
                    objModule.AllTabs = false;
                    var moduleCtl = new ModuleController();
                    moduleCtl.AddModule(objModule);

                    Response.Redirect(Globals.NavigateURL(newTab.TabID), true);
                }
                else
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                }
            }
            else
            {
                //Redirect to main extensions page
                Response.Redirect(Globals.NavigateURL(), true);
            }
        }
예제 #25
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Adds a New Module to a Pane
        /// </summary>
        /// <param name="align">The alignment for the Modue</param>
        /// <param name="desktopModuleId">The Id of the DesktopModule</param>
        /// <param name="permissionType">The View Permission Type for the Module</param>
        /// <param name="title">The Title for the resulting module</param>
        /// <param name="paneName">The pane to add the module to</param>
        /// <param name="position">The relative position within the pane for the module</param>
        /// <history>
        /// 	[cnurse]	01/11/2008  documented
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void AddNewModule(string title, int desktopModuleId, string paneName, int position, ViewPermissionType permissionType, string align)
        {
            TabPermissionCollection objTabPermissions = PortalSettings.ActiveTab.TabPermissions;
            var objPermissionController = new PermissionController();
            var objModules = new ModuleController();
            try
            {
                DesktopModuleInfo desktopModule;
                if (!DesktopModuleController.GetDesktopModules(PortalSettings.PortalId).TryGetValue(desktopModuleId, out desktopModule))
                {
                    throw new ArgumentException("desktopModuleId");
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }
            int UserId = -1;
            if (Request.IsAuthenticated)
            {
                UserInfo objUserInfo = UserController.GetCurrentUserInfo();
                UserId = objUserInfo.UserID;
            }
            foreach (ModuleDefinitionInfo objModuleDefinition in
                ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                var 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.PaneName = paneName;
                objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                if (objModuleDefinition.DefaultCacheTime > 0)
                {
                    objModule.CacheTime = objModuleDefinition.DefaultCacheTime;
                    if (PortalSettings.Current.DefaultModuleId > Null.NullInteger && PortalSettings.Current.DefaultTabId > Null.NullInteger)
                    {
                        ModuleInfo defaultModule = objModules.GetModule(PortalSettings.Current.DefaultModuleId, PortalSettings.Current.DefaultTabId, true);
                        if (defaultModule != null)
                        {
                            objModule.CacheTime = defaultModule.CacheTime;
                        }
                    }
                }
                switch (permissionType)
                {
                    case ViewPermissionType.View:
                        objModule.InheritViewPermissions = true;
                        break;
                    case ViewPermissionType.Edit:
                        objModule.InheritViewPermissions = false;
                        break;
                }
				
                //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 == ViewPermissionType.View)
                    {
						//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
                    int j;
                    for (j = 0; j <= arrSystemModulePermissions.Count - 1; j++)
                    {
                        PermissionInfo objSystemModulePermission;
                        objSystemModulePermission = (PermissionInfo) arrSystemModulePermissions[j];
                        if (objSystemModulePermission.PermissionKey == "VIEW" && permissionType == ViewPermissionType.Edit && 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);
                        }
                    }
					
                    //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 - 1; j++)
                        {
							//create the module permission
                            PermissionInfo objCustomModulePermission;
                            objCustomModulePermission = (PermissionInfo) arrCustomModulePermissions[j];
                            AddModulePermission(objModule, objCustomModulePermission, objTabPermission.RoleID, objTabPermission.UserID, objTabPermission.AllowAccess);
                        }
                    }
                }

                if (PortalSettings.Current.ContentLocalizationEnabled)
                {
                    Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalSettings.Current.PortalId);
                    //set the culture of the module to that of the tab
                    var tabInfo = new TabController().GetTab(objModule.TabID, PortalSettings.Current.PortalId, false);
                    objModule.CultureCode = tabInfo != null ? tabInfo.CultureCode : defaultLocale.Code;
                }
                else
                {
                    objModule.CultureCode = Null.NullString;
                }

                objModule.AllTabs = false;
                objModule.Alignment = align;
                objModules.AddModule(objModule);
            }
        }
예제 #26
0
        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 ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleId).Values)
            {
                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>
        ///   SaveTabData saves the Tab to the Database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name = "strAction">The action to perform "edit" or "add"</param>
        /// <history>
        ///   [cnurse]	9/10/2004	Updated to reflect design changes for Help, 508 support
        ///   and localisation
        ///   [jlucarino]	2/26/2009	Added CreatedByUserID and LastModifiedByUserID
        /// </history>
        private int SaveTabData(string strAction)
        {
            string strIcon = ctlIcon.Url;
            string strIconLarge = ctlIconLarge.Url;

            var objTabs = new TabController();

            Tab.TabName = txtTabName.Text;
            Tab.Title = txtTitle.Text;
            Tab.Description = txtDescription.Text;
            Tab.KeyWords = txtKeyWords.Text;
            Tab.IsVisible = chkMenu.Checked;
            Tab.DisableLink = chkDisableLink.Checked;

            TabInfo parentTab = null;
            if (cboParentTab.SelectedItem != null)
            {
                var parentTabId = cboParentTab.SelectedItemValueAsInt;
                var controller = new TabController();
                parentTab = controller.GetTab(parentTabId, -1, false);
            }

            if (parentTab != null)
            {
                Tab.PortalID = parentTab.PortalID;
                Tab.ParentId = parentTab.TabID;
            }
            else
            {
                Tab.ParentId = Null.NullInteger;
            }
            Tab.IconFile = strIcon;
            Tab.IconFileLarge = strIconLarge;
            Tab.IsDeleted = false;
            Tab.Url = ctlURL.Url;

            Tab.TabPermissions.Clear();
            if (Tab.PortalID != Null.NullInteger)
            {
                Tab.TabPermissions.AddRange(dgPermissions.Permissions);
            }

            Tab.Terms.Clear();
            Tab.Terms.AddRange(termsSelector.Terms);

            Tab.SkinSrc = pageSkinCombo.SelectedValue;
            Tab.ContainerSrc = pageContainerCombo.SelectedValue;
            Tab.TabPath = Globals.GenerateTabPath(Tab.ParentId, Tab.TabName);

            //Check for invalid
            string invalidType;
            if (!TabController.IsValidTabName(Tab.TabName, out invalidType))
            {
                ShowWarningMessage(string.Format(Localization.GetString(invalidType, LocalResourceFile), Tab.TabName));
                return Null.NullInteger;
            }

            //Validate Tab Path
            if (!IsValidTabPath(Tab, Tab.TabPath))
            {
                return Null.NullInteger;
            }

            //Set Culture Code
            var positionTabId = Null.NullInteger;
            if (cboPositionTab.SelectedItem != null)
            {
                positionTabId = Int32.Parse(cboPositionTab.SelectedItem.Value);
            }

            if (strAction != "edit")
            {
                if (PortalSettings.ContentLocalizationEnabled)
                {
                    switch (cultureTypeList.SelectedValue)
                    {
                        case "Localized":
                            var defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalId);
                            Tab.CultureCode = defaultLocale.Code;
                            break;
                        case "Culture":
                            Tab.CultureCode = PortalSettings.CultureCode;
                            break;
                        default:
                            Tab.CultureCode = Null.NullString;
                            break;
                    }

                    var tabLocale = LocaleController.Instance.GetLocale(Tab.CultureCode) ?? LocaleController.Instance.GetDefaultLocale(PortalId);

                    //Fix parent 
                    if (Tab.ParentId > Null.NullInteger)
                    {
                        parentTab = objTabs.GetTab(Tab.ParentId, PortalId, false);
                        if (parentTab.CultureCode != Tab.CultureCode)
                        {
                            parentTab = objTabs.GetTabByCulture(Tab.ParentId, PortalId, tabLocale);
                        }
                        if (parentTab != null)
                        {
                            Tab.ParentId = parentTab.TabID;
                        }
                    }

                    //Fix position TabId
                    if (positionTabId > Null.NullInteger)
                    {
                        var positionTab = objTabs.GetTab(positionTabId, PortalId, false);
                        if (positionTab.CultureCode != Tab.CultureCode)
                        {
                            positionTab = objTabs.GetTabByCulture(positionTabId, PortalId, tabLocale);
                        }
                        if (positionTab != null)
                        {
                            positionTabId = positionTab.TabID;
                        }
                    }
                }
                else
                {
                    Tab.CultureCode = Null.NullString;
                }
            }

            //Validate Tab Path
            if (string.IsNullOrEmpty(strAction))
            {
                var tabID = TabController.GetTabByTabPath(Tab.PortalID, Tab.TabPath, Tab.CultureCode);

                if (tabID != Null.NullInteger)
                {
                    var existingTab = objTabs.GetTab(tabID, PortalId, false);
                    if (existingTab != null && existingTab.IsDeleted)
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabRecycled", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
                    }
                    else
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TabExists", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    }
                    return Null.NullInteger;
                }
            }

            Tab.StartDate = datepickerStartDate.SelectedDate != null ? datepickerStartDate.SelectedDate.Value : Null.NullDate;
            Tab.EndDate = datepickerEndDate.SelectedDate != null ? datepickerEndDate.SelectedDate.Value : Null.NullDate;

            if (Tab.StartDate > Null.NullDate && Tab.EndDate > Null.NullDate && Tab.StartDate.AddDays(1) >= Tab.EndDate)
            {
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("InvalidTabDates", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return Null.NullInteger;
            }

            if (!valRefreshInterval.IsValid)
            {
                return Null.NullInteger;
            }
            Tab.RefreshInterval = txtRefreshInterval.Text == "" ? Null.NullInteger : Convert.ToInt32(txtRefreshInterval.Text);

            if (!valPriorityRequired.IsValid || !valPriority.IsValid)
            {
                return Null.NullInteger;
            }
            Tab.SiteMapPriority = float.Parse(txtPriority.Text);
            Tab.PageHeadText = txtPageHeadText.Text;
            Tab.IsSecure = chkSecure.Checked;
            Tab.PermanentRedirect = chkPermanentRedirect.Checked;

            UpdateTabSettings(Tab);
            if (strAction == "edit")
            {
                // trap circular tab reference
                if (cboParentTab.SelectedItem != null && Tab.TabID != cboParentTab.SelectedItemValueAsInt && !IsCircularReference(cboParentTab.SelectedItemValueAsInt, Tab.PortalID))
                {
                    objTabs.UpdateTab(Tab);
                    if (IsHostMenu && Tab.PortalID != Null.NullInteger)
                    {
                        //Host Tab moved to Portal so clear Host cache
                        objTabs.ClearCache(Null.NullInteger);
                    }
                    if (!IsHostMenu && Tab.PortalID == Null.NullInteger)
                    {
                        //Portal Tab moved to Host so clear portal cache
                        objTabs.ClearCache(PortalId);
                    }
                }
            }
            else
            {
                if (positionTabId == Null.NullInteger)
                {
                    Tab.TabID = objTabs.AddTab(Tab);
                }
                else
                {
                    if (rbInsertPosition.SelectedValue == "After" && positionTabId > Null.NullInteger)
                    {
                        Tab.TabID = objTabs.AddTabAfter(Tab, positionTabId);
                    }
                    else if (rbInsertPosition.SelectedValue == "Before" && positionTabId > Null.NullInteger)
                    {
                        Tab.TabID = objTabs.AddTabBefore(Tab, positionTabId);
                    }
                    else
                    {
                        Tab.TabID = objTabs.AddTab(Tab);
                    }
                }

                //Create Localized versions
                if (PortalSettings.ContentLocalizationEnabled && cultureTypeList.SelectedValue == "Localized")
                {
                    objTabs.CreateLocalizedCopies(Tab);
                    //Refresh tab
                    _tab = objTabs.GetTab(Tab.TabID, Tab.PortalID, true);
                }

                var copyTabId = cboCopyPage.Visible && cboCopyPage.SelectedItem != null ? cboCopyPage.SelectedItemValueAsInt : Null.NullInteger;

                if (copyTabId != Null.NullInteger)
                {
                    var objModules = new ModuleController();
                    ModuleInfo objModule;
                    CheckBox chkModule;
                    RadioButton optCopy;
                    RadioButton optReference;
                    TextBox txtCopyTitle;

                    foreach (DataGridItem objDataGridItem in grdModules.Items)
                    {
                        chkModule = (CheckBox)objDataGridItem.FindControl("chkModule");
                        if (chkModule.Checked)
                        {
                            var intModuleID = Convert.ToInt32(grdModules.DataKeys[objDataGridItem.ItemIndex]);
                            optCopy = (RadioButton)objDataGridItem.FindControl("optCopy");
                            optReference = (RadioButton)objDataGridItem.FindControl("optReference");
                            txtCopyTitle = (TextBox)objDataGridItem.FindControl("txtCopyTitle");

                            objModule = objModules.GetModule(intModuleID, copyTabId, false);
                            ModuleInfo newModule = null;
                            if ((objModule != null))
                            {
                                //Clone module as it exists in the cache and changes we make will update the cached object
                                newModule = objModule.Clone();

                                newModule.TabID = Tab.TabID;
                                newModule.DefaultLanguageGuid = Null.NullGuid;
                                newModule.CultureCode = Tab.CultureCode;
                                newModule.ModuleTitle = txtCopyTitle.Text;

                                if (!optReference.Checked)
                                {
                                    newModule.ModuleID = Null.NullInteger;
                                    objModules.InitialModulePermission(newModule, newModule.TabID, 0);
                                }

                                newModule.ModuleID = objModules.AddModule(newModule);

                                if (optCopy.Checked)
                                {
                                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                                    {
                                        var objObject = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                                        if (objObject is IPortable)
                                        {
                                            var content = Convert.ToString(((IPortable)objObject).ExportModule(intModuleID));
                                            if (!string.IsNullOrEmpty(content))
                                            {
                                                ((IPortable)objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, UserInfo.UserID);
                                            }
                                        }
                                    }
                                }
                            }

                            if (optReference.Checked)
                            {
                                //Make reference copies on secondary language
                                foreach (var m in objModule.LocalizedModules.Values)
                                {
                                    var newLocalizedModule = m.Clone();
                                    var localizedTab = Tab.LocalizedTabs[m.CultureCode];
                                    newLocalizedModule.TabID = localizedTab.TabID;
                                    newLocalizedModule.CultureCode = localizedTab.CultureCode;
                                    newLocalizedModule.ModuleTitle = txtCopyTitle.Text;
                                    newLocalizedModule.DefaultLanguageGuid = newModule.UniqueId;
                                    newLocalizedModule.ModuleID = objModules.AddModule(newLocalizedModule);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // create the page from a template
                    if (cboTemplate.SelectedItem != null && cboTemplate.SelectedItem.Value != Null.NullInteger.ToString())
                    {
                        var xmlDoc = new XmlDocument();
                        try
                        {
                            // open the XML file
                            var folder = FolderManager.Instance.GetFolder(cboFolders.SelectedItemValueAsInt);
                            if (folder != null)
                                xmlDoc.Load(PortalSettings.HomeDirectoryMapPath + folder.FolderPath + cboTemplate.SelectedValue);
                        }
                        catch (Exception ex)
                        {
                            Exceptions.LogException(ex);

                            Skin.AddModuleMessage(this, Localization.GetString("BadTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return Null.NullInteger;
                        }
                        TabController.DeserializePanes(xmlDoc.SelectSingleNode("//portal/tabs/tab/panes"), Tab.PortalID, Tab.TabID, PortalTemplateModuleAction.Ignore, new Hashtable());
                        //save tab permissions
                        RibbonBarManager.DeserializeTabPermissions(xmlDoc.SelectNodes("//portal/tabs/tab/tabpermissions/permission"), Tab);

                        var tabIndex = 0;
                        var exceptions = string.Empty;
                        foreach (XmlNode tabNode in xmlDoc.SelectSingleNode("//portal/tabs").ChildNodes)
                        {
                            //Create second tab onward tabs. Note first tab is already created above.
                            if (tabIndex > 0)
                            {
                                try
                                {
                                    TabController.DeserializeTab(tabNode, null, PortalId, PortalTemplateModuleAction.Replace);
                                }
                                catch (Exception ex)
                                {
                                    Exceptions.LogException(ex);
                                    exceptions += string.Format("Template Tab # {0}. Error {1}<br/>", tabIndex + 1, ex.Message);
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(Tab.SkinSrc) && !String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "skinsrc", "")))
                                {
                                    Tab.SkinSrc = XmlUtils.GetNodeValue(tabNode, "skinsrc", "");
                                }
                                if (string.IsNullOrEmpty(Tab.ContainerSrc) && !String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "containersrc", "")))
                                {
                                    Tab.ContainerSrc = XmlUtils.GetNodeValue(tabNode, "containersrc", "");
                                }
                                objTabs.UpdateTab(Tab);
                            }
                            tabIndex++;
                        }

                        if (!string.IsNullOrEmpty(exceptions))
                        {
                            Skin.AddModuleMessage(this, exceptions, ModuleMessage.ModuleMessageType.RedError);
                            return Null.NullInteger;
                        }
                    }
                }
            }

            // url tracking
            var objUrls = new UrlController();
            objUrls.UpdateUrl(PortalId, ctlURL.Url, ctlURL.UrlType, 0, Null.NullDate, Null.NullDate, ctlURL.Log, ctlURL.Track, Null.NullInteger, ctlURL.NewWindow);

            //Clear the Tab's Cached modules
            DataCache.ClearModuleCache(TabId);

            //Update Cached Tabs as TabPath may be needed before cache is cleared
            TabInfo tempTab;
            if (new TabController().GetTabsByPortal(PortalId).TryGetValue(Tab.TabID, out tempTab))
            {
                tempTab.TabPath = Tab.TabPath;
            }

            //Update Custom Url
            if (!Tab.IsSuperTab)
            {
                var tabUrl = Tab.TabUrls.SingleOrDefault(t => t.IsSystem
                                                                && t.HttpStatus == "200"
                                                                && t.SeqNum == 0);
                var url = urlTextBox.Text;


                if (!String.IsNullOrEmpty(url))
                {
                    if (!url.StartsWith("/"))
                    {
                        url = "/" + url;
                    }

                    string currentUrl = String.Empty;
                    var friendlyUrlSettings = new FriendlyUrlSettings(PortalId);
                    if (Tab.TabID > -1 && !Tab.IsSuperTab)
                    {
                        var baseUrl = Globals.AddHTTP(PortalAlias.HTTPAlias) + "/Default.aspx?TabId=" + Tab.TabID;
                        var path = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(Tab,
                                                                                    baseUrl,
                                                                                    Globals.glbDefaultPage,
                                                                                    PortalAlias.HTTPAlias,
                                                                                    false, //dnndev-27493 :we want any custom Urls that apply
                                                                                    friendlyUrlSettings,
                                                                                    Guid.Empty);

                        currentUrl = path.Replace(Globals.AddHTTP(PortalAlias.HTTPAlias), "");
                    }

                    if (url != currentUrl)
                    {
                        if (tabUrl == null)
                        {
                            tabUrl = new TabUrlInfo()
                            {
                                TabId = Tab.TabID,
                                SeqNum = 0,
                                PortalAliasId = -1,
                                PortalAliasUsage = PortalAliasUsageType.Default,
                                QueryString = String.Empty,
                                Url = url,
                                HttpStatus = "200",
                                IsSystem = true
                            };
                        }
                        else
                        {
                            tabUrl.Url = url;
                        }

                        //Delete any redirects to the same url
                        foreach (var redirecturl in TestableTabController.Instance.GetTabUrls(Tab.TabID, Tab.PortalID))
                        {
                            if (redirecturl.Url == url && redirecturl.HttpStatus != "200")
                            {
                                TestableTabController.Instance.DeleteTabUrl(redirecturl, Tab.PortalID, false);
                            }
                        }
                        //Save url
                        TestableTabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
                    }
                }
                else
                {
                    if (tabUrl != null)
                    {
                        TestableTabController.Instance.DeleteTabUrl(tabUrl, PortalId, true);
                    }
                }
            }

            return Tab.TabID;
        }
예제 #28
0
        /// <summary>
        /// Restores selected modules in the listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Adds a log entry for each restored module to the EventLog
        /// </remarks>
        /// <history>
        /// 	[VMasanas]	18/08/2004	Added support for multiselect listbox
        /// </history>
        protected void cmdRestoreModule_Click( Object sender, ImageClickEventArgs e )
        {
            EventLogController objEventLog = new EventLogController();
            ModuleController objModules = new ModuleController();
            ListItem item;

            if( cboTab.SelectedItem != null )
            {
                foreach( ListItem tempLoopVar_item in lstModules.Items )
                {
                    item = tempLoopVar_item;
                    if( item.Selected )
                    {
                        ModuleInfo objModule = objModules.GetModule( int.Parse( item.Value ), Null.NullInteger );
                        if( objModule != null )
                        {
                            objModule.IsDeleted = false;
                            objModule.TabID = Null.NullInteger;
                            objModules.UpdateModule( objModule );

                            // set defaults
                            objModule.CacheTime = 0;
                            objModule.Alignment = "";
                            objModule.Color = "";
                            objModule.Border = "";
                            objModule.IconFile = "";
                            objModule.Visibility = VisibilityState.Maximized;
                            objModule.ContainerSrc = "";
                            objModule.DisplayTitle = true;
                            objModule.DisplayPrint = true;
                            objModule.DisplaySyndicate = false;
                            objModule.AllTabs = false;

                            // get default module settings
                            Hashtable settings = PortalSettings.GetSiteSettings( PortalId );
                            if( Convert.ToString( settings["defaultmoduleid"] ) != "" && Convert.ToString( settings["defaulttabid"] ) != "" )
                            {
                                ModuleInfo objDefaultModule = objModules.GetModule( int.Parse( Convert.ToString( settings["defaultmoduleid"] ) ), int.Parse( Convert.ToString( settings["defaulttabid"] ) ) );
                                if( objDefaultModule != null )
                                {
                                    objModule.CacheTime = objDefaultModule.CacheTime;
                                    objModule.Alignment = objDefaultModule.Alignment;
                                    objModule.Color = objDefaultModule.Color;
                                    objModule.Border = objDefaultModule.Border;
                                    objModule.IconFile = objDefaultModule.IconFile;
                                    objModule.Visibility = objDefaultModule.Visibility;
                                    objModule.ContainerSrc = objDefaultModule.ContainerSrc;
                                    objModule.DisplayTitle = objDefaultModule.DisplayTitle;
                                    objModule.DisplayPrint = objDefaultModule.DisplayPrint;
                                    objModule.DisplaySyndicate = objDefaultModule.DisplaySyndicate;
                                }
                            }

                            // add tab module
                            objModule.TabID = int.Parse( cboTab.SelectedItem.Value );
                            objModule.PaneName = Globals.glbDefaultPane;
                            objModule.ModuleOrder = - 1;
                            objModules.AddModule( objModule );

                            objEventLog.AddLog( objModule, PortalSettings, UserId, "", EventLogController.EventLogType.MODULE_RESTORED );
                        }
                    }
                }
                BindData();
            }
        }