<?
include('cfg.php');
echo '<link rel="stylesheet" type="text/css" href="style.css"/><div class="head">';

switch($_GET[a])
	{
    default:
    echo '
	Страна: '.$user[country].'</div>
	<div class="info"><b>Статистика</b></div><div class="info">';
	echo $istat;
	$countries = mysql_result(mysql_query("SELECT count(`id`) FROM `users` WHERE `defeat`='0' AND `bun_end`='0' AND `rank`!='Админ'"),0); //всего стран
	echo 'Стран на карте мира: '.$countries.'<br />';

	$countries2 = mysql_result(mysql_query("SELECT count(`id`) FROM `users` WHERE `defeat`='1' AND `bun_end`='0' AND `rank`!='Админ'"),0); //всего стран
	echo 'Одержанных побед: '.$countries2.'<br />';

	$wars = mysql_result(mysql_query("SELECT count(`id`) FROM `wars`"),0); //всего войн
	echo 'Войн: '.$wars.'<br />';

	$allys = mysql_result(mysql_query("SELECT count(`id`) FROM `ally` WHERE `accept`='1'"),0); //всего союзов
	echo 'Союзов: '.$allys.'<br />';

	$buildings = mysql_result(mysql_query("SELECT count(`id`) FROM `ubuildings`"),0); //всего Строений
	echo 'Строений: '.$buildings.'<br />';
	echo ' <div style="clear: left"></div>';
	echo '</div><div class="info"><b>Всего ресурсов</b></div><div class="info">';

    	$res = mysql_fetch_array(mysql_query("SELECT sum(lumber),sum(iron),sum(stone),sum(grain) FROM `users`  WHERE `rank`!='Админ'"));

	echo 'Дерева: '.$res[0];

	echo '<br/>Железa: '.$res[1];


	echo '<br/>Камня: '.$res[2];


	echo '<br/>Зерна: '.$res[3].'<br />';

	echo '</div><div class="info"><b>Лидеры:</b></div><div class="info">';

	$lider_time = mysql_fetch_array(mysql_query("SELECT `time_reg`,`country` FROM `users` WHERE `rank`='Игрок' AND `bun_end`='0' AND `defeat`='0' ORDER by `time_reg` ASC"));
	echo '> Самая продолжительная страна - '.$lider_time['country'].' <b>('.intval(((time()-$lider_time[time_reg])/3600)).' </b>часов)';

	if ($wars > '0')
		{
	$war_n = mysql_fetch_array(mysql_query("SELECT `id_attacker`,`time_in` FROM `wars` ORDER by `time_in` ASC"));
	$lider_war = mysql_fetch_array(mysql_query("SELECT `country` FROM `users` WHERE `id`='$war_n[id_attacker]'"));
	if (empty($lider_war))
		{
		} else	echo '<br />> Инициатор самой продолжительной войны - '.$lider_war[country].' <b>('.intval((time()-$war_n[time_in])/3600).'</b> часов)';
		}

	$rich = mysql_fetch_array(mysql_query("SELECT `country`,`money` FROM `users` WHERE `defeat`='0' AND `bun_end`='0' AND `rank`='Игрок' ORDER by `money` DESC"));
	echo '<br />> Самая богатая страна - '.$rich['country'].' <b>('.$rich['money'].'</b> денег)';

	$login_biggest = '';
	$land_biggest = '';
	$b_sql = mysql_query("SELECT `land`,`woods`,`mountains`,`country` FROM `users` WHERE `rank`!='Админ'");
	while($the_biggest = mysql_fetch_assoc($b_sql))
		{

		$all_landi = $the_biggest['land']+$the_biggest['woods']+$the_biggest['mountains'];
		if ($all_landi > $land_biggest)
			{
			$login_biggest = $the_biggest['country'];
			$land_biggest = $all_landi;
			}

		}
		echo '<br />> Самая большая страна (свободная земля+лес+горы): '.$login_biggest.' (<b>'.$land_biggest.'</b> земли)';


	$login_resnik = '';
	$resnik_moreer = '';
	$b_sql = mysql_query("SELECT `lumber`,`grain`,`stone`,`iron`,`country` FROM `users` WHERE  `rank`!='Админ' AND `bun_end`='0'");
	while($more_resnik = mysql_fetch_assoc($b_sql))
		{

		$all_resnik = $more_resnik['lumber']+$more_resnik['grain']+$more_resnik['stone']+$more_resnik['iron'];
		if ($all_resnik > $resnik_moreer)
			{
			$login_resnik = $more_resnik['country'];
			$resnik_moreer = $all_resnik;
			}

		}
		echo '<br />> Больше всего ресурсов у: '.$login_resnik.' (<b>'.$resnik_moreer.'</b> едениц)';



	$login_resnik = '';
	$resnik_moreer = '';
	$b_sql = mysql_query("SELECT `workers`,`scientists`,`country` FROM `users` WHERE  `rank`!='Админ' AND `bun_end`='0'");
	while($more_resnik = mysql_fetch_assoc($b_sql))
		{

		$all_resnik = $more_resnik['workers']+$more_resnik['scientists'];
		if ($all_resnik > $resnik_moreer)
			{
			$login_resnik = $more_resnik['country'];
			$resnik_moreer = $all_resnik;
			}

		}
		echo '<br />> Больше всего населения: '.$login_resnik.' (<b>'.$resnik_moreer.'</b> ученых+рабочих)';



		$zaxwati = mysql_fetch_array(mysql_query("SELECT `country`,`win` FROM `users` WHERE `rank`!='Админ' AND `bun_end`='0' ORDER by `win` DESC"));
		echo '<br />> Больше всего захватов: '.$zaxwati['country'].' (<b>'.$zaxwati['win'].'</b> захватов)';


		$sql_geni = mysql_query("SELECT * FROM `general`");
		$the_best_navik = 0;
			$the_best_moral = 0;
		while($res_geni = mysql_fetch_assoc($sql_geni))
			{
			if (($res_geni['navik']+$res_geni['moral']) > ($the_best_navik+$the_best_moral))
				{
				$the_best_navik=$res_geni['navik'];
				$the_best_moral=$res_geni['moral'];
				$id_user_geni = $res_geni['id_user'];
				}
			}
			$user_gen_country = mysql_fetch_array(mysql_query("SELECT country from users WHERE `id`='$id_user_geni' AND `bun_end`='0'"));

			echo '<br />> Самый сильный генерал у '.$user_gen_country[country].' ('.($the_best_navik+$the_best_moral).' навык+мораль)';



			$sql_geni = mysql_query("SELECT * FROM `general`");
			$the_best_opit = 0;
			while($res_geni = mysql_fetch_assoc($sql_geni))
			{
			$id_user_geni = $res_geni['id_user'];
			$defeat = mysql_fetch_array(mysql_query("SELECT `defeat` FROM `users` WHERE `defeat`='0' AND `rank`='Игрок'"));;
			if ($res_geni['exp'] > $the_best_opit AND $defeat['defeat']=='0')
				{
				$the_best_opit = $res_geni['exp'];

				}
			}
			$user_gen_country = mysql_fetch_array(mysql_query("SELECT country from users WHERE `id`='$id_user_geni'"));
			echo '<br />> Самый опытный генерал у '.$user_gen_country[country].' ('.$the_best_opit.' опыта)';



				$sql_geni = mysql_query("SELECT * FROM `general`");
			$the_best_opit = 0;
			while($res_geni = mysql_fetch_assoc($sql_geni))
			{
			$id_user_geni = $res_geni['id_user'];
			$defeat = mysql_fetch_array(mysql_query("SELECT `defeat` FROM `users` WHERE `defeat`='0' AND `bun_end`='0' AND `rank`='Игрок'"));;
			if ($res_geni['age'] > $the_best_opit AND $defeat['defeat']=='0')
				{
				$the_best_opit = $res_geni['age'];

				}
			}
			$user_gen_country = mysql_fetch_array(mysql_query("SELECT country from users WHERE  `id`='$id_user_geni' AND `bun_end`='0'"));
			echo '<br />> Самый старый генерал у '.$user_gen_country[country].' ('.$the_best_opit.' лет)';





			$sql_army = mysql_query("SELECT `solders`,`archers`,`horses`,`country` FROM `users` WHERE `rank`='Игрок' AND `bun_end`='0'");
			$archers = 0;
			$solders = 0;
			$horses = 0;
			while($res = mysql_fetch_assoc($sql_army))
				{
				if (($res['solders']+$res['archers']+$res['horses'])>($archers+$solders+$horses))
					{
					$archers = $res['archers'];
					$solders = $res['solders'];
					$horses = $res['horses'];
					$id_user_geni = $res['country'];
					}
				}
			echo '<br />> Самое большое войско у '.$id_user_geni.' (Армия: '.($archers+$solders+$horses).' чел.)';




			$sql_sc = mysql_fetch_array(mysql_query("SELECT `country` FROM `users` WHERE `rank`='Игрок' ORDER BY `sc_lumber`+`sc_stone`+`sc_iron`+`sc_grain`+`sc_wood`+`sc_lvl`+`sc_workers`+`sc_army`+`sc_arive`+`sc_savem`+`sc_savew` DESC"));
			$sql_sc_sum = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `rank`='Игрок' ORDER BY `sc_lumber`+`sc_stone`+`sc_iron`+`sc_grain`+`sc_wood`+`sc_lvl`+`sc_workers`+`sc_army`+`sc_arive`+`sc_savem`+`sc_savew` DESC"));

			echo '<br />> Самое развитое гос-во '.$sql_sc[0].' (Развитие науки на: '.intval(($sql_sc_sum['sc_lumber']+$sql_sc_sum['sc_stone']+$sql_sc_sum['sc_iron']+$sql_sc_sum['sc_grain']+$sql_sc_sum['sc_wood']+$sql_sc_sum['sc_lvl']+$sql_sc_sum['sc_workers']+$sql_sc_sum['sc_army']+$sql_sc_sum['sc_arive']+$sql_sc_sum['sc_savem']+$sql_sc_sum['sc_savew'])*100/1100).'%)';


			$clan_exp = mysql_fetch_array(mysql_query("SELECT `exp`,`title` FROM `clan` ORDER by `exp` DESC"));
			echo '<br />> Самый опытный клан: '.$clan_exp['title'].' ('.$clan_exp[exp].' опыта)';

			$clan_wins = mysql_fetch_array(mysql_query("SELECT `wins`,`title` FROM `clan` ORDER by `wins` DESC"));
			echo '<br />> Больше всех завоеваний у клана: '.$clan_wins['title'].' ('.$clan_wins[wins].' побед)';

			$post = mysql_fetch_array(mysql_query("SELECT `post`,`country` FROM `users` WHERE `bun_end`='0' ORDER by `post` DESC"));
			echo '<br />> Самое общительное гос-во: '.$post['country'].' ('.$post[post].' поста в чате)';

    break;

	//1100 - 100%
	//моя сумма - х%

    case 'view':

    break;
	}

echo '</div>';
echo '
<a class="razd" href="game.php">'.$iback.' Назад</a>
<a class="razd" href="exit.php">'.$iexit.' Выход</a>
<div class="footer"><center><a href="http://wapworld.pp.ua">© WapWorld Games</a><br/><br />
<script type="text/javascript" src="http://mobtop.ru/c/73888.js"></script><noscript><a href="http://mobtop.ru/in/73888"><img src="http://mobtop.ru/73888.gif" alt="MobTop.Ru - Рейтинг и статистика мобильных сайтов"/></a></noscript>
</div>
</body></html>
';


?>