<?php
define('_IN_JOHNCMS', 1);
$textl='Рейтинг бомбардиров'; 
require_once("../incfiles/core.php");
require_once("../incfiles/head.php");
require_once("manfunc.php"); 

echo"<h2 align='center'>Рейтинг бомбардиров</h2>";
if(empty($_GET['state']))
{
	$sql = mysql_query("select * from `fman_lands` order by `name`;");
	if(mysql_num_rows($sql))
	{
		while($state = mysql_fetch_assoc($sql))
		{
			echo'<div class="menu"><img style="vertical-align:middle;" src="flags_icon/'.$state['code'].'.png" /> <a href="?state='.$state['code'].'">'.$state['name'].'</a></div>';
		}
	}
}
else
{
	$code = functions::check($_GET['state']);
	$sql = mysql_query("select * from `fman_lands` where `code` = '$code' limit 1");
	if(mysql_num_rows($sql))
	{
		$state = mysql_fetch_assoc($sql);
		echo'<div class="phdr"><img style="vertical-align:middle;" src="flags_icon/'.$state['code'].'.png" /> <b>'.$state['name'].'</b></div>';
		$sql = mysql_query("select `fman_players`.`id`,(select count(*) from `fman_clubs` where `fman_clubs`.`id`=`fman_players`.`team_id` and `land`='$code' limit 1) as `count` from `fman_players` having `count`='1'");
		$total = mysql_num_rows($sql);

		$sql = mysql_query("SELECT `fman_players`.*,(select count(*) from `fman_clubs` where `fman_clubs`.`id`=`fman_players`.`team_id` and `land`='$code' limit 1) as `count`,`fman_clubs`.`user_id`,`fman_clubs`.`name` as `cname` FROM `fman_players` LEFT JOIN `fman_clubs` ON `fman_clubs`.`id`=`fman_players`.`team_id` and `land`='$code' HAVING `count`='1' ORDER BY `goals` desc limit $start, $kmess");
		if(mysql_num_rows($sql))
		{
			while($player = mysql_fetch_assoc($sql))
			{
				if($player['user_id']==0)
				{
					$man_name = 'Нет';
				}
				else
				{
					$lider = mysql_fetch_assoc(mysql_query("select `name` from `users` where `id`='$player[user_id]' limit 1"));
					$man_name = '<a href="../users/profile.php?user='.$player['user_id'].'">'.$lider['name'].'</a>';
				}
				echo'<div class="menu">
				<table>
				<tr><th colspan="3">'.(++$start).' место</th></tr>
				<tr><td><img src="'.$player['foto'].'"/></td><td>
				Игрок:<br/>
				Клуб:<br/>
				Менеджер:<br/>
				Голов:
				</td>
				<td>
				<a href="player.php?id='.$player['id'].'">'.$player['name'].'</a><br/>
				<a href="club.php?id='.$player['team_id'].'">'.$player['cname'].'</a><br/>
				'.$man_name.'<br/>
				'.$player['goals'].'
				</td>
				</tr>
				</table>
				</div>';
				
			}
			if ($total > $kmess) 
			{
				echo '<div class="topmenu">' . functions::display_pagination('rait_bomb.php?state='.$code.'&amp;', $start-1, $total, $kmess) . '</div>' .
				'<form action="rait_bomb.php?state='.$code.'" method="post"><p>' .
				'<input type="text" name="page" size="2"/>' .
				'<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/>' .
				'</p></form>';
			}
			echo '<div class="bmenu">Всего: ' . $total . '</div>';
		}
		else
		{
			echo'<div class="menu">Рейтинг пуст!</div>';
		}
	}
	else
	{
		echo'<div class="menu">Нет такого рейтинга!</div>';
	}
}
echo"<div class='phdr'><a href='?'>Назад</a></div>";
echo"<div class='phdr'><a href='index.php'>Фут.менеджер</a></div>";
require_once("../incfiles/end.php"); 
?>
