<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<%
	Dim ID, BatchNumber

	PageHeader

	If Session("IsAdminLogin") Then
		AdminMenu
	Else
		UserLogin
		Response.End
	End If


	ID		= Str2Num(Request.Querystring("ID"))
	Command	= Request.Querystring("Command")


	If Command = "Delete" Then
		DBC.Execute("DELETE FROM Payments WHERE ID = " & Str2Num(Request.Querystring("ID")))
	End If

	If Len(Request.Form.Item) > 0 Then
		ID = Str2Num(Request("ID"))

		BatchNumber = Str2Num(Request("PAYMENT_BATCH_NUM"))

		Set rs = DBC.Execute("SELECT COUNT(*) FROM Payments WHERE BatchNumber = " & BatchNumber)

		If rs(0) = 0 Then
			DBC.Execute("UPDATE Payments SET BatchNumber = " & BatchNumber & " WHERE ID = " & ID)
		End If
	End If


%>
	<p align=center>
	<a href="admin_payments.asp">Show all waiting payments</a>
	</p>
<%
	If Command = "Send" Then
		Send
	Else
		UnPaidList
	End If

	Response.Write "</body>"
	Response.Write "</html>"


	Sub UnPaidList()

		Dim i

		Set rs = DBC.Execute("SELECT * FROM Payments WHERE BatchNumber = 0")
%>
		<table border=0 align=center bgcolor=FFEFB2 cellspacing=1 cellpadding=2>
		<tr class=PageText>
			<td>&nbsp;</td>
			<td align=center><font color=black>E-Gold</font></td>
			<td align=center><font color=black>Win</font></td>
			<td><font color=black>Description</font></td>
			<td>&nbsp;</td>
		</tr>
<%
		i = 0

		Do While Not rs.EOF
%>
		<tr bgcolor=white class=PageText>
			<td align=center>
				<%= i + 1 %>.
			</td>
			<td align=center>
				<%= rs("To") %>
			</td>
			<td align=right>
				$ <%= FormatNumber(rs("Cash"), 4) %>
			</td>
			<td>
				<%= rs("Description") %>
			</td>
			<td align=center>
				<a href=admin_payments.asp?Command=Send&ID=<%= rs("ID") %>>Send Money to Player</a>&nbsp;
				<a href="javascript: Delete(<%= rs("ID") %>)">Delete</a>
			</td>
		</tr>
<%
			i = i + 1
			rs.MoveNext
		Loop
%>
		</table>

		<script language=JavaScript>
		<!--
		function Delete(ID)
		{
			if (confirm("This record will be delete. Do you want to proceed."))
				document.location = "admin_payments.asp?Command=Delete&ID=" + ID;
		}
		//-->
		</script>
<%
	End Sub


	Sub Send()

		Set rs = DBC.Execute("SELECT * FROM Payments WHERE ID = " & ID)

		If rs.EOF Then
			Response.Write "Error."
			Exit Sub
		End If
%>
		<form action="https://www.e-gold.com/sci_asp/payments.asp" method=POST>
		<input type=hidden name=PAYEE_ACCOUNT value=<%= rs("To") %>>
		<input type=hidden name=PAYEE_NAME value="">
		<input type=hidden name=PAYMENT_UNITS value=1>
		<input type=hidden name=PAYMENT_METAL_ID value=1>
		<input type=hidden name=STATUS_URL value="NULL">
		<input type=hidden name=PAYMENT_URL value="<%= CurrentFile %>">
		<input type=hidden name=NOPAYMENT_URL value="<%= CurrentFile %>">

		<table border=0 align=center bgcolor=FFEFB2 cellspacing=1 cellpadding=2>
		<tr class=PageText>
			<td colspan=2 align=center>
				<font color=black>Send Money</font>
			</td>
		</tr>
		<tr bgcolor=white>
			<td class=PageText>
				Player wins ($)
			</td>
			<td>
				<input name=PAYMENT_AMOUNT value="<%= rs("Cash") %>" class=ClientText>
			</td>
		</tr>
		<tr bgcolor=white>
			<td class=PageText>
				Description
			</td>
			<td>
				<input name=SUGGESTED_MEMO value="<%= rs("Description") %>" class=ClientText>
			</td>
		</tr>
		<tr bgcolor=white>
			<td colspan=2 align=center>
				<input type=hidden name=BAGGAGE_FIELDS value="ID">
				<input type=hidden name=ID value="<%= ID %>">
				<input type=submit name=PAYMENT_METHOD value="Send Money">
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>