<?php
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(!isset($user)){
echo '<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">
Играть могут лишь зарегистрированные пользователи!</td>
</tr>
</table>';
exit;
}
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">
Здесь ты можешь посмотреть свои приглашения и приглашения соперников!
</br>


<?

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']."'"));
   $all_racer=mysql_result(mysql_query("SELECT COUNT(*) FROM `super_race` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
   $my_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `super_race` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
     $sop_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `super_race` WHERE `id_2`='".$user['id']."' AND `act`='0'"),0);

  
  if($arr['color']!='0'){
if($arr['color']==1)
$color='red_';
elseif($arr['color']==2)
$color='blue_';
elseif($arr['color']==3)
$color='green_'; 
}
if(isset($_GET['oprace'])){
?>

</td>
</tr>
</table>
<table class="wdt garage-table">
<tr>
<td align="right"  style="padding-top: 10px;">
<table class="wdt">
<tr>
<td style="vertical-align: top; padding-left: 10px;" align="left" rowspan="4">
</td>
<td align="left" class="white" style="vertical-align: top" width="40%"><b>
<?
echo"".$car['name']."";
?>
</b>
</td>
</tr>
<tr>
<td align="left" class="white" nowrap="nowrap" style="font-size: 14px">Мощность:&nbsp;<img src="icon/power-ic.png"><b class="orange">
<?
echo"".$arr['speed']."";
?> км.ч.</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Уровень: <img src="icon/raiting-.png"><b class="yellow">
<?
echo"".$arr['level']."";
?>
</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Опыт: <img src="icon/fuel-ico.png"><b class="yellow" style="color: #000"><span id="FUELTIME">
<?
echo"".$arr['exp']."";
?></span></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" style="padding-bottom: 0px; padding-left: 10px; padding-right: 10px;" valign="bottom">
<?
echo"<img class='wdt' src='car/".(isset($color) ? "".$color."".$car['screen']."" : "".$car['screen']."")."' alt=''/> <br/>";
?>
</br>
<img class="wdt" style="margin-top: -18px;" src="icon/car_shad.png">
</td>
</tr>
</table>

</table>
<table class="wdt brown-header">
<tr>
<td align="left">Заявки:</td>
</tr>
</table>

<?
if($sop_race==0){
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<input type="submit" class="wdt race-btn" value="Гонок нет!"/>
</form>
</td>
</tr>
</table>
<?
?>

<?
}
else
{
if(isset($_POST['submit'])){
$user_id_2=mysql_result(mysql_query("SELECT `id_1` FROM `super_race` WHERE `id`='".intval($_GET['id_race'])."'"),0);
$arr_2=mysql_fetch_array(mysql_query("SELECT `speed`, `uprav` FROM `supergonki` WHERE `id_u`='".$user_id_2."'"));
$raznica_speed=$arr['speed']-$arr_2['speed'];
if($raznica_speed<0){
$raznica_speed=$arr_2['speed']-$arr['speed'];
$invers=1;
}
if($raznica_speed>16)
$invers=3;
if($raznica_speed==0)
$invers=2;
if($raznica_speed>=1 && $raznica_speed<=15)
$invers=2;
if($raznica_speed>=1 && $raznica_speed<=15 && $invers==2)
$invers=2;
if($invers==1){
$pob=rand(1,6);
if($pob!=3){
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");
mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}
else
{
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}}
elseif($invers==2){
$pob=rand(1,2);
if($pob!=2){
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");

mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}
else
{
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}
}
elseif($invers==3){
$pob=rand(1,6);
if($pob==3){
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user_id_2."'");
mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}
else
{
mysql_query("UPDATE `supergonki` SET `win`=`win`+1, `exp`=`exp`+$pob, `money`=`money`+500, `resp`=`resp`+200, `samoobl`=`samoobl`+250, `reak`=`reak`+310 WHERE `id_u`='".$user['id']."'");
mysql_query("UPDATE `supergonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<?
echo"<input type='submit' class='wdt race-btn' value='
Гонка успешно проведенна! Выиграл ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>
</td>
</tr>
</table>
<?
}}
mysql_query("DELETE FROM `super_race` WHERE `id`='".intval($_GET['id_race'])."'");

}
else
{
$k_page=k_page($sop_race,10);
$page=page($k_page);
$start=10*$page-10;
$queryy=mysql_query("SELECT * FROM `super_race` WHERE `id_2`='".$user['id']."' AND `act`='0' ORDER BY `id` DESC LIMIT $start,10");
while($po=mysql_fetch_array($queryy)){
$pos=mysql_fetch_array(mysql_query("SELECT * FROM `supergonki` WHERE `id_u`='".$po['id_1']."'"));
  $carp=mysql_fetch_array(mysql_query("SELECT * FROM `super_car` WHERE `id`='".$pos['car']."'"));
  if($pos['color']!='0'){
if($pos['color']==1)
$color2='red_';
elseif($pos['color']==2)
$color2='blue_';
elseif($pos['color']==3)
$color2='green_'; 
}
?>
<table class="wdt gray-table" style="font-size: 10pt">
<tr>
<td class="white td-cell" align="center" style="width: 60px; padding-right: 0px">
<?
echo"<img src='car/".(isset($color2) ? "".$color2."".$carp['screen']."" : "".$carp['screen']."")."' width='128px'>";
?>
</td>
<td class="td-cell white" align="left" style="vertical-align: top">
<br>
<?
echo"<a class='orange' href='/info.php?id=".$po['id_1']."'>".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$po['id_1']."'"),0)."</a>";
?>
<br>
<?
echo"".$pos['speed']."";
?>км.ч.<br>

</td>
<td class="td-cell" align="right" style="padding-right: 10px; width: 45%">
<?
echo"<form action='allrace.php?load&amp;oprace&amp;act&amp;id_race=".$po['id']."' method='post'>";
?>
<input type="submit" name='submit' class="upgrade-btn" value="Принять заявку">
</form>
</td>
</tr>
</table>

<?

}
if($k_page>'1')str('?load&amp;oprace&amp;',$k_page,$page);
}}

}

 
if(!isset($_GET['oprace']) && isset($_GET['myrace'])){
?></br>
</td>
</tr>
</table>
<table class="wdt garage-table">
<tr>
<td align="right"  style="padding-top: 10px;">
<table class="wdt">
<tr>
<td style="vertical-align: top; padding-left: 10px;" align="left" rowspan="4">
</td>
<td align="left" class="white" style="vertical-align: top" width="40%"><b>
<?
echo"".$car['name']."";
?>
</b>
</td>
</tr>
<tr>
<td align="left" class="white" nowrap="nowrap" style="font-size: 14px">Мощность:&nbsp;<img src="icon/power-ic.png"><b class="orange">
<?
echo"".$arr['speed']."";
?> км.ч.</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Уровень: <img src="icon/raiting-.png"><b class="yellow">
<?
echo"".$arr['level']."";
?>
</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Опыт: <img src="icon/fuel-ico.png"><b class="yellow" style="color: #000"><span id="FUELTIME">
<?
echo"".$arr['exp']."";
?></span></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" style="padding-bottom: 0px; padding-left: 10px; padding-right: 10px;" valign="bottom">
<?
echo"<img class='wdt' src='car/".(isset($color) ? "".$color."".$car['screen']."" : "".$car['screen']."")."' alt=''/> <br/>";
?>
</br>
<img class="wdt" style="margin-top: -18px;" src="icon/car_shad.png">
</td>
</tr>
</table>

</table>
<table class="wdt brown-header">
<tr>
<td align="left">Мои приглашения:</td>
</tr>
</table>
<?
if($my_race==0){

?>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php" method="get">
<input type="submit" class="wdt race-btn" value="Гонок нет!"/>
</form>
</td>
</tr>
</table>
<?
}
else
{
if(isset($_POST['submit'])){
mysql_query("DELETE FROM `super_race` WHERE `id`='".intval($_GET['id_race'])."' LIMIT 1");
msg('');


}
else
{
$k_page=k_page($my_race,10);
$page=page($k_page);
$start=10*$page-10;
$queryy=mysql_query("SELECT * FROM `super_race` WHERE `id_1`='".$user['id']."' AND `act`='0' ORDER BY `id` DESC LIMIT $start,10");
while($po=mysql_fetch_array($queryy)){
$pos=mysql_fetch_array(mysql_query("SELECT * FROM `supergonki` WHERE `id_u`='".$po['id_2']."'"));
 if($pos['color']!='0'){
if($pos['color']==1)
$color2='red_';
elseif($pos['color']==2)
$color2='blue_';
elseif($pos['color']==3)
$color2='green_'; 
}
  $carp=mysql_fetch_array(mysql_query("SELECT * FROM `super_car` WHERE `id`='".$pos['car']."'"));

?>





<table class="wdt gray-table" style="font-size: 10pt">
<tr>
<td class="white td-cell" align="center" style="width: 60px; padding-right: 0px">
<?
echo"<img src='car/".$color2."".$carp['screen']."' width='128px'>";
?>
</td>
<td class="td-cell white" align="left" style="vertical-align: top">
<br>
<?
echo"<a class='orange' href='/info.php?id=".$po['id_2']."'>".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$po['id_2']."'"),0)."</a>";
?>
<br>
<?
echo"".$pos['speed']."";
?>км.ч.<br>

</td>
<td class="td-cell" align="right" style="padding-right: 10px; width: 45%">
<?
echo"<form action='allrace.php?load&amp;myrace&amp;act&amp;id_race=".$po['id']."' method='post'>";
?>
<input type="submit" name='submit' class="upgrade-btn" value="Удалить заявку">
</form>
</td>
</tr>
</table>
<?


}
if($k_page>'1')str('?load&amp;myrace&amp;',$k_page,$page);
}}}


?>


<?

if(!isset($_GET['load'])){
?>
</br>
</td>
</tr>
</table>
<table class="wdt garage-table">
<tr>
<td align="right"  style="padding-top: 10px;">
<table class="wdt">
<tr>
<td style="vertical-align: top; padding-left: 10px;" align="left" rowspan="4">
</td>
<td align="left" class="white" style="vertical-align: top" width="40%"><b>
<?
echo"".$car['name']."";
?>
</b>
</td>
</tr>
<tr>
<td align="left" class="white" nowrap="nowrap" style="font-size: 14px">Мощность:&nbsp;<img src="icon/power-ic.png"><b class="orange">
<?
echo"".$arr['speed']."";
?> км.ч.</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Уровень: <img src="icon/raiting-.png"><b class="yellow">
<?
echo"".$arr['level']."";
?>
</b></td>
</tr>
<tr>
<td align="left" class="white" style="font-size: 14px">Опыт: <img src="icon/fuel-ico.png"><b class="yellow" style="color: #000"><span id="FUELTIME">
<?
echo"".$arr['exp']."";
?></span></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" style="padding-bottom: 0px; padding-left: 10px; padding-right: 10px;" valign="bottom">
<?
echo"<img class='wdt' src='car/".(isset($color) ? "".$color."".$car['screen']."" : "".$car['screen']."")."' alt=''/> <br/>";
?>
</br>
<img class="wdt" style="margin-top: -18px;" src="icon/car_shad.png">
</td>
</tr>
</table>

<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php?load&amp;myrace" method="post">
<?

echo"<input type='submit' class='wdt race-btn' value='Мои приглашения ".($my_race>0 ? '+'.$my_race.'' :'')."'/>";

?>
</form>
</td>
</tr>
</table>
<td class="white td-cell" align="center" style="height:30px;">
<form action="allrace.php?load&amp;oprace" method="post">
<?
echo"<input type='submit' class='wdt race-btn' value='Приглашения соперников ".($sop_race>0 ? '+'.$sop_race.'' :'')."'/>";
?>
</form>
</td>
</tr>
</table>

<?

}
else{
}
?>
<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>

