<?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/user.php';
$set['title'] = 'Мои гонки';
/*
=========================
Автор: BleIK
=========================
Игра: Мои гонки
=========================
*/

?>

<link rel="stylesheet" type="text/css" href="style.css"/>
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<?

if(!$user)
{
echo 'Зарегестрируйтесь ';
exit();
}
echo '
  <table class="tb00">
    <tbody>
      <tr>';
include'bleik.php';
echo '
	  <td class="raml"></td>
        <td class="dbody1">
          <table class="tb00">
            <tbody>
              <tr>
                <td class="logo_l"></td>
                <td class="logo_f">
                  <img src="images/logo_.gif" alt="Мои гонки">
                </td>
                <td class="logo_r"></td>
              </tr>
            </tbody>
          </table>
          <div class="dbody">';

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `moigonki` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `moigonki`(`id_u`) VALUES('".$user['id']."')");
  $arr=mysql_fetch_array(mysql_query("SELECT * FROM `moigonki` WHERE `id_u`='".$user['id']."'"));
   $car=mysql_fetch_array(mysql_query("SELECT * FROM `moi_gonkis` 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(mysql_result(mysql_query("SELECT COUNT(*) FROM `moigonki` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `moigonki`(`id_u`) VALUES('".$user['id']."')");

  $arr=mysql_fetch_array(mysql_query("SELECT * FROM `moigonki` WHERE `id_u`='".$user['id']."'"));
   $car=mysql_fetch_array(mysql_query("SELECT * FROM `moi_gonkis` WHERE `id`='".$arr['car']."'"));
   $all_racer=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_moi` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
   $my_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_moi` WHERE `id_1`='".$user['id']."' AND `act`='0'"),0);
     $sop_race=mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_moi` 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'])){
if($sop_race==0){
?>
<fieldset>

  <legend class="h1">
    <img src="images/flag.gif" alt=".">
    Гонщики гуляют 
  </legend>
  <div class="dt100">
    <p>
      <a class="ag100 center" href="zaezd.php">
        <img src="images/green.gif" alt="start">
        К сожелению сейчас нет никаких гонок
        <img src="images/green.gif" alt="start">
      </a>
    </p>
    <div class="clear"></div>


   
    <div class="clear"></div>
  </div>
</fieldset>

<?
}
else
{
echo '<fieldset>

  <legend class="h1">
    <img src="images/flag.gif" alt=".">
    Гонки проходят на трассе BleIK 
  </legend>  <div class="dt100">
    <p>';

if(isset($_POST['submit'])){
$user_id_2=mysql_result(mysql_query("SELECT `id_1` FROM `racing_moi` WHERE `id`='".intval($_GET['id_race'])."'"),0);
$arr_2=mysql_fetch_array(mysql_query("SELECT `speed`, `uprav` FROM `moigonki` 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 `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>
<?
}
else
{
mysql_query("UPDATE `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>
<?
}}
elseif($invers==2){
$pob=rand(1,2);
if($pob!=2){
mysql_query("UPDATE `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>

<?
}
else
{
mysql_query("UPDATE `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>

<?
}
}
elseif($invers==3){
$pob=rand(1,6);
if($pob==3){
mysql_query("UPDATE `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user['id']."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user_id_2."'"),0)."'/>";
?>
</form>

<?
}
else
{
mysql_query("UPDATE `moigonki` 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 `moigonki` SET `lose`=`lose`+1 WHERE `id_u`='".$user_id_2."'");
?>

<form action="zaezd.php" method="get">
<?
echo"<input type='submit' class='a100' value='
Заезд закончен победитель   ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$user['id']."'"),0)."'/>";
?>
</form>

<?
}}
mysql_query("DELETE FROM `racing_moi` 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 `racing_moi` 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 `moigonki` WHERE `id_u`='".$po['id_1']."'"));
  $carp=mysql_fetch_array(mysql_query("SELECT * FROM `moi_gonkis` 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_'; 
}
echo"<img src='images/cars/".(isset($color2) ? "".$color2."".$carp['screen']."" : "".$carp['screen']."")."'>";
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>";
echo"&nbsp&nbsp&nbsp".$pos['speed']."";
?>км/ч<br>



<?
echo"<form action='zaezd.php?load&amp;oprace&amp;act&amp;id_race=".$po['id']."' method='post'>";
?>
<input type="submit" name='submit' class="a100" value="Я принимаю вызов гонщика">
</form>
<?

}
if($k_page>'1')str('?load&amp;oprace&amp;',$k_page,$page);
}
echo '     </p>
    <div class="clear"></div>


   
    <div class="clear"></div>
  </div>
</fieldset>';
}

}

 
if(!isset($_GET['oprace']) && isset($_GET['myrace'])){
if($my_race==0){
?>
<form action="zaezd.php" method="get">
<input type="submit" class="wdt race-btn" value="Гонок нет!"/>
</form>
<?
}
else
{
if(isset($_POST['submit'])){
mysql_query("DELETE FROM `racing_moi` 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 `racing_moi` 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 `moigonki` 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 `moi_gonkis` WHERE `id`='".$pos['car']."'"));
?>

<fieldset>
  <legend>Вызовы которые я отправил</legend>
  <div class="dt100">
    <div class="fll daf">
	  <?echo"<img src='images/cars/".$color2."".$carp['screen']."'>";?>
      <?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>
    </div>
    <div class="fll ml10">

      <span class="color9 mini">мощность:</span>
       <?echo"".$pos['speed']."";?>км/ч<br>

      <br>

    </div>
	
	<?echo"<form action='zaezd.php?load&amp;myrace&amp;act&amp;id_race=".$po['id']."' method='post'>";
?>
<input type="submit" name='submit' class="a100" value="Удалить заявку">
</form>
<div class="clear"></div>
   
  </div>
</fieldset>
<?
}
if($k_page>'1')str('?load&amp;myrace&amp;',$k_page,$page);
}}}
if(!isset($_GET['load'])){
?>
</br>
<fieldset>
  <legend><?echo"".$crr['name']."";?></legend>
  <div class="dt100">
	<a class="a100" href="zaezd.php?load&amp;oprace">Приглашения соперников <?echo "".($sop_race>0 ? '+'.$sop_race.'' :'')."";?></a>
<a class="a100" href="zaezd.php?load&amp;myrace">Мои приглашения  <?echo "".($my_race>0 ? '+'.$my_race.'' :'')."";?></a>   
   <div class="clear"></div>
   
  </div>
</fieldset>


<?

}
else{
}

echo '<fieldset>
  <legend class="path">
    <a href="/online_games/racing/index1.php.php">
      <img src="images/green.gif" alt="/" style="margin:0px 4px 0px 0px;">
      Главная
    </a>
     » 
   
  </legend>
</fieldset>
<br class="br1">
          </div>
        </td>
        <td class="ramr"></td>
      </tr>
    </tbody>
  </table>
  <div class="ramd"></div>
  <br>
  <span class="mini2">
    <center>by xLoF.Ru</center>
    <br>
    
  </span>';

include_once'../sys/inc/tfoot.php';
?>