<!--#include file="../library/libraryinc.inc" -->
<%
Server.ScriptTimeout = 1000

response.buffer = true

response.cachecontrol = "no-cache"

Timeout(1)

Set Upload = Server.CreateObject("Persits.Upload")
Upload.ProgressID = Request.QueryString("PID")
Upload.OverwriteFiles = False

'-----------------------------------------------------------------
' Capture uploaded file. Save returns the number of files uploaded
'-----------------------------------------------------------------
Count = Upload.Save(server.mappath("../../Uploads"))
strRedirect  = Upload.Form("FrontEnd")

set con = server.createobject("ADODB.Connection")
con.open Application("CString")

set rsPage = server.createobject("ADODB.Recordset")
rsPage.open "SELECT * FROM CMS_Page WHERE PageID = "& Upload.Form("id"), con, 1, 3

if not rsPage.EOF then

	rsPage.MoveFirst()
	strPrevFile = rsPage("FileName")
	strPrevZip = rsPage("ImageName")
	rsPage.MoveFirst()
	strHeading 				= Upload.Form("Heading")
	rsPage("Heading") 		= strHeading

	If Count > 0 Then
	
	'-------------------------------------------------
	' Obtain File object representing uploaded file
	'-------------------------------------------------
	Set File = Upload.Files(1)
	
	set oFS=Server.CreateObject("Scripting.FileSystemObject")
	
	if Right(File.ExtractFileName, 4) = ".zip" then
	
		Set Zip = server.createobject("aspZip.EasyZIP")
		Zip.ZipFileName = server.mappath("../../Uploads/"& File.ExtractFileName)

		if CInt(Zip.GetZipItemsCount) > 1 then
			
			strFile			= File.FileName
			intZipSize		= File.Size
			strMainFile		= File.FileName
			intMainSize		= File.Size		
			
		else

			strFile			= File.FileName
			intZipSize		= File.Size
			strMainFile		= Zip.GetZipItem_FIleName(0)
			intMainSize		= Zip.GetZipItem_UNCompressedSize(0)		

			Zip.ArgsClear
			Zip.ArgsAdd("*.*")   'Unzip all files
			Zip.UnZip
		
			set Zip = nothing
			
		end if
	
	else
	
		theArray = Split(File.ExtractFileName, ".")
	
		if UBound(theArray) = 0 then
			strFileName = CStr(File.ExtractFileName) & ".zip"
		else
			intCount = 0
		
			strFileName = ""
		
			do while intCount <= (UBound(theArray) - 1)
				strFileName = strFileName & theArray(intCount)
			intCount = intCount + 1
			loop
		
			strFileName = strFileName & ".zip"
		
		end if
	
		set ZIP = server.createobject("aspZip.EasyZIP")
		Zip.ZipFileName = server.mappath("../../Uploads/"& strFileName)
		Zip.ArgsClear
		Zip.ArgsAdd(server.mappath("../../Uploads/"& File.ExtractFileName))
		Zip.Zip
		
		set Zip = nothing
		
		Set thefile = oFS.GetFile(server.mappath("../../Uploads/"& File.ExtractFileName))
		intMainSize = thefile.Size
	
		Set thefile = nothing
	
		Set thefile = oFS.GetFile(server.mappath("../../Uploads/"& strFileName))
		intZipSize = thefile.Size

		strMainFile = File.ExtractFileName
		strFile = strFileName
		
	end if
		
	set oFS = nothing
	set thefile = nothing
	

	rsPage("FileName")		= strMainFile
	rsPage("FileSize")		= intMainSize
	rsPage("ImageName")	= strFile
	rsPage("ImageDesc")	= intZipSize
	rsPage("UploadDate") 	= Now()
	
End If

	rsPage.Update()
	
end if	

rsPage.Close()
set rsPage = Nothing

con.Close()
set con = Nothing

DeleteFile server.mappath("../../Uploads/temp/"& strMainFile)
DeleteFile server.mappath("../../Uploads/temp/"& strFile)
DeleteFile server.mappath("../../Uploads/"& strPrevFile)
DeleteFile server.mappath("../../Uploads/"& strPrevZip)
DeleteFile server.mappath("../../Uploads/easyZip.txt")

intField = Upload.Form("FieldID")
intProjectID =  Upload.Form("ProjectID")
ProjName = Upload.Form("ProjName")
FieldName = Upload.Form("FieldName")

OldDesc = Upload.Form("OldDesc")



response.redirect("Member_Document.asp?MemberID="&Upload.Form("MemberID")&"&buster="& server.URLEncode(now))
Set Upload = nothing

%>