//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Blogs.Components;
using CommunityServer.Configuration;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for UploadAttachment.
	/// </summary>
	public class UploadAttachment : CommunityServer.Controls.UploadAttachment
	{
		protected override Section Section
		{
			get
			{
				return this.Weblog;
			}
		}

		private Weblog _weblog;
		public virtual Weblog Weblog
		{
			get
			{
				return _weblog;
			}
			set
			{
				_weblog = value;
			}
		}

		protected override bool IsFileValid(string filename, bool isRemote, int fileSizeBytes, ref string message)
		{
			AttachmentSettings fs = WeblogConfiguration.Instance().AttachmentSettings;
			if(fs.ValidateExtensions && !CSContext.Current.User.IsBlogAdministrator)
			{ 
				if (!fs.ValidationRegex.IsMatch(filename))
				{
					message = string.Format(ResourceManager.GetString("UploadAttachment_InvalidFileExtension"), fs.Extensions.Replace(";", ","));
					return false;
				}
				else
					return true;
			}
			else
				return true;
		}
	}
}
