<!--#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
			sCategoryDesc 		= SQLEncode(Trim(objUpload("sCategoryDesc").Value))
			sIDParentCategory 	= SQLEncode(Trim(objUpload("sIDParentCategory").Value))
			sActive				= SQLEncode(Trim(objUpload("sActive").Value))
			sLongHTML			= SQLEncode(Trim(objUpload("sLongHTML").Value))
			sShortHTML			= SQLEncode(Trim(objUpload("sShortHTML").Value))
			sFeatured			= SQLEncode(Trim(objUpload("sFeatured").Value))
			
			If ( objUpload("sImageCategory").Length > 0 ) Then
				sFileName = objUpload("sImageCategory").FileName
			Else
				sFileName = ""
			End If
		End If
	
		If ( sFeatured = "" ) then sFeatured = 0
		If ( sCategoryDesc = "" ) then sCategoryDesc = " "
		If ( sFileName = "" ) then sFileName = " "
		If ( sActive = "" ) then sActive = 0
		If ( sLongHTML = "" ) then sLongHTML = " "
		If ( sShortHTML = "" ) then sShortHTML = " "
		If ( sCategoryDesc = "" ) then sCategoryDesc = " "
		If ( sActive <> "-1" ) Then sActive="0"
		
		sSQLText = "SELECT idCategory FROM categories WHERE categoryDesc = '" & lCase(sCategoryDesc) & "' and idParentCategory = " & sIDParentCategory
		Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
		if not rsStoreData.eof then 
			sMessage = LANG_DT( "ADDCATEGORY_DUP_NAME", "Cannot add category: duplicate name" )
		Else
			sMessage = G_UPLOAD_SaveFile("sImageCategory", sOWCategoryImage, "", sFileName)
			If ( sMessage = "" ) Then
				sSQLText = "INSERT INTO categories (categoryDesc, idParentCategory, imageCategory, displayOrder, active, shortHTML, featured, longHTML) VALUES ('" &sCategoryDesc& "'," &sIDParentCategory& ", '" &sFileName& "',0," &sActive& ", '" & sShortHTML & "', " & sFeatured  &", '" & sLongHTML & "')"
				Call DB_updateDatabase(sSQLText)
			End If
		End If
				
	End If
	%>
	<script language = "javascript">
		parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage=<%=Server.URLEncode(sMessage)%>";
		location="owListCategories.asp?sSort=<%=sSort%>&sSearch=<%=sSearch%>&sSearchText=<%=sSearchText%>&idcategory=<%=pIdcategory%>";
	</script>