/// <summary> /// Displays info label, if any module is disabled /// </summary> private bool DisplayErrorText() { GlobalObjects = ";" + GlobalObjects + ";"; SiteObjects = ";" + SiteObjects + ";"; String invalidKeys = String.Empty; bool keyDisabled = false; bool isAnyKeySite = false; bool settingChecked = false; bool showSite = false; bool showGlobal = false; if (!String.IsNullOrEmpty(SettingsKeys)) { // Iterate through all settings keys int i = 0; foreach (String key in SettingsKeys.Split(';')) { if (key != String.Empty) { String objectKey = ";" + key + ";"; bool globalObject = GlobalObjects.Contains(objectKey); bool siteObject = SiteObjects.Contains(objectKey); String siteKeyName = SiteName + "." + key; String keyName = (SiteOrGlobal || globalObject || KeyScope == DisabledModuleScope.Global) ? key : siteKeyName; // If module disabled if (!SettingsKeyProvider.GetBoolValue(keyName) || (siteObject && !SettingsKeyProvider.GetBoolValue(siteKeyName))) { // For siteorglobal settings check site setting separately if (SiteOrGlobal && SettingsKeyProvider.GetBoolValue(siteKeyName)) { settingChecked = true; i++; continue; } // If atleastone is checked, info error is set later if (!AtLeastOne) { // If setting is global - hide site button SettingsKeyInfo ski = SettingsKeyProvider.GetSettingsKeyInfo(key); if ((ski != null) && (!ski.KeyIsGlobal)) { isAnyKeySite = true; } // Get text (either from collection of text or from single text property) String text = (InfoTexts.Count != 0 && InfoTexts.Count > i) ? InfoTexts[i] : InfoText; // Add new text to label lblText.Text += text; // Add this key to collection of disabled keys invalidKeys = key + ";"; // Make this info label visible keyDisabled = true; if (!siteObject && !globalObject) { showSite = (KeyScope != DisabledModuleScope.Global); showGlobal = (KeyScope != DisabledModuleScope.Site); } else { showSite |= siteObject; showGlobal |= globalObject; } } } else { settingChecked = true; } } i++; } } // If atleastone is set, check if any setting is checked. If no, display warning message if (AtLeastOne && !settingChecked) { keyDisabled = true; lblText.Text = InfoText; } // If parent panel is set, show(hide) it if (ParentPanel != null) { ParentPanel.Visible = keyDisabled; } // Show/hide this control if module disabled Visible = keyDisabled; // Show site button only if any key is site pnlSiteButton.Visible = isAnyKeySite; // Set result to property SettingsEnabled = !keyDisabled; pnlSiteButton.Visible &= showSite; pnlGlobalButton.Visible &= showGlobal; return(!keyDisabled); }
/// <summary> /// Saves the changed settings /// </summary> /// <param name="isSite">Indicates whether changed settings is global or site</param> private void Save(bool isSite) { // This action is permitted only for global administrators if (CMSContext.CurrentUser.IsGlobalAdministrator) { if (!String.IsNullOrEmpty(SettingsKeys)) { String[] keys = SettingsKeys.Split(';'); foreach (String key in keys) { if (key != String.Empty) { String objectKey = ";" + key + ";"; String siteKeyName = SiteName + "." + key; bool globalObject = GlobalObjects.Contains(objectKey); bool siteObject = SiteObjects.Contains(objectKey); // If setting is global or site (or both), set global(site) settings no matter what button (site or global) was clicked if (globalObject || siteObject) { if (globalObject) { if (!SettingsKeyProvider.GetBoolValue(key)) { ObjectHelper.SetSettingsKeyValue(key, true); } } if (siteObject) { if (!SettingsKeyProvider.GetBoolValue(siteKeyName)) { ObjectHelper.SetSettingsKeyValue(siteKeyName, true); } } continue; } // Test first if settings is disabled if (!SettingsKeyProvider.GetBoolValue(siteKeyName)) { String keyName = isSite ? siteKeyName : key; try { ObjectHelper.SetSettingsKeyValue(keyName, true); } catch (Exception) { if (isSite) { // Site settings does not exists. Save as global then ObjectHelper.SetSettingsKeyValue(key, true); } } // If global enabled and site still disabled - enable it also if (!isSite && (KeyScope != DisabledModuleScope.Global)) { // If settings not enabled, inherit from global if (!SettingsKeyProvider.GetBoolValue(siteKeyName)) { ObjectHelper.SetSettingsKeyValue(siteKeyName, null); } } } } } } URLHelper.Redirect(URLHelper.CurrentURL); } }
/// <summary> /// Displays info label, if any module is disabled /// </summary> private bool DisplayErrorText() { GlobalObjects = ";" + GlobalObjects + ";"; SiteObjects = ";" + SiteObjects + ";"; bool keyDisabled = false; bool isAnyKeySite = false; bool settingChecked = false; bool showSite = false; bool showGlobal = false; // Check config keys - stronger if (!String.IsNullOrEmpty(ConfigKeys)) { var keys = ConfigKeys.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string key in keys) { if (!ValidationHelper.GetBoolean(SettingsHelper.AppSettings[key], false)) { if (!AtLeastOne) { settingChecked = false; break; } } else { settingChecked = true; } } } // Check settings if (!settingChecked && !String.IsNullOrEmpty(SettingsKeys)) { int i = 0; var keys = SettingsKeys.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string key in keys) { String objectKey = ";" + key + ";"; bool globalObject = GlobalObjects.Contains(objectKey); bool siteObject = SiteObjects.Contains(objectKey); String siteKeyName = SiteName + "." + key; String keyName = (SiteOrGlobal || globalObject || KeyScope == DisabledModuleScope.Global) ? key : siteKeyName; // If module disabled if (!SettingsKeyInfoProvider.GetBoolValue(keyName) || (siteObject && !SettingsKeyInfoProvider.GetBoolValue(siteKeyName))) { // For site or global settings check site setting separately if (SiteOrGlobal && SettingsKeyInfoProvider.GetBoolValue(siteKeyName)) { settingChecked = true; i++; continue; } // If at least one is checked, info error is set later if (!AtLeastOne) { // If setting is global - hide site button var ski = SettingsKeyInfoProvider.GetSettingsKeyInfo(key); if ((ski != null) && (!ski.KeyIsGlobal)) { isAnyKeySite = true; } // Get text (either from collection of text or from single text property) String text = (InfoTexts.Count != 0 && InfoTexts.Count > i) ? InfoTexts[i] : InfoText; if (String.IsNullOrEmpty(text) && (ski != null)) { text = GenerateInfoText(ski); } if (lblText.Text != "") { lblText.Text += " "; } // Add new text to label lblText.Text += text; // Add this key to collection of disabled keys // Make this info label visible keyDisabled = !String.IsNullOrEmpty(text); if (!siteObject && !globalObject) { showSite = (KeyScope != DisabledModuleScope.Global); showGlobal = (KeyScope != DisabledModuleScope.Site); } else { showSite |= siteObject; showGlobal |= globalObject; } } } else { settingChecked = true; } i++; } } // If atleastone is set, check if any setting is checked. If no, display warning message if (AtLeastOne && !settingChecked) { keyDisabled = true; lblText.Text = InfoText; } // If parent panel is set, show(hide) it if (ParentPanel != null) { ParentPanel.Visible = keyDisabled; } // Show/hide this control if module disabled Visible = keyDisabled; // Show site button only if any key is site btnSite.Visible = isAnyKeySite; // Set result to property SettingsEnabled = !keyDisabled; btnSite.Visible &= showSite; btnGlobal.Visible &= showGlobal; return(!keyDisabled); }