Ejemplo n.º 1
0
        public void MustHaveTestPageAdded()
        {
            //Create a tabInfo obj, then use TabController AddTab Method?
            TabInfo newPage = new TabInfo
            {
                TabName      = "Test Page",
                PortalID     = 0,
                SkinSrc      = "[G]Skins/DarkKnight/Home-Mega-Menu.ascx",
                ContainerSrc = "[G]Containers/DarkKnight/SubTitle_Grey.ascx"
            };
            TabController tabController = new TabController();
            var           tab           = tabController.GetTabByName("Test Page", 0);

            if (tab == null)
            {
                try
                {
                    tabController.AddTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Add Tab result: " + exc.Message);
                }
                //tabController.AddTab(newPage);
                newPage = tabController.GetTabByName("Test Page", 0);
                TabPermissionInfo tabPermission = new TabPermissionInfo();
                tabPermission.PermissionID = 3;
                tabPermission.TabID        = newPage.TabID;
                tabPermission.AllowAccess  = true;
                tabPermission.RoleID       = 0;
                newPage.TabPermissions.Add(tabPermission);
                try
                {
                    tabController.UpdateTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Update Tab result: " + exc.Message);
                }
                newPage = tabController.GetTabByName("Test Page", 0);
                tabPermission.RoleID       = 0;
                tabPermission.PermissionID = 4;
                tabPermission.TabID        = newPage.TabID;
                tabPermission.AllowAccess  = true;
                newPage.TabPermissions.Add(tabPermission);
                try
                {
                    tabController.UpdateTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Update Tab Permissions result: " + exc.Message);
                }
            }
            else
            {
                tabController.RestoreTab(tab, PortalController.GetCurrentPortalSettings());
            }
            Config.Touch();
        }
Ejemplo n.º 2
0
    private void createPage(String tabName, List <TabPermissionInfo> permissions, bool visible, bool superTab, string parent)
    {
        PortalSettings portalSettings = new PortalSettings();
        int            portalId       = portalSettings.PortalId;
        TabController  TC             = new TabController();
        TabInfo        ti             = new TabInfo();

        ti.TabName  = tabName;
        ti.PortalID = portalId;
        ti.Title    = tabName;
        if (TC.GetTabByName(parent, portalId) != null)
        {
            ti.ParentId = TC.GetTabByName(parent, portalId).TabID;
        }
        ti.Description = tabName;
        ti.KeyWords    = tabName;
        ti.IsVisible   = visible;
        ti.DisableLink = false;
        ti.IsDeleted   = false;
        ti.Url         = "";
        ti.IsSuperTab  = superTab;
        foreach (TabPermissionInfo p in permissions)
        {
            ti.TabPermissions.Add(p);
        }
        TC.AddTab(ti);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Upgrades the module.
        /// </summary>
        /// <param name="Version">The version.</param>
        /// <returns>System.String.</returns>
        public string UpgradeModule(string Version)
        {
            TabController tabs = new TabController();

            foreach (PortalInfo p in new PortalController().GetPortals())
            {
                TabInfo tabInfo = tabs.GetTabByName("Vanity Urls", p.PortalID);
                if (tabInfo == null)
                {
                    tabInfo          = new TabInfo();
                    tabInfo.TabID    = -1;
                    tabInfo.ParentId = tabs.GetTabByName("Admin", p.PortalID).TabID;
                    tabInfo.PortalID = p.PortalID;
                    tabInfo.TabName  = "Vanity Urls";
                    try
                    {
                        int tabId = tabs.AddTab(tabInfo);
                        AddModuleToPage(p.PortalID, tabId);
                        return("Vanity Urls page added");
                    }
                    catch (Exception ex)
                    {
                        DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                    }
                }
            }

            return("");
        }
Ejemplo n.º 4
0
        private static TabInfo CreateNewTab(string tabName)
        {
            var portalSettings = PortalSettings.Current;
            var name           = GetAvailableTabName(tabName, string.Empty);

            var tab = new TabInfo();

            tab.PortalID    = portalSettings.PortalId;
            tab.TabName     = name;
            tab.Title       = name;
            tab.IsVisible   = true;
            tab.DisableLink = false;
            tab.IsDeleted   = false;
            tab.IsSuperTab  = false;

            foreach (PermissionInfo p in PermissionController.GetPermissionsByTab())
            {
                switch (p.PermissionKey)
                {
                case "VIEW":
                    AddTabPermission(tab, p, portalSettings.AdministratorRoleId, true);
                    break;

                case "EDIT":
                    AddTabPermission(tab, p, portalSettings.AdministratorRoleId, true);
                    break;
                }
            }

            var tabController = new TabController();

            tabController.AddTab(tab, true);
            return(tab);
        }
Ejemplo n.º 5
0
        public void GivenThereIsAPageCalled(string pageName, Table permissions)
        {
            var reset         = false;
            var tabController = new TabController();
            var tab           = tabController.GetTabByName(pageName, PortalId);

            if (tab == null)
            {
                tab = new TabInfo
                {
                    TabName  = pageName,
                    PortalID = 0
                };
                tab.TabID = tabController.AddTab(tab);
                foreach (var row in permissions.Rows)
                {
                    var roleId         = -1;
                    var roleController = new RoleController();
                    if (row[0] == "All Users")
                    {
                        roleId = -1;
                    }
                    else
                    {
                        var role = roleController.GetRoleByName(PortalId, row[0]);
                        if (role == null)
                        {
                            if (roleController.GetRoleByName(Null.NullInteger, row[0]) == null)
                            {
                                role = new RoleInfo {
                                    RoleName = row[0], RoleGroupID = Null.NullInteger
                                };
                                roleId = roleController.AddRole(role);
                            }
                        }
                    }
                    var permissionController = new PermissionController();
                    var permission           = permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", row[1]);
                    var tabPermission        = new TabPermissionInfo
                    {
                        PermissionID = 3,
                        TabID        = tab.TabID,
                        AllowAccess  = true,
                        RoleID       = roleId
                    };
                    tab.TabPermissions.Add(tabPermission);
                }

                tabController.UpdateTab(tab);
                reset = true;
            }
            Page = tab;
            if (reset)
            {
                Config.Touch();
            }
        }
Ejemplo n.º 6
0
        public void MustHaveTestPageAdded()
        {
            //Create a tabInfo obj, then use TabController AddTab Method?
            TabInfo newPage = new TabInfo();

            newPage.TabName      = "Test Page";
            newPage.PortalID     = 0;
            newPage.SkinSrc      = "[G]Skins/Aphelia/twoColumn-rightAside.ascx";
            newPage.ContainerSrc = "[G]Containers/Aphelia/Title.ascx";
            TabController tabController = new TabController();
            var           tab           = tabController.GetTabByName("Test Page", 0);

            if (tab == null)
            {
                try
                {
                    tabController.AddTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Add Tab result: " + exc.Message);
                }
                //tabController.AddTab(newPage);
                newPage = tabController.GetTabByName("Test Page", 0);
                TabPermissionInfo tabPermission = new TabPermissionInfo();
                tabPermission.PermissionID = 3;
                tabPermission.TabID        = newPage.TabID;
                tabPermission.AllowAccess  = true;
                tabPermission.RoleID       = 0;
                newPage.TabPermissions.Add(tabPermission);
                try
                {
                    tabController.UpdateTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Update Tab result: " + exc.Message);
                }
                newPage = tabController.GetTabByName("Test Page", 0);
                tabPermission.RoleID       = 0;
                tabPermission.PermissionID = 4;
                tabPermission.TabID        = newPage.TabID;
                tabPermission.AllowAccess  = true;
                newPage.TabPermissions.Add(tabPermission);
                try
                {
                    tabController.UpdateTab(newPage);
                }
                catch (Exception exc)
                {
                    Assert.IsTrue(false, "Update Tab Permissions result: " + exc.Message);
                }
                Thread.Sleep(1500);
            }
        }
Ejemplo n.º 7
0
        private TabInfo CreateTab(string tabName)
        {
            var tc  = new TabController();
            var tab = new TabInfo {
                PortalID = PortalId, TabName = tabName
            };

            tc.AddTab(tab);

            return(tab);
        }
Ejemplo n.º 8
0
        public TabInfo AddPluggPage(string tabName, string tabTitle)
        {
            PortalSettings portalSettings = new PortalSettings();
            int            portalId       = portalSettings.PortalId;

            TabController tabController = new TabController();
            TabInfo       getTab        = tabController.GetTabByName(tabName, portalId);

            if (getTab != null)
            {
                throw new Exception("Cannot create Page. Page with this PageName already exists");
            }

            TabInfo newTab = new TabInfo();

            newTab.PortalID     = portalId;
            newTab.TabName      = tabName;
            newTab.Title        = tabTitle;
            newTab.SkinSrc      = "[G]Skins/20047-UnlimitedColorPack-033/PluggPage.ascx";
            newTab.ContainerSrc = portalSettings.DefaultPortalContainer;
            CommonTabSettings(newTab);
            AddViewPermissions(newTab);

            int tabId = tabController.AddTab(newTab, true);

            DotNetNuke.Common.Utilities.DataCache.ClearModuleCache(tabId);

            AddTabURL(newTab); //Makes the URL of Page /4 or /C4

            // add modules to new page

            AddModuleToPage(newTab, ModuleType.DisplayPlugg);

            AddModuleToPage(newTab, ModuleType.CourseMenu);

            AddModuleToPage(newTab, ModuleType.Rating);

            AddModuleToPage(newTab, ModuleType.Comments);

            AddModuleToPage(newTab, ModuleType.DisplayPluggeTitle);

            return(newTab);
        }
Ejemplo n.º 9
0
        private TabInfo CreatePage(TabInfo tab, int portalId, int parentTabId, string tabName, bool includeInMenu)
        {
            int id           = -1;
            var tc           = new TabController();
            var tPermissions = new TabPermissionCollection();
            var newTab       = new TabInfo();

            if (tab != null)
            {
                foreach (TabPermissionInfo t in tab.TabPermissions)
                {
                    var tNew = new TabPermissionInfo
                    {
                        AllowAccess     = t.AllowAccess,
                        DisplayName     = t.DisplayName,
                        ModuleDefID     = t.ModuleDefID,
                        PermissionCode  = t.PermissionCode,
                        PermissionID    = t.PermissionID,
                        PermissionKey   = t.PermissionKey,
                        PermissionName  = t.PermissionName,
                        RoleID          = t.RoleID,
                        RoleName        = t.RoleName,
                        TabID           = -1,
                        TabPermissionID = -1,
                        UserID          = t.UserID,
                        Username        = t.Username
                    };
                    newTab.TabPermissions.Add(t);
                }
            }

            newTab.ParentId  = parentTabId;
            newTab.PortalID  = portalId;
            newTab.TabName   = tabName;
            newTab.Title     = tabName;
            newTab.IsVisible = includeInMenu;
            newTab.SkinSrc   = GetSkin();

            id  = tc.AddTab(newTab);
            tab = tc.GetTab(id, portalId, true);

            return(tab);
        }
Ejemplo n.º 10
0
    private bool createPage(String tabName, List <TabPermissionInfo> permissions, bool visible, bool superTab, string parent)
    {
        PortalSettings portalSettings = new PortalSettings();
        int            portalId       = portalSettings.PortalId;
        TabController  TC             = new TabController();
        TabInfo        ti             = new TabInfo();

        ti.TabName  = tabName;
        ti.PortalID = portalId;
        ti.Title    = "Courrier du District " + tabName;
        if (TC.GetTabByName(parent, portalId) != null)
        {
            ti.ParentId = TC.GetTabByName(parent, portalId).TabID;
        }
        ti.Description = tabName;
        ti.KeyWords    = tabName;
        ti.IsVisible   = visible;
        ti.DisableLink = false;
        ti.IsDeleted   = false;
        ti.Url         = "";
        ti.IsSuperTab  = superTab;
        foreach (TabPermissionInfo p in permissions)
        {
            ti.TabPermissions.Add(p);
        }
        try
        {
            TC.AddTab(ti);
        }
        catch (Exception ee)
        {
            if (TC != null && ti != null && ti.TabName != null && TC.GetTabByName(ti.TabName, portalId) != null && TC.GetTabByName(ti.TabName, portalId).IsDeleted)
            {
                lbl_pageExists.Visible = false;
                lbl_pageInBin.Visible  = true;
                hlk_pageExists.Visible = false;
            }
            return(false);
        }
        return(true);
    }
Ejemplo n.º 11
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     AddPage adds a Tab Page
        /// </summary>
        /// <param name="portalId">The Id of the Portal</param>
        /// <param name="parentId">The Id of the Parent Tab</param>
        /// <param name="tabName">The Name to give this new Tab</param>
        /// <param name="description">Description.</param>
        /// <param name="tabIconFile">The Icon for this new Tab</param>
        /// <param name="tabIconFileLarge">The large Icon for this new Tab</param>
        /// <param name="isVisible">A flag indicating whether the tab is visible</param>
        /// <param name="permissions">Page Permissions Collection for this page</param>
        /// <param name="isAdmin">Is and admin page</param>
        private static TabInfo AddPage(int portalId, int parentId, string tabName, string description,
                                       string tabIconFile, string tabIconFileLarge, bool isVisible, TabPermissionCollection permissions,
                                       bool isAdmin)
        {
            var tabController = new TabController();

            var tab = tabController.GetTabByName(tabName, portalId, parentId);

            if (tab == null || tab.ParentId != parentId)
            {
                tab = new TabInfo
                {
                    TabID         = Null.NullInteger,
                    PortalID      = portalId,
                    TabName       = tabName,
                    Title         = "",
                    Description   = description,
                    KeyWords      = "",
                    IsVisible     = isVisible,
                    DisableLink   = false,
                    ParentId      = parentId,
                    IconFile      = tabIconFile,
                    IconFileLarge = tabIconFileLarge,
                    IsDeleted     = false
                };
                tab.TabID = tabController.AddTab(tab, !isAdmin);

                if (((permissions != null)))
                {
                    foreach (TabPermissionInfo tabPermission in permissions)
                    {
                        tab.TabPermissions.Add(tabPermission, true);
                    }
                    TabPermissionController.SaveTabPermissions(tab);
                }
            }

            return(tab);
        }
Ejemplo n.º 12
0
        public HttpResponseMessage DoOne(GenerateOneTabPostModel model)
        {
            var objTabs       = new TabController();
            var startingLevel = 0;
            var parentTabId   = Null.NullInteger;
            TabPermissionCollection defaultTabPermissionCollection = CreateTabPermissions();

            // see if user selected another page to put the tree under.
            // we need the startingTabID and the StartingLevel
            if (model.ParentTabId > 0)
            {
                TabInfo tempTab = objTabs.GetTab(model.ParentTabId, PortalSettings.PortalId, true);
                startingLevel = tempTab.Level + 1;
                parentTabId   = model.ParentTabId;
            }

            string  prevTabName = "";
            int     prevLevel   = 0;
            TabInfo prevTab     = null;

            if (model.PreviousTabId == 0)
            {
                // it's the first tab
                parentTabId = model.ParentTabId;
            }
            else
            {
                prevTabName = model.PreviousTabName;
                prevLevel   = startingLevel;
                prevTab     = objTabs.GetTab(model.PreviousTabId, PortalSettings.PortalId, true);
                GetLevelFromPageName(model.IndentCharacter, ref prevTabName, ref prevLevel);
            }

            var tabName = model.TabName;
            var level   = startingLevel;

            GetLevelFromPageName(model.IndentCharacter, ref tabName, ref level);

            if (level == 0)
            {
                // top level page: nothing to do
            }
            else if (model.PreviousTabId > 0 && level == prevLevel)
            {
                // sibling of previous page, so same parent
                parentTabId = prevTab.ParentId;
            }
            else if (model.PreviousTabId > 0 && level == prevLevel + 1)
            {
                // child of previous tab
                parentTabId = model.PreviousTabId;
            }
            else if (model.PreviousTabId > 0 && level < prevLevel)
            {
                var tempTab = prevTab;
                for (int i = 0; i < prevLevel - level; i++)
                {
                    tempTab = objTabs.GetTab(tempTab.ParentId, PortalSettings.PortalId, true);
                }

                parentTabId = tempTab.ParentId;
            }

            // create the new page
            TabInfo newTab = new TabInfo()
            {
                PortalID          = PortalSettings.PortalId,
                TabName           = tabName,
                ParentId          = parentTabId > 0 ? parentTabId : Null.NullInteger,
                IsVisible         = true,
                DisableLink       = false,
                IsSecure          = false,
                PermanentRedirect = false,
                SiteMapPriority   = (float)0.5,
                Level             = level
            };

            newTab.TabPermissions.AddRange(defaultTabPermissionCollection);

            try
            {
                // adding the tab returns a tabId, so we can set that to the tab object
                newTab.TabID = objTabs.AddTab(newTab);
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new { TabId = newTab.TabID }));
        }
Ejemplo n.º 13
0
        public HttpResponseMessage Do(GenerateTabsPostModel model)
        {
            List <string> PageTree = model.PageTree.Split('\n').ToList();

            TabController objTabs = new TabController();

            if (PageTree.First().StartsWith(model.IndentCharacter))
            {
                // we have to make sure that the first item in the list is not starting with an indent,
                // since we are adding this tree (optionaly) below another page anyway
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"PageTree being added cannot start with the set indent character ({model.IndentCharacter})"));
            }

            TabPermissionCollection defaultTabPermissionCollection = CreateTabPermissions();

            int level               = 0;
            int startingLevel       = 0;
            int previousLevel       = -1;
            int lineCounter         = 0;
            int startingParentTabId = Null.NullInteger;

            // see if user selected another page to put the tree under.
            // we need the startingTabID and the StartingLevel
            if (model.ParentTabId > 0)
            {
                startingParentTabId = model.ParentTabId;
                TabInfo tempTab = objTabs.GetTab(startingParentTabId, PortalSettings.PortalId, true);
                startingLevel = tempTab.Level + 1;
            }
            int            parentTabId = Null.NullInteger;
            List <TabInfo> tabList     = new List <TabInfo>();

            // first check whether all levels are ok, if there is an error we are not going to do anything
            foreach (string pageName in PageTree)
            {
                // reset level to 0
                level = 0;
                // save the original pagenane, since GetLevelFromPageName is going to alter the pagename
                string originalPageName = pageName;
                string newPageName      = pageName;

                // get the level from the pagename. This removes the indent characters from the beginning from the pagename
                level = GetLevelFromPageName(model.IndentCharacter, ref newPageName, ref level);

                // there might a typo in the list.
                // eg if item x has text ">>PageName",
                // then item x+1 cannot have either just "PageName" or ">>>>PageName"
                // in other words, levels cannot differ by more than 1
                if ((level - previousLevel > 1) && (level != 0))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"Unexpected Level at line {lineCounter + 1}, text: {originalPageName}"));
                }
                lineCounter  += 1;
                previousLevel = level;
            }

            lineCounter   = 0;
            previousLevel = -1;
            foreach (string pageName in PageTree)
            {
                level = 0;
                // save the original pagename, since GetLevelFromPageName is going to alter the pagename
                string originalPageName = pageName;
                string newPageName      = pageName;

                // get the level from the pagename. This removes the indent characters from the beginning from the pagename
                level = GetLevelFromPageName(model.IndentCharacter, ref newPageName, ref level);

                // get the parentTabId
                parentTabId = startingParentTabId;
                if ((level > 0) && (lineCounter >= tabList.Count))
                {
                    // For i As Integer = tabList.Count - 1 To 0 Step -1
                    for (int i = 0; i <= tabList.Count - 1; i++)
                    {
                        // walk the list of already created back up
                        // in order to find the first previous tab of 1 level up
                        if (tabList[i].Level == startingLevel + level - 1)
                        {
                            parentTabId = tabList[i].TabID;
                        }
                    }
                }

                // create the new page
                TabInfo newTab = new TabInfo()
                {
                    PortalID          = PortalSettings.PortalId,
                    TabName           = newPageName,
                    ParentId          = parentTabId,
                    IsVisible         = true,
                    DisableLink       = false,
                    IsSecure          = false,
                    PermanentRedirect = false,
                    SiteMapPriority   = (float)0.5,
                    Level             = level
                };
                newTab.TabPermissions.AddRange(defaultTabPermissionCollection);

                try
                {
                    // adding the tab returns a tabId, so we can set that to the tab object
                    newTab.TabID = objTabs.AddTab(newTab);

                    // add the newly created tab to a list
                    tabList.Add(newTab);
                }
                catch (Exception ex)
                {
                }

                lineCounter  += 1;
                previousLevel = level;
            }

            // Clear the tabcache, so we know for sure that we will get a correct menu next page refresh
            //DotNetNuke.Common.Utilities.DataCache.ClearTabsCache(PortalId);

            return(Request.CreateResponse(HttpStatusCode.OK, "OK"));
        }
        protected void OnImportClick(object sender, EventArgs e)
        {
            try
            {
                if (cboTemplate.SelectedItem == null || cboTemplate.SelectedValue == "None_Specified")
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyFile", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                if (optMode.SelectedIndex == -1)
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyMode", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(PortalSettings.HomeDirectoryMapPath + cboFolders.SelectedValue + cboTemplate.SelectedValue);
                XmlNode nodeTab = xmlDoc.SelectSingleNode("//portal/tabs/tab");
                TabInfo objTab;
                if (optMode.SelectedValue == "ADD")
                {
                    if (string.IsNullOrEmpty(txtTabName.Text))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    //New Tab
                    objTab = new TabInfo {
                        PortalID = PortalId, TabName = txtTabName.Text, IsVisible = true
                    };
                    if (cboParentTab.SelectedItem != null)
                    {
                        objTab.ParentId = Int32.Parse(cboParentTab.SelectedItem.Value);
                    }
                    objTab.TabPath = Globals.GenerateTabPath(objTab.ParentId, objTab.TabName);
                    int tabID   = TabController.GetTabByTabPath(objTab.PortalID, objTab.TabPath, Null.NullString);
                    var objTabs = new TabController();

                    //Check if tab exists
                    if (tabID != Null.NullInteger)
                    {
                        TabInfo 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;
                    }

                    int positionTabID = Int32.Parse(cboPositionTab.SelectedItem.Value);

                    var objEventLog = new EventLogController();
                    if (rbInsertPosition.SelectedValue == "After" && positionTabID > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabAfter(objTab, positionTabID);
                    }
                    else if (rbInsertPosition.SelectedValue == "Before" && positionTabID > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabBefore(objTab, positionTabID);
                    }
                    else
                    {
                        objTab.TabID = objTabs.AddTab(objTab);
                    }
                    objEventLog.AddLog(objTab, PortalSettings, UserId, "", EventLogController.EventLogType.TAB_CREATED);

                    //Update Tab properties from template
                    objTab = TabController.DeserializeTab(nodeTab, objTab, PortalId, PortalTemplateModuleAction.Replace);
                }
                else
                {
                    //Replace Existing Tab
                    objTab = TabController.DeserializeTab(nodeTab, Tab, PortalId, PortalTemplateModuleAction.Replace);
                }
                switch (optRedirect.SelectedValue)
                {
                case "VIEW":
                    Response.Redirect(Globals.NavigateURL(objTab.TabID), true);
                    break;

                default:
                    Response.Redirect(Globals.NavigateURL(objTab.TabID, "Tab", "action=edit"), true);
                    break;
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Ejemplo n.º 15
0
        private TabInfo CreateTab(string tabName, bool isSuperTab = true)
        {
            //Create Tab
            TabController tabController = new TabController();

            TabInfo tab = new TabInfo();

            tab.PortalID = PortalId;
            tab.TabName  = tabName;
            tab.Title    = tabName;

            //works for include in menu option. if true, will be shown in menus, else will not be shown, we have to redirect internally
            tab.IsVisible   = true;
            tab.DisableLink = false;

            //if this tab has any parents provide parent tab id, so that it will be shown in parent tab menus sub menu list, else is NULL
            //and will be in main menu list
            if (!isSuperTab)
            {
                tab.ParentId = TabId;
            }
            tab.IsDeleted = false;
            tab.Url       = "";
            //if true, it has no parents, else false
            tab.IsSuperTab   = isSuperTab;
            tab.SkinSrc      = "[G]Skins/Artfolio001/page.ascx"; //provide skin src, else will take default skin
            tab.ContainerSrc = "[G]Containers/Artfolio001/Block.ascx";
            int tabId = tabController.AddTab(tab, true);         //true to load defalut modules

            //Set Tab Permission
            TabPermissionController objTPC = new TabPermissionController();

            TabPermissionInfo tpi = new TabPermissionInfo();

            tpi.TabID          = tabId;
            tpi.PermissionID   = 3; //for view
            tpi.PermissionKey  = "VIEW";
            tpi.PermissionName = "View Tab";
            tpi.AllowAccess    = true;
            tpi.RoleID         = 0; //Role ID of administrator
            objTPC.AddTabPermission(tpi);

            TabPermissionInfo tpi1 = new TabPermissionInfo();

            tpi1.TabID          = tabId;
            tpi1.PermissionID   = 4; //for edit
            tpi1.PermissionKey  = "EDIT";
            tpi1.PermissionName = "Edit Tab";
            tpi1.AllowAccess    = true;
            tpi1.RoleID         = 0; //Role ID of administrator
            objTPC.AddTabPermission(tpi1);

            TabPermissionInfo tpi4 = new TabPermissionInfo();

            tpi4.TabID          = tabId;
            tpi4.PermissionID   = 3;
            tpi4.PermissionKey  = "VIEW";
            tpi4.PermissionName = "View Tab";
            tpi4.AllowAccess    = true;
            tpi4.RoleID         = -1; //All users
            objTPC.AddTabPermission(tpi4);

            return(tab);
        }
Ejemplo n.º 16
0
        protected void OnImportClick(object sender, EventArgs e)
        {
            try
            {
                if (cboTemplate.SelectedItem == null || cboTemplate.SelectedValue == "None_Specified")
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyFile", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                if (optMode.SelectedIndex == -1)
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyMode", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                if (cboFolders.SelectedItem == null)
                {
                    return;
                }
                var selectedFolder = FolderManager.Instance.GetFolder(cboFolders.SelectedItemValueAsInt);
                if (selectedFolder == null)
                {
                    return;
                }

                var xmlDoc = new XmlDocument();
                xmlDoc.Load(PortalSettings.HomeDirectoryMapPath + selectedFolder.FolderPath + cboTemplate.SelectedValue);

                var tabNodes         = new List <XmlNode>();
                var selectSingleNode = xmlDoc.SelectSingleNode("//portal/tabs");
                if (selectSingleNode != null)
                {
                    tabNodes.AddRange(selectSingleNode.ChildNodes.Cast <XmlNode>());
                }
                if (tabNodes.Count == 0)
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("NoTabsInTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                TabInfo objTab;
                if (optMode.SelectedValue == "ADD")
                {
                    if (string.IsNullOrEmpty(txtTabName.Text))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("SpecifyName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    //New Tab
                    objTab = new TabInfo {
                        PortalID = PortalId, TabName = txtTabName.Text, IsVisible = true
                    };
                    var parentId = cboParentTab.SelectedItemValueAsInt;
                    if (parentId != Null.NullInteger)
                    {
                        objTab.ParentId = parentId;
                    }
                    objTab.TabPath = Globals.GenerateTabPath(objTab.ParentId, objTab.TabName);
                    var tabId   = TabController.GetTabByTabPath(objTab.PortalID, objTab.TabPath, Null.NullString);
                    var objTabs = new TabController();

                    //Check if tab exists
                    if (tabId != Null.NullInteger)
                    {
                        TabInfo 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;
                    }

                    var positionTabId = Int32.Parse(cboPositionTab.SelectedItem.Value);

                    //var pc = new PermissionController();

                    //var permission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "VIEW");
                    //if (permission.Count > 0)
                    //{
                    //    var pid = ((PermissionInfo)permission[0]).PermissionID;
                    //    objTab.TabPermissions.Add(new TabPermissionInfo { PermissionID = pid, AllowAccess = true, RoleID = 0 });
                    //}

                    //permission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "EDIT");
                    //if (permission.Count > 0)
                    //{
                    //    var pid = ((PermissionInfo)permission[0]).PermissionID;
                    //    objTab.TabPermissions.Add(new TabPermissionInfo { PermissionID = pid, AllowAccess = true, RoleID = 0 });
                    //}

                    var objEventLog = new EventLogController();
                    if (rbInsertPosition.SelectedValue == "After" && positionTabId > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabAfter(objTab, positionTabId);
                    }
                    else if (rbInsertPosition.SelectedValue == "Before" && positionTabId > Null.NullInteger)
                    {
                        objTab.TabID = objTabs.AddTabBefore(objTab, positionTabId);
                    }
                    else
                    {
                        objTab.TabID = objTabs.AddTab(objTab);
                    }
                    objEventLog.AddLog(objTab, PortalSettings, UserId, "", EventLogController.EventLogType.TAB_CREATED);

                    objTab = TabController.DeserializeTab(tabNodes[0], objTab, PortalId, PortalTemplateModuleAction.Replace);

                    var exceptions = string.Empty;
                    //Create second tabs onwards. For firs tab, we like to use tab details from text box, for rest it'll come from template
                    for (var tab = 1; tab < tabNodes.Count; tab++)
                    {
                        try
                        {
                            TabController.DeserializeTab(tabNodes[tab], null, PortalId, PortalTemplateModuleAction.Replace);
                        }
                        catch (Exception ex)
                        {
                            Exceptions.LogException(ex);
                            exceptions += string.Format("Template Tab # {0}. Error {1}<br/>", tab + 1, ex.Message);
                        }
                    }
                    if (!string.IsNullOrEmpty(exceptions))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, exceptions, ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                }
                else
                {
                    //Replace Existing Tab
                    objTab = TabController.DeserializeTab(tabNodes[0], Tab, PortalId, PortalTemplateModuleAction.Replace);
                }
                switch (optRedirect.SelectedValue)
                {
                case "VIEW":
                    Response.Redirect(Globals.NavigateURL(objTab.TabID), true);
                    break;

                default:
                    Response.Redirect(Globals.NavigateURL(objTab.TabID, "Tab", "action=edit"), true);
                    break;
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Ejemplo n.º 17
0
        private void AddUserProfilePage(int portalId, bool setAsPortalUserProfile)
        {
            var tabController    = new TabController();
            var moduleController = new ModuleController();

            // Get Azure AD B2C User profile module
            var moduleFriendlyName = "AzureAD.B2C.UserProfile";
            var moduleDef          = ModuleDefinitionController.GetModuleDefinitionByFriendlyName(moduleFriendlyName);

            //Add User Profile page under root
            var     parentId = TabController.GetTabByTabPath(PortalId, "//", Null.NullString);
            var     tabId    = TabController.GetTabByTabPath(PortalId, "//UserProfile", Null.NullString);
            int     moduleId;
            TabInfo tabInfo;


            if (tabId == Null.NullInteger)
            {
                tabInfo = new TabInfo()
                {
                    PortalID        = PortalId,
                    TabName         = "UserProfile",
                    Title           = "User Profile",
                    Description     = "Manage Azure AD B2C User profile",
                    KeyWords        = "profile",
                    IsDeleted       = false,
                    IsSuperTab      = false,
                    IsVisible       = false,
                    DisableLink     = false,
                    IconFile        = null,
                    SiteMapPriority = 0,
                    Url             = null,
                    ParentId        = parentId
                };
                tabInfo.TabSettings.Add("AllowIndex", "False");
                // Add User Profile page
                tabId = tabController.AddTab(tabInfo);


                // Allow access to "Registered Users" role
                var permissions = new TabPermissionInfo()
                {
                    AllowAccess  = true,
                    RoleID       = PortalSettings.RegisteredRoleId,
                    RoleName     = PortalSettings.RegisteredRoleName,
                    TabID        = tabId,
                    PermissionID = 3 // View
                };
                tabInfo.TabPermissions.Add(permissions, true);
                PermissionProvider.Instance().SaveTabPermissions(tabInfo);
            }
            else
            {
                tabInfo = tabController.GetTab(tabId, PortalId, false);

                foreach (var kvp in moduleController.GetTabModules(tabId))
                {
                    if (kvp.Value.DesktopModule.ModuleName == moduleFriendlyName)
                    {
                        // Preview module so hard delete
                        moduleController.DeleteTabModule(tabId, kvp.Value.ModuleID, false);
                        break;
                    }
                }
            }

            //Add module to page
            moduleId = Upgrade.AddModuleToPage(tabInfo, moduleDef.ModuleDefID, "User Profile", "", true);

            var moduleTab = moduleController.GetTabModules(tabInfo.TabID)
                            .FirstOrDefault(x => x.Value.ModuleID == moduleId);

            if (moduleTab.Value != null)
            {
                moduleController.UpdateTabModuleSetting(moduleTab.Value.TabModuleID, "hideadminborder", "True");
            }

            // Change User profile page on the Portal settings
            var portalInfo = PortalController.Instance.GetPortal(PortalId);

            portalInfo.UserTabId = setAsPortalUserProfile ? tabId : Null.NullInteger;
            PortalController.Instance.UpdatePortalInfo(portalInfo);
        }
Ejemplo n.º 18
0
        private TabInfo CreateSubTab(string tabName, int departmentId, string settingsName = "department", int?parentTabID = null)
        {
            //Create Tab
            TabController tabController = new TabController();

            TabInfo tab = new TabInfo();

            tab.PortalID = PortalId;
            tab.TabName  = tabName;
            tab.Title    = tabName;

            //works for include in menu option. if true, will be shown in menus, else will not be shown, we have to redirect internally
            tab.IsVisible   = true;
            tab.DisableLink = false;

            //if this tab has any parents provide parent tab id, so that it will be shown in parent tab menus sub menu list, else is NULL
            //and will be in main menu list
            if (parentTabID == null)
            {
                tab.ParentId = TabId;
            }
            else
            {
                tab.ParentId = parentTabID.Value;
            }
            tab.IsDeleted    = false;
            tab.Url          = "";
            tab.IsSuperTab   = false;                            //if true, it has no parents, else false
            tab.SkinSrc      = "[G]Skins/Artfolio001/page.ascx"; //provide skin src, else will take default skin
            tab.ContainerSrc = "[G]Containers/Artfolio001/Block.ascx";
            int tabId = tabController.AddTab(tab, true);         //true to load defalut modules

            //Set Tab Permission
            TabPermissionController objTPC = new TabPermissionController();

            TabPermissionInfo tpi = new TabPermissionInfo();

            tpi.TabID          = tabId;
            tpi.PermissionID   = 3; //for view
            tpi.PermissionKey  = "VIEW";
            tpi.PermissionName = "View Tab";
            tpi.AllowAccess    = true;
            tpi.RoleID         = 0; //Role ID of administrator
            objTPC.AddTabPermission(tpi);

            TabPermissionInfo tpi1 = new TabPermissionInfo();

            tpi1.TabID          = tabId;
            tpi1.PermissionID   = 4; //for edit
            tpi1.PermissionKey  = "EDIT";
            tpi1.PermissionName = "Edit Tab";
            tpi1.AllowAccess    = true;
            tpi1.RoleID         = 0; //Role ID of administrator
            objTPC.AddTabPermission(tpi1);

            TabPermissionInfo tpi4 = new TabPermissionInfo();

            tpi4.TabID          = tabId;
            tpi4.PermissionID   = 3;
            tpi4.PermissionKey  = "VIEW";
            tpi4.PermissionName = "View Tab";
            tpi4.AllowAccess    = true;
            tpi4.RoleID         = -1; //All users
            objTPC.AddTabPermission(tpi4);

            //Add Module
            DesktopModuleController objDMC            = new DesktopModuleController();
            DesktopModuleInfo       desktopModuleInfo = objDMC.GetDesktopModuleByName("Clothes");

            ModuleDefinitionInfo moduleDefinitionInfo = new ModuleDefinitionInfo();
            ModuleInfo           moduleInfo           = new ModuleInfo();

            moduleInfo.PortalID                     = PortalId;
            moduleInfo.TabID                        = tabId;
            moduleInfo.ModuleOrder                  = 1;
            moduleInfo.ModuleTitle                  = "Clothes";
            moduleInfo.PaneName                     = "Clothes";
            moduleInfo.ModuleDefID                  = 160;
            moduleInfo.CacheTime                    = moduleDefinitionInfo.DefaultCacheTime; //Default Cache Time is 0
            moduleInfo.InheritViewPermissions       = true;                                  //Inherit View Permissions from Tab
            moduleInfo.AllTabs                      = false;
            moduleInfo.ModuleSettings[settingsName] = departmentId;

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

            //Set Module Permission
            ModulePermissionController objMPC = new ModulePermissionController();

            ModulePermissionInfo mpi1 = new ModulePermissionInfo();

            mpi1.ModuleID     = moduleId;
            mpi1.PermissionID = 1; //View Permission
            mpi1.AllowAccess  = true;
            mpi1.RoleID       = 0; //Role ID of Administrator
            objMPC.AddModulePermission(mpi1);

            ModulePermissionInfo mpi2 = new ModulePermissionInfo();

            mpi2.ModuleID     = moduleId;
            mpi2.PermissionID = 2; //Edit Permission
            mpi2.AllowAccess  = true;
            mpi2.RoleID       = 0; //Role ID of Administrator
            objMPC.AddModulePermission(mpi2);

            ModulePermissionInfo mpi5 = new ModulePermissionInfo();

            mpi5.ModuleID     = moduleId;
            mpi5.PermissionID = 1; //View Permission
            mpi5.AllowAccess  = true;
            mpi5.RoleID       = 1; //Role ID of Registered User
            objMPC.AddModulePermission(mpi5);
            return(tab);
        }
Ejemplo n.º 19
0
    /// <summary>
    /// Add the module to a page
    /// </summary>
    /// <param name="friendlyNameModule"></param>
    /// <returns></returns>
    protected bool AddModuleToPage(String friendlyNameModule)
    {
        TextBox        tbx            = (TextBox)FindControl("tbx_nom");
        PortalSettings portalSettings = new PortalSettings();
        int            portalId       = portalSettings.PortalId;

        //Creating page
        TabController tabController = new TabController();

        TabInfo tab = null;

        //Checking if the page already exists
        if (!tabController.GetTabsByPortal(portalId).Values.Contains(tabController.GetTabByName(tbx.Text, portalId)))
        {
            tab             = new TabInfo();
            tab.PortalID    = portalId;
            tab.TabName     = tbx.Text;
            tab.Title       = tbx.Text;
            tab.Description = tbx.Text;
            tab.KeyWords    = tbx.Text;
            tab.IsVisible   = true;
            tab.DisableLink = false;
            tab.IsDeleted   = false;
            tab.Url         = "";
            tab.IsSuperTab  = true;

            AddPermissionsOnTab(tab);
            int tabId = tabController.AddTab(tab, false);
            tbx.Text = "";
        }
        else if (!tabController.GetTabByName(tbx.Text, portalId).IsDeleted)
        {
            tab = tabController.GetTabByName(tbx.Text, portalId);
        }
        else
        {
            return(false);
        }

        DesktopModuleInfo desktopModuleInfo = null;

        foreach (KeyValuePair <int, DesktopModuleInfo> kvp in DesktopModuleController.GetDesktopModules(portalId))
        {
            DesktopModuleInfo mod = kvp.Value;
            if (mod != null)
            {
                if ((mod.FriendlyName == friendlyNameModule || mod.ModuleName == friendlyNameModule) && (mod.FriendlyName != "AIS_Installer" || mod.ModuleName != "AIS.Installer"))
                {
                    desktopModuleInfo = mod;
                }
            }
        }

        if (desktopModuleInfo != null && tab != null)
        {
            foreach (ModuleDefinitionInfo moduleDefinitionInfo in ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(desktopModuleInfo.DesktopModuleID).Values)
            {
                ModuleInfo moduleInfo = new ModuleInfo();
                moduleInfo.PortalID               = portalId;
                moduleInfo.TabID                  = tab.TabID;
                moduleInfo.ModuleOrder            = 1;
                moduleInfo.ModuleTitle            = desktopModuleInfo.FriendlyName;
                moduleInfo.PaneName               = "ContentPane";
                moduleInfo.ModuleDefID            = moduleDefinitionInfo.ModuleDefID;
                moduleInfo.CacheTime              = moduleDefinitionInfo.DefaultCacheTime;
                moduleInfo.InheritViewPermissions = true;
                moduleInfo.AllTabs                = false;
                ModuleController moduleController = new ModuleController();
                int moduleId = moduleController.AddModule(moduleInfo);
            }
        }
        //Clearing cache
        DotNetNuke.Common.Utilities.DataCache.ClearModuleCache(tab.TabID);
        DotNetNuke.Common.Utilities.DataCache.ClearTabsCache(PortalId);
        DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(PortalId, false);

        return(true);
    }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        //todo: Settings
        //Public Function SaveTabInfoObject(ByVal newTab As DotNetNuke.Entities.Tabs.TabInfo, ByVal relativeToTab As DotNetNuke.Entities.Tabs.TabInfo, ByVal location As TabRelativeLocation, ByVal templateMapPath As String, ByVal tabSettings As Hashtable) As Integer
        public static int SaveTabInfoObject(TabInfo tab, TabInfo relativeToTab, TabRelativeLocation location, string templateMapPath)
        {
            TabController tabCtrl = new TabController();

            //Validation:
            //Tab name is required
            //Tab name is invalid
            if ((tab.TabName == string.Empty))
            {
                throw new DotNetNukeException("Page name is required.", DotNetNukeErrorCode.PageNameRequired);
            }
            else if ((Regex.IsMatch(tab.TabName, "^LPT[1-9]$|^COM[1-9]$", RegexOptions.IgnoreCase)))
            {
                throw new DotNetNukeException("Page name is invalid.", DotNetNukeErrorCode.PageNameInvalid);
            }
            else if ((Regex.IsMatch(HtmlUtils.StripNonWord(tab.TabName, false), "^AUX$|^CON$|^NUL$|^SITEMAP$|^LINKCLICK$|^KEEPALIVE$|^DEFAULT$|^ERRORPAGE$", RegexOptions.IgnoreCase)))
            {
                throw new DotNetNukeException("Page name is invalid.", DotNetNukeErrorCode.PageNameInvalid);
            }
            else if ((Validate_IsCircularReference(tab.PortalID, tab.TabID)))
            {
                throw new DotNetNukeException("Cannot move page to that location.", DotNetNukeErrorCode.PageCircularReference);
            }

            bool usingDefaultLanguage = (tab.CultureCode == PortalSettings.Current.DefaultLanguage) || tab.CultureCode == null;

            if (PortalSettings.Current.ContentLocalizationEnabled)
            {
                if ((!usingDefaultLanguage))
                {
                    TabInfo defaultLanguageSelectedTab = tab.DefaultLanguageTab;

                    if ((defaultLanguageSelectedTab == null))
                    {
                        //get the siblings from the selectedtab and iterate through until you find a sibbling with a corresponding defaultlanguagetab
                        //if none are found get a list of all the tabs from the default language and then select the last one
                        var selectedTabSibblings = tabCtrl.GetTabsByPortal(tab.PortalID).WithCulture(tab.CultureCode, true).AsList();
                        foreach (TabInfo sibling in selectedTabSibblings)
                        {
                            TabInfo siblingDefaultTab = sibling.DefaultLanguageTab;
                            if (((siblingDefaultTab != null)))
                            {
                                defaultLanguageSelectedTab = siblingDefaultTab;
                                break;
                            }
                        }

                        //still haven't found it
                        if ((defaultLanguageSelectedTab == null))
                        {
                            var defaultLanguageTabs = tabCtrl.GetTabsByPortal(tab.PortalID).WithCulture(PortalSettings.Current.DefaultLanguage, true).AsList();
                            defaultLanguageSelectedTab = defaultLanguageTabs[defaultLanguageTabs.Count];
                            //get the last tab
                        }
                    }

                    relativeToTab = defaultLanguageSelectedTab;
                }
            }


            if ((location != TabRelativeLocation.NOTSET))
            {
                //Check Host tab - don't allow adding before or after
                if ((IsHostConsolePage(relativeToTab) && (location == TabRelativeLocation.AFTER || location == TabRelativeLocation.BEFORE)))
                {
                    throw new DotNetNukeException("You cannot add or move pages before or after the Host tab.", DotNetNukeErrorCode.HostBeforeAfterError);
                }

                TabInfo parentTab      = GetParentTab(relativeToTab, location);
                string  permissionList = "ADD,COPY,EDIT,MANAGE";
                //Check permissions for Page Editors when moving or inserting
                if ((!PortalSecurity.IsInRole("Administrators")))
                {
                    if (((parentTab == null) || !TabPermissionController.HasTabPermission(parentTab.TabPermissions, permissionList)))
                    {
                        throw new DotNetNukeException("You do not have permissions to add or move pages to this location. You can only add or move pages as children of pages you can edit.",
                                                      DotNetNukeErrorCode.PageEditorPermissionError);
                    }
                }

                if (((parentTab != null)))
                {
                    tab.ParentId = parentTab.TabID;
                    tab.Level    = parentTab.Level + 1;
                }
                else
                {
                    tab.ParentId = Null.NullInteger;
                    tab.Level    = 0;
                }
            }

            if ((tab.TabID > Null.NullInteger && tab.TabID == tab.ParentId))
            {
                throw new DotNetNukeException("Parent page is invalid.", DotNetNukeErrorCode.ParentTabInvalid);
            }

            tab.TabPath = Globals.GenerateTabPath(tab.ParentId, tab.TabName);
            //check whether have conflict between tab path and portal alias.
            if (TabController.IsDuplicateWithPortalAlias(PortalSettings.Current.PortalId, tab.TabPath))
            {
                throw new DotNetNukeException("The page path is duplicate with a site alias", DotNetNukeErrorCode.DuplicateWithAlias);
            }

            try
            {
                if ((tab.TabID < 0))
                {
                    if ((tab.TabPermissions.Count == 0 && tab.PortalID != Null.NullInteger))
                    {
                        //Give admin full permission
                        ArrayList permissions = PermissionController.GetPermissionsByTab();

                        foreach (PermissionInfo permission in permissions)
                        {
                            TabPermissionInfo newTabPermission = new TabPermissionInfo();
                            newTabPermission.PermissionID   = permission.PermissionID;
                            newTabPermission.PermissionKey  = permission.PermissionKey;
                            newTabPermission.PermissionName = permission.PermissionName;
                            newTabPermission.AllowAccess    = true;
                            newTabPermission.RoleID         = PortalSettings.Current.AdministratorRoleId;
                            tab.TabPermissions.Add(newTabPermission);
                        }
                    }

                    PortalSettings _PortalSettings = PortalController.GetCurrentPortalSettings();

                    if (_PortalSettings.ContentLocalizationEnabled)
                    {
                        Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(tab.PortalID);
                        tab.CultureCode = defaultLocale.Code;
                    }
                    else
                    {
                        tab.CultureCode = Null.NullString;
                    }

                    if ((location == TabRelativeLocation.AFTER && (relativeToTab != null)))
                    {
                        tab.TabID = tabCtrl.AddTabAfter(tab, relativeToTab.TabID);
                    }
                    else if ((location == TabRelativeLocation.BEFORE && (relativeToTab != null)))
                    {
                        tab.TabID = tabCtrl.AddTabBefore(tab, relativeToTab.TabID);
                    }
                    else
                    {
                        tab.TabID = tabCtrl.AddTab(tab);
                    }

                    if (_PortalSettings.ContentLocalizationEnabled)
                    {
                        tabCtrl.CreateLocalizedCopies(tab);
                    }

                    tabCtrl.UpdateTabSetting(tab.TabID, "CacheProvider", "");
                    tabCtrl.UpdateTabSetting(tab.TabID, "CacheDuration", "");
                    tabCtrl.UpdateTabSetting(tab.TabID, "CacheIncludeExclude", "0");
                    tabCtrl.UpdateTabSetting(tab.TabID, "IncludeVaryBy", "");
                    tabCtrl.UpdateTabSetting(tab.TabID, "ExcludeVaryBy", "");
                    tabCtrl.UpdateTabSetting(tab.TabID, "MaxVaryByCount", "");
                }
                else
                {
                    tabCtrl.UpdateTab(tab);

                    if ((location == TabRelativeLocation.AFTER && (relativeToTab != null)))
                    {
                        tabCtrl.MoveTabAfter(tab, relativeToTab.TabID);
                    }
                    else if ((location == TabRelativeLocation.BEFORE && (relativeToTab != null)))
                    {
                        tabCtrl.MoveTabBefore(tab, relativeToTab.TabID);
                    }
                }
            }
            catch (Exception ex)
            {
                DnnLog.Error(ex);

                if (ex.Message.StartsWith("Page Exists"))
                {
                    throw new DotNetNukeException(ex.Message, DotNetNukeErrorCode.PageExists);
                }
            }

            // create the page from a template
            if ((!string.IsNullOrEmpty(templateMapPath)))
            {
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.Load(templateMapPath);
                    TabController.DeserializePanes(xmlDoc.SelectSingleNode("//portal/tabs/tab/panes"), tab.PortalID, tab.TabID, PortalTemplateModuleAction.Ignore, new Hashtable());

                    //save tab permissions
                    DeserializeTabPermissions(xmlDoc.SelectNodes("//portal/tabs/tab/tabpermissions/permission"), tab);
                }
                catch (Exception ex)
                {
                    Exceptions.LogException(ex);
                    throw new DotNetNukeException("Unable to process page template.", ex, DotNetNukeErrorCode.DeserializePanesFailed);
                }
            }

            //todo: reload tab from db or send back tabid instead?
            return(tab.TabID);
        }