/// <summary>
 /// Handles the UniGrid's OnAction event.
 /// </summary>
 /// <param name="actionName">Name of item (button) that throws event</param>
 /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
 protected void uniGrid_OnAction(string actionName, object actionArgument)
 {
     if (CMSString.Equals(actionName, "edit", true))
     {
         RedirectToEditUrl(actionArgument);
     }
     else if (CMSString.Equals(actionName, "delete", true))
     {
         int queryId = ValidationHelper.GetInteger(actionArgument, -1);
         if (queryId > 0)
         {
             QueryInfoProvider.DeleteQueryInfo(queryId);
         }
     }
 }
 private void InitPreviewUrl()
 {
     if (Node.DocumentWorkflowCycleGUID != Guid.Empty)
     {
         lnkPreviewURL.Visible    = true;
         lblNoPreviewGuid.Visible = false;
         bool isFile = CMSString.Equals(Node.NodeClassName, SystemDocumentTypes.File, true);
         lnkPreviewURL.Attributes.Add("href", Node.GetPreviewLink(CurrentUser.UserName, isFile));
     }
     else
     {
         lnkPreviewURL.Visible    = false;
         lblNoPreviewGuid.Visible = true;
     }
 }
Esempio n. 3
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));
        }
    }
    /// <summary>
    /// Handles OnAfterValidate event of the UI form.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void OnAfterValidate(object sender, EventArgs e)
    {
        int    cultureId    = Control.EditedObject.Generalized.ObjectID;
        string cultureCode  = ValidationHelper.GetString(Control.GetFieldValue("CultureCode"), String.Empty).Trim();
        string cultureAlias = ValidationHelper.GetString(Control.GetFieldValue("CultureAlias"), String.Empty).Trim();

        // Check validity of culture code
        if (!CultureHelper.IsValidCultureInfoName(cultureCode))
        {
            Control.ShowError(Control.GetString("Culture.ErrorNoGlobalCulture"));
            Control.StopProcessing = true;
        }

        if (CultureHelper.IsNeutralCulture(cultureCode) && !Control.StopProcessing)
        {
            Control.ShowError(Control.GetString("culture.neutralculturecannotbeused"));
            Control.StopProcessing = true;
        }

        // Check if culture already exists for new created cultures
        if (cultureId == 0 && CultureInfoProvider.GetCultureInfo(cultureCode) != null && !Control.StopProcessing)
        {
            Control.ShowError(Control.GetString("culture_new.cultureexists"));
            Control.StopProcessing = true;
        }

        // Check whether culture alias is unique
        if (cultureId == 0 && !String.IsNullOrEmpty(cultureAlias) && !Control.StopProcessing)
        {
            CultureInfo cultureInfo = CultureInfoProvider.GetCultureInfoForCulture(cultureAlias);
            if ((cultureInfo != null) || CMSString.Equals(cultureAlias, cultureCode, true))
            {
                Control.ShowError(Control.GetString("Culture.AliasNotUnique"));
                Control.StopProcessing = true;
            }
        }

        // Show warning if culture is UI and there is no resx file
        bool isUiCulture = ValidationHelper.GetBoolean(Control.GetFieldValue("CultureIsUICulture"), false);

        if (!Control.StopProcessing && !LocalizationHelper.ResourceFileExistsForCulture(cultureCode) && isUiCulture)
        {
            string url          = "http://www.kentico.com/Support/Support-files/Localization-packs";
            string downloadPage = String.Format(@"<a href=""{0}"" target=""_blank"" >{1}</a> ", url, HTMLHelper.HTMLEncode(url));
            Control.ShowWarning(String.Format(Control.GetString("culture.noresxwarning"), downloadPage));
        }
    }
Esempio n. 5
0
 private void InitPreviewUrl()
 {
     if (Node.DocumentWorkflowCycleGUID != Guid.Empty)
     {
         lnkPreviewURL.Visible    = true;
         lblNoPreviewGuid.Visible = false;
         lnkPreviewURL.Text       = ResHelper.GetString("GeneralProperties.ShowPreview");
         bool isFile = CMSString.Equals(Node.NodeClassName, "cms.file", true);
         lnkPreviewURL.NavigateUrl = Node.GetPreviewLink(CurrentUser.UserName, isFile);
     }
     else
     {
         lnkPreviewURL.Visible    = false;
         lblNoPreviewGuid.Visible = true;
         lblNoPreviewGuid.Text    = GetString("GeneralProperties.NoPreviewGuid");
     }
 }
        /// <summary>Performs validation of the reCAPTCHA component.</summary>
        /// <param name="validationContext">The validation context.</param>
        /// <returns>A collection that holds failed-validation information.</returns>
        public override IEnumerable <ValidationResult> Validate(
            ValidationContext validationContext)
        {
            var validationResultList = new List <ValidationResult>();

            validationResultList.AddRange(base.Validate(validationContext));
            if (!this.IsConfigured | VirtualContext.IsInitialized)
            {
                return((IEnumerable <ValidationResult>)validationResultList);
            }
            var recaptchaValidator = new InvisibleRecaptchaValidator
            {
                PrivateKey = PrivateKey,
                RemoteIP   = RequestContext.UserHostAddress,
                Response   = RecaptchaResponse
            };

            var recaptchaResponse = recaptchaValidator.Validate();

            if (recaptchaResponse != null)
            {
                if (!string.IsNullOrEmpty(recaptchaResponse.ErrorMessage))
                {
                    validationResultList.Add(new ValidationResult(recaptchaResponse.ErrorMessage));
                }
                if (Action != null && !CMSString.Equals(Action, recaptchaResponse.Action))
                {
                    validationResultList.Add(new ValidationResult(ResHelper.GetString("recaptcha.error.actioninvalid")));
                }
                if (recaptchaResponse.Score < Score)
                {
                    validationResultList.Add(new ValidationResult(ResHelper.GetString("recaptcha.error.scoreinvalid")));
                }
            }
            else
            {
                validationResultList.Add(new ValidationResult(ResHelper.GetString("recaptcha.error.serverunavailable",
                                                                                  (string)null, true)));
            }

            return((IEnumerable <ValidationResult>)validationResultList);
        }
    /// <summary>
    /// Reloads the data in the control.
    /// </summary>
    protected void ReloadData()
    {
        if (drpField.Items.Count == 0)
        {
            // Load dropdownlist with fields of specified class
            FormInfo fi = FormHelper.GetFormInfo(ClassName, false);
            if (fi != null)
            {
                if (CMSString.Equals(ClassName, "cms.user", true))
                {
                    // Combine user fields with those of user settings
                    FormInfo coupledInfo = FormHelper.GetFormInfo("cms.usersettings", false);
                    if (coupledInfo != null)
                    {
                        fi.CombineWithForm(coupledInfo, false);
                    }
                }

                IEnumerable <FormFieldInfo> fields;
                if (FieldDataType != CMS.DataEngine.FieldDataType.Unknown)
                {
                    fields = fi.GetFields(FieldDataType);
                }
                else
                {
                    fields = fi.GetFields(true, true);
                }

                foreach (var fieldInfo in fields)
                {
                    drpField.Items.Add(new ListItem(fieldInfo.GetDisplayName(MacroResolver.GetInstance()), fieldInfo.Name));
                }
            }

            if (AllowNone)
            {
                // Add '(none)' item
                drpField.Items.Insert(0, new ListItem(GetString("general.selectnone"), string.Empty));
            }
        }
    }
Esempio n. 8
0
        public override bool IsValid(object value)
        {
            var responseValue = ValidationHelper.GetString(value, string.Empty);

            if (!IsConfigured | VirtualContext.IsInitialized)
            {
                return(false);
            }

            var recaptchaValidator = new InvisibleRecaptchaValidator
            {
                PrivateKey = PrivateKey,
                RemoteIP   = RequestContext.UserHostAddress,
                Response   = responseValue
            };

            var recaptchaResponse = recaptchaValidator.Validate();

            if (recaptchaResponse != null)
            {
                if (!string.IsNullOrEmpty(recaptchaResponse.ErrorMessage))
                {
                    return(false);
                }
                if (Action != null && !CMSString.Equals(Action, recaptchaResponse.Action))
                {
                    return(false);
                }
                if (recaptchaResponse.Score < Score)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        PortalHelper.EnsureScriptManager(Page);

        // Initialize checkbox for special values
        if ((FieldInfo != null) && (FieldInfo.DataType != FormFieldDataTypeEnum.Boolean))
        {
            if (CheckedValue == null)
            {
                CheckedValue = DataHelper.GetNotEmpty(GetValue("CheckedValue"), "");
            }
            if (UncheckedValue == null)
            {
                UncheckedValue = DataHelper.GetNotEmpty(GetValue("UncheckedValue"), "");
            }

            string innerValueString = ValidationHelper.GetString(innerValue, null);
            checkbox.Checked = CMSString.Equals(CheckedValue.ToString(), innerValueString);
        }
    }
Esempio n. 10
0
    /// <summary>
    /// Reloads the data in the control.
    /// </summary>
    protected void ReloadData()
    {
        if (drpField.Items.Count == 0)
        {
            // Load dropdownlist with fields of specified class
            FormInfo fi = FormHelper.GetFormInfo(ClassName, false);
            if (fi != null)
            {
                if (CMSString.Equals(ClassName, "cms.user", true))
                {
                    // Combine user fields with those of user settings
                    FormInfo coupledInfo = FormHelper.GetFormInfo("cms.usersettings", false);
                    if (coupledInfo != null)
                    {
                        fi.CombineWithForm(coupledInfo, false, null, false);
                    }
                }

                if (FieldDataType == FormFieldDataTypeEnum.Unknown)
                {
                    // Get all form fields
                    drpField.DataSource = fi.GetFields(true, true);
                }
                else
                {
                    // Get form fields of specific data type
                    drpField.DataSource = fi.GetFields(FieldDataType);
                }

                drpField.DataTextField  = DataTextField;
                drpField.DataValueField = DataValueField;
                drpField.DataBind();
            }
            // Add '(none)' item
            drpField.Items.Insert(0, new ListItem(GetString("general.selectnone"), string.Empty));
        }
    }
Esempio n. 11
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // History back count
        BackCount++;
        string result = null;

        // Trim the key before save
        string key = txtKey.Text.Trim();

        // Validate the code name if default culture
        if (uic.UICultureCode == CultureHelper.DefaultUICulture)
        {
            result = new Validator()
                     .NotEmpty(key, rfvKey.ErrorMessage)
                     .IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName"))
                     .Result;
        }

        if (!string.IsNullOrEmpty(result))
        {
            // Display error message
            ShowError(result);
            return;
        }

        // Update the string
        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(stringID, uiCultureID);

        if (ri != null)
        {
            // Check if string with given key is not already defined
            ResourceStringInfo existing = SqlResourceManager.GetResourceStringInfo(key);
            if ((existing == null) || (existing.StringId == ri.StringId))
            {
                ri.StringIsCustom  = chkCustomString.Checked;
                ri.UICultureCode   = uic.UICultureCode;
                ri.TranslationText = txtText.Text;

                if (txtKey.Visible)
                {
                    // If key changed, log deletion of old string
                    string newKey = key;

                    if ((!CMSString.Equals(ri.StringKey, newKey, true)) &&
                        (ri.Generalized.LogSynchronization == SynchronizationTypeEnum.LogSynchronization))
                    {
                        SynchronizationHelper.LogObjectChange(ri, TaskTypeEnum.DeleteObject);
                    }

                    ri.StringKey = key;
                }

                // Update key
                SqlResourceManager.SetResourceStringInfo(ri);

                ShowChangesSaved();

                tabs[1, 0] = ri.StringKey;
            }
            else
            {
                ShowError(string.Format(GetString("Administration-UICulture_String_New.StringExists"), key));
            }
        }
    }
    /// <summary>
    /// Compares inner string value with checked value and sets the check box accordingly.
    /// </summary>
    private void HandleStringValue()
    {
        var innerValueString = ValidationHelper.GetString(mInnerValue, null);

        checkbox.Checked = CMSString.Equals(CheckedValue.ToString(), innerValueString);
    }
Esempio n. 13
0
    /// <summary>
    /// Handles btnOK's OnClick event - Update resource info.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // finds whether required fields are not empty
        string result = new Validator()
                        .NotEmpty(txtCultureName.Text.Trim(), rfvCultureName.ErrorMessage)
                        .NotEmpty(txtCultureCode.Text.Trim(), rfvCultureCode.ErrorMessage)
                        .Result;

        if (txtCultureCode.Text.Trim().Length > 10)
        {
            result = GetString("Culture.MaxLengthError");
        }

        try
        {
            // Chech if global culture exists
            if (new System.Globalization.CultureInfo(txtCultureCode.Text.Trim()) == null)
            {
                result = GetString("Culture.ErrorNoGlobalCulture");
            }
        }
        catch
        {
            result = GetString("Culture.ErrorNoGlobalCulture");
        }

        txtCultureAlias.Text = URLHelper.GetSafeUrlPart(txtCultureAlias.Text.Trim(), String.Empty);
        string cultureAlias = txtCultureAlias.Text.Trim().Replace("'", "''");

        // Check whether culture alias is unique
        if (!string.IsNullOrEmpty(cultureAlias))
        {
            string where = string.Format("(CultureCode = N'{0} 'OR CultureAlias = N'{0}') AND CultureID <> {1}", cultureAlias, culture.CultureID);
            DataSet cultures = CultureInfoProvider.GetCultures(where, null, 1, "CultureID");
            if ((!DataHelper.DataSourceIsEmpty(cultures)) ||
                (CMSString.Equals(cultureAlias, txtCultureCode.Text.Trim(), true)))
            {
                result = GetString("Culture.AliasNotUnique");
            }
        }

        if (result != string.Empty)
        {
            ShowError(result);
            return;
        }

        // finds if the culture code is unique
        CultureInfo uniqueCulture = CultureInfoProvider.GetCultureInfoForCulture(txtCultureCode.Text.Trim());

        // if culture code already exists and it is just editing culture -> update
        if ((uniqueCulture == null) || (uniqueCulture.CultureID == culture.CultureID))
        {
            UpdateCulture();
        }
        // if culture code already exists and it is another culture -> error
        else
        {
            ShowError(GetString("Culture_New.CultureExists"));
        }
    }
Esempio n. 14
0
    private void InitPreviewUrl()
    {
        bool isFile = CMSString.Equals(Node.NodeClassName, SystemDocumentTypes.File, true);

        lnkPreviewURL.Attributes.Add("href", Node.GetPreviewLink(CurrentUser.UserName, isFile, embededInAdministration: false));
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        #region "Watermark extender"

        // Watermark extender
        // Disable watermark extender for nonempty fields (issue with value which is same as the watermark text)
        string resolvedWatermarkText = ContextResolver.ResolveMacros(WatermarkText);
        if (!String.IsNullOrEmpty(WatermarkText) && !String.IsNullOrEmpty(resolvedWatermarkText) && !CMSString.Equals(textbox.Text, WatermarkText))
        {
            // Create extender
            TextBoxWatermarkExtender exWatermark = new TextBoxWatermarkExtender();
            exWatermark.ID = "exWatermark";
            exWatermark.TargetControlID = textbox.ID;
            exWatermark.EnableViewState = false;
            Controls.Add(exWatermark);

            // Initialize extender
            exWatermark.WatermarkText     = resolvedWatermarkText;
            exWatermark.WatermarkCssClass = textbox.CssClass + " " + ValidationHelper.GetString(GetValue("WatermarkCssClass"), WatermarkCssClass);
        }

        #endregion


        #region "Filter extender"

        if (FilterEnabled)
        {
            // Create extender
            FilteredTextBoxExtender exFilter = new FilteredTextBoxExtender();
            exFilter.ID = "exFilter";
            exFilter.TargetControlID = textbox.ID;
            exFilter.EnableViewState = false;
            Controls.Add(exFilter);

            // Filter extender
            exFilter.FilterInterval = FilterInterval;

            // Set the filter type
            if (FilterTypeValue == null)
            {
                exFilter.FilterType = FilterType;
            }
            else
            {
                if (!string.IsNullOrEmpty(FilterTypeValue))
                {
                    FilterTypes filterType = 0;
                    string[]    types      = FilterTypeValue.Split(new char[] { ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (types.Length > 0)
                    {
                        foreach (string typeStr in types)
                        {
                            int type = ValidationHelper.GetInteger(typeStr, 0);
                            switch (type)
                            {
                            case FILTER_NUMBERS:
                                filterType |= FilterTypes.Numbers;
                                break;

                            case FILTER_LOWERCASE:
                                filterType |= FilterTypes.LowercaseLetters;
                                break;

                            case FILTER_UPPERCASE:
                                filterType |= FilterTypes.UppercaseLetters;
                                break;

                            case FILTER_CUSTOM:
                                filterType |= FilterTypes.Custom;
                                break;
                            }
                        }
                        exFilter.FilterType = filterType;
                    }
                }
            }

            FilterModes filterMode = FilterMode;

            // Set valid and invalid characters
            if (exFilter.FilterType == FilterTypes.Custom)
            {
                // When filter type is Custom only, filter mode can be anything
                exFilter.FilterMode = filterMode;

                if (filterMode == FilterModes.InvalidChars)
                {
                    exFilter.InvalidChars = InvalidChars;
                }
                else
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
            else
            {
                // Otherwise filter type must be valid chars
                exFilter.FilterMode = FilterModes.ValidChars;

                // Set valid chars only if original filter mode was valid chars and filter type contains Custom
                if ((filterMode == FilterModes.ValidChars) && ((exFilter.FilterType & FilterTypes.Custom) != 0))
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
        }

        #endregion


        #region "Autocomplete extender"

        // Autocomplete extender
        if (!string.IsNullOrEmpty(AutoCompleteServiceMethod) && !string.IsNullOrEmpty(AutoCompleteServicePath))
        {
            // Create extender
            AutoCompleteExtender exAuto = new AutoCompleteExtender();
            exAuto.ID = "exAuto";
            exAuto.TargetControlID = textbox.ID;
            exAuto.EnableViewState = false;
            Controls.Add(exAuto);

            exAuto.ServiceMethod                           = AutoCompleteServiceMethod;
            exAuto.ServicePath                             = URLHelper.ResolveUrl(AutoCompleteServicePath);
            exAuto.MinimumPrefixLength                     = AutoCompleteMinimumPrefixLength;
            exAuto.ContextKey                              = ContextResolver.ResolveMacros(AutoCompleteContextKey);
            exAuto.CompletionInterval                      = AutoCompleteCompletionInterval;
            exAuto.EnableCaching                           = AutoCompleteEnableCaching;
            exAuto.CompletionSetCount                      = AutoCompleteCompletionSetCount;
            exAuto.CompletionListCssClass                  = AutoCompleteCompletionListCssClass;
            exAuto.CompletionListItemCssClass              = AutoCompleteCompletionListItemCssClass;
            exAuto.CompletionListHighlightedItemCssClass   = AutoCompleteCompletionListHighlightedItemCssClass;
            exAuto.DelimiterCharacters                     = AutoCompleteDelimiterCharacters;
            exAuto.FirstRowSelected                        = AutoCompleteFirstRowSelected;
            exAuto.ShowOnlyCurrentWordInCompletionListItem = AutoCompleteShowOnlyCurrentWordInCompletionListItem;
        }

        #endregion
    }
    protected void drpTransformationType_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Get the current code
        string code = TransformationCode;

        switch (drpType.SelectedValue.ToLowerCSafe())
        {
        case "ascx":
            // Convert to ASCX syntax
            if (CMSString.Equals(drpType.SelectedValue, "ascx", true))
            {
                code = MacroSecurityProcessor.RemoveSecurityParameters(code, false, null);

                code = code.Replace("{% Register", "<%@ Register").Replace("{%", "<%#").Replace("%}", "%>");
            }

            ShowMessage();
            break;

        case "xslt":
            // No transformation
            break;

        default:
            // Convert to macro syntax
            code = code.Replace("<%@", "{%").Replace("<%#", "{%").Replace("<%=", "{%").Replace("<%", "{%").Replace("%>", "%}");
            break;
        }

        // Move the content if necessary
        if (CMSString.Equals(drpType.SelectedValue, "html", true))
        {
            // Move from text to WYSIWYG
            if (txtCode.Visible)
            {
                tbWysiwyg.ResolvedValue = code;
                tbWysiwyg.Visible       = true;

                txtCode.Text    = string.Empty;
                txtCode.Visible = false;
            }
        }
        else
        {
            // Move from WYSIWYG to text
            if (tbWysiwyg.Visible)
            {
                code = HttpUtility.HtmlDecode(code);

                txtCode.Text    = code;
                txtCode.Visible = true;

                tbWysiwyg.ResolvedValue = string.Empty;
                tbWysiwyg.Visible       = false;
            }
            else
            {
                txtCode.Text = code;
            }
        }

        SetEditor();
    }
    /// <summary>
    /// Sends e-mail to all attendees.
    /// </summary>
    protected void Send()
    {
        // Check 'Modify' permission
        if (!CheckPermissions("cms.eventmanager", "Modify"))
        {
            return;
        }

        txtSenderName.Text  = txtSenderName.Text.Trim();
        txtSenderEmail.Text = txtSenderEmail.Text.Trim();
        txtSubject.Text     = txtSubject.Text.Trim();

        // Validate the fields
        string errorMessage = new Validator().NotEmpty(txtSenderName.Text, GetString("Events_SendEmail.EmptySenderName"))
                              .NotEmpty(txtSenderEmail.Text, GetString("Events_SendEmail.EmptySenderEmail"))
                              .NotEmpty(txtSubject.Text, GetString("Events_SendEmail.EmptyEmailSubject"))
                              .IsEmail(txtSenderEmail.Text, GetString("Events_SendEmail.InvalidEmailFormat"))
                              .Result;

        if (!String.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return;
        }

        string subject   = txtSubject.Text;
        string emailBody = htmlEmail.ResolvedValue;

        // Get event node data
        TreeProvider mTree = new TreeProvider();
        DocTreeNode  node  = mTree.SelectSingleNode(EventID);

        if (node != null && CMSString.Equals(node.NodeClassName, "cms.bookingevent", true))
        {
            // Initialize macro resolver
            ContextResolver resolver = ContextResolver.GetInstance();
            resolver.KeepUnresolvedMacros = true;
            resolver.SourceData           = new object[] { node };
            // Add named source data
            resolver.SetNamedSourceData("Event", node);

            // Event date string macro
            DateTime eventDate    = ValidationHelper.GetDateTime(node.GetValue("EventDate"), DateTimeHelper.ZERO_TIME);
            DateTime eventEndDate = ValidationHelper.GetDateTime(node.GetValue("EventEndDate"), DateTimeHelper.ZERO_TIME);
            bool     isAllDay     = ValidationHelper.GetBoolean(node.GetValue("EventAllDay"), false);

            string[,] macro           = new string[1, 2];
            macro[0, 0]               = "eventdatestring";
            macro[0, 1]               = EventProvider.GetEventDateString(eventDate, eventEndDate, isAllDay, TimeZoneHelper.GetSiteTimeZoneInfo(CMSContext.CurrentSite), CMSContext.CurrentSiteName);
            resolver.SourceParameters = macro;

            // Resolve e-mail body and subject macros and make links absolute
            emailBody = resolver.ResolveMacros(emailBody);
            emailBody = URLHelper.MakeLinksAbsolute(emailBody);
            subject   = TextHelper.LimitLength(resolver.ResolveMacros(subject), 450);

            // EventSendEmail manages sending e-mails to all attendees
            EventSendEmail ese = new EventSendEmail(EventID, CMSContext.CurrentSiteName,
                                                    subject, emailBody, txtSenderName.Text.Trim(), txtSenderEmail.Text.Trim());

            ShowConfirmation(GetString("Events_SendEmail.EmailSent"));
        }
    }
Esempio n. 18
0
    /// <summary>
    /// External history binding.
    /// </summary>
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView drv;

        switch (sourceName.ToLowerInvariant())
        {
        case "action":
            drv = (DataRowView)parameter;
            bool wasRejected = ValidationHelper.GetBoolean(drv["WasRejected"], false);

            // Get type of the steps
            WorkflowStepTypeEnum       stepType       = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "StepType"), 0);
            WorkflowStepTypeEnum       targetStepType = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "TargetStepType"), (int)stepType);
            WorkflowTransitionTypeEnum transitionType = (WorkflowTransitionTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "HistoryTransitionType"), 0);

            // Get name of steps
            string stepName       = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "StepName"), String.Empty);
            string targetStepName = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "TargetStepName"), stepName);
            if (!wasRejected)
            {
                // If step type defined, use it for identification
                if (targetStepType != WorkflowStepTypeEnum.Undefined)
                {
                    bool   isAutomatic  = (transitionType == WorkflowTransitionTypeEnum.Automatic);
                    string actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") + " ({0})" : "{0}";
                    // Return correct step title
                    switch (targetStepType)
                    {
                    case WorkflowStepTypeEnum.DocumentArchived:
                        actionString = string.Format(actionString, GetString("WorfklowProperties.Archived"));
                        break;

                    case WorkflowStepTypeEnum.DocumentPublished:
                        actionString = string.Format(actionString, GetString("WorfklowProperties.Published"));
                        break;

                    case WorkflowStepTypeEnum.DocumentEdit:
                        actionString = GetString("WorfklowProperties.NewVersion");
                        break;

                    default:
                        if (stepType == WorkflowStepTypeEnum.DocumentEdit)
                        {
                            actionString = GetString("WorfklowProperties.NewVersion");
                        }
                        else
                        {
                            actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") : GetString("WorfklowProperties.Approved");
                        }
                        break;
                    }

                    return(actionString);
                }
                // Backward compatibility
                else
                {
                    // Return correct step title
                    switch (targetStepName.ToLowerInvariant())
                    {
                    case "archived":
                        return(GetString("WorfklowProperties.Archived"));

                    case "published":
                        return(GetString("WorfklowProperties.Published"));

                    case "edit":
                        return(GetString("WorfklowProperties.NewVersion"));

                    default:
                        if (CMSString.Equals(stepName, "edit", true))
                        {
                            return(GetString("WorfklowProperties.NewVersion"));
                        }
                        return(GetString("WorfklowProperties.Approved"));
                    }
                }
            }
            else
            {
                return(GetString("WorfklowProperties.Rejected"));
            }

        // Get approved time
        case "approvedwhen":
        case "approvedwhentooltip":
            if (string.IsNullOrEmpty(parameter.ToString()))
            {
                return(string.Empty);
            }
            else
            {
                if (currentUserInfo == null)
                {
                    currentUserInfo = MembershipContext.AuthenticatedUser;
                }

                if (currentSiteInfo == null)
                {
                    currentSiteInfo = SiteContext.CurrentSite;
                }

                if (sourceName.EqualsCSafe("approvedwhen", StringComparison.InvariantCultureIgnoreCase))
                {
                    DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
                    return(TimeZoneHelper.ConvertToUserTimeZone(time, true, currentUserInfo, currentSiteInfo));
                }
                else
                {
                    return(TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo));
                }
            }

        case "stepname":
            drv = (DataRowView)parameter;
            string step       = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "StepDisplayName"), String.Empty);
            string targetStep = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "TargetStepDisplayName"), String.Empty);
            if (!string.IsNullOrEmpty(targetStep))
            {
                step += " -> " + targetStep;
            }
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(step)));
        }
        return(parameter);
    }
Esempio n. 19
0
    /// <summary>
    /// Saves resource translations and returns TRUE if save was successful. Returns FALSE if any error occurred.
    /// </summary>
    private bool Save()
    {
        bool saved = true;

        // Check permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            // Change resource key
            string key = txtStringKey.Text.Trim();
            if (key != rsi.StringKey)
            {
                // Validate the key
                string result = new Validator().NotEmpty(key, rfvKey.ErrorMessage).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;
                if (String.IsNullOrEmpty(result))
                {
                    ResourceStringInfo riNew = SqlResourceManager.GetResourceStringInfo(txtStringKey.Text.Trim());

                    // Check if string with given key is not already defined
                    if ((riNew == null) || (rsi.StringId == riNew.StringId))
                    {
                        // Log deletion of old string
                        if ((!CMSString.Equals(key, rsi.StringKey, true)) &&
                            (rsi.Generalized.LogSynchronization == SynchronizationTypeEnum.LogSynchronization))
                        {
                            SynchronizationHelper.LogObjectChange(rsi, TaskTypeEnum.DeleteObject);
                        }

                        rsi.StringKey = key;
                        SqlResourceManager.SetResourceStringInfo(rsi);
                    }
                    // New resource key collides with already existing resource key
                    else
                    {
                        ShowError(String.Format(GetString("Administration-UICulture_String_New.StringExists"), key));
                        saved = false;
                    }
                }
                // New resource string key is not code name
                else
                {
                    ShowError(result);
                    saved = false;
                }
            }

            string existingTranslation    = null;
            string newTranslation         = null;
            FormEngineUserControl control = null;

            // Go through all cultures
            foreach (string cultureCode in translations.Keys)
            {
                // Check if translation in given culture exists
                existingTranslation = SqlResourceManager.GetStringStrictly(txtStringKey.Text, cultureCode);
                // Get control for given culture
                control = (FormEngineUserControl)translations[cultureCode];

                if (control != null)
                {
                    // Translation is not already created
                    if (String.IsNullOrEmpty(existingTranslation))
                    {
                        // Get new translation
                        newTranslation = ValidationHelper.GetString(control.Value, String.Empty).Trim();

                        // Create new translation in given culture
                        if (!String.IsNullOrEmpty(newTranslation))
                        {
                            UpdateString(cultureCode, newTranslation);
                        }
                        // Translation of default culture must exist
                        else if (cultureCode == CultureHelper.DefaultUICulture)
                        {
                            ShowError(String.Format(ResHelper.GetString("localizable.deletedefault"), defaultCultureName));
                            saved = false;
                        }
                    }
                    // Existing translation is being updated
                    else
                    {
                        newTranslation = ValidationHelper.GetString(control.Value, String.Empty).Trim();

                        // Delete translation if new translation is empty
                        if (String.IsNullOrEmpty(newTranslation))
                        {
                            // Delete translation
                            if (cultureCode != CultureHelper.DefaultUICulture)
                            {
                                SqlResourceManager.DeleteResourceStringInfo(txtStringKey.Text, cultureCode);
                            }
                            // Translation in default culture cannot be deleted or set to empty in Localizable textbox
                            else
                            {
                                ShowError(String.Format(ResHelper.GetString("localizable.deletedefault"), defaultCultureName));
                                saved = false;
                            }
                        }
                        // Update translation if new translation is not empty
                        else
                        {
                            UpdateString(cultureCode, newTranslation);
                        }
                    }

                    // Set updated translation in current culture
                    if (cultureCode == CultureHelper.PreferredUICulture)
                    {
                        defaultTranslation = newTranslation;
                    }
                }
            }
        }
        // Current user is not global admin
        else
        {
            ShowError(GetString("general.actiondenied"));
            saved = false;
            pnlControls.Visible = false;
        }

        return(saved);
    }