<!--#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 iBeginPagination, sURL, iTtlNumItems, iDBLoc, sQuerystring
	Dim sTarget, iPaginationCount, sTempSearch, sOrderStatus
	
	sAction				= Trim(Request("sAction"))
	sSort				= Trim(Request("sSort"))
	sOrderStatus		= Trim(Request("sOrderStatus"))
	bResetDBLoc			= False
	sURL				= "owListOrders.asp"
	sQuerystring		= "sAction=" & sAction & "&sOrderStatus=" & sOrderStatus & "&sSort=" & sSort
	sTarget				= "owMain"
	pOrderStatus		= CONVERSION_SQLEncode2(Request("orderStatus"),10)
	sAccountUnq			= CONVERSION_SQLEncode2(Request("AccountUnq"),10)
	
	If ( sAction = "Delete" ) Then
		For Each sCheckbox In Request.Form
			If ( InStr(sCheckbox, "sDelete") > 0 ) Then
				sTemp = Replace(sCheckbox, "sDelete", "")
				sSuccess = DeleteOrder(sTemp)
			End If
		Next
		bResetDBLoc = True
	ElseIf ( sAction = "Search" ) Then
		If ( sOrderStatus <> "" ) Then
			sTempSearch = " WHERE orderstatus = " & sOrderStatus
		Else
			sTempSearch = ""
		End If
	End If
	If ( sSort <> "" ) Then
		sSort = " ORDER BY " & sSort
	End If

	sSQLText	= "SELECT * FROM Orders" & sTempSearch & sSort
	sSQLCount	= "SELECT Count(*) FROM Orders" & sTempSearch
	
	iBeginPagination = SetupPagination( sSQLCount, bResetTtlNumItems, bResetDBLoc )
	Call PaginationQuery( sSQLText, rsStoreData, iBeginPagination )
	
	%>
	<script language = "javascript">
		parent.owBodyFooter.location="owBodyFooter.asp?<%=sQueryString%><%=sSort%>&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( "ORDERS_NOTFOUND", "** No orders under that search **" ))%>"
			</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 = "sOrderStatus=" & Server.URLEncode(sOrderStatus) & "&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 style="font-family: Arial; font-size: 11px" topmargin="0" leftmargin="0" bgcolor=C3DAF9>
	<div id="tablediv" style="position: absolute; top: 0px; height: 100%; width:100%">
		<table width=100% border="0" cellpadding="2" cellspacing="0" style="font-size: 11px" bgcolor=FFFFFF>
		<form action='owListOrders.asp' method='post' name='OrderList'>
			<input type='hidden' name='sAction' value=''>
			<tr>
				<td class="ColumnHead" align="center"><%=LANG_DT( "SELECT", "Select" )%></td>
				<td onclick="location.href='owListOrders.asp?<%=sQueryString%>idOrder'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "ORDERID", "Order ID" )%></td>
				<td onclick="location.href='owListOrders.asp?<%=sQueryString%>name'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "CUSTOMER", "Customer" )%></td>
				<td onclick="location.href='owListOrders.asp?<%=sQueryString%>orderDate'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "ORDERDATE", "Order Date" )%></td>
				<td onclick="location.href='owListOrders.asp?<%=sQueryString%>total'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" align="center"><%=LANG_DT( "TOTAL", "Total" )%></td>
				<td onclick="location.href='owListOrders.asp?<%=sQueryString%>orderStatus'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" bgcolor="#C3DAF9" align="center"><%=LANG_DT( "STATUS", "Status" )%></td>
			</tr>
			<%
			If ( NOT rsStoreData.EOF ) Then
				iPaginationCount = 0
				While ( ( NOT rsStoreData.EOF ) And ( iPaginationCount < iOWNumPerPage ) )
					pName				= rsStoreData("FName") & " " & rsStoreData("LName")
					sIDOrder			= rsStoreData("idOrder")
					pOrderDate			= rsStoreData("orderDate")
					pTotal				= rsStoreData("total") 
					pOrderStatus		= rsStoreData("orderStatus")   
					sCurrentCreditOwed	= rsStoreData("CurrentCreditOwed")
					bOwe				= False
					
					If ( sCurrentCreditOwed <> "" ) And ( NOT IsNull(sCurrentCreditOwed) ) Then
						If ( IsNumeric(sCurrentCreditOwed) ) Then
							If ( CDbl(sCurrentCreditOwed) > 0 ) Then
								bOwe = True
							End If
						End If
					End If
					
					sQueryString2	= sQueryString & sSort & "&idorder=" & sIDOrder
					%>
					<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<%=sIDOrder%>" value="46"></td>
						<td width=10% onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="center"><%=sOWOrderPrefix & sIDOrder%>&nbsp;</td>
						<td width=25% onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="left"><%=pName%>&nbsp;</td>
						<td width=10% onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="left">
							<%=pOrderDate%>&nbsp;
						</td>
						<td width=10% onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="left"><%=CONVERSION_Currency(pTotal)%>&nbsp;</td>
						<%If ( bOwe ) Then%>
						<td width=10% onMouseOver='window.status = "<%=LANG_DT( "CUSTOMER_CREDITOWEDMSG", "Credit owed on this order" )%>: <%=CONVERSION_Currency(sCurrentCreditOwed)%>";' onMouseOut='window.status = "";' onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="left">
						<%Else%>
						<td width=10 onclick="location.href='owModifyOrder.asp?<%=sQueryString2%>'" class='ColumnData' align="left">
						<%End If%>
							<%
							Select Case pOrderStatus
								Case C_PENDING
									response.write LANG_DT( "ORDERS_PEND", "Pending" )
								Case C_DELIVERED
									response.write LANG_DT( "ORDERS_DEL", "Delivered" )
								Case C_CANCELLED
									response.write LANG_DT( "ORDERS_CANCELLED", "Cancelled" )
								Case C_PAID
									response.write LANG_DT( "ORDERS_PAID", "Paid" )   		
								Case C_CHARGEBACK
									response.write LANG_DT( "ORDERS_CHARGEBACK", "Chargeback" )
								Case C_REFUNDED
									response.write LANG_DT( "ORDERS_REFUNDED", "Refunded" )
								Case C_UNFINALIZED
									response.write LANG_DT( "ORDERS_UNFINALIZED", "Unfinalized" )
							End Select
							If ( bOwe ) Then
								Response.Write "*"
							End If
							%> 
						</td>
					</tr>
					<%
					rsStoreData.movenext
					iPaginationCount = iPaginationCount + 1
				Wend
			End If
			
			%>
		</form>
	</table>
	<%%>
	<!--#include file="../footer.asp"-->
	
<%
	Function DeleteOrder(sIDOrder)

		Call DB_updateDatabase("DELETE FROM OrdersProdOptions WHERE idOrder = " & sIDOrder)
		Call DB_updateDatabase("DELETE FROM OrdersProdRef WHERE idOrder = " & sIDOrder)
		call DB_updateDatabase("DELETE FROM OrdersCreditCards WHERE idOrder=" & sIDOrder)
		call DB_updateDatabase("DELETE FROM ordersTaxes WHERE idOrder=" & sIDOrder)
		call DB_updateDatabase("DELETE FROM orders WHERE idOrder = " & sIDOrder)
		
		DeleteOrder = LANG_DT( "ORDERS_DELOK", "** Deletion Successful **" )
	
	End Function
%>