<!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 Management</h2>
<hr/>
<?
$query = $request->get("name", "");
$accid = $request->getInt("accountid", 0);
$newstatus = $request->getInt("newstatus", 0);
$type = $request->get("type", "");
?>
<form method="get" action="accounts.html">
<b>Account Search:</b><br>
<input name="type" type="radio" value="account" <?if($type ne "char") { print "checked"; } ?> > Account Name &nbsp;
<input name="type" type="radio" value="char" <?if($type eq "char") { print "checked"; } ?> > Character Name
<br>
<input name="name" type="text" value="<?print $query;?>">
<input name="" type="submit" value="Search">
</form>
<?
if($accid > 0) {
	my $q2 = "UPDATE account SET status=$newstatus WHERE id=$accid";
	$EQDB->query($q2);
	print "Status update for Account ID: $accid Completed";
}

if ($query) {
	$query = $EQDB->escape_string($query);
	my $q;
	if($type eq "account") {
		$q="select id,name,status from account where name rlike '$query'";
	} else {
		$q="select b.name as cname,a.id,a.name,a.status from account a, character_ b where b.account_id= a.id and b.name rlike '$query'";
	}

	my $res=$EQDB->query($q);
	if ($res) {

		print "<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" class=\"zonelist\">\n";
		print "\t<tr>\n";
		if ($type eq "char") {
			printf "\t\t<th scope=\"col\" width=\"150\">Char Name</th>\n";
		}
		printf "\t\t<th scope=\"col\" width=\"75\">ID</th>\n";
		printf "\t\t<th scope=\"col\" width=\"150\">Acct Name</th>\n";
		printf "\t\t<th scope=\"col\" width=\"75\">Status</th>\n";
		printf "\t\t<th scope=\"col\" width=\"130\">New Status</th>\n";
		printf "\t</tr>\n";
		while(my $row=$res->fetch_row_hash) {
			print "\t<tr>\n";
			if ($type eq "char") {
				printf "\t\t<td>%s</td>\n",$row->{cname};
			}
			printf "\t\t<td>%d</td>\n",$row->{id};
			printf "\t\t<td><a href=\"account.html?name=%s\">%s</a></td>\n",$row->{name},$row->{name};
			printf "\t\t<td>%d</td>\n",$row->{status};
			print "<form method=\"get\" action=\"accounts.html\">";
			printf "\t\t<input type=\"hidden\" name=\"accountid\" value=\"%d\">\n",$row->{id};
			printf "\t\t<input type=\"hidden\" name=\"name\" value=\"$query\">\n",
			printf "\t\t<input type=\"hidden\" name=\"type\" value=\"$type\">\n",
			printf "\t\t<td><input name=\"newstatus\" type=\"text\" size=\"1\" value=\"0\">  <input name=\"\" type=\"submit\" value=\"Set Status\"></td>\n";
			print "\t</tr>\n";
			print "</form>";
		}
		print "</table>";
	}
}
?>
</body>
</html>
