<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" title="Default" href="main.css" type="text/css" />
</head>
<body>
<h2 align="center">Account Details</h2>
<hr/>
<?
my $acct = $request->get("name", "");
my $act = $request->get("action", "");
if($acct eq "") {
	print "Missing account name.";
} elsif($act eq "move") {
	my $cid = $request->getInt("charid", 0);
	my $cname = $request->get("charname", "NONE");
	if($cid < 1) {
		print "Missing char ID";
	} else {
		print <<"HTML";
		<form action="?" method="POST">
		Move $cname to another account...<br>
		<input type="hidden" name="action" value="move2">
		<input type="hidden" name="name" value="$acct">
		<input type="hidden" name="charid" value="$cid">
		<input type="hidden" name="charname" value="$cname">
		New Account ID: <input type="text" name="newacct"><br>
		<input type="submit" value="Move">
		</form>
HTML
	}
} elsif($act eq "move2") {
	my $cid = $request->getInt("charid", 0);
	my $na = $request->getInt("newacct", 0);
	my $cname = $request->get("charname", "NONE");
	my $acctE = $EQDB->escape_string($acct);
	if($cid < 1 || $na < 1) {
		print "Missing char ID";
	} else {
		my $q = "SELECT name FROM account WHERE id=$na";
		my $res=$EQDB->query($q);
		my $a;
		if(!$res) {
			print "Query name error.";
		} elsif(!($a = $res->fetch_row_hash)) {
			print "No such account $na.";
		} else {
			$an = $a->{name};
			$q = "UPDATE character_ SET account_id=$na WHERE id=$cid";
			if($EQDB->query($q)) {
				print "$cname has been moved to account $an ($na)";
				print "<br><br><a href='?name=$acct'>Back to $acct...</a>";
				print "<br><a href='?name=$an'>Go to $an...</a>";
			} else {
				print "Update error.";
			}
		}
	}
} elsif($act eq "listips") {
	my $ipadd = $request->get("ipaddress", "NONE");
	my $acctE = $EQDB->escape_string($acct);
	if($ipadd eq '') {
		print "Missing IP Address";
	} else {
		my $q = "SELECT accid FROM account_ip WHERE ip='$ipadd'";
		my $res=$EQDB->query($q);
		if($res) {
			print <<"HTML";
			<br>
			<table border='1'>
			<tr>
			<th align="center">Account ID</th>
			<th align="center">Account Name</th>
			<th align="center">IP Address</th>
			</tr>
HTML
			while(my $row4 = $res->fetch_row_hash) {
				my $accountid = $row4->{accid};
				my $q;
				$q = "SELECT name FROM account WHERE id=$accountid";
				my $res2=$EQDB->query($q);
				if ($res2) {
					my $row5=$res2->fetch_row_hash;
					print <<"CHAR";
						<tr>
						<td align="center">$row4->{accid}</td>
						<td align="center"><a href="accounts.html?name=$row5->{name}&action=accounts.html&type='account'">$row5->{name}</a></td>
						<td align="center">$ipadd</td>
						</tr>
CHAR
				} else {
					print "Account Name query error.";
				}
			}
			print "</table>";
		} else {
			print "IP Address query error.";
		}
	}
} else {
	my $acctE = $EQDB->escape_string($acct);
	my $q;
	$q="select id,charname,sharedplat,status,revoked from account where name='$acctE'";

	my $res=$EQDB->query($q);
	if ($res) {
		my $row=$res->fetch_row_hash;
		print <<"HTML";
		<table border="1">
		<tr><th>Name:</th><td>$acct</td></tr>
		<tr><th>Account ID:</th><td>$row->{id}</td></tr>
		<tr><th>Status:</th><td>$row->{status}</td></tr>
		<tr><th>Revoked:</th><td>$row->{revoked}</td></tr>
		<tr><th>Last Used Char:</th><td>$row->{charname}</td></tr>
		<tr><th>Shared Platinum:</th><td>$row->{sharedplat}</td></tr>
		</table>
HTML
		$q = "SELECT id,name,zonename FROM character_ WHERE account_id=$row->{id}";
		my $res2 = $EQDB->query($q);
		if($res2) {
			print <<"HTML";
			<br>
			<table border='1'>
			<tr>
			<th align="center">ID</th>
			<th align="center">Char Name</th>
			<th align="center">Current Zone</th>
			<th align="center">Actions</th>
			</tr>
HTML
			while(my $row2 = $res2->fetch_row_hash) {
				print <<"CHAR";
					<tr>
					<td align="center">$row2->{id}</td>
					<td align="center">$row2->{name}</td>
					<td align="center">$row2->{zonename}</td>
					<td align="center">
						delete,
						<a href="?name=$acct&action=move&charid=$row2->{id}&charname=$row2->{name}">move acct</a>,
						move zone
						</td>
					</tr>
CHAR
			}
			print "</table>";
		} else {
			print "Char query error.";
		}

		$q="SELECT ip,count FROM account_ip WHERE accid=$row->{id}";
		my $res3=$EQDB->query($q);
		if($res3) {
			print <<"HTML";
			<br>
			<table border='1'>
			<tr>
			<th align="center">IPs Used</th>
			<th align="center">Count</th>
			</tr>
HTML
			while(my $row3 = $res3->fetch_row_hash) {
				print <<"CHAR";
					<tr>
					<td align="center"><a href="?name=$acct&action=listips&ipaddress=$row3->{ip}">$row3->{ip}</a></td>
					<td align="center">$row3->{count}</td>
					</tr>
CHAR
			}
			print "</table>";
		} else {
			print "No IPs associated with this account or IP query error.";
		}

		print <<"HTML";
		<hr>
		<form action="action.html" method="POST">
		<input type='hidden' name='name' value='$acct'>
		<input type='hidden' name='action' value='acctpasswd'>
		Telnet/HTTP Password: <input type="password" name="password"> <input type='submit' value="Change"> (blank=disable)
		</form>
HTML
	} else {
		print "Query error.";
	}

	print "Actions: ban/unban, set status, set world password, delete chars, move chars, delete account and chars";
}

?>
</body>
</html>