/// <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 (MembershipContext.AuthenticatedUser.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) || KeyScope == DisabledModuleScope.Global);
                        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 (!SettingsKeyInfoProvider.GetBoolValue(key))
                                {
                                    SettingsKeyInfoProvider.SetValue(key, true);
                                }
                            }

                            if (siteObject)
                            {
                                if (!SettingsKeyInfoProvider.GetBoolValue(siteKeyName))
                                {
                                    SettingsKeyInfoProvider.SetValue(siteKeyName, true);
                                }
                            }

                            continue;
                        }

                        // Test first if settings is disabled
                        if (!SettingsKeyInfoProvider.GetBoolValue(siteKeyName))
                        {
                            String keyName = isSite ? siteKeyName : key;
                            try
                            {
                                SettingsKeyInfoProvider.SetValue(keyName, true);
                            }
                            catch (Exception)
                            {
                                if (isSite)
                                {
                                    // Site settings does not exists. Save as global then
                                    SettingsKeyInfoProvider.SetValue(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 (!SettingsKeyInfoProvider.GetBoolValue(siteKeyName))
                                {
                                    SettingsKeyInfoProvider.SetValue(siteKeyName, null);
                                }
                            }
                        }
                    }
                }
            }

            // Reload UI if necessary
            if (ReloadUIWhenModuleEnabled)
            {
                URLHelper.Redirect(RequestContext.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 += "<br />";
                        }

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