示例#1
0
    /// <summary>
    /// Gets and bulk updates UI cultures. Called when the "Get and bulk update cultures" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateUICultures()
    {
        // Prepare the parameters
        string where = "UICultureCode LIKE N'my-cu%'";

        // Get the data
        DataSet cultures = UICultureInfoProvider.GetUICultures(where, null);

        if (!DataHelper.DataSourceIsEmpty(cultures))
        {
            // Loop through the individual items
            foreach (DataRow cultureDr in cultures.Tables[0].Rows)
            {
                // Create object from DataRow
                UICultureInfo modifyCulture = new UICultureInfo(cultureDr);

                // Update the properties
                modifyCulture.UICultureName = modifyCulture.UICultureName.ToUpper();

                // Save the changes
                UICultureInfoProvider.SetUICultureInfo(modifyCulture);
            }

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Initialize the tab control on the master page.
    /// </summary>
    private void InitializeMenu()
    {
        string[,] tabs = new string[2, 4];

        string defaultCulture = CultureHelper.DefaultUICulture;

        // Default UI culture strings
        tabs[0, 0] = GetString("UICultures.Default");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'uicultures_defaultculture');";
        tabs[0, 2] = "ResourceString/List.aspx?uicultureid=";
        try
        {
            UICultureInfo ci = UICultureInfoProvider.GetUICultureInfo(defaultCulture);
            if (ci != null)
            {
                tabs[0, 2] += ci.UICultureID;
            }
        }
        catch
        {
        }

        tabs[1, 0] = GetString("UICultures.Other");
        tabs[1, 1] = "SetHelpTopic('helpTopic', 'uicultures_tab_other');";
        tabs[1, 2] = "UICulture/List.aspx";

        // Set the target iFrame
        CurrentMaster.Tabs.UrlTarget = "uiculturesContent";

        // Assign tabs data
        CurrentMaster.Tabs.Tabs = tabs;
    }
 protected int SaveNewUICulture()
 {
     UICultureInfo ui = new UICultureInfo();
     ui.UICultureCode = txtUICultureCode.Text;
     ui.UICultureName = txtUICultureName.Text;
     UICultureInfoProvider.SetUICultureInfo(ui);
     return ui.UICultureID;
 }
示例#4
0
    protected int SaveNewUICulture()
    {
        UICultureInfo ui = new UICultureInfo();

        ui.UICultureCode = txtUICultureCode.Text;
        ui.UICultureName = txtUICultureName.Text;
        UICultureInfoProvider.SetUICultureInfo(ui);
        return(ui.UICultureID);
    }
示例#5
0
    /// <summary>
    /// Deletes UI culture. Called when the "Delete culture" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool DeleteUICulture()
    {
        // Get the UI culture
        UICultureInfo deleteCulture = UICultureInfoProvider.GetUICultureInfo("my-cu");

        // Delete the UI culture
        UICultureInfoProvider.DeleteUICultureInfo(deleteCulture);

        return(deleteCulture != null);
    }
示例#6
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Find whether required fields are not empty
        string result = new Validator()
                        .NotEmpty(txtUICultureCode.Text, GetString("UICultures_New.EmptyCultureCode"))
                        .NotEmpty(txtUICultureName.Text, GetString("UICultures_New.EmptyCultureName"))
                        .Result;

        try
        {
            System.Globalization.CultureInfo obj = new System.Globalization.CultureInfo(txtUICultureCode.Text);
            if (obj != null)
            {
                // Neutral cultures are not allowed in UI cultures
                if (obj.IsNeutralCulture)
                {
                    result = GetString("uiculture.neutralculturecannotbeused");
                }
            }
            else
            {
                result = GetString("UICulture.ErrorNoGlobalCulture");
            }
        }
        catch
        {
            result = GetString("UICulture.ErrorNoGlobalCulture");
        }

        if (String.IsNullOrEmpty(result))
        {
            try
            {
                UICultureInfo ui = UICultureInfoProvider.GetUICultureInfo(txtUICultureCode.Text);
                lblError.Visible = true;
                lblError.Text    = GetString("UICulture.UICultureAlreadyExist");
            }
            catch
            {
                int uiCultureId = SaveNewUICulture();

                if (uiCultureId > 0)
                {
                    URLHelper.Redirect("Frameset.aspx?uicultureid=" + uiCultureId + "&update=1");
                }
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = result;
        }
    }
示例#7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        // Get requested culture
        ui = UICultureInfoProvider.GetSafeUICulture(uiCultureID);

        UICultureInfo dui = null;

        // Check if edited UI culture is the default UI culture
        if ((ui != null) && CMSString.Equals(ui.UICultureCode, CultureHelper.DefaultUICulture, true))
        {
            dui = ui;
            // Use different grid definition
            gridStrings.GridName = "List_defaultculture.xml";
        }
        else
        {
            // Ty to get default UI culture
            try
            {
                dui = UICultureInfoProvider.GetUICultureInfo(CultureHelper.DefaultUICulture);
            }
            catch
            {
            }
        }

        if (dui != null)
        {
            EditedObject = ui;

            // Prepare query params for the grid
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@Culture", ui.UICultureID);
            parameters.AddId("@DefaultUICultureID", dui.UICultureID);

            // Setup the grid
            gridStrings.QueryParameters      = parameters;
            gridStrings.OnAction            += UniGridUICultures_OnAction;
            gridStrings.OnExternalDataBound += UniGridStrings_OnExternalDataBound;

            InitializeMasterPage();
        }
        else
        {
            // Default UI culture does not exist - hide the grid and display error message
            gridStrings.StopProcessing = true;

            ShowError(String.Format(GetString("uiculture.defaultnotexist"), CultureHelper.DefaultUICulture));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        // Get requested culture
        ui = UICultureInfoProvider.GetSafeUICulture(uiCultureID);

        UICultureInfo dui = null;
        // Check if edited UI culture is the default UI culture
        if ((ui != null) && CMSString.Equals(ui.UICultureCode, CultureHelper.DefaultUICulture, true))
        {
            dui = ui;
            // Use different grid definition
            gridStrings.GridName = "List_defaultculture.xml";
        }
        else
        {
            // Ty to get default UI culture
            try
            {
                dui = UICultureInfoProvider.GetUICultureInfo(CultureHelper.DefaultUICulture);
            }
            catch
            {
            }
        }

        if (dui != null)
        {
            EditedObject = ui;

            // Prepare query params for the grid
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@Culture", ui.UICultureID);
            parameters.AddId("@DefaultUICultureID", dui.UICultureID);

            // Setup the grid
            gridStrings.QueryParameters = parameters;
            gridStrings.OnAction += UniGridUICultures_OnAction;
            gridStrings.OnExternalDataBound += UniGridStrings_OnExternalDataBound;

            InitializeMasterPage();
        }
        else
        {
            // Default UI culture does not exist - hide the grid and display error message
            gridStrings.StopProcessing = true;

            ShowError(String.Format(GetString("uiculture.defaultnotexist"), CultureHelper.DefaultUICulture));
        }
    }
示例#9
0
    /// <summary>
    /// Creates UI culture. Called when the "Create culture" button is pressed.
    /// </summary>
    private bool CreateUICulture()
    {
        // Create new UI culture object
        UICultureInfo newCulture = new UICultureInfo();

        // Set the properties
        newCulture.UICultureName = "My new culture";
        newCulture.UICultureCode = "my-cu";

        // Save the UI culture
        UICultureInfoProvider.SetUICultureInfo(newCulture);

        return(true);
    }
    /// <summary>
    /// Creates UI culture. Called when the "Create culture" button is pressed.
    /// </summary>
    private bool CreateUICulture()
    {
        // Create new UI culture object
        UICultureInfo newCulture = new UICultureInfo();

        // Set the properties
        newCulture.UICultureName = "My new culture";
        newCulture.UICultureCode = "my-cu";

        // Save the UI culture
        UICultureInfoProvider.SetUICultureInfo(newCulture);

        return true;
    }
示例#11
0
    private void DeleteUICulture(int cultureId)
    {
        UICultureInfo culture = UICultureInfoProvider.GetSafeUICulture(cultureId);

        EditedObject = culture;

        if (!CMSString.Equals(culture.UICultureCode, CultureHelper.DefaultUICulture, true))
        {
            // Delete UI culture object if it is not the default one
            UICultureInfoProvider.DeleteUICultureInfo(culture);
        }
        else
        {
            ShowError(string.Format(GetString("Development-UICulture_List.DeleteError"), culture.UICultureName));
        }
    }
示例#12
0
    /// <summary>
    /// Save UI culture that is being edited.
    /// </summary>
    /// <returns>ID of the saved culture</returns>
    protected void SaveUICulture(string cultureCode)
    {
        if (!String.IsNullOrEmpty(cultureCode))
        {
            UICultureInfo culture     = UICultureInfoProvider.GetUICultureInfo(cultureCode, false);
            string        cultureName = txtUICultureName.Text.Trim();

            // Update UI culture
            if ((UIcultureID > 0) && (((culture != null) && (culture.UICultureID == UIcultureID)) || (culture == null)))
            {
                if (culture == null)
                {
                    culture = UICultureInfoProvider.GetSafeUICulture(UIcultureID);
                }

                if (culture != null)
                {
                    culture.UICultureCode         = cultureCode;
                    culture.UICultureName         = cultureName;
                    culture.UICultureLastModified = DateTime.Now;
                    UICultureInfoProvider.SetUICultureInfo(culture);
                    ShowChangesSaved();
                }
            }
            // Create new UI culture
            else if ((UIcultureID <= 0) && (culture == null))
            {
                culture = new UICultureInfo();
                culture.UICultureGUID         = Guid.NewGuid();
                culture.UICultureCode         = cultureCode;
                culture.UICultureName         = cultureName;
                culture.UICultureLastModified = DateTime.Now;
                UICultureInfoProvider.SetUICultureInfo(culture);
                ShowChangesSaved();
            }
            // Culture with specified code already exists
            else
            {
                ShowError(GetString("UICulture_New.CultureExists"));
            }
        }
        // Provided culture code is empty
        else
        {
            ShowError(GetString("UICulture.ErrorNoGlobalCulture"));
        }
    }
示例#13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        // Get requested culture
        ui           = UICultureInfoProvider.GetSafeUICulture(uiCultureID);
        EditedObject = ui;

        UICultureInfo dui = null;

        if (string.Equals(ui.UICultureCode, CultureHelper.DefaultUICulture, StringComparison.InvariantCultureIgnoreCase))
        {
            dui = ui;
            gridStrings.GridName = "List_defaultculture.xml";
        }
        else
        {
            // Ty to get default UI culture
            try
            {
                dui = UICultureInfoProvider.GetUICultureInfo(CultureHelper.DefaultUICulture);
            }
            catch
            { }
        }

        if (dui != null)
        {
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@Culture", ui.UICultureID);
            parameters.AddId("@DefaultUICultureID", dui.UICultureID);

            // Setup the grid
            gridStrings.QueryParameters      = parameters;
            gridStrings.OnAction            += UniGridUICultures_OnAction;
            gridStrings.OnExternalDataBound += UniGridStrings_OnExternalDataBound;

            InitializeMasterPage();
        }
        else
        {
            // Default UI culture does not exist - hide the grid and display error message
            gridStrings.StopProcessing = true;
        }
    }
示例#14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        contentUrl = ResolveUrl("ResourceString/List.aspx?uicultureid=");

        // Default UI culture strings
        string defaultCulture = CultureHelper.DefaultUICulture;

        try
        {
            UICultureInfo ci = UICultureInfoProvider.GetUICultureInfo(defaultCulture);
            if (ci != null)
            {
                contentUrl += ci.UICultureID;
            }
        }
        catch { }
    }
示例#15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        // Get requested culture
        ui = UICultureInfoProvider.GetSafeUICulture(uiCultureID);
        EditedObject = ui;

        UICultureInfo dui = null;
        if (string.Equals(ui.UICultureCode, CultureHelper.DefaultUICulture, StringComparison.InvariantCultureIgnoreCase))
        {
            dui = ui;
            gridStrings.GridName = "List_defaultculture.xml";
        }
        else
        {
            // Ty to get default UI culture
            try
            {
                dui = UICultureInfoProvider.GetUICultureInfo(CultureHelper.DefaultUICulture);
            }
            catch
            { }
        }

        if (dui != null)
        {
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@Culture", ui.UICultureID);
            parameters.AddId("@DefaultUICultureID", dui.UICultureID);

            // Setup the grid
            gridStrings.QueryParameters = parameters;
            gridStrings.OnAction += UniGridUICultures_OnAction;
            gridStrings.OnExternalDataBound += UniGridStrings_OnExternalDataBound;

            InitializeMasterPage();
        }
        else
        {
            // Default UI culture does not exist - hide the grid and display error message
            gridStrings.StopProcessing = true;
        }
    }
示例#16
0
    /// <summary>
    /// Gets and updates UI culture. Called when the "Get and update culture" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool GetAndUpdateUICulture()
    {
        // Get the UI culture
        UICultureInfo updateCulture = UICultureInfoProvider.GetUICultureInfo("my-cu");

        if (updateCulture != null)
        {
            // Update the properties
            updateCulture.UICultureName = updateCulture.UICultureName.ToLower();

            // Save the changes
            UICultureInfoProvider.SetUICultureInfo(updateCulture);

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        if (!RequestHelper.IsPostBack())
        {
            InitalizeMenu();
        }

        EditedObject = uici = UICultureInfoProvider.GetSafeUICulture(uiCultureID);

        if (uici != null)
        {
            currentUICultureName = uici.UICultureName;
        }

        InitializeMasterPage();
    }
示例#18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        if (!RequestHelper.IsPostBack())
        {
            InitalizeMenu();
        }

        EditedObject = uici = UICultureInfoProvider.GetSafeUICulture(uiCultureID);

        if (uici != null)
        {
            currentUICultureName = uici.UICultureName;
        }

        InitializeMasterPage();
    }
示例#19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        rfvUICultureName.ErrorMessage = GetString("UICulture_Edit_General.ErrorEmptyCultureName");
        rfvUICultureCode.ErrorMessage = GetString("UICulture_Edit_General.ErrorEmptyCultureCode");

        // Get UIcultureID
        UIcultureID = QueryHelper.GetInteger("uicultureid", 0);
        if (UIcultureID != 0)
        {
            UICultureInfo myUICultureInfo = UICultureInfoProvider.GetSafeUICulture(UIcultureID);
            EditedObject = myUICultureInfo;

            if (!RequestHelper.IsPostBack())
            {
                txtUICultureName.Text = myUICultureInfo.UICultureName;
                txtUICultureCode.Text = myUICultureInfo.UICultureCode;
            }
        }
    }
示例#20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get UI culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        lblEnglishText.Text = String.Format(GetString("Administration-UICulture_String_New.EnglishText"), CultureHelper.DefaultUICulture);
        rfvKey.ErrorMessage = GetString("Administration-UICulture_String_New.EmptyKey");

        if (!RequestHelper.IsPostBack())
        {
            chkCustomString.Checked = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSCreateCustomStringsByDefault"], true);
        }

        // Get the culture info
        uic = UICultureInfoProvider.GetUICultureInfo(uiCultureID);

        // If default culture, do not show field for the default text
        plcDefaultText.Visible = !uic.UICultureCode.Equals(CultureHelper.DefaultUICulture, StringComparison.InvariantCultureIgnoreCase);

        InitializeMasterPage(plcDefaultText.Visible);
    }
示例#21
0
    /// <summary>
    /// Loads data of edited user from DB into TextBoxes.
    /// </summary>
    protected void LoadData()
    {
        // Fill lstUICulture (loop over and localize them first)
        DataSet uiCultures = UICultureInfoProvider.GetUICultures(null, "UICultureName ASC");

        LocalizeCultureNames(uiCultures);
        lstUICulture.DataSource     = uiCultures.Tables[0].DefaultView;
        lstUICulture.DataTextField  = "UICultureName";
        lstUICulture.DataValueField = "UICultureID";
        lstUICulture.DataBind();

        lstUICulture.Items.Insert(0, GetString("Administration-User_Edit.Default"));
        lstUICulture.Items[0].Value = "0";

        if (ui != null)
        {
            txtEmail.Text      = ui.Email;
            txtFirstName.Text  = ui.FirstName;
            txtFullName.Text   = ui.FullName;
            txtLastName.Text   = ui.LastName;
            txtMiddleName.Text = ui.MiddleName;
            ucUserName.Value   = ui.UserName;

            CheckBoxEnabled.Checked  = ui.Enabled;
            CheckBoxIsEditor.Checked = ui.IsEditor;
            CheckBoxLabelIsGlobalAdministrator.Checked = ui.IsGlobalAdministrator;
            chkIsExternal.Checked          = ui.IsExternal;
            chkIsDomain.Checked            = ui.UserIsDomain;
            chkIsHidden.Checked            = ui.UserIsHidden;
            chkSiteManagerDisabled.Checked = ui.UserSiteManagerDisabled;

            password = ui.GetValue("UserPassword").ToString();

            if (ui.IsPublic())
            {
                ucUserName.Enabled = false;
            }

            myCulture   = ui.PreferredCultureCode;
            myUICulture = ui.PreferredUICultureCode;

            txtUserStartingPath.Text = ui.UserStartingAliasPath;
        }

        cultureSelector.Value = myCulture;

        if (!string.IsNullOrEmpty(myUICulture))
        {
            try
            {
                UICultureInfo ciUI = UICultureInfoProvider.GetUICultureInfo(myUICulture);
                lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue(ciUI.UICultureID.ToString()));
            }
            catch
            {
                lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0"));
            }
        }
        else
        {
            lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0"));
        }

        if (ui != null)
        {
            lblCreatedInfo.Text   = ui.UserCreated.ToString();
            lblLastLogonTime.Text = ui.LastLogon.ToString();

            LoadUserLogon(ui);

            if (ui.UserCreated == DataHelper.DATETIME_NOT_SELECTED)
            {
                lblCreatedInfo.Text = GetString("general.na");
            }

            if (ui.LastLogon == DataHelper.DATETIME_NOT_SELECTED)
            {
                lblLastLogonTime.Text = GetString("general.na");
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get parameters from query string
        GetParameters();

        if (saved)
        {
            ShowChangesSaved();
        }

        lblEnglishText.Text = string.Format(GetString("Administration-UICulture_String_New.EnglishText"), CultureHelper.DefaultUICulture);
        rfvKey.ErrorMessage = GetString("Administration-UICulture_String_New.EmptyKey");

        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(stringID, uiCultureID);
        EditedObject = ri;

        string defaultCulture = CultureHelper.DefaultUICulture;

        uic = UICultureInfoProvider.GetUICultureInfo(uiCultureID);
        if (uic.UICultureCode == defaultCulture)
        {
            // Default culture
            plcDefaultText.Visible = false;
            txtKey.Visible = true;
            lblKeyEng.Visible = false;

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture);
            }
        }
        else
        {
            // Other cultures
            plcDefaultText.Visible = true;
            txtKey.Visible = false;
            rfvKey.Enabled = false;
            lblKeyEng.Visible = true;

            lblKeyEng.Text = ri.StringKey;
            lblEnglishValue.Text = HTMLHelper.HTMLEncode(MacroResolver.RemoveSecurityParameters(SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture), true, null));

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, uic.UICultureCode);
            }

            // Set default culture text to translate
            txtText.AllowTranslationServices = true;
            txtText.TranslationSourceText = ResHelper.GetString(ri.StringKey, defaultCulture);
            txtText.TranslationSourceLanguage = defaultCulture;
            txtText.TranslationTargetLanguage = uic.UICultureCode;
        }

        if (!DialogMode)
        {
            // Initialize master page
            InitializeMasterPage(ri, plcDefaultText.Visible);
        }
        else
        {
            txtKey.Enabled = false;
            plcCustom.Visible = false;
        }

        if (!RequestHelper.IsPostBack() && (!DialogMode))
        {
            chkCustomString.Checked = ri.StringIsCustom;
        }
    }
    /// <summary>
    /// Gets and bulk updates UI cultures. Called when the "Get and bulk update cultures" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateUICultures()
    {
        // Prepare the parameters
        string where = "UICultureCode LIKE N'my-cu%'";

        // Get the data
        DataSet cultures = UICultureInfoProvider.GetUICultures(where, null);
        if (!DataHelper.DataSourceIsEmpty(cultures))
        {
            // Loop through the individual items
            foreach (DataRow cultureDr in cultures.Tables[0].Rows)
            {
                // Create object from DataRow
                UICultureInfo modifyCulture = new UICultureInfo(cultureDr);

                // Update the properties
                modifyCulture.UICultureName = modifyCulture.UICultureName.ToUpper();

                // Save the changes
                UICultureInfoProvider.SetUICultureInfo(modifyCulture);
            }

            return true;
        }

        return false;
    }
示例#24
0
    /// <summary>
    /// Button localize click. In AutomaticMode available only.
    /// </summary>
    void btnLocalize_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(textbox.Text.Trim()))
        {
            // Get maximum length of resource key
            int    maxKeyLength = MAX_KEY_LENGTH;
            string prefix       = ResourceKeyPrefix;
            if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(ResourceKeyPrefix))
            {
                prefix = PREFIX;
            }

            if (!String.IsNullOrEmpty(prefix))
            {
                maxKeyLength -= prefix.Length;
            }

            // Initialize resource string
            string newResource = TextHelper.LimitLength(ValidationHelper.GetCodeName(textbox.Text.Trim()), maxKeyLength, String.Empty, true);

            int i = 0;
            if (!newResource.StartsWithCSafe(prefix))
            {
                hdnValue.Value = prefix + newResource;
            }
            else
            {
                hdnValue.Value = newResource;
            }
            // If key exists then create new one with number as a suffix
            while (SqlResourceManager.GetResourceStringInfo(hdnValue.Value) != null)
            {
                // If newly created resource key is longer then allowed length then trim end by one character
                if ((prefix.Length + newResource.Length + ++i) > MAX_KEY_LENGTH)
                {
                    newResource = newResource.Substring(0, newResource.Length - 1);
                }

                if (!newResource.StartsWithCSafe(prefix))
                {
                    hdnValue.Value = prefix + newResource + i;
                }
                else
                {
                    hdnValue.Value = newResource + i;
                }
            }

            // Check if current user's culture exists
            UICultureInfo uiCulture   = null;
            string        cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Save ResourceString
            ResourceStringInfo ri = new ResourceStringInfo();
            ri.StringKey       = hdnValue.Value;
            ri.UICultureCode   = cultureCode;
            ri.TranslationText = textbox.Text;
            ri.StringIsCustom  = !SettingsKeyProvider.DevelopmentMode;
            SqlResourceManager.SetResourceStringInfo(ri);

            // Open 'localization to other languages' window
            ScriptHelper.RegisterStartupScript(this, typeof(string), "OpenLocalization", ScriptHelper.GetScript("modalDialog('" + ResolveUrl(LOCALIZE_STRING) + "?hiddenValueControl=" + hdnValue.ClientID + "&stringKey=" + ri.StringKey + "&parentTextbox=" + textbox.ClientID + "', 'localizableString', 600, 635, null, null, true);"));

            // Set macro settings
            Value = MACRO_START + hdnValue.Value + MACRO_END;
            Reload();
        }
        else
        {
            lblError.Visible        = true;
            lblError.ResourceString = "localize.entertext";
        }
    }
示例#25
0
    /// <summary>
    /// Button OK clicked.
    /// </summary>
    void btnOk_Click(object sender, EventArgs e)
    {
        // Check permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            string             key = null;
            ResourceStringInfo ri  = null;

            // Check if current user's culture exists
            UICultureInfo uiCulture   = null;
            string        cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Creating new resource string
            if (lstExistingOrNew.SelectedIndex == 0)
            {
                if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(resourceKeyPrefix))
                {
                    key = txtNewResource.Text.Trim();
                }
                else
                {
                    key = resourceKeyPrefix + txtNewResource.Text.Trim();
                }
                ri = SqlResourceManager.GetResourceStringInfo(key);

                // Resource string doesn't exists yet
                if (ri == null)
                {
                    lblError.Text = new Validator().NotEmpty(key, GetString("Administration-UICulture_String_New.EmptyKey")).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;
                    if (!String.IsNullOrEmpty(lblError.Text))
                    {
                        lblError.Visible = true;
                    }
                    else
                    {
                        // Save ResourceString
                        ri                 = new ResourceStringInfo();
                        ri.StringKey       = key;
                        ri.UICultureCode   = cultureCode;
                        ri.TranslationText = plainText;
                        ri.StringIsCustom  = !SettingsKeyProvider.DevelopmentMode;
                        SqlResourceManager.SetResourceStringInfo(ri);

                        ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResourceAndOpen('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(plainText) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                    }
                }
                // If resource string already exists with different translation
                else
                {
                    lblError.Visible        = true;
                    lblError.ResourceString = "localize.alreadyexists";
                }
            }
            // Using existing resource string
            else
            {
                key = ValidationHelper.GetString(resourceSelector.Value, String.Empty).Trim();
                ri  = SqlResourceManager.GetResourceStringInfo(key);

                // Key not found in DB
                if (ri == null)
                {
                    // Try to find it in .resx file and save it in DB
                    FileResourceManager resourceManager = ResHelper.GetFileManager(cultureCode);
                    if (resourceManager != null)
                    {
                        string translation = resourceManager.GetString(key);
                        if (!String.IsNullOrEmpty(translation))
                        {
                            ri                 = new ResourceStringInfo();
                            ri.StringKey       = key;
                            ri.StringIsCustom  = !SettingsKeyProvider.DevelopmentMode;
                            ri.UICultureCode   = cultureCode;
                            ri.TranslationText = translation;
                            SqlResourceManager.SetResourceStringInfo(ri);

                            ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(translation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                        }
                        else
                        {
                            lblError.Visible        = true;
                            lblError.ResourceString = "localize.doesntexist";
                        }
                    }
                    else
                    {
                        lblError.Visible        = true;
                        lblError.ResourceString = "localize.doesntexist";
                    }
                }
                // Send to parent window selected resource key
                else
                {
                    string existingTranslation = GetString(key);
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(existingTranslation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                }
            }
        }
        else
        {
            lblError.ResourceString = "general.actiondenied";
            lblError.Visible        = true;
            pnlControls.Visible     = false;
        }
    }
    /// <summary>
    /// Save UI culture that is being edited.
    /// </summary>
    /// <returns>ID of the saved culture</returns>
    protected void SaveUICulture(string cultureCode)
    {
        if (!String.IsNullOrEmpty(cultureCode))
        {
            UICultureInfo culture = UICultureInfoProvider.GetUICultureInfo(cultureCode, false);
            string cultureName = txtUICultureName.Text.Trim();

            // Update UI culture
            if ((UIcultureID > 0) && (((culture != null) && (culture.UICultureID == UIcultureID)) || (culture == null)))
            {
                if (culture == null)
                {
                    culture = UICultureInfoProvider.GetSafeUICulture(UIcultureID);
                }

                if (culture != null)
                {
                    culture.UICultureCode = cultureCode;
                    culture.UICultureName = cultureName;
                    culture.UICultureLastModified = DateTime.Now;
                    UICultureInfoProvider.SetUICultureInfo(culture);
                    ShowChangesSaved();
                }
            }
            // Create new UI culture
            else if ((UIcultureID <= 0) && (culture == null))
            {
                culture = new UICultureInfo();
                culture.UICultureGUID = Guid.NewGuid();
                culture.UICultureCode = cultureCode;
                culture.UICultureName = cultureName;
                culture.UICultureLastModified = DateTime.Now;
                UICultureInfoProvider.SetUICultureInfo(culture);
                ShowChangesSaved();
            }
            // Culture with specified code already exists
            else
            {
                ShowError(GetString("UICulture_New.CultureExists"));
            }
        }
        // Provided culture code is empty
        else
        {
            ShowError(GetString("UICulture.ErrorNoGlobalCulture"));
        }
    }
示例#27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get parameters from query string
        GetParameters();

        if (saved)
        {
            ShowChangesSaved();
        }

        lblEnglishText.Text = string.Format(GetString("Administration-UICulture_String_New.EnglishText"), CultureHelper.DefaultUICulture);
        rfvKey.ErrorMessage = GetString("Administration-UICulture_String_New.EmptyKey");

        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(stringID, uiCultureID);

        EditedObject = ri;

        string defaultCulture = CultureHelper.DefaultUICulture;

        uic = UICultureInfoProvider.GetUICultureInfo(uiCultureID);
        if (uic.UICultureCode == defaultCulture)
        {
            // Default culture
            plcDefaultText.Visible = false;
            txtKey.Visible         = true;
            lblKeyEng.Visible      = false;

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text  = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture);
            }
        }
        else
        {
            // Other cultures
            plcDefaultText.Visible = true;
            txtKey.Visible         = false;
            rfvKey.Enabled         = false;
            lblKeyEng.Visible      = true;

            lblKeyEng.Text       = ri.StringKey;
            lblEnglishValue.Text = HTMLHelper.HTMLEncode(MacroResolver.RemoveSecurityParameters(SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture), true, null));

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text  = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, uic.UICultureCode);
            }

            // Set default culture text to translate
            txtText.AllowTranslationServices  = true;
            txtText.TranslationSourceText     = ResHelper.GetString(ri.StringKey, defaultCulture);
            txtText.TranslationSourceLanguage = defaultCulture;
            txtText.TranslationTargetLanguage = uic.UICultureCode;
        }

        if (!DialogMode)
        {
            // Initialize master page
            InitializeMasterPage(ri, plcDefaultText.Visible);
        }
        else
        {
            txtKey.Enabled    = false;
            plcCustom.Visible = false;
        }

        if (!RequestHelper.IsPostBack() && (!DialogMode))
        {
            chkCustomString.Checked = ri.StringIsCustom;
        }
    }
示例#28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get UI culture ID from query string
        uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);

        lblEnglishText.Text = String.Format(GetString("Administration-UICulture_String_New.EnglishText"), CultureHelper.DefaultUICulture);
        rfvKey.ErrorMessage = GetString("Administration-UICulture_String_New.EmptyKey");

        if (!RequestHelper.IsPostBack())
        {
            chkCustomString.Checked = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSCreateCustomStringsByDefault"], true);
        }

        // Get the culture info
        uic = UICultureInfoProvider.GetUICultureInfo(uiCultureID);

        // If default culture, do not show field for the default text
        plcDefaultText.Visible = !uic.UICultureCode.Equals(CultureHelper.DefaultUICulture, StringComparison.InvariantCultureIgnoreCase);

        InitializeMasterPage(plcDefaultText.Visible);
    }
示例#29
0
    /// <summary>
    /// Loads data of edited user from DB into TextBoxes.
    /// </summary>
    protected void LoadData()
    {
        // Fill lstUICulture (loop over and localize them first)
        DataSet uiCultures = UICultureInfoProvider.GetUICultures(null, "UICultureName ASC");

        LocalizeCultureNames(uiCultures);
        lstUICulture.DataSource     = uiCultures.Tables[0].DefaultView;
        lstUICulture.DataTextField  = "UICultureName";
        lstUICulture.DataValueField = "UICultureID";
        lstUICulture.DataBind();

        lstUICulture.Items.Insert(0, GetString("Administration-User_Edit.Default"));
        lstUICulture.Items[0].Value = "0";

        if (ui != null)
        {
            // Get user info properties
            txtEmail.Text      = ui.Email;
            txtFirstName.Text  = ui.FirstName;
            txtFullName.Text   = ui.FullName;
            txtLastName.Text   = ui.LastName;
            txtMiddleName.Text = ui.MiddleName;
            ucUserName.Value   = ui.UserName;

            CheckBoxEnabled.Checked  = ui.Enabled;
            CheckBoxIsEditor.Checked = ui.IsEditor;
            CheckBoxLabelIsGlobalAdministrator.Checked = ui.IsGlobalAdministrator;
            chkIsExternal.Checked          = ui.IsExternal;
            chkIsDomain.Checked            = ui.UserIsDomain;
            chkIsHidden.Checked            = ui.UserIsHidden;
            chkSiteManagerDisabled.Checked = ui.UserSiteManagerDisabled;

            password = ui.GetValue("UserPassword").ToString();

            // Disable username textbox for public user
            if (ui.IsPublic())
            {
                ucUserName.Enabled = false;
            }

            myCulture   = ui.PreferredCultureCode;
            myUICulture = ui.PreferredUICultureCode;

            lblInvalidLogonAttemptsNumber.Text = string.Format(GetString("general.attempts"), ui.UserInvalidLogOnAttempts);
            if (ui.UserInvalidLogOnAttempts > 0)
            {
                lblInvalidLogonAttemptsNumber.Style.Add(HtmlTextWriterStyle.Color, "Red");
            }
            else
            {
                btnResetLogonAttempts.Enabled = (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached));
            }

            LoadPasswordExpiration(ui);

            txtUserStartingPath.Text = ui.UserStartingAliasPath;
        }

        // Set content culture
        cultureSelector.Value = myCulture;

        if (!string.IsNullOrEmpty(myUICulture))
        {
            // Set UI culture
            try
            {
                UICultureInfo ciUI = UICultureInfoProvider.GetUICultureInfo(myUICulture);
                lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue(ciUI.UICultureID.ToString()));
            }
            catch
            {
                lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0"));
            }
        }
        else
        {
            lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0"));
        }

        if (ui != null)
        {
            // If new user
            lblCreatedInfo.Text   = ui.UserCreated.ToString();
            lblLastLogonTime.Text = ui.LastLogon.ToString();

            LoadUserLogon(ui);

            if (ui.UserCreated == DataHelper.DATETIME_NOT_SELECTED)
            {
                lblCreatedInfo.Text = GetString("general.na");
            }

            if (ui.LastLogon == DataHelper.DATETIME_NOT_SELECTED)
            {
                lblLastLogonTime.Text = GetString("general.na");
            }
        }
    }
示例#30
0
    /// <summary>
    /// Saves data of edited user from TextBoxes into DB.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check "modify" permission
        if (!currentUser.IsAuthorizedPerResource("CMS.Users", "Modify"))
        {
            RedirectToAccessDenied("CMS.Users", "Modify");
        }

        string result = ValidateGlobalAndDeskAdmin(userId);

        // Find whether user name is valid
        if (result == String.Empty)
        {
            if (!ucUserName.IsValid())
            {
                result = ucUserName.ValidationError;
            }
        }

        String userName = ValidationHelper.GetString(ucUserName.Value, String.Empty);

        if (result == String.Empty)
        {
            // Finds whether required fields are not empty
            result = new Validator().NotEmpty(txtFullName.Text, GetString("Administration-User_New.RequiresFullName")).Result;
        }

        if ((result == String.Empty) && (ui != null))
        {
            // If site prefixed allowed - ad site prefix
            if ((SiteID != 0) && UserInfoProvider.UserNameSitePrefixEnabled(CMSContext.CurrentSiteName))
            {
                if (!UserInfoProvider.IsSitePrefixedUser(userName))
                {
                    userName = UserInfoProvider.EnsureSitePrefixUserName(userName, CMSContext.CurrentSite);
                }
            }

            // Validation for site prefixed users
            if (!UserInfoProvider.IsUserNamePrefixUnique(userName, ui.UserID))
            {
                result = GetString("Administration-User_New.siteprefixeduserexists");
            }

            // Ensure same password
            password = ui.GetValue("UserPassword").ToString();

            // Test for unique username
            UserInfo uiTest = UserInfoProvider.GetUserInfo(userName);
            if ((uiTest == null) || (uiTest.UserID == userId))
            {
                if (ui == null)
                {
                    ui = new UserInfo();
                }

                bool globAdmin = ui.IsGlobalAdministrator;
                bool editor    = ui.IsEditor;

                // Email format validation
                string email = txtEmail.Text.Trim();
                if ((email != string.Empty) && (!ValidationHelper.IsEmail(email)))
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Administration-User_New.WrongEmailFormat");
                    return;
                }

                bool oldGlobal = ui.IsGlobalAdministrator;
                bool oldEditor = ui.IsEditor;

                if (ui.UserName != userName)
                {
                    // Refresh the breadcrumb
                    ScriptHelper.RefreshTabHeader(Page, null);
                }

                ui.Email        = email;
                ui.FirstName    = txtFirstName.Text.Trim();
                ui.FullName     = txtFullName.Text.Trim();
                ui.LastName     = txtLastName.Text.Trim();
                ui.MiddleName   = txtMiddleName.Text.Trim();
                ui.UserName     = userName;
                ui.Enabled      = CheckBoxEnabled.Checked;
                ui.IsEditor     = CheckBoxIsEditor.Checked;
                ui.UserIsHidden = chkIsHidden.Checked;

                // Only admins who have access to site manager can set this
                if (!currentUser.UserSiteManagerDisabled)
                {
                    ui.UserSiteManagerDisabled = chkSiteManagerDisabled.Checked;

                    // Only admin who have access to site manager can create another global admin
                    ui.IsGlobalAdministrator = currentUser.IsGlobalAdministrator && CheckBoxLabelIsGlobalAdministrator.Checked;
                }

                ui.IsExternal   = chkIsExternal.Checked;
                ui.UserIsDomain = chkIsDomain.Checked;
                ui.SetValue("UserPassword", password);
                ui.UserID = userId;
                ui.UserStartingAliasPath = txtUserStartingPath.Text.Trim();

                LoadUserLogon(ui);

                // Set values of cultures.
                string culture = ValidationHelper.GetString(cultureSelector.Value, "");
                ui.PreferredCultureCode = culture;

                if (lstUICulture.SelectedValue == "0")
                {
                    ui.PreferredUICultureCode = "";
                }
                else
                {
                    UICultureInfo ciUI = UICultureInfoProvider.GetUICultureInfo(Convert.ToInt32(lstUICulture.SelectedValue));
                    ui.PreferredUICultureCode = ciUI.UICultureCode;
                }

                // Define domain variable
                string domains = null;

                // Get all user sites
                DataTable ds = UserInfoProvider.GetUserSites(ui.UserID, null, null, 0, "SiteDomainName");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    foreach (DataRow dr in ds.Rows)
                    {
                        domains += ValidationHelper.GetString(dr["SiteDomainName"], string.Empty) + ";";
                    }

                    // Remove  ";" at the end
                    if (domains != null)
                    {
                        domains = domains.Remove(domains.Length - 1);
                    }
                }
                else
                {
                    DataSet siteDs = SiteInfoProvider.GetSites(null, null, "SiteDomainName");
                    if (!DataHelper.DataSourceIsEmpty(siteDs))
                    {
                        domains = TextHelper.Join(";", SqlHelperClass.GetStringValues(siteDs.Tables[0], "SiteDomainName"));
                    }
                }

                // Check limitations for Global administrator
                if (ui.IsGlobalAdministrator && !oldGlobal)
                {
                    if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.GlobalAdmininistrators, VersionActionEnum.Insert, globAdmin))
                    {
                        lblError.Visible = true;
                        lblError.Text    = GetString("License.MaxItemsReachedGlobal");
                    }
                }

                // Check limitations for editors
                if (ui.IsEditor && !oldEditor)
                {
                    if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.Editors, VersionActionEnum.Insert, editor))
                    {
                        lblError.Visible = true;
                        lblError.Text    = GetString("License.MaxItemsReachedEditor");
                    }
                }

                // Check whether email is unique if it is required
                if (!UserInfoProvider.IsEmailUnique(email, ui))
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("UserInfo.EmailAlreadyExist");
                    return;
                }

                if (!lblError.Visible)
                {
                    // Check whether the username of the currently logged user has been changed
                    if ((currentUser != null) && (currentUser.UserID == ui.UserID) && (currentUser.UserName != ui.UserName))
                    {
                        // Ensure that an update search task will be created but NOT executed when updating the user
                        CMSActionContext.EnableSearchIndexer = false;
                    }

                    // Update the user
                    UserInfoProvider.SetUserInfo(ui);

                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("General.ChangesSaved");
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = GetString("Administration-User_New.UserExists");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = result;
        }

        // Display impersonation link if current user is global administrator
        if (CurrentMaster.HeaderActions.Actions != null)
        {
            if (currentUser.IsGlobalAdministrator && RequestHelper.IsFormsAuthentication() && (ui != null) && (ui.UserID != currentUser.UserID))
            {
                if (!currentUser.UserSiteManagerDisabled || !ui.UserIsGlobalAdministrator || ui.UserSiteManagerDisabled)
                {
                    string message = GetImpersonalMessage(ui);
                    CurrentMaster.HeaderActions.Actions[0, 2] = "if (!confirm('" + message + "')) { return false; }";
                    CurrentMaster.HeaderActions.ReloadData();
                }
            }
        }
    }