/// <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; }
/// <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; }
/// ----------------------------------------------------------------------------- /// <summary> /// ImportModule implements the IPortable ImportModule Interface /// </summary> /// <remarks> /// </remarks> /// <param name="ModuleID">The Id of the module to be imported</param> /// <history> /// [cnurse] 17 Nov 2004 documented /// [aglenwright] 18 Feb 2006 Added new fields: Createddate, description, /// modifiedbyuser, modifieddate, OwnedbyUser, SortorderIndex /// Added DocumentsSettings /// [togrean] 10 Jul 2007 Fixed issues with importing documet settings since new fileds /// were added: AllowSorting, default folder, list name /// [togrean] 13 Jul 2007 Added support for importing documents Url tracking options /// </history> /// ----------------------------------------------------------------------------- public void ImportModule (int moduleId, string content, string version, int userId) { var mCtrl = new ModuleController (); var module = mCtrl.GetModule (moduleId, Null.NullInteger); var xmlDocuments = Globals.GetContent (content, "documents"); var documentNodes = xmlDocuments.SelectNodes ("document"); foreach (XmlNode documentNode in documentNodes) { var document = new DocumentInfo (); document.ModuleId = moduleId; document.Title = documentNode ["title"].InnerText; var strUrl = documentNode ["url"].InnerText; document.Url = strUrl.StartsWith ("fileid=", StringComparison.InvariantCultureIgnoreCase) ? strUrl : Globals.ImportUrl (moduleId, strUrl); document.Category = documentNode ["category"].InnerText; document.Description = XmlUtils.GetNodeValue (documentNode, "description"); document.OwnedByUserId = XmlUtils.GetNodeValueInt (documentNode, "ownedbyuserid"); document.SortOrderIndex = XmlUtils.GetNodeValueInt (documentNode, "sortorderindex"); document.LinkAttributes = XmlUtils.GetNodeValue (documentNode, "linkattributes"); document.ForceDownload = XmlUtils.GetNodeValueBoolean (documentNode, "forcedownload"); document.IsPublished = XmlUtils.GetNodeValueBoolean (documentNode, "ispublished"); document.CreatedByUserId = userId; document.ModifiedByUserId = userId; var now = DateTime.Now; document.CreatedDate = now; document.ModifiedDate = now; Add<DocumentInfo> (document); // Update Tracking options var urlType = document.Url.StartsWith ("fileid=", StringComparison.InvariantCultureIgnoreCase)? "F" : "U"; var urlCtrl = new UrlController (); // If nodes not found, all values will be false urlCtrl.UpdateUrl (module.PortalID, document.Url, urlType, XmlUtils.GetNodeValueBoolean (documentNode, "logactivity"), XmlUtils.GetNodeValueBoolean (documentNode, "trackclicks", true), moduleId, XmlUtils.GetNodeValueBoolean (documentNode, "newwindow")); } var xmlSettings = Globals.GetContent (content, "documents/settings"); if (xmlSettings != null) { var settings = new DocumentsSettings (module); settings.AllowUserSort = XmlUtils.GetNodeValueBoolean (xmlSettings, "allowusersort"); settings.ShowTitleLink = XmlUtils.GetNodeValueBoolean (xmlSettings, "showtitlelink"); settings.UseCategoriesList = XmlUtils.GetNodeValueBoolean (xmlSettings, "usecategorieslist"); settings.CategoriesListName = XmlUtils.GetNodeValue (xmlSettings, "categorieslistname"); settings.DefaultFolder = Utils.ParseToNullableInt (XmlUtils.GetNodeValue (xmlSettings, "defaultfolder")); settings.DisplayColumns = XmlUtils.GetNodeValue (xmlSettings, "displaycolumns"); settings.SortOrder = XmlUtils.GetNodeValue (xmlSettings, "sortorder"); // Need Utils.SynchronizeModule() call } }
public void UpdateDocumentUrl (DocumentInfo document, string oldUrl, int PortalId, int ModuleId) { if (document.Url != oldUrl) { var ctrlUrl = new UrlController (); // get tracking data for the old URL var url = ctrlUrl.GetUrlTracking (PortalId, oldUrl, ModuleId); // delete old URL tracking data DataProvider.Instance ().DeleteUrlTracking (PortalId, oldUrl, ModuleId); // create new URL tracking data ctrlUrl.UpdateUrl (PortalId, document.Url, url.UrlType, url.LogActivity, url.TrackClicks, ModuleId, url.NewWindow); } }
private void Update (bool Override) { try { // Only Update if Input Data is Valid if (Page.IsValid == true) { if (!Override) { // Test file exists, security if (!CheckFileExists (ctlUrl.Url) || !CheckFileSecurity (ctlUrl.Url)) { this.cmdUpdateOverride.Visible = true; this.cmdUpdate.Visible = false; // '' Display page-level warning instructing users to click update again if they want to ignore the warning DotNetNuke.UI.Skins.Skin.AddPageMessage (this.Page, Localization.GetString ("msgFileWarningHeading.Text", this.LocalResourceFile), DotNetNuke.Services.Localization.Localization.GetString ("msgFileWarning.Text", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning); return; } } // Get existing document record var objDocument = DocumentsController.GetDocument (ItemID, ModuleId); if (objDocument == null) { // New record objDocument = new DocumentInfo (); objDocument.ItemId = ItemID; objDocument.ModuleId = ModuleId; objDocument.CreatedByUserId = UserInfo.UserID; // Default ownerid value for new documents is current user, may be changed // by the value of the dropdown list (below) objDocument.OwnedByUserId = UserId; } objDocument.IsPublished = checkIsPublished.Checked; objDocument.ModifiedByUserId = UserInfo.UserID; objDocument.Title = txtName.Text; objDocument.Description = txtDescription.Text; objDocument.ForceDownload = chkForceDownload.Checked; var oldUrl = objDocument.Url; objDocument.Url = ctlUrl.Url; objDocument.LinkAttributes = textLinkAttributes.Text; if (lstOwner.Visible) { if (lstOwner.SelectedValue != string.Empty) { objDocument.OwnedByUserId = Convert.ToInt32 (lstOwner.SelectedValue); } else { objDocument.OwnedByUserId = -1; } } else { // User never clicked "change", leave ownedbyuserid as is } if (txtCategory.Visible) { objDocument.Category = txtCategory.Text; } else { if (lstCategory.SelectedItem.Text == Localization.GetString ("None_Specified")) { objDocument.Category = ""; } else { objDocument.Category = lstCategory.SelectedItem.Value; } } // getting sort index int sortIndex; objDocument.SortOrderIndex = int.TryParse (txtSortIndex.Text, out sortIndex) ? sortIndex : 0; #region Update date & time var now = DateTime.Now; if (pickerCreatedDate.SelectedDate != null) { if (Null.IsNull (ItemID) || objDocument.CreatedDate != pickerCreatedDate.SelectedDate.Value) objDocument.CreatedDate = pickerCreatedDate.SelectedDate.Value; // else leave CreatedDate as is } else { objDocument.CreatedDate = now; } if (pickerLastModifiedDate.SelectedDate != null) { if (!checkDontUpdateLastModifiedDate.Checked) { if (Null.IsNull (ItemID) || objDocument.ModifiedDate != pickerLastModifiedDate.SelectedDate.Value) objDocument.ModifiedDate = pickerLastModifiedDate.SelectedDate.Value; else // update ModifiedDate objDocument.ModifiedDate = now; } } else { objDocument.ModifiedDate = now; } #endregion if (Null.IsNull (ItemID)) { DocumentsController.Add (objDocument); } else { DocumentsController.Update (objDocument); if (objDocument.Url != oldUrl) { // delete old URL tracking data DocumentsController.DeleteDocumentUrl (oldUrl, PortalId, ModuleId); } } // add or update URL tracking var ctrlUrl = new UrlController (); ctrlUrl.UpdateUrl (PortalId, ctlUrl.Url, ctlUrl.UrlType, ctlUrl.Log, ctlUrl.Track, ModuleId, ctlUrl.NewWindow); Synchronize (); // Redirect back to the portal home page Response.Redirect (Globals.NavigateURL (), true); } //Module failed to load } catch (Exception exc) { Exceptions.ProcessModuleLoadException (this, exc); } }
/// <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; }
/* protected override void OnLoad (EventArgs e) { base.OnLoad (e); try { if (!IsPostBack) { } else { } } catch (Exception ex) { // module failed to load Exceptions.ProcessModuleLoadException (this, ex); } }*/ protected void buttonImport_Click (object sender, EventArgs e) { try { var mctrl = new ModuleController (); var module = mctrl.GetModule (int.Parse (comboModule.SelectedValue), TabId); var mdef = module.ModuleDefinition.DefinitionName.ToLowerInvariant (); foreach (ListItem item in listDocuments.Items) { if (item.Selected) { DocumentInfo document = null; if (mdef == "r7.documents") document = DocumentsController.GetDocument (int.Parse (item.Value), module.ModuleID); else if (mdef == "documents") document = DocumentsController.GetDNNDocument (int.Parse (item.Value), module.ModuleID); if (document != null) { var ctrlUrl = new UrlController (); // get original document tracking data var url = ctrlUrl.GetUrlTracking (PortalId, document.Url, document.ModuleId); document.ItemId = Null.NullInteger; document.ModuleId = ModuleId; document.IsPublished = true; // add new document DocumentsController.Add (document); // add new url tracking data ctrlUrl.UpdateUrl (PortalId, document.Url, url.UrlType, url.LogActivity, url.TrackClicks, ModuleId, url.NewWindow); // NOTE: using url.Clicks, url.LastClick, url.CreatedDate not working } } } Synchronize (); // redirect back to the portal home page Response.Redirect (Globals.NavigateURL (), true); } catch (Exception ex) { // module failed to load Exceptions.ProcessModuleLoadException (this, ex); } }