<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#INCLUDE file="../../owFunctions/clsUpload.asp"-->
<!--#INCLUDE file="../Functions/I_Upload.asp"-->
<%
	'************************************************************************************
	'*																					*
	'*	MODIFICATION TO THIS SCRIPT OR ANY FILES INCLUDED WITH 							*
	'*		ONEWORLDSTORE IS DONE AT YOUR OWN RISK!										*
	'*	Product  : OneWorldStore														*
	'*	Version  : 9.0000																*
	'*	Modified : June 2004															*
	'*	Copyright:	Copyright (C) 2004 OneWorldStore.Com								*
	'*				Registration Number: 1024507										*
	'*				http://strategis.ic.gc.ca/											*
	'*																					*
	'************************************************************************************

	Dim sMessage, ctArray, sTemp, objUpload, sFileName
	
	If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
	
		Server.ScriptTimeout = 5400
	
		ctArray = Split(Request.ServerVariables( "HTTP_CONTENT_TYPE"), ";")
		If ( UBound(ctArray) > 0 ) Then
			sTemp = Trim(UCase(ctArray(0)))
		End If
	
		If ( sTemp = "MULTIPART/FORM-DATA" ) Then
			Set objUpload		= New clsUpload
			sIDCategory			= CONVERSION_Numeric(objUpload("sIDCategory").Value, C_INTEGER)
			sDisplayOrder		= CONVERSION_Numeric(objUpload("sDisplayOrder").Value, C_INTEGER)
			sDelCurImage		= SQLEncode(Trim(objUpload("sDelCurImage").Value))
			sOriginalImageName	= SQLEncode(Trim(objUpload("sOriginalImageName").Value))
			sCategoryDesc 		= SQLEncode(Trim(objUpload("sCategoryDesc").Value))
			sIDParentCategory 	= SQLEncode(Trim(objUpload("sIDParentCategory").Value))
			sActive				= CONVERSION_Numeric(objUpload("sActive").Value, C_INTEGER)
			sLongHTML			= SQLEncode(Trim(objUpload("sLongHTML").Value))
			sShortHTML			= SQLEncode(Trim(objUpload("sShortHTML").Value))
			sFeatured			= CONVERSION_Numeric(objUpload("sFeatured").Value, C_INTEGER)
			
			If ( objUpload("sImageCategory").Length > 0 ) Then
				sFileName = objUpload("sImageCategory").FileName
			Else
				sFileName = ""
			End If
		End If
		
		If ( sCategoryDesc = "" ) then sCategoryDesc = " "
		If ( sFileName = "" ) then sFileName = " "
		If ( sLongHTML = "" ) then sLongHTML = " "
		If ( sShortHTML = "" ) then sShortHTML = " "
		If ( sCategoryDesc = "" ) then sCategoryDesc = " "

		If ( sDelCurImage = "Y" ) Then
			DeleteCategoryImage(sOriginalImageName)
		End If
		
		If ( sOriginalImageName <> sFileName ) And ( objUpload("sImageCategory").Length > 0 ) Then
			' they swapped out images so delete the original one
			DeleteCategoryImage(sOriginalImageName)
		End If
	
		sMessage = G_UPLOAD_SaveFile("sImageCategory", sOWCategoryImage, "", sFileName)
		If ( sMessage = "" ) Then
			If ( objUpload("sImageCategory").Length <= 0 ) And ( sDelCurImage <> "Y" ) Then	' leave the current image alone
				sSQLText = "UPDATE categories set categoryDesc = '" & sCategoryDesc & "', idparentcategory=" & sIDParentCategory & ", active = " & sActive & ", displayOrder = " & sDisplayOrder & ", longHTML = '" & sLongHTML & "', shortHTML = '" & sShortHTML & "', Featured = '" & sFeatured & "' WHERE idCategory = " & sIDCategory
			Else
				sSQLText = "UPDATE categories set categoryDesc = '" & sCategoryDesc & "', idparentcategory=" & sIDParentCategory & ", sImageCategory = '" & sFileName & "', active = " & sActive & ", displayOrder = " & sDisplayOrder & ", longHTML = '" & sLongHTML & "', shortHTML = '" & sShortHTML & "', Featured = '" & sFeatured & "' WHERE idCategory = " & sIDCategory
			End If
			Call DB_updateDatabase(sSQLText)
		End If
			
	End If

	%>
	<script language = "javascript">
		location="owModifyCategories.asp?bRefresh=TRUE&sSort=<%=sSort%>&sSearch=<%=sSearch%>&sSearchText=<%=sSearchText%>&idcategory=<%=sIDCategory%>";
	</script>
	
<%
	'************************************************************************************
	'*																					*
	'*	This saves the file (if any). 													*
	'*																					*
	'************************************************************************************
	Sub DeleteCategoryImage(sFileName)
	
		Dim sFilePath, lf, f
	
		Set lf = server.createObject("Scripting.FileSystemObject")
		sFilePath	= "../../" & sOWCategoryImage
		sFilePath	= Replace(sFilePath, "\", "/")
		sFilePath	= Replace(sFilePath, "//", "/")
		sFilePath	= server.mappath(sFilePath) & "\" & sFileName
		If ( lf.FileExists(sFilePath) ) Then	
			Set f = lf.GetFile(sFilePath)
			f.Delete
			Set f = Nothing
		End If
		Set lf = Nothing
	
	End Sub
	'************************************************************************************
%>