<?

include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/adm_check.php';
include_once '../sys/inc/user.php';
?>
<title>Супер гонки</title>';
<?
?>
<link rel="stylesheet" href="style000.css" type="text/css" />

<?
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `supergonki` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `supergonki`(`id_u`) VALUES('".$user['id']."')");
  $arr=mysql_fetch_array(mysql_query("SELECT * FROM `supergonki` WHERE `id_u`='".$user['id']."'"));
   $car=mysql_fetch_array(mysql_query("SELECT * FROM `super_car` WHERE `id`='".$arr['car']."'"));
if($arr['color']!='0'){
if($arr['color']==1)
$color='red_';
elseif($arr['color']==2)
$color='blue_';
elseif($arr['color']==3)
$color='green_'; 
}

?>


<table class="wdt black">
<tr>
<td class="yellow" align="left" style="vertical-align: top; padding-bottom: 0px">
<img src="icon/fuelico.png"><span id="FUELCNT">
<?
echo"".$arr['exp']."";
?>
</span>
</td>
<td class="orange" align="left"  style="vertical-align: top;  padding-bottom: 0px">
<img src="icon/2.png"> 
<?
echo"".$arr['speed']."";
?> км.ч.
</td>
<td class="white"  style="vertical-align: top;  padding-bottom: 0px">
ур.
<?
echo"".$arr['level']."";
?>
</td>
<td class="white" align="right"  style="vertical-align: top; padding-bottom: 0px">
<img src="icon/1.png">
<?
echo"".$arr['money']."";
?>
</td>
<td class="green" align="right"  style="vertical-align: top; padding-bottom: 0px">
<img src="icon/goldico.png">
<?
echo"".$user['balls']."";
?>
</td>
</tr>
<tr>
<td align="left" class="white" style="vertical-align: top; padding: 0px; height: 3px" colspan="5" height="3px">
<img src="icon/expline.png" width="35%" height="3px" style="height: 3px;">
</td>
</tr>
</table>


<table class="wdt black" style="border-bottom: 1px solid #767676;">
<tr>
<td class="white" align="left" style="padding-top: 0px;">
<a class="white" href="index.php">Гараж</a>
</td>
<td class="white" align="left" style="padding-top: 0px;">
<a class="white" href="race.php">Гонки</a>
</td>
<td class="gray" align="left" style="padding-top: 0px;">
<a class="white" href="bank.php">Дилер</a>
</td>
<td class="gray" align="right" style="padding-top: 0px;">
<a class="white" href="rate.php">Топ</a>
</td>
</tr>
</table>
<table class="wdt msg-table">
<tr>
<td align="left" style="vertical-align: top; width: 10%">
<img src="icon/face-mex.png">
</td>
<td align="left" style="vertical-align: top">
<? 
if(isset($_POST['submit'])){
$id=abs(intval($_GET['id_user']));

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `super_race` WHERE `id_2`='".$user['id']."' AND `id_1`='".$id."' AND `act`='0'"),0)==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `super_race` WHERE `id_1`='".$user['id']."' AND `id_2`='".$id."' AND `act`='0'"),0)==0){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `supergonki` WHERE `id_u`='".$id."'"),0)!=0){
mysql_query("INSERT `super_race`(`id_1`, `id_2`) VALUES('".$user['id']."', '".$id."')");
msg('Ваше предложение будет рассмотрено соперником');
}

}
else
{
msg('У вас не все гонки завершены с данным пользователем');
}

}
if($arr['race_last']<time()){
if(isset($_GET['b'])){
$rand=rand(1,2);
if($rand==1){
mysql_query("UPDATE `supergonki` SET `race_kol`=`race_kol`+1, `win`=`win`+1, `exp`=`exp`+3, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
msg('Поздравляем! Вы выиграли гонку!');
}
else
{
mysql_query("UPDATE `supergonki` SET `race_kol`=`race_kol`+1, `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
msg('К сожалению вы проиграли');

}


}}
else
{
msg("Вы устали и не сможете гонятся ближайшие ".sictime($arr['race_last']-time())."");
$t=1;
}

if(!isset($user)){
echo 'Вы неавторизованы';
include_once '../sys/inc/tfoot.php';
exit;
}
function sictime($timediff){

$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
$time_1="$hourfield ч. $minutefield м. $secondfield c";
return $time_1;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `supergonki` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `supergonki`(`id_u`) VALUES('".$user['id']."')");
  $arr=mysql_fetch_array(mysql_query("SELECT * FROM `supergonki` WHERE `id_u`='".$user['id']."'"));
   $car=mysql_fetch_array(mysql_query("SELECT * FROM `super_car` WHERE `id`='".$arr['car']."'"));
   if($arr['color']!='0'){
if($arr['color']==1)
$color='red_';
elseif($arr['color']==2)
$color='blue_';
elseif($arr['color']==3)
$color='green_'; 
}

if($arr['race_kol']>5){
$newtime=time()+60*60*12;
mysql_query("UPDATE `supergonki` SET `race_kol`='0', `race_last`='".$newtime."' WHERE `id_u`='".$user['id']."'");
msg('Вы устали и не сможете гонятся ближайшие 12 часов');

}
if(isset($_GET['a'])){
msg('Здесь вы можете погонять в случайной гонке!');
}

?>
</td>
</tr>
</table>


<table class="wdt green-header">
<tr>
<td align="left">Доступные гонки:</td>
</tr>
</table>
<table class="wdt gray-table">
<tr>

<?
$cars=mysql_fetch_array(mysql_query("SELECT * FROM `super_car` WHERE `class`='".$car['class']."' ORDER BY RAND() DESC LIMIT 1"));

if($t!=1){
?>


<td class="td-cell" align="left" style="width: 50%; vertical-align: bottom;">

<?
echo "<img src='car/".$cars['screen']."' class='wdt'/>";
?>
 <br>
<img class="wdt" style="margin-top: -18px;" src="icon/car_shad.png">
</td>
<td class="td-cell" align="left">
<b class="white">
<a class='white' href=''>Случайный гонщик</a><br/>
</b>
<img src="icon/power-ic.png"><b class="orange" style="font-size: 13pt">
<?
echo "".$cars['name']."";
?>
</b><br>
<table><tr>
<td style="width: 35px; padding-left: 0px; padding-right: 0px;">

</td>
<td style="width: 100%;">
<form method='post' action='bot_race.php?b'>
<input class='wdt race-btn' type='submit' name='submit' value='гонка'/></form>
</td></tr></table>
</td>
</tr>
</table>
<?
}

?>
<table class="wdt gray-header">
<tr>
<td align="left">
<?
echo " <a class='white' href='bot_race.php?a'> Искать гонщиков</a><br/>";
?>
</td>
</tr>
</table>
<td class="white td-cell" align="center" style="height:30px;">
<form action="race.php" method="get">
<input type="submit" class="wdt race-btn" value="Закрыть"/>
</form>
</td>
</tr>
</table>