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

	Command = Request.Form("Command")

	PageBegin
	PageContent
	PageEnd


	Sub PageContent()

	If Command = "Cancel" Then
		Password = Request.Form("Password")

		If Len(Password) > 0 Then
			OpenConnection

			Set rs = DBC.Execute("SELECT * FROM Members WHERE MemberID = " & MemberID & " AND Password = " & EscapeSQLData(Password))

			If rs.EOF Then
				Response.Write "<br><br><p align=center class=PageText><font color=red>Incorrect password</font></p>"
			Else
				SendMail ContactEMail, "Terminated account", "EGold: " & rs("EGold") & vbNewLine & "Cash: " & rs("Cash") & vbNewLine & "Reason: " & Request.Form("Reason")
				DBC.Execute("DELETE FROM History WHERE MemberID = " & MemberID)
				DBC.Execute("DELETE FROM Members WHERE MemberID = " & MemberID & " AND Password = " & EscapeSQLData(Password))
				DBC.Execute("UPDATE Members SET SponsorEGold = 0 WHERE SponsorEGold = " & Session(Prefix & "EGold"))

				Response.Write "<br><br>Your account has been terminated succesfully!<br><br>"
				MemberID		= 0
				Session(Prefix & "MemberID")	= MemberID

				Application.Lock
				Application(Prefix & "TotalMembers") = Str2Num(Application(Prefix & "TotalMembers")) - 1
				If Session(Prefix & "IsGold") Then
					Application(Prefix & "TotalGoldMembers") = Str2Num(Application(Prefix & "TotalGoldMembers")) - 1
				End If
				Application.Unlock

				Exit Sub
			End If
		End If
	End If

	If MemberID = 0 Then
		Response.Write "<br>Your session has been expired. Please <a href=log.asp>log in</a> again.<br>"
	Else
%>
		<table border=0 cellspacing=2 cellpadding=0>
		<tr class=Title>
			<td colspan=2 align=center>
				Member's Area<br><br class=HalfBreak>
			</td>
		</tr>
<%
		OpenConnection

		If Command = "Update" Then
			Password = Request.Form("Password")

			If Len(Password) > 0 Then
				DBC.Execute("UPDATE Members SET Password=" & EscapeSQLData(Password) & " WHERE MemberID = " & MemberID)
			End If
%>
		<tr>
			<td colspan=2 align=center class=PageText>
				<font color=red>Your password has been updated succesfully!</font><br><br>
			</td>
		</tr>
<%
		End If
%>
		<tr class=Odd>
			<td colspan=2 align=center>
				Account <%= Session(Prefix & "EGold") %> - <%= IIf(Session(Prefix & "IsGold"), "GOLD", "FREE") %> Member<br><br>

				<a href=list.asp>Paid Clicks</a>&nbsp;&nbsp;&nbsp;
				<%= IIf(Session(Prefix & "IsGold"), "", "<a href=goldupgrade.asp>Upgrade to GOLD Member</a>&nbsp;&nbsp;&nbsp;") %>
				<a href=advertise.asp>Purchase Advertising</a>&nbsp;&nbsp;&nbsp;
				<a href=advertiser.asp?EGold=<%= Session(Prefix & "EGold") %>>Advertising Stats</a>&nbsp;&nbsp;&nbsp;
				<a href=member.asp?Command=LogOut>Log Out</a>
				<br>
				<a href=memberaccount.asp?Command=ShowAll>Last <%= LastPayouts %> payouts, Referral links, Change password, Cancel account</a>
				<br>
			</td>
		</tr>
		<tr>
			<td colspan=2><% Stat %></td>
		</tr>
<%
		If Request.QueryString("Command") = "ShowAll" Then
%>
		<tr valign=top>
			<td><% PaymentHistory %></td>
			<td><% ReferralLink %></td>
		</tr>
		<tr valign=top>
			<td><% ChangePassword %></td>
			<td><% CancelAccount %></td>
		</tr>
<%
		End If
%>
		<tr>
			<td colspan=2><% LastMessages(LastMessagesInMembersArea) %></td>
		</tr>
		</table>
<%
	End If

	End Sub


	Sub ChangePassword()
%>
	<script language=JavaScript>
	<!--
	function UpdateAccount()
	{
		var Pass1 = document.F.Password.value;
		var Pass2 = document.F.Password2.value;

		if (! (Pass1.indexOf(Pass2) == 0 && Pass1.length == Pass2.length))
		{
			alert ('The passwords do not match!');
			document.F.Password.value = "";
			document.F.Password2.value = "";
			document.F.Password.focus();
			return false;
		}

		return true;
	}
	//-->
	</script>

	<img src="images/1pixel.gif" width=100% height=1>
	<table border=0 cellpadding=2 cellspacing=0 align=center width=280>
	<col width=200>
	<col>
	<form name=F method=POST onsubmit="return UpdateAccount()">

	<tr class=Title>
		<td align=center colspan=2>
			<br class=HalfBreak>Change Password
		</td>
	</tr>
	<tr class=Odd>
		<td align=right>New Password</td>
		<td>
			<input type=password name=Password maxlength=15 size=15 class=ClientText>
		</td>
	</tr>
	<tr class=Odd>
		<td align=right>Retype the Password</td>
		<td>
			<input type=password name=Password2 maxlength=15 size=15 class=ClientText>
		</td>
	</tr>
	<tr class=Odd>
		<td valign=top align=center colspan=2>
			<input type=submit name=Command value=Update class=Button>
		</td>
	</tr>
	</form>
	</table>
<%
	End Sub


	Sub Stat()
%>
	<br>
	<table border=0 cellpadding=4 cellspacing=0 align=center width=660>
	<tr class=Odd valign=top>
		<td align=center>
			Your Earnings: <b>$<%= FormatNumber(Session(Prefix & "Cash"), 3) %></b><br>
<%
			If CDbl(Session(Prefix & "Cash")) >= CDbl(IIf(Session(Prefix & "IsGold"), GoldMinimumPayout, MinimumPayout)) Then
				Response.Write "<a href='member.asp?Command=RequestPayment'>Request Payment</a>"
			End If
%>
		</td>
		<td align=right>
			Your Downline Count:
		</td>
		<td>
<%
			Dim a
			a = Split(Trim(Session(Prefix & "MemberDownLine")), " ")

			Response.Write "<b>" & UBound(a) + 1 & "</b>"
%>
		</td>
		<td align=right>
			Your Downline:
		</td>
		<td>
			<select>
			<option>e-gold number</option>
<%
			For i = 0 to UBound(a)
				Response.Write "<option>" & a(i) & "</option>"
			Next
%>
			</select>
		</td>
	</tr>
	</table>
<%
	End Sub


	Sub PaymentHistory()

	Dim rs
	Set rs = DBC.Execute("SELECT TOP " & LastPayouts & " Cash, BatchNumber, Description " & _
				"FROM Payouts " & _
				"WHERE ToEGold = " & Str2Num(Session(Prefix & "EGold")) & " " & _
				"ORDER BY ID DESC")
%>
	<img src="images/1pixel.gif" width=100% height=1>
	<table border=0 cellpadding=2 cellspacing=0 align=center width=280>
	<tr class=Title>
		<td align=center colspan=2>
			<br class=HalfBreak>Last <%= LastPayouts %> Payouts<br><br class=HalfBreak>
		</td>
	</tr>
	<tr class=Header valign=top>
		<td align=center><b>Description</b></td>
		<td align=center width=50><b>Cash</b></td>
	</tr>
<%
	i = 0

	Do While Not rs.EOF
%>
	<tr class=Odd <%= IIf(i Mod 2 = 0, "", "bgcolor=EEEEEE") %>>
		<td><%= rs("Description") %></td>
		<td align=right>$ <%= FormatNumber(rs("Cash"), 3) %><br>
		<%= IIf(rs("BatchNumber") > 0, "<font color=green>Done", "<font color=red>waiting") %></font></td>
	</tr>
<%
		i = i + 1
		rs.MoveNext
	Loop
%>
	</table>
<%
	End Sub


	Sub ReferralLink()
%>
	<img src="images/1pixel.gif" width=100% height=1>
	<table border=0 cellpadding=0 cellspacing=0 width=468 align=center>
	<tr class=Title>
		<td align=center>
			<br class=HalfBreak>Referral Link & Advertiser Referral Link
		</td>
	</tr>
	<tr>
		<td align=center class=PageText>
			<%= CurrentPath %>default.asp?sponsor=<%= Session(Prefix & "EGold") %><br><br class=HalfBreak>

			You MUST save the banner below by right clicking on the image and selecting &quot;Save Image&quot;.
			Upload it to your web site to display the banner on your web site.<br><br class=HalfBreak>

			<img src=images/1a468x60.gif border=1 width=468 height=60><br><br class=HalfBreak>
		</td>
	</tr>
	</table>
<%
	End Sub


	Sub CancelAccount()
%>
	<img src="images/1pixel.gif" width=100% height=1>
	<table border=0 cellpadding=2 cellspacing=0 align=center width=440>
	<col width=200>
	<col>
	<form method=post onsubmit="return (this.Password.value != '')">

	<tr class=Title>
		<td align=center colspan=2>
			<br class=HalfBreak>Cancel Account
		</td>
	</tr>
	<tr class=Odd>
		<td align=right>Your Password</td>
		<td>
			<input type=password name=Password maxlength=15 size=15 class=ClientText>
		</td>
	</tr>
	<tr class=Odd>
		<td align=right>Your Reason?</td>
		<td>
			<input name=Reason maxlength=255 size=15 class=ClientText>
		</td>
	</tr>
	<tr class=Odd>
		<td valign=top align=center colspan=2>
			<input type=submit name=Command value=Cancel class=Button>
		</td>
	</tr>
	<tr class=Odd>
		<td align=center colspan=2>
			If you cancel your account, you will forfeit all money earned and all referrals obtained. 
			Your cancelation will take effect immediately.
		</td>
	</tr>
	</form>
	</table>
<%
	End Sub


	Sub LastMessages(N)
		Dim rs, m
%>
		<img src="images/1pixel.gif" width=100% height=1>

		<center class=Title>
		Last <%= N %> messages<br><br class=HalfBreak>
		</center>

		<table align=center cellspacing=0 cellpadding=1>
		<tr>
			<td colspan=4 align=center class=PageText>
				Your ad could be seen by <%= IIf(Application(Prefix & "TotalMembers") < 1000, "hundreds", "thousands") %> here -> UNLIMITED website hits!<br>
				<a href=msgaddselect.asp>Add your message</a><br><br>
			</td>
		</tr>
		</table>

		<table border=0 width=90% align=center cellspacing=1 cellpadding=3 bgcolor=8C8ECE>
<%
		Set rs = DBC.Execute("SELECT TOP " & N & " * FROM MsgBoard ORDER BY MID DESC")

		Do While Not rs.EOF
%>
		<tr>
			<td class=PageText bgcolor=<%= IIf(rs("IsHighlight"), MsgBoardHighlightedColor, "white") %>>
				<a href='<%= rs("URL") %>' target=_blank>
<%
				If rs("IsBold") Then
					Response.Write "<b>" & HTMLEncode(rs("Title")) & "</b>"
				Else
					Response.Write HTMLEncode(rs("Title"))
				End If

				Response.Write "</a><br>" & rs("Msg")
%>
			</td>
		</tr>
<%
			rs.MoveNext
		Loop

		rs.Close
%>
		</table>
<%
	End Sub


	Function HTMLEncode (s)
		If IsNull(s) Then
			HTMLEncode = ""
		Else
			HTMLEncode = Server.HTMLEncode(s)
		End If
	End Function
%>