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/TDijk1/erp-apps.eu/wwwroot/CMSWebParts/DeviceProfile/SwitchDeviceDetection.ascx.cs
using System;

using CMS.PortalControls;
using CMS.UIControls;
using CMS.Helpers;
using CMS.Controls;
using CMS.PortalEngine;

public partial class CMSWebParts_DeviceProfile_SwitchDeviceDetection : CMSAbstractWebPart
{

    private bool? mShowDesktopVersion = null;
    
    #region Properties

    /// <summary>
    /// Gets or sets LinkContentMobile property.
    /// </summary>
    public string LinkContentMobile
    {
        get
        {
            return DataHelper.GetNotEmpty(GetValue("LinkContentMobile"), String.Empty);
        }
        set
        {
            SetValue("LinkContentMobile", value);
        }
    }


    /// <summary>
    /// Gets or sets LinkContentDesktop property.
    /// </summary>
    public string LinkContentDesktop
    {
        get
        {
            return DataHelper.GetNotEmpty(GetValue("LinkContentDesktop"), String.Empty);
        }
        set
        {
            SetValue("LinkContentDesktop", value);
        }
    }


    /// <summary>
    /// Indicates if visitor wants to show desktop version of the page
    /// </summary>
    public bool ShowDesktopVersion
    {
        get
        {
            if (!mShowDesktopVersion.HasValue)
            {
                mShowDesktopVersion = ValidationHelper.GetBoolean(CookieHelper.GetValue(CookieName.ShowDesktopVersion), false);
            }
            return mShowDesktopVersion.Value;
        }
        set
        {
            CookieHelper.SetValue(CookieName.ShowDesktopVersion, value.ToString(), DateTime.Now.AddYears(1));
            mShowDesktopVersion = value;
        }
    }

    #endregion


    protected void Page_Load(object sender, EventArgs e)
    {                 
        // Check if current device is desktop
        if ((CookieHelper.CurrentCookieLevel < CookieLevel.Essential) || (String.IsNullOrEmpty(DeviceContext.CurrentDeviceProfileName) && String.IsNullOrEmpty(DeviceProfileInfoProvider.GetOriginalCurrentDevicProfileName(CurrentSite.SiteName))))
        {
            pnlContent.Visible = false;
            return;
        } 

        bool useDesktop = ViewMode.IsLiveSite() ? ShowDesktopVersion : String.IsNullOrEmpty(DeviceContext.CurrentDeviceProfileName);
        lnkLink.Text = ContextResolver.ResolveMacros(useDesktop ? LinkContentDesktop : LinkContentMobile);
    }


    protected void lnkLink_OnClick(object sender, EventArgs e)
    {
        if (ViewMode != ViewModeEnum.LiveSite)
        {
            return;
        }
        ShowDesktopVersion = ShowDesktopVersion ? false : true;
        URLHelper.Redirect(RequestContext.CurrentURL);
    }

}