HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/wwwroot/CMSFormControls/Classes/SelectTransformation.ascx.cs
using System;
using CMS.DataEngine;
using CMS.FormControls;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.Membership;
using CMS.PortalEngine;
using CMS.SiteProvider;
using CMS.UIControls;

public partial class CMSFormControls_Classes_SelectTransformation : FormEngineUserControl
{
    #region "Variables"

    private bool mDisplayClearButton = true;

    #endregion


    #region "Properties"

    /// <summary>
    /// Gets or sets the enabled state of the control.
    /// </summary>
    public override bool Enabled
    {
        get
        {
            return base.Enabled;
        }
        set
        {
            base.Enabled = value;
            UniSelector.Enabled = value;
        }
    }


    /// <summary>
    /// If true, control is in site manager.
    /// </summary>
    public bool IsSiteManager
    {
        get
        {
            return UniSelector.IsSiteManager;
        }
        set
        {
            UniSelector.IsSiteManager = value;
        }
    }


    /// <summary>
    /// If true selector shows hierarchical transformation.
    /// </summary>
    public bool ShowHierarchicalTransformation
    {
        get
        {
            return GetValue("ShowHierarchicalTransformation", false);
        }
        set
        {
            SetValue("ShowHierarchicalTransformation", value);
        }
    }


    /// <summary>
    /// Returns ClientID of the textbox with transformation.
    /// </summary>
    public override string ValueElementID
    {
        get
        {
            return UniSelector.TextBoxSelect.ClientID;
        }
    }


    /// <summary>
    /// Name of the edit window.
    /// </summary>
    public string EditWindowName
    {
        get
        {
            return UniSelector.EditWindowName;
        }
        set
        {
            UniSelector.EditWindowName = value;
        }
    }


    /// <summary>
    /// Path to the dialog for uniselector.
    /// </summary>
    public string NewDialogPath
    {
        get
        {
            return GetValue("NewDialogPath", "~/CMSModules/DocumentTypes/Pages/Development/DocumentType_Edit_Transformation_New.aspx");
        }
        set
        {
            SetValue("NewDialogPath", value);
        }
    }


    /// <summary>
    /// Gets or sets the field value.
    /// </summary>
    public override object Value
    {
        get
        {
            return UniSelector.Value;
        }
        set
        {
            UniSelector.Value = value;
        }
    }


    /// <summary>
    /// Gets or sets the value which determines, whether to display Clear button.
    /// </summary>
    public bool DisplayClearButton
    {
        get
        {
            return mDisplayClearButton;
        }
        set
        {
            mDisplayClearButton = value;
            UniSelector.AllowEmpty = value;
        }
    }


    /// <summary>
    /// Gets or sets the codename of setting key with default value
    /// </summary>
    public string WatermarkValueSettingKey
    {
        get
        {
            return ValidationHelper.GetString(GetValue("WatermarkValueSettingKey"), null);
        }
        set
        {
            SetValue("WatermarkValueSettingKey", value);
        }
    }


    /// <summary>
    /// Specifies aditional where condition.
    /// </summary>
    public string WhereCondition
    {
        get
        {
            return GetValue("WhereCondition", string.Empty);
        }
        set
        {
            SetValue("WhereCondition", value);
        }
    }


    /// <summary>
    /// Gets current selector.
    /// </summary>
    private UniSelector UniSelector
    {
        get
        {
            EnsureChildControls();
            return uniSelector;
        }
    }


    /// <summary>
    /// Gets underlying form control.
    /// </summary>
    protected override FormEngineUserControl UnderlyingFormControl
    {
        get
        {
            return uniSelector;
        }
    }

    #endregion


    #region "Methods"


    /// <summary>
    /// Page_Load event handler.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            uniSelector.StopProcessing = true;
        }
        else
        {
            ReloadData();
        }
    }


    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        uniSelector.ButtonClear.Visible = false;
        uniSelector.AllowEmpty = DisplayClearButton;
        uniSelector.SetValue("FilterMode", TransformationInfo.OBJECT_TYPE);
        uniSelector.EditDialogWindowWidth = 1200;
     
        // Set default value from settings as textbox watermark
        if (!String.IsNullOrEmpty(WatermarkValueSettingKey))
        {
            string watermark = SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + "." + WatermarkValueSettingKey);
            if (!String.IsNullOrEmpty(watermark))
            {
                uniSelector.TextBoxSelect.WatermarkText = watermark;
            }
        }

        // Check if user can edit the transformation
        var currentUser = MembershipContext.AuthenticatedUser;
        bool deskAuthorized = currentUser.IsAuthorizedPerUIElement("CMS.Content", "Content");
        bool contentAuthorized = currentUser.IsAuthorizedPerUIElement("CMS.Design", new [] { "Design", "Design.WebPartProperties" }, SiteContext.CurrentSiteName);

        if (deskAuthorized && contentAuthorized)
        {
            bool editAuthorized = currentUser.IsAuthorizedPerUIElement("CMS.Design", new [] { "WebPartProperties.EditTransformations" }, SiteContext.CurrentSiteName);
            bool createAuthorized = currentUser.IsAuthorizedPerUIElement("CMS.Design", new [] { "WebPartProperties.NewTransformations" }, SiteContext.CurrentSiteName);

            // Alias path for preview transformation
            String aliasPath = QueryHelper.GetString("aliaspath", String.Empty);
            String aliasPathParam = (aliasPath == String.Empty) ? "" : "&aliaspath=" + aliasPath;

            // Instance GUID
            String instanceGUID = QueryHelper.GetString("instanceGUID", String.Empty);
            String instanceGUIDParam = (instanceGUID == String.Empty) ? "" : "&instanceguid=" + instanceGUID;

            // Transformation editing authorized
            if (editAuthorized)
            {
                string isSiteManagerStr = IsSiteManager ? "&siteManager=true" : String.Empty;
                string query = String.Format("objectid=##ITEMID##{0}&editonlycode=1&dialog=1", isSiteManagerStr) + aliasPathParam + instanceGUIDParam;

                string url = UIContextHelper.GetElementUrl("CMS.DocumentEngine", "EditTransformation");
                url = URLHelper.AppendQuery(url, query);
                uniSelector.EditItemPageUrl = url;
            }

            // Creating of new transformation authorized
            if (createAuthorized)
            {
                string isSiteManagerStr = IsSiteManager ? "&siteManager=true" : String.Empty;
                string url = NewDialogPath + "?editonlycode=1&dialog=1" + isSiteManagerStr + "&selectedvalue=##ITEMID##" + aliasPathParam + instanceGUIDParam;
                url = URLHelper.AddParameterToUrl(url, "hash", QueryHelper.GetHash("?editonlycode=1"));

                uniSelector.NewItemPageUrl = url;
                uniSelector.EditDialogWindowHeight = 760;
            }
        }

        string where = null;

        if (!ShowHierarchicalTransformation)
        {
            where = "(TransformationIsHierarchical IS NULL) OR (TransformationIsHierarchical = 0)";
        }

        if (!string.IsNullOrEmpty(WhereCondition))
        {
            where = SqlHelper.AddWhereCondition(where, WhereCondition);
        }

        if (where != null)
        {
            uniSelector.WhereCondition = where;
        }
    }


    /// <summary>
    /// Returns true if user control is valid.
    /// </summary>
    public override bool IsValid()
    {
        // If macro or special value, do not validate
        string value = uniSelector.TextBoxSelect.Text.Trim();
        if (!MacroProcessor.ContainsMacro(value) && (value != string.Empty))
        {
            // Check if culture exists
            TransformationInfo ti = TransformationInfoProvider.GetTransformation(value);
            if (ti == null)
            {
                ValidationError = GetString("formcontrols_selecttransformation.notexist").Replace("%%code%%", value);
                return false;
            }
            else
            {
                return true;
            }
        }
        return true;
    }

    #endregion
}