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


	PageHeader

	If Not Session("IsAdminLogin") Then
		PageLogin
		Response.End
	End If



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


	OpenConnection

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

		DBC.Execute("UPDATE Payouts SET " & _
				"BatchNumber = " & BatchNumber & ", " & _
				"PaymentOn = '" & Month(Now()) & "/" & Day(Now()) & "/" & Year(Now()) & " " & Hour(Now()) & ":" & Minute(Now()) & "' " & _
				"WHERE ID = " & ID)

		Application.Lock
		Application(Prefix & "Payouts") = Str2Float(Application(Prefix & "Payouts")) + Str2Float(Request.Form("PAYMENT_AMOUNT"))
		Application.Unlock
	End If


	AdminPageBegin "Waiting Payouts"

	If Command = "Send" Then
		Send
	Else
		If Command = "Delete" Then
			DBC.Execute("DELETE FROM Payouts WHERE ID = " & ID)
		End If

		UnPaidList
	End If

	AdminPageEnd


	Sub UnPaidList()
		Dim i

		Set rs = DBC.Execute("SELECT * FROM Payouts WHERE BatchNumber = 0")
%>
		<table border=0 align=center bgcolor=black width=600 cellspacing=1 cellpadding=3>
		<tr class=SelectedParent>
			<td>&nbsp;</td>
			<td align=center>Member</td>
			<td align=center>Cash</td>
			<td align=center>Description</td>
			<td>&nbsp;</td>
		</tr>
<%
		i = 0

		Do While Not rs.EOF
%>
		<tr class=Odd>
			<td align=center><%= i + 1 %>.</td>
			<td align=center><%= rs("ToEGold") %></td>
			<td align=right>$ <%= FormatNumber(rs("Cash"), 3) %></td>
			<td><%= rs("Description") %></td>
			<td align=center>
				<a href=payouts.asp?Command=Send&ID=<%= rs("ID") %>>Payout</a>&nbsp;&nbsp;
				<a href="javascript: ShowReferrals(<%= rs("ToEGold") %>)">Show referrals</a>&nbsp;&nbsp;
				<a href="javascript: Delete(<%= rs("ID") %>)">Delete</a>
			</td>
		</tr>
<%
			i = i + 1
			rs.MoveNext
		Loop
%>
		</table>


		<form name=F action="member_list.asp" method=POST target=_blank>
		<input type=hidden name=FilterSponsor value="">
		</form>


		<script language=JavaScript>
		<!--
		function ShowReferrals(SponsorEGold)
		{
			document.F.FilterSponsor.value = SponsorEGold;
			document.F.submit();
		}

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


	Sub Send()

		Set rs = DBC.Execute("SELECT * FROM Payouts 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=FORCED_PAYER_ACCOUNT value=<%= MyEGold %>>
		<input type=hidden name=PAYEE_ACCOUNT value=<%= rs("ToEGold") %>>
		<input type=hidden name=PAYEE_NAME value="<%= SiteName %>">
		<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 %>">
		<input type=hidden name=BAGGAGE_FIELDS value="ID">
		<input type=hidden name=ID value="<%= ID %>">

		<table border=0 align=center bgcolor=black cellspacing=1 cellpadding=3>
		<tr class=SelectedParent>
			<td colspan=2 align=center>Payout</td>
		</tr>
		<tr class=Odd>
			<td>Cash ($)</td>
			<td>
				<input name=PAYMENT_AMOUNT value="<%= rs("Cash") %>" size=30 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Memo</td>
			<td>
				<input name=SUGGESTED_MEMO value="<%= rs("Description") %>" size=30 class=ClientText>
			</td>
		</tr>
		<tr>
			<td colspan=2 bgcolor=white align=center>
				<input type=submit name=PAYMENT_METHOD value=Send>
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>