<?php
	date_default_timezone_set('Europe/Madrid'); 
	require("../config/config.php");
	if (!isset($_SESSION)){
		session_name(SESSION);
		session_start();
	}
	require("../config/functions.php");
	header('Content-Type: text/html; charset=UTF-8');
	include("../config/languages/lang.".GetLang().".php");

	$type = ((!empty($_POST["type"]))) ? GetConexion()->real_escape_string($_POST["type"]) : 0;
	if ($type == 0){
		?>
		<div class="clearfix"></div>
		<table>
			<?php
			$pos = 1;
			$query = "SELECT player.id,player.playtime,player.job,player.skill_group,player.name,player.level,player.gold,player.exp,player_index.empire,guild.name AS guild_name,guild.id as guild_id 
							FROM ".DB_PLAYER.".player 
							LEFT JOIN ".DB_PLAYER.".player_index 
							ON player_index.id=player.account_id 
							LEFT JOIN ".DB_PLAYER.".guild_member 
							ON guild_member.pid=player.id 
							LEFT JOIN ".DB_PLAYER.".guild 
							ON guild.id=guild_member.guild_id
							INNER JOIN ".DB_ACCOUNT.".account 
							ON account.id=player.account_id
							WHERE player.name NOT LIKE '[%]%' AND account.status !='BLOCK'
							ORDER BY player.level DESC, player.exp DESC, player.playtime ASC 
							LIMIT 9;";
			$conex = mysqli_query(GetConexion(),$query);
			while($obj = mysqli_fetch_object($conex)){
				?>
				<tr>
					<th class="pink-rank"><?php echo $pos; ?></th>
					<th><?php echo $obj->name; ?></th>
					<th class="pink-rank"><?php echo $obj->level; ?></th>
				</tr>
				<?php
				$pos++;
			}
			while ($pos < 10){
				?>
				<tr>
					<th class="pink-rank"><?php echo $pos; ?></th>
					<th>...</th>
					<th class="pink-rank">?</th>
				</tr>
				<?php
				$pos++;
			}
			?>
		</table>
		<?php
	}
	else if ($type == 1){
		?>
		<div class="clearfix"></div>
		<table>
			<?php
			$pos = 1;
			$query = "SELECT id,name,master,level,exp,win,draw,loss,ladder_point
			FROM ".DB_PLAYER.".guild
			ORDER BY level DESC, exp DESC, win DESC, ladder_point DESC LIMIT 9;";
			$conex = mysqli_query(GetConexion(),$query);
			while($obj = mysqli_fetch_object($conex)){
				?>
				<tr>
					<th class="pink-rank"><?php echo $pos; ?></th>
					<th><?php echo $obj->name; ?></th>
					<th class="pink-rank"><?php echo $obj->level; ?></th>
				</tr>
				<?php
				$pos++;
			}
			while ($pos < 10){
				?>
				<tr>
					<th class="pink-rank"><?php echo $pos; ?></th>
					<th>...</th>
					<th class="pink-rank">?</th>
				</tr>
				<?php
				$pos++;
			}
			?>
		</table>
		<?php
	}
?>
