<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="../header.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 pIdCategory, pCategoryDesc
	Dim sSearchText, sSearch, sSQLCount, bResetTtlNumItems, bResetDBLoc
	Dim iBeginPagination, sURL, iTtlNumItems, iDBLoc, sQuerystring
	Dim sTarget, iPaginationCount, sSort, sSuccess, sQueryString2
	Dim sSupplier, sTempSearch
	
	sAction				= Trim(Request("sAction"))
	sSort				= Trim(Request("sSort"))
	sSearchText			= Trim(Request("sSearchText"))
	sSearch				= Trim(Request("sSearch"))
	bResetDBLoc			= False
	sURL				= "owListProducts.asp"
	sQuerystring		= "sAction=" & sAction & "&sSearchText=" & sSearchText & "&sSearch=" & sSearch & "&sSort=" & sSort
	sTarget				= "owMain"

	If ( sAction = "Delete" ) Then
		If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
			For Each sCheckbox In Request.Form
				If ( InStr(sCheckbox, "sDelete") > 0 ) Then
					sTemp		= Replace(sCheckbox, "sDelete", "")
					sSuccess	= DeleteProducts(sTemp)
				End If
			Next
			bResetTtlNumItems	= True
			bResetDBLoc			= True
		End If
	End If
	
	If ( sSearchText <> "" ) Then
		If ( sSearch = "FirstChar" ) Then
			sTempSearch = " WHERE description LIKE '" & sSearchText & "%'"
		Else
			sTempSearch = " WHERE " & sSearch & " LIKE '%" & sSearchText & "%'"
		End If
	Else
		sTempSearch = ""
	End If

	'sSQLText	= "SELECT * FROM Products P LEFT OUTER JOIN Customers C ON C.AccountUnq = P.idsupplier" & sTempSearch
	'sSQLCount	= "SELECT Count(*) FROM Products P LEFT OUTER JOIN Customers C ON C.AccountUnq = P.idsupplier" & sTempSearch
	sSQLText	= "SELECT * FROM Products" & sTempSearch
	sSQLCount	= "SELECT Count(*) FROM Products" & sTempSearch

	If ( sSort <> "" ) Then
		sSQLText = sSQLText & " ORDER BY " & sSort
	End If

	iBeginPagination = SetupPagination( sSQLCount, bResetTtlNumItems, bResetDBLoc )
	Call PaginationQuery( sSQLText, rsStoreData, iBeginPagination )
	
	%>
	<script language = "javascript">
		parent.owBodyFooter.location="owBodyFooter.asp?<%=sQuerystring%>&iOWNumPerPage=<%=iOWNumPerPage%>&iTtlNumItems=<%=iTtlNumItems%>&iDBLoc=<%=iDBLoc%>"
	</script>
	<%
	
	If ( sSuccess <> "" ) Or ( rsStoreData.EOF ) Then
		If ( sSuccess <> "" ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage=<%=Server.URLEncode(sSuccess)%>"
			</script>
			<%
		End If
		If ( rsStoreData.EOF ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage=<%=Server.URLEncode(LANG_DT( "PRODUCT_NONEFOUND", "** No products found **" ))%>"
			</script>
			<%
		End If
	Else
		' just refresh the top bar to remove any "Save" buttons or old messages
		%>
		<script language = "javascript">
			parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage="
		</script>
		<%
	End If
	
	sQueryString = "sSearchText=" & Server.URLEncode(sSearchText) & "&sSearch=" & Server.URLEncode(Trim(sSearch)) & "&sSort="
	%>
	<script language = "javascript">
		
		function ColumnOn(sStyle)
		{
			sStyle.background	= "#F5C058";
		}
		function ColumnOff(sStyle)
		{
			sStyle.background	= "#C3DAF9";
		}
		
		function ColumnDataOn(sStyle)
		{
			sStyle.background	= "#EAF1F9";
		}
		function ColumnDataOff(sStyle)
		{
			sStyle.background	= "#FFFFFF";
		}
		
	</script>
	<body bgcolor="C3DAF9" text="#000000" topmargin="0" leftmargin="0">
		<table width=100% border="0" cellpadding="2" cellspacing="0" style="font-size: 11px" bgcolor=FFFFFF>
		<form action='owListProducts.asp' method='post' name='ProductList'>
			<input type='hidden' name='sAction' value=''>
			<input type='hidden' name='sSort' value=''>
			<tr> 
				<td class="ColumnHead" align="center"><%=LANG_DT( "SELECT", "Select" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>p.sku'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align=center><%=LANG_DT( "PRODUCT_SKU", "SKU" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>p.description'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_DESC", "Description" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>p.price'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_PRICE", "Price" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>C.CustomerCompany'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_BRAND", "Brand" )%></td>
				<td class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_CAT", "Category" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>p.showinhome'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_FEATURED", "Featured?" )%></td>
				<td onClick="location.href='owListProducts.asp?<%=sQueryString%>p.active'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "PRODUCT_ACTIVEQUEST", "Active?" )%></td>
			</tr>
			<%
			' iterates through the child categories
			sSQLCount = 0
			While ( ( NOT rsStoreData.EOF ) And ( sSQLCount < iOWNumPerPage ) )
				idProduct		= rsStoreData("idProduct")
				sDescription	= rsStoreData("description")
				sPrice			= rsStoreData("price")
				sSKU			= rsStoreData("sku")
				sSupplier		= rsStoreData("idSupplier")
				If ( ( sSupplier <> "" ) And ( NOT IsNull(sSupplier) ) ) Then
					sSupplier	= ACCNT_ReturnADV("OW_CUSTCOMPANY", "V", rsStoreData("idSupplier"), C_OVERRIDE_ADV)
				End If
				sQueryString2	= sQueryString & sSort & "&idProduct=" & idProduct
				If ( sSKU = "" ) Then
					sSKU = "&nbsp;"
				End If
				%>
				<tr onMouseOver="ColumnDataOn(this.style);" onMouseOut="ColumnDataOff(this.style);"> 
					<td width=5% class='ColumnData' align="center"><input size="1" type="checkbox" style="font-size: 6px;" name="sDelete<%=idProduct%>" value="46"></td>
					<td width=15% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="left"><%=sSKU%>&nbsp;</td>
					<td onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="left"><%=sDescription%>&nbsp;</td>
					<td width=5% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="center"><%=CONVERSION_Currency(sPrice)%>&nbsp;</td>
					<td width=20% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="center"><%=sSupplier%>&nbsp;</td>
					<td width=20% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="center">
						<%
						sSQLText = "SELECT C.CategoryDesc FROM CatProdMap CP, Categories C WHERE CP.idProduct = " & idProduct & " AND CP.idCategory = C.idCategory"
						Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
						If ( NOT rsStoreData2.EOF ) Then
							Response.Write rsStoreData2("CategoryDesc")
						End If
						Call DB_closeRecordset(rsStoreData2)
						%>
					</td>
					<td width=5% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="center">
						<%
						If ( rsStoreData("showinhome") = -1 ) Then
							Response.Write LANG_DT( "YES", "Yes" )
						Else
							Response.Write LANG_DT( "NO", "No" )
						End If
						%>
					</td>
					<td width=5% onClick="location.href='owModifyProductForm.asp?<%=sQueryString2%>'" class='ColumnData' align="center">
						<%
						If ( rsStoreData("active") = -1 ) Then
							Response.Write LANG_DT( "YES", "Yes" )
						Else
							Response.Write LANG_DT( "NO", "No" )
						End If
						%>
					</td>
				</tr>
				<%
				sSQLCount = sSQLCount + 1
				rsStoreData.moveNext
			Wend
			Call DB_closeRecordset(rsStoreData)
			%>
    		</form>
  		</table>
	<!--#include file="../footer.asp"-->
	
<%
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function DeleteProducts(sIDProduct)
		
		Dim sTemp
		
		DeleteProducts = ""
		
		sSQLText = "SELECT idCartRow FROM CartProducts WHERE idProduct = " & sIDProduct
		Call DB_getFromDatabase(sSQLText, rsStoreData, "owDeleteItemExec.asp") 
'		if not rsStoreData.eof then
'			DeleteProducts = "** Remove from order before deleting **"
'			Call DB_closeRecordset(rsStoreData)
'		Else
			Call DB_closeRecordset(rsStoreData)

			Call DB_updateDatabase("DELETE FROM CatProdMap WHERE idProduct = " & sIDProduct)
			Call DB_updateDatabase("DELETE FROM optionsGroups_products WHERE idproduct = " & sIDProduct)
			
			sSQLText = "SELECT imageUrl, smallImageUrl FROM products WHERE idProduct = " & sIDProduct
			Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
			If ( NOT rsStoreData.EOF ) Then
				sTemp = Trim(rsStoreData("imageUrl"))
				If ( NOT bOWAdvancedImages ) Then	' Advanced images are turned off
					If ( sTemp <> "" ) Then
						Call DeleteCategoryImage(sTemp, "")
					End If
					sTemp = Trim(rsStoreData("smallImageUrl"))
					If ( sTemp <> "" ) Then
						Call DeleteCategoryImage(sTemp, "/small")
					End If
				Else
					DeleteAllImages(sTemp)
				End If				
			End If
			Call DB_closeRecordset(rsStoreData)
			
			' delete product from products table
			Call DB_updateDatabase("DELETE FROM products WHERE idproduct = " & sIDProduct)
			
			DeleteProducts = LANG_DT( "PRODUCTS_DELSUCCESS", "** Products(s) successfully deleted **" )
'		End If
		
	End Function
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*	This saves the file (if any). 													*
	'*																					*
	'************************************************************************************
	Sub DeleteCategoryImage(sFileName, sThumbDir)
	
		Dim sFilePath, lf, f
	
		Set lf = server.createObject("Scripting.FileSystemObject")
		sFilePath	= "../../" & sOWImagesDir & sThumbDir
		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
	'************************************************************************************
%>