<?php
define('_IN_JOHNCMS', 1);
$textl='To`purarlar reytingi'; 
require_once("../incfiles/core.php");
require_once("../incfiles/head.php");
require_once("manfunc.php"); 

echo"<div class='phdr' align='center'><i class='fa fa-bar-chart-o'></i> To`purarlar reytingi</div>";
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");
$i =1;
        if(mysql_num_rows($sql))
        { 
	echo'<table class="table"  width="100%" border="0" cellspacing="1" cellpadding="4">
	            <tr class="un_title">
	            <td align="center"><b>№</b></td>
				<td align="center"><b>O\'yinchi</b></td>
				<td align="center"><b>Gollari</b></td></tr>';
				
            while($player = mysql_fetch_assoc($sql))
            {
              
               
				echo $i % 2 ? '<tr class="list1">' : '<tr class="list2">'; echo'<td align="center">'.(++$start).'</td><td>&#160;<a href="player.php?id='.$player['id'].'">'.$player['name'].'</a></td> <td align="center"><b>'.$player['goals'].'</b></td></tr>';
		++$i;		
                
                
            }
			echo'</table>';
            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">Hammasi: ' . $total . '</div>';
        }
        else
        {
            echo'<div class="menu">Reyting bo`sh!</div>';
        }
    }
    else
    {
        echo'<div class="menu">Bunday reyting yo`q!</div>';
    }
}
echo"<div class='gmenu'><a href='?'>Orqaga</a></div>";
echo"<div class='phdr'><a href='index.php'>Futbol menejer</a></div>";
require_once("../incfiles/end.php"); 
?>