<!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">Guild Details</h2>
<hr/>
<?
my $gid = $request->getInt("id", 0);
if($gid > 0) {
	my $act = $request->get("action", "");

	#note: delete action should be done on the actions.html page, so we can redirect elsewhere.
	if($act eq "makeleader") {
		my $char = $request->getInt("char", 0);
		if($char > 0) {
			if(!$EQW->SetGuildLeader($gid, $char)) {
				print "Failed to change guild leader, check your logs.<hr />";
			} else {
				print "Guild leader changed.<hr />";
			}
		} else {
			print "Invalid char in makeleader.<hr/>";
		}
	} elsif($act eq "remove") {
		my $char = $request->getInt("char", 0);
		if($char > 0) {
			if(!$EQW->SetGuild($char, -1, 3)) {
				print "Failed to remove member, check your logs.<hr />";
			} else {
				print "Guild member removed.<hr />";
			}
		} else {
			print "Invalid char in remove member.<hr/>";
		}
	}



	my $q = "SELECT g.id,g.name,g.leader,g.motd,g.motd_setter,g.tribute,c.name AS lname FROM guilds AS g LEFT JOIN character_ AS c ON g.leader=c.id WHERE g.id=$gid";
	my $res=$EQDB->query($q);
	my $row;
	if($res && ($row = $res->fetch_row_hash)) {
		print <<"HTML";
		<table border="1">
		<tr><th>Name:</th><td>$row->{name}</td></tr>
		<tr><th>Leader:</th><td>$row->{lname} ($row->{leader})</td></tr>
		<tr><th>MOTD:</th><td>$row->{motd_setter} - $row->{motd}</td></tr>
		<tr><th>Tribute:</th><td>$row->{tribute}</td></tr>
		</table>
		<hr>
		<h4>Guild Members</h4>
HTML
		$q = "SELECT g.char_id,c.name,g.rank,gr.title,g.banker,g.public_note,g.tribute_enable,g.total_tribute "
			."FROM guild_members AS g "
			."LEFT JOIN character_  AS c ON g.char_id=c.id "
			."LEFT JOIN guild_ranks AS gr ON g.rank=gr.rank AND g.guild_id=gr.guild_id "
			."WHERE g.guild_id=$gid";

		my $res2 = $EQDB->query($q);
		if($res2) {
			print <<"HTML";
			<br>
			<table border='1'>
			<tr>
			<th align="center">Char ID</th>
			<th align="center">Char Name</th>
			<th align="center">Rank</th>
			<th align="center">Tribute</th>
			<th align="center">Public Note</th>
			<th align="center">Actions</th>
			</tr>
HTML
			while(my $row2 = $res2->fetch_row_hash) {
				my $tline = "Off";
				if($row2->{tribute_enable}) {
					$tline = "On";
				}
				my $bline = "";
				if($row2->{banker}) {
					$bline = "<b>Banker</b>";
				}
				print <<"CHAR";
					<tr>
					<td align="center">$row2->{char_id}</td>
					<td align="center">$row2->{name}</td>
					<td align="center">$row2->{title} ($row2->{rank}) $bline</td>
					<td align="center">$tline/$row2->{total_tribute}</td>
					<td align="center">$row2->{public_note}</td>
					<td align="center">
						<a href="guild.html?id=$gid&action=remove&char=$row2->{char_id}">Remove</a> -
						<a href="guild.html?id=$gid&action=makeleader&char=$row2->{char_id}">Make Leader</a></td>
					</tr>
CHAR
			}
			print "</table>";
		}
	} else {
		print "Unable to query guild details.";
	}
} else {
	print "Invalid guild id.";
}

?>

TODO:<br>
online status, delete guild, add member, change motd, change public note, set tribute, make banker, rename guild, view/edit custom ranks, view/edit guild relations.
</body>
</html>
