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/CMS/CMSModules/Forums/Controls/AttachmentDisplayer.ascx.cs
using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using CMS.Forums;
using CMS.Helpers;

public partial class CMSModules_Forums_Controls_AttachmentDisplayer : ForumViewer
{
    private int mPostID = 0;
    private int mPostAttachmentCount = 0;
    protected string mAttachmentSeparator = " ";


    #region "Public variables"

    /// <summary>
    /// Gets or sets ID of forum posts.
    /// </summary>
    public int PostID
    {
        get
        {
            return ValidationHelper.GetInteger(ViewState["AttachmentDisplayer_PostID"], mPostID);
        }
        set
        {
            if (value > 0)
            {
                ViewState["AttachmentDisplayer_PostID"] = value;
                mPostID = value;
            }
        }
    }


    /// <summary>
    /// Gets or sets attachments count.
    /// </summary>
    public int PostAttachmentCount
    {
        get
        {
            return ValidationHelper.GetInteger(ViewState["AttachmentDisplayer_PostAttachmentCount"], mPostAttachmentCount);
        }
        set
        {
            if (value > 0)
            {
                ViewState["AttachmentDisplayer_PostAttachmentCount"] = value;
                mPostAttachmentCount = value;
            }
        }
    }


    /// <summary>
    /// Gets or sets the attachment separator.
    /// </summary>
    public string AttachmentSeparator
    {
        get
        {
            return mAttachmentSeparator;
        }
        set
        {
            mAttachmentSeparator = value;
        }
    }

    #endregion


    /// <summary>
    /// OnPreRender reload data.
    /// </summary>
    protected override void OnPreRender(EventArgs e)
    {
        ReloadData();
    }


    /// <summary>
    /// Returns HTML code with link to attachment.
    /// </summary>
    /// <param name="attachmentName">Attachment file name</param>
    /// <param name="attachmentGuid">Attachment GUID</param>    
    protected string GetAttachmentLink(object data)
    {
        // try retype data as datarow view
        DataRowView drv = data as DataRowView;

        if (drv != null)
        {
            string guid = ValidationHelper.GetString(drv.Row["AttachmentGUID"], "");
            string name = HTMLHelper.HTMLEncode(ValidationHelper.GetString(drv.Row["AttachmentFileName"], ""));
            string mime = ValidationHelper.GetString(drv.Row["AttachmentMimeType"], "");
            string url = ResolveUrl("~/CMSModules/Forums/CMSPages/GetForumAttachment.aspx?fileguid=" + guid);

            if (DisplayAttachmentImage && ImageHelper.IsMimeImage(mime))
            {
                return "<a target=\"_blank\" title=\"" + name + "\" href=\"" + url + "\">" +
                       "<img src=\"" + url + "&maxsidesize=" + AttachmentImageMaxSideSize + "\" border=\"none\" alt=\"" + name + "\" /></a>";
            }
            else
            {
                return "<a target=\"_blank\" title=\"" + name + "\" href=\"" + url + "\">" + name + "</a>";
            }
        }

        return "";
    }


    public override void ReloadData()
    {
        // Try to copy forum viewer properties from parent
        CopyValuesFromParent(this);

        // Retrieve from DB only if post has some attachments
        if ((PostAttachmentCount > 0) && ((PostID > 0)))
        {
            ltlHeader.Text = GetString("forums.postattachments");

            DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(PostID, false);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                rptAttachments.DataSource = ds;
                rptAttachments.DataBind();
                plcPostAttachments.Visible = true;
            }
        }
        // Hide if there is no attachment
        else
        {
            plcPostAttachments.Visible = false;
        }

        base.ReloadData();
    }


    /// <summary>
    /// Clear viewestate data.
    /// </summary>
    public void ClearData()
    {
        ViewState["AttachmentDisplayer_PostID"] = null;
        ViewState["AttachmentDisplayer_PostAttachmentCount"] = null;
    }
}