<?php if (!defined('FLUX_ROOT')) exit; 
$sqlgvg  = "SELECT g.guild_id, g.name AS gname, g.emblem_len, (
					SELECT COUNT( c.castle_id ) 
					FROM guild_castle c
					WHERE c.guild_id = g.guild_id
					) AS castles, g.master, g.guild_lv, ( 
					SELECT COUNT( char_id ) 
					FROM  `char` 
					WHERE  `char`.guild_id = g.guild_id
					) AS members 
					FROM guild AS g 
					LEFT JOIN  `char` AS ch ON ch.char_id = g.char_id 
					LEFT JOIN login ON login.account_id = ch.account_id 
					ORDER BY castles DESC, members DESC , g.max_member DESC , g.next_exp ASC 
					LIMIT 1";
$sthgvg  = $server->connection->getstatement($sqlgvg);
$sthgvg->execute();
$hofguilds = $sthgvg->fetchall();
?>

<?php if($hofguilds): ?>

<div class="agit-lord-emblem">
<?php if ($hofguilds[0]->emblem_len): ?>
	<img width="24" src="<?php echo $this->emblem($hofguilds[0]->guild_id) ?>" />
<?php else: ?>
	X
<?php endif ?>
</div>


<div class="agit-lord-name">
<?php if ($hofguilds[0]->gname): ?>
	<table border="0" width="100%" cellpadding="0">
		<tr>
			<td align="center" style="padding-top:2px;">
			<font class="hof">
			<?php echo htmlspecialchars(substr($hofguilds[0]->gname,0 ,15)) ?>
			<?php else: ?>
			None
			<?php endif ?>
			</font>
			</td>
		</tr>
	</table>
</div>
<div class="agit-lord-leader">
	<table border="0" width="100%">
		<tr>
			<td align="center" style="padding-top:2px;">
			<font class="hof">
				<?php
				echo $hofguilds[0]->master;
				?>
			</font>
			</td>
		</tr>
	</table>
</div>
<div class="agit-lord-level">
	<table border="0" width="100%">
		<tr>
			<td align="center" style="padding-top:2px;">
			<font class="hof">
				<?php
				echo $hofguilds[0]->guild_lv;
				?>
			</font>
			</td>
		</tr>
	</table>
</div>
<div class="agit-lord-owned">
	<table border="0" width="100%">
		<tr>
			<td align="center" style="padding-top:2px;">
			<font class="hof">
				<?php
				echo $hofguilds[0]->castles;
				?>
			</font>
			</td>
		</tr>
	</table>
</div>

<?php endif ?>