/// <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 "";
        }
Esempio n. 2
0
        public TabInfo AddCoursePage(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/CoursePage.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.DisplayCourse);

            AddModuleToPage(newTab, ModuleType.Rating);

            AddModuleToPage(newTab, ModuleType.Comments);

            return newTab;
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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);
     }
 }
Esempio n. 5
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="TabIconFile">The 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 TabIconFile, bool IsVisible, TabPermissionCollection permissions, bool IsAdmin)
        {
            TabController objTabs = new TabController();
            TabInfo objTab;

            objTab = objTabs.GetTabByName(TabName, PortalId, ParentId);
            if (objTab == null)
            {
                objTab = new TabInfo();
                objTab.TabID = Null.NullInteger;
                objTab.PortalID = PortalId;
                objTab.TabName = TabName;
                objTab.Title = "";
                objTab.Description = "";
                objTab.KeyWords = "";
                objTab.IsVisible = IsVisible;
                objTab.DisableLink = false;
                objTab.ParentId = ParentId;
                objTab.IconFile = TabIconFile;
                objTab.AdministratorRoles = Null.NullString;
                objTab.IsDeleted = false;
                objTab.TabPermissions = permissions;
                objTab.TabID = objTabs.AddTab(objTab, !IsAdmin);
            }

            return objTab;
        }
        private int CreateTabFromParent(TabInfo objRoot, string tabName, int parentId)
        {
            var tab = new TabInfo
            {
                PortalID = PortalId,
                TabName = tabName,
                ParentId = parentId,
                Title = "",
                Description = "",
                KeyWords = "",
                IsVisible = true,
                DisableLink = false,
                IconFile = "",
                IconFileLarge = "",
                IsDeleted = false,
                Url = "",
                SkinSrc = "",
                ContainerSrc = "",
                CultureCode = Null.NullString
            };

            if (objRoot != null)
            {
                tab.IsVisible = objRoot.IsVisible;
                tab.DisableLink = objRoot.DisableLink;
                tab.SkinSrc = objRoot.SkinSrc;
                tab.ContainerSrc = objRoot.ContainerSrc;
            }

            var portalSettings = PortalController.GetCurrentPortalSettings();
            if (portalSettings.ContentLocalizationEnabled)
            {
                tab.CultureCode = LocaleController.Instance.GetDefaultLocale(tab.PortalID).Code;
            }

            var controller = new TabController();
            var parentTab = controller.GetTab(parentId, -1, false);

            if (parentTab != null)
            {
                tab.PortalID = parentTab.PortalID;
                tab.ParentId = parentTab.TabID;
                if (parentTab.IsSuperTab)
                    ShowPermissions(false);
            }
            else
            {
                //return Null.NullInteger;
                tab.PortalID = PortalId;
                tab.ParentId = Null.NullInteger;
            }

            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;
            }

            //Inherit permissions from parent
            tab.TabPermissions.Clear();
            if (tab.PortalID != Null.NullInteger && objRoot != null)
            {
                tab.TabPermissions.AddRange(objRoot.TabPermissions);
            }
            else if (tab.PortalID != Null.NullInteger)
            {
                //Give admin full permission
                ArrayList permissions = PermissionController.GetPermissionsByTab();

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

            //Inherit other information from Parent
            if (objRoot != null)
            {
                tab.Terms.Clear();
                tab.StartDate = objRoot.StartDate;
                tab.EndDate = objRoot.EndDate;
                tab.RefreshInterval = objRoot.RefreshInterval;
                tab.SiteMapPriority = objRoot.SiteMapPriority;
                tab.PageHeadText = objRoot.PageHeadText;
                tab.IsSecure = objRoot.IsSecure;
                tab.PermanentRedirect = objRoot.PermanentRedirect;
            }

            var ctrl = new TabController();
            tab.TabID = ctrl.AddTab(tab);
            ApplyDefaultTabTemplate(tab);

            //create localized tabs if content localization is enabled
            if (portalSettings.ContentLocalizationEnabled)
            {
                ctrl.CreateLocalizedCopies(tab);
            }

            ShowSuccessMessage(string.Format(Localization.GetString("TabCreated", LocalResourceFile), tab.TabName));
            return tab.TabID;
        }
        /// <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;
        }
Esempio n. 8
0
        private TabInfo CreateTab(string tabName)
        {
            var tc = new TabController();
            var tab = new TabInfo { PortalID = PortalId, TabName = tabName };

            tc.AddTab(tab);

            return tab;
        }
        /// <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;
        }
        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);

                var tabNodes = new List<XmlNode>();
                foreach (XmlNode tabNode in xmlDoc.SelectSingleNode("//portal/tabs").ChildNodes)
                {
                    tabNodes.Add(tabNode);
                }
                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};
                    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 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);

                    //Update Tab properties from template - for the first tab only
                    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);
            }
        }
Esempio 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>
        /// <history>
        /// 	[cnurse]	11/11/2004	created 
        /// </history>
        /// -----------------------------------------------------------------------------
        private static TabInfo AddPage(int portalId, int parentId, string tabName, string description, string tabIconFile, string tabIconFileLarge, bool isVisible, TabPermissionCollection permissions, bool isAdmin)
        {
            DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddPage:" + tabName);
            var tabController = new TabController();

            TabInfo 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;
        }
Esempio n. 12
0
        /// <summary>
        /// Processes a single tab from the template
        /// </summary>
        /// <param name="nodeTab">Template file node for the tabs</param>
        /// <param name="PortalId">PortalId of the new portal</param>
        /// <param name="IsAdminTemplate">True when processing admin template, false when processing portal template</param>
        /// <param name="mergeTabs">Flag to determine whether Module content is merged.</param>
        /// <param name="hModules">Used to control if modules are true modules or instances</param>
        /// <param name="hTabs">Supporting object to build the tab hierarchy</param>
        /// <param name="IsNewPortal">Flag to determine is the template is applied to an existing portal or a new one.</param>
        /// <remarks>
        /// When a special tab is found (HomeTab, UserTab, LoginTab, AdminTab) portal information will be updated.
        /// </remarks>
        /// <history>
        /// 	[VMasanas]	26/08/2004	Removed code to allow multiple tabs with same name.
        /// 	[VMasanas]	15/10/2004	Modified for new skin structure
        ///		[cnurse]	15/10/2004	Modified to allow for merging template
        ///								with existing pages
        ///     [cnurse]    11/21/2204  modified to use GetNodeValueDate for Start and End Dates
        /// </history>
        private int ParseTab( XmlNode nodeTab, int PortalId, bool IsAdminTemplate, PortalTemplateModuleAction mergeTabs, ref Hashtable hModules, ref Hashtable hTabs, bool IsNewPortal )
        {
            TabInfo objTab = null;
            TabController objTabs = new TabController();
            string strName = XmlUtils.GetNodeValue( nodeTab, "name", "" );
            int intTabId = 0;
            PortalInfo objportal = null;
            bool tabExists = true;
            string tabName = null;

            objportal = GetPortal( PortalId );

            if( strName != "" )
            {
                if( !IsNewPortal ) // running from wizard: try to find the tab by path
                {
                    string parenttabname = "";

                    if( XmlUtils.GetNodeValue( nodeTab, "parent", "" ) != "" )
                    {
                        parenttabname = XmlUtils.GetNodeValue( nodeTab, "parent", "" ) + "/";
                    }
                    if( !( hTabs[parenttabname + strName] == null ) )
                    {
                        objTab = objTabs.GetTab( Convert.ToInt32( hTabs[parenttabname + strName] ), PortalId, false );
                    }
                }

                if( objTab == null | IsNewPortal )
                {
                    tabExists = false;

                    objTab = new TabInfo();
                    intTabId = Null.NullInteger;

                    objTab.TabID = intTabId;
                    objTab.PortalID = PortalId;
                    objTab.TabName = XmlUtils.GetNodeValue( nodeTab, "name", "" );
                    objTab.Title = XmlUtils.GetNodeValue( nodeTab, "title", "" );
                    objTab.Description = XmlUtils.GetNodeValue( nodeTab, "description", "" );
                    objTab.KeyWords = XmlUtils.GetNodeValue( nodeTab, "keywords", "" );
                    objTab.IsVisible = XmlUtils.GetNodeValueBoolean( nodeTab, "visible", true );
                    objTab.DisableLink = XmlUtils.GetNodeValueBoolean( nodeTab, "disabled", false );
                    objTab.IconFile = ImportFile( PortalId, XmlUtils.GetNodeValue( nodeTab, "iconfile", "" ) );
                    objTab.Url = XmlUtils.GetNodeValue( nodeTab, "url", "" );
                    objTab.StartDate = XmlUtils.GetNodeValueDate( nodeTab, "startdate", Null.NullDate );
                    objTab.EndDate = XmlUtils.GetNodeValueDate( nodeTab, "enddate", Null.NullDate );
                    objTab.RefreshInterval = XmlUtils.GetNodeValueInt( nodeTab, "refreshinterval", Null.NullInteger );
                    objTab.PageHeadText = XmlUtils.GetNodeValue( nodeTab, "pageheadtext", Null.NullString );

                    XmlNodeList nodeTabPermissions = nodeTab.SelectNodes( "tabpermissions/permission" );
                    objTab.TabPermissions = ParseTabPermissions( nodeTabPermissions, objportal, objTab.TabID, IsAdminTemplate );

                    // set tab skin and container
                    if( XmlUtils.GetNodeValue( nodeTab, "skinsrc", "" ) != "" )
                    {
                        objTab.SkinSrc = XmlUtils.GetNodeValue( nodeTab, "skinsrc", "" );
                    }
                    if( XmlUtils.GetNodeValue( nodeTab, "containersrc", "" ) != "" )
                    {
                        objTab.ContainerSrc = XmlUtils.GetNodeValue( nodeTab, "containersrc", "" );
                    }

                    // process of parent tab
                    objTab.ParentId = Null.NullInteger;
                    tabName = objTab.TabName;

                    if( XmlUtils.GetNodeValue( nodeTab, "parent", "" ) != "" )
                    {
                        if( !( hTabs[XmlUtils.GetNodeValue( nodeTab, "parent", "" )] == null ) )
                        {
                            // parent node specifies the path (tab1/tab2/tab3), use saved tabid
                            objTab.ParentId = Convert.ToInt32( hTabs[XmlUtils.GetNodeValue( nodeTab, "parent", "" )] );
                            tabName = XmlUtils.GetNodeValue( nodeTab, "parent", "" ) + "/" + objTab.TabName;
                        }
                        else
                        {
                            // Parent node doesn't spcecify the path, search by name.
                            // Possible incoherence if tabname not unique
                            TabInfo objParent = objTabs.GetTabByName( XmlUtils.GetNodeValue( nodeTab, "parent", "" ), PortalId );
                            if( objParent != null )
                            {
                                objTab.ParentId = objParent.TabID;
                                tabName = objParent.TabName + "/" + objTab.TabName;
                            }
                            else
                            {
                                // parent tab not found!
                                objTab.ParentId = Null.NullInteger;
                                tabName = objTab.TabName;
                            }
                        }
                    }
                    // create tab
                    intTabId = objTabs.AddTab( objTab );
                    // extra check for duplicate tabs in same level
                    if( hTabs[tabName] == null )
                    {
                        hTabs.Add( tabName, intTabId );
                    }
                }

                if( IsAdminTemplate )
                {
                    // when processing the admin template we should identify the Admin tab
                    if( objTab.TabName == "Admin" )
                    {
                        objportal.AdminTabId = intTabId;
                        DataProvider.Instance().UpdatePortalSetup( PortalId, objportal.AdministratorId, objportal.AdministratorRoleId, objportal.RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );
                    }
                }
                else
                {
                    // when processing the portal template we can find: hometab, usertab, logintab
                    switch( XmlUtils.GetNodeValue( nodeTab, "tabtype", "" ) )
                    {
                        case "splashtab":
                            objportal.SplashTabId = intTabId;
                            DataProvider.Instance().UpdatePortalSetup( PortalId, objportal.AdministratorId, objportal.AdministratorRoleId, objportal.RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );
                            break;
                        case "hometab":
                            objportal.HomeTabId = intTabId;
                            DataProvider.Instance().UpdatePortalSetup( PortalId, objportal.AdministratorId, objportal.AdministratorRoleId, objportal.RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );
                            break;
                        case "logintab":
                            objportal.LoginTabId = intTabId;
                            DataProvider.Instance().UpdatePortalSetup( PortalId, objportal.AdministratorId, objportal.AdministratorRoleId, objportal.RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );
                            break;
                        case "usertab":
                            objportal.UserTabId = intTabId;
                            DataProvider.Instance().UpdatePortalSetup( PortalId, objportal.AdministratorId, objportal.AdministratorRoleId, objportal.RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );
                            break;
                    }
                }

                //If tab does not already exist parse modules
                if( !tabExists )
                {
                    if( nodeTab.SelectSingleNode( "panes" ) != null )
                    {
                        ParsePanes( nodeTab.SelectSingleNode( "panes" ), PortalId, intTabId, mergeTabs, hModules );
                    }
                }
            }
            return 0;
        }
Esempio n. 13
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;
        }
Esempio n. 14
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;
        }
Esempio n. 15
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;
        }
Esempio n. 16
0
        /// <summary>
        /// Deserializes the tab.
        /// </summary>
        /// <param name="tabNode">The node tab.</param>
        /// <param name="tab">The obj tab.</param>
        /// <param name="tabs">The h tabs.</param>
        /// <param name="portalId">The portal id.</param>
        /// <param name="isAdminTemplate">if set to <c>true</c> [is admin template].</param>
        /// <param name="mergeTabs">The merge tabs.</param>
        /// <param name="modules">The h modules.</param>
        /// <returns></returns>
        public static TabInfo DeserializeTab(XmlNode tabNode, TabInfo tab, Hashtable tabs, int portalId,
                                             bool isAdminTemplate, PortalTemplateModuleAction mergeTabs,
                                             Hashtable modules)
        {
            var tabController = new TabController();
            string tabName = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "name");
            if (!String.IsNullOrEmpty(tabName))
            {
                if (tab == null)
                {
                    tab = new TabInfo { TabID = Null.NullInteger, ParentId = Null.NullInteger, TabName = tabName };
                }
                tab.PortalID = portalId;
                tab.Title = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "title");
                tab.Description = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "description");
                tab.KeyWords = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "keywords");
                tab.IsVisible = XmlUtils.GetNodeValueBoolean(tabNode, "visible", true);
                tab.DisableLink = XmlUtils.GetNodeValueBoolean(tabNode, "disabled");
                tab.IconFile = Globals.ImportFile(portalId, XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "iconfile"));
                tab.IconFileLarge = Globals.ImportFile(portalId,
                                                       XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "iconfilelarge"));
                tab.Url = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "url");
                tab.StartDate = XmlUtils.GetNodeValueDate(tabNode, "startdate", Null.NullDate);
                tab.EndDate = XmlUtils.GetNodeValueDate(tabNode, "enddate", Null.NullDate);
                tab.RefreshInterval = XmlUtils.GetNodeValueInt(tabNode, "refreshinterval", Null.NullInteger);
                tab.PageHeadText = XmlUtils.GetNodeValue(tabNode, "pageheadtext", Null.NullString);
                tab.IsSecure = XmlUtils.GetNodeValueBoolean(tabNode, "issecure", false);
                tab.SiteMapPriority = XmlUtils.GetNodeValueSingle(tabNode, "sitemappriority", (float)0.5);
                tab.CultureCode = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "cultureCode");
                //objTab.UniqueId = New Guid(XmlUtils.GetNodeValue(nodeTab, "guid", Guid.NewGuid.ToString()));
                //objTab.VersionGuid = New Guid(XmlUtils.GetNodeValue(nodeTab, "versionGuid", Guid.NewGuid.ToString()));
                tab.UseBaseFriendlyUrls = XmlUtils.GetNodeValueBoolean(tabNode, "UseBaseFriendlyUrls", false);

                tab.TabPermissions.Clear();
                DeserializeTabPermissions(tabNode.SelectNodes("tabpermissions/permission"), tab, isAdminTemplate);

                DeserializeTabSettings(tabNode.SelectNodes("tabsettings/tabsetting"), tab);

                //set tab skin and container
                if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "skinsrc", "")))
                {
                    tab.SkinSrc = XmlUtils.GetNodeValue(tabNode, "skinsrc", "");
                }
                if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "containersrc", "")))
                {
                    tab.ContainerSrc = XmlUtils.GetNodeValue(tabNode, "containersrc", "");
                }

                tabName = tab.TabName;
                if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "parent")))
                {
                    if (tabs[XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "parent")] != null)
                    {
                        //parent node specifies the path (tab1/tab2/tab3), use saved tabid
                        tab.ParentId = Convert.ToInt32(tabs[XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "parent")]);
                        tabName = XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "parent") + "/" + tab.TabName;
                    }
                    else
                    {
                        //Parent node doesn't spcecify the path, search by name.
                        //Possible incoherence if tabname not unique
                        TabInfo objParent =
                            tabController.GetTabByName(XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "parent"),
                                                       portalId);
                        if (objParent != null)
                        {
                            tab.ParentId = objParent.TabID;
                            tabName = objParent.TabName + "/" + tab.TabName;
                        }
                        else
                        {
                            //parent tab not found!
                            tab.ParentId = Null.NullInteger;
                            tabName = tab.TabName;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "defaultLanguageTab")))
                {
                    if (tabs[XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "defaultLanguageTab")] != null)
                    {
                        //parent node specifies the path (tab1/tab2/tab3), use saved tabid
                        int defaultLanguageTabId =
                            Convert.ToInt32(tabs[XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "defaultLanguageTab")]);
                        TabInfo defaultLanguageTab = tabController.GetTab(defaultLanguageTabId, portalId, false);
                        if (defaultLanguageTab != null)
                        {
                            tab.DefaultLanguageGuid = defaultLanguageTab.UniqueId;
                        }
                    }
                    else
                    {
                        //Parent node doesn't spcecify the path, search by name.
                        //Possible incoherence if tabname not unique
                        TabInfo defaultLanguageTab =
                            tabController.GetTabByName(
                                XmlUtils.GetNodeValue(tabNode.CreateNavigator(), "defaultLanguageTab"), portalId);
                        if (defaultLanguageTab != null)
                        {
                            tab.DefaultLanguageGuid = defaultLanguageTab.UniqueId;
                        }
                    }
                }

                //create/update tab
                if (tab.TabID == Null.NullInteger)
                {
                    tab.TabID = tabController.AddTab(tab);
                }
                else
                {
                    tabController.UpdateTab(tab);
                }

                //extra check for duplicate tabs in same level
                if (tabs[tabName] == null)
                {
                    tabs.Add(tabName, tab.TabID);
                }
            }

            //Parse Panes
            if (tabNode.SelectSingleNode("panes") != null)
            {
                DeserializePanes(tabNode.SelectSingleNode("panes"), portalId, tab.TabID, mergeTabs, modules);
            }

            //Finally add "tabid" to node
            tabNode.AppendChild(XmlUtils.CreateElement(tabNode.OwnerDocument, "tabid", tab.TabID.ToString()));
            return tab;
        }
Esempio n. 17
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;
                }
                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);
            }
        }