<?php
session_start();
include_once "inc/db_connect.php";
include_once "inc/fnc.php";
header('Content-Type: text/html;charset=utf8');
$err = "";
if(isset($_POST['regok'])){unset($_SESSION['reg_ok']);}
if(!isset($_SESSION['user'])){
	header("Location: index.php?");
	exit();
}else{
	$data_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `nick`='".$_SESSION['user']."'")) or die(mysql_error());
	include 'head.php';
?>
<div class='title'>Топ</div>
<div class="mono">
<center>
<a href="?my"><input type="submit" class="btn2" value="Топ моего уровня" /></a>
<a href="?all"><input type="submit" class="btn2" value="Общий топ" /></a><br>
<a href='?dolar'><input class="btn2" type='submit' value='Серебро' /></a>
<a href='?zoloto'><input class="btn2" type='submit' value='Золото' /></a><br>
<a href='?vgonka'><input class="btn2" type='submit' value='Великая Гонка' /></a>
<a href='search.php'><input class="btn2" type='submit' value='Поиск' /></a>
</center>
</div>
<?php
if(isset($_GET['my'])){
echo "<div class='title'>Топ моего уровня:</div>";
$my = mysql_query("SELECT * FROM `users` WHERE `level`='".$data_user['level']."' ORDER BY `raiting` DESC LIMIT 10") or die(mysql_error());
$my_row = mysql_fetch_array($my);
$mesto = 1;
$act="";
do{
echo "<div class='mono'><table>
	<tr>
<td><div class='menu'><b>".$mesto++." место</b></div><br/><div class='karo'>
		<b>".$my_row['carname']."</b><br/>
		<img src='".$my_row['car']."' alt='".$my_row['carname']."' width='115' style='margin-top:8px;' />
</div></td>
		<td>
			<center>Гонщик: <b><a href='info.php?id=".$my_row['id']."'>".$my_row['nick']."</a></b></br>
			<left><b>Рейтинг: </b>".$my_row['raiting']."<br/></left>
		        <font color='#cc0000'>".$my_row['level']." ур.<br/>
			<a href='cars.php?id=".$my_row['id']."' class='boldtext'; '><b>Гараж</b></a>

		</td>
		</center>
	</div></tr></div>
	</table></div>";
}while($my_row = mysql_fetch_array($my));
}
elseif(isset($_GET['all'])){
echo "<div class='title'>Общий топ:</div>";
$all = mysql_query("SELECT * FROM `users` ORDER BY `raiting` DESC LIMIT 10") or die(mysql_error());
$all_row = mysql_fetch_array($all);
$mesto = 1;
do{
echo "<table class='wdt menu'>
	<tr>
	<td><div class='boldtext'><b>".$mesto++." место</b></div><br/>
		<b>".$all_row['carname']."</b><br/>
		<img src='".$all_row['car']."' alt='".$all_row['carname']."' width='115' style='margin-top:8px;' /></div>
	</td>
		<td>
			<center>Гонщик: <br/><img src='".$all_row['avatar']."' alt='.' width='45' height='45'  style='padding:0;width:46px;border-radius:23px;-moz-border-radius:23px;-webkit-border-radius:23px;-khtml-border-radius:23px;'/><br/>
			<b><a href='info.php?id=".$all_row['id']."'>".$all_row['nick']."</a></b><br/>
			<b>Рейтинг:</b> <img src='img/raiting.png' alt='raiting' width='15' height='15'/> <div class='boldtext'>".$all_row['raiting']."</div><br/>
			<font color='#cc0000'>".$all_row['level']." ур.</div><br/>
			<a href='cars.php?id=".$all_row['id']."' class='boldtext'><b>Гараж</b></a>
			</center>
		</td>
		</center>
	</tr>
	</table></div>";
}while($all_row = mysql_fetch_array($all));
}
elseif(isset($_GET['dolar'])){
echo "<div class='title'>Топ по серебру:</div>";
$dol = mysql_query("SELECT * FROM `users` ORDER BY `money` DESC LIMIT 3") or die(mysql_error());
$dolar_row = mysql_fetch_array($dol);
$mesto = 1;
do{
	echo "<table class='wdt menu'>
	<tr>
	<td><div class='boldtext'><b>".$mesto++." место</b></div><br/>
		<b>".$dolar_row['carname']."</b><br/>
		<img src='".$dolar_row['car']."' alt='".$dolar_row['carname']."' width='115' style='margin-top:8px;' />
	</td>
		<td>
			<center>
			Гонщик: <br/><img src='".$dolar_row['avatar']."' alt='.' width='45' height='45'  style='padding:0;width:46px;border-radius:23px;-moz-border-radius:23px;-webkit-border-radius:23px;-khtml-border-radius:23px;'/><br/>
			<b><a href='info.php?id=".$dolar_row['id']."'>".$dolar_row['nick']."</a></b><br/>
			Серебро: <font color='#23b900'><b>".$dolar_row['money']."</b></div><br/>
			<a href='cars.php?id=".$dolar_row['id']."' class='boldtext'><b>Гараж</b></a>
		</td>
		</center>
	</tr>
	</table></div>";
}while($dolar_row = mysql_fetch_array($dol));
}
elseif(isset($_GET['zoloto'])){
echo "<div class='title'>Топ по золоту:</div>";
$zoloto = mysql_query("SELECT * FROM `users` ORDER BY `money2` DESC LIMIT 3") or die(mysql_error());
$zoloto_row = mysql_fetch_array($zoloto);
$mesto = 1;
do{
	echo "<table class='wdt menu'>
	<tr>
	<td><div class='boldtext'><b>".$mesto++." место</b></div><br/>
		<b>".$zoloto_row['carname']."</b><br/>
		<img src='".$zoloto_row['car']."' alt='".$zoloto_row['carname']."' width='115' style='margin-top:8px;' />
	</td>
		<td>
			<center>
			Гонщик: <br/><img src='".$zoloto_row['avatar']."' alt='.' width='45' height='45'  style='padding:0;width:46px;border-radius:23px;-moz-border-radius:23px;-webkit-border-radius:23px;-khtml-border-radius:23px;'/><br/>
			<b><a href='info.php?id=".$zoloto_row['id']."'>".$zoloto_row['nick']."</a></b><br/>
			Золото: <font color='#23b900'><b>".$zoloto_row['money2']."</b></div><br/>
			<a href='cars.php?id=".$zoloto_row['id']."' class='boldtext'><b>Гараж</b></a>
		</td>
		</center>
	</tr>
	</table></div>";
}while($zoloto_row = mysql_fetch_array($zoloto));
}
elseif(isset($_GET['vgonka'])){
echo "<div class='title'>Текущий лидер:</div>";
echo "<div class='menu'><center>
Сделано заездов: <b>".$data_user['vgonka']."</b>
</center></div>";
echo "<div class='mono'><center>
Призовое авто лидеру:<br> 
<img src='car/EvilEmpire.png' />
<br><b>2034 л.с</b>
</center></div>";
$vgonka = mysql_query("SELECT * FROM `users` ORDER BY `vgonka` DESC LIMIT 10") or die(mysql_error());
$vgonka_row = mysql_fetch_array($vgonka);
$mesto = 1;
do{
	echo "<table class='wdt menu'>
	<tr>
	<td><div class='boldtext'><b>".$mesto++." место</b></div><br/>
		<b>".$vgonka_row['carname']."</b><br/>
		<img src='".$vgonka_row['car']."' alt='".$vgonka_row['carname']."' width='115' style='margin-top:8px;' />
	</td>
		<td>
			<center>
			Гонщик: <br/><img src='".$vgonka_row['avatar']."' alt='.' width='45' height='45' /><br/>
			<b><a href='info.php?id=".$vgonka_row['id']."'>".$vgonka_row['nick']."</a></b><br/>
			Заездов: <font color='#23b900'><b>".$vgonka_row['vgonka']."</b></div><br/>
			<a href='cars.php?id=".$vgonka_row['id']."' class='boldtext'><b>Гараж</b></a>
		</td>
		</center>
	</tr>
	</table>";
}while($vgonka_row = mysql_fetch_array($vgonka));
}
else{
	echo "<div class='title'>Топ моего уровня:</div>";
$my = mysql_query("SELECT * FROM `users` WHERE `level`='".$data_user['level']."' ORDER BY `raiting` DESC LIMIT 10") or die(mysql_error());
$my_row = mysql_fetch_array($my);
$mesto = 1;
$act="";
do{
	echo "<table class='wdt menu' >
	<tr>
	<td><div class='boldtext'><b>".$mesto++." место</b></div><br/>
		<b>".$my_row['carname']."</b><br/>
		<img src='".$my_row['car']."' alt='".$my_row['carname']."' width='115' style='margin-top:8px;' />
	</td>
		<td>
			<center>Гонщик: <br/><img src='".$my_row['avatar']."' alt='.' width='45' height='45' /><br/>
			<b><a href='info.php?id=".$my_row['id']."'>".$my_row['nick']."</a></b><br/>
			<b>Рейтинг:</b> <img src='img/raiting.png' alt='raiting' width='15' height='15'/> <div class='boldtext'>".$my_row['raiting']."</div><br/>
			<font color='#cc0000'>".$my_row['level']." ур.</div><br/>
			<a href='cars.php?id=".$my_row['id']."' class='boldtext'><b>Гараж</b></a>
			</center>
		</td>
		</center>
	</tr>
	</table>";
}while($my_row = mysql_fetch_array($my));
}
?>
</div></div></div></div></div></div>
</body>
</html>
<?
}
include 'foot.php';
?> 