<% Option Explicit %>
<!--#include file="../config.asp"-->
<!--#include file="../common.asp"-->
<!--#include file="main.asp"-->
<%
	Dim Count

	PageHeader

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



	OpenConnection

	If Request.Querystring("Command") = "Delete" Then
		DBC.Execute "DELETE FROM Members " & _
				"WHERE MemberID IN (" & Request.Querystring("MemberIDs") & ")", Count

		Application.Lock
		Application(Prefix & "TotalMembers") = 0
		Application.Unlock
	End If

	AdminPageBegin "Duplicate Accounts"
	DuplicateIPs
	AdminPageEnd


	Sub DuplicateIPs()
		Dim rs, rsIPs, i, HTML, IDs

		Set rsIPs = DBC.Execute("SELECT LastIP, COUNT(*) AS Count " & _
								"FROM Members " & _
								"WHERE Len(LastIP) > 0 " & _
								"GROUP BY LastIP " & _
								"ORDER BY COUNT(*) DESC")

		Do While Not rsIPs.EOF
			If rsIPs("Count") > 1 Then
				Set rs = DBC.Execute("SELECT * FROM Members " & _
							"WHERE LastIP = " & EscapeSQLData(rsIPs("LastIP")))

		HTML	= "<p align=center>Duplicate IPs</p>"
		IDs	= ""

		HTML = HTML &	"<table border=0 align=center bgcolor=black width=500 cellspacing=1 cellpadding=3>" & _
				"<col width=20>" & _
				"<col width=100 align=center>" & _
				"<col width=100 align=right>" & _
				"<col width=100 align=center>" & _
				"<col align=center>" & _
				"<tr class=SelectedParent>" & _
					"<td>&nbsp;</td>" & _
					"<td align=center>Member</td>" & _
					"<td align=center>Cash</td>" & _
					"<td align=center>Last Login</td>" & _
					"<td align=center>Last IP</td>" & _
				"</tr>"

		i = 1

		Do While Not rs.EOF
			IDs = IDs & rs("MemberID") & ","
			HTML = HTML &	"<tr class=Odd>" & _
						"<td>" & i & ".</td>" & _
						"<td>" & rs("EGold") & "</td>" & _
						"<td align=right>$" & FormatNumber(rs("Cash"), 3) & "</td>" & _
						"<td align=right>" & rs("LastLogin") & "</td>" & _
						"<td bgcolor=FF8888 align=right>" & rs("LastIP") & "</td>" & _
					"</tr>"

			i = i + 1

			rs.MoveNext
		Loop

		HTML = HTML & "</table>"

		If i > 1 Then
			Response.Write HTML
			Response.Write "<center><a href='duplicate_list.asp?Command=Delete&MemberIDs=" & IDs & "'>Delete members above</a></center>"
		End If

		End If
			rsIPs.MoveNext
		Loop
	End Sub
%>