<?php
if(!isset($_SESSION))
{
session_start();
ob_start();
} 
mysql_connect("localhost","db1383817715","123456789a") or die(mysql_error());
mysql_select_db("db1383817715");
$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());
if($data_user['ip']!==$_SERVER['REMOTE_ADDR'])
{
mysql_query("UPDATE `users` SET `ip` = '".($_SERVER['REMOTE_ADDR'])."' WHERE `id` = '$data_user[id]'") or die (mysql_error());
}
        setFuel($data_user); // сетим обьем бенза
        {

if($data_user['banned'] > time() or $data_user['banned'] != 0){

 function ban_time($tl){
$d=3600*24;
$day=floor($tl/$d);
$tl=$tl-($d*$day);

$hour=floor($tl/3600);
$tl=$tl-(3600*$hour);

$minute=floor($tl/60);
$tl=$tl-(60*$minute);

$second=floor($tl);

$dayt="".($day>0?"$day д. ":null)."";
$hourt="".($hour>0?"$hour ч. ":null)."";
$minutet="".($minute>0?"$minute м. ":null)."";
$secondt="".($second>0?"$second с. ":null)."";
if($day>0)
{
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0)
{
$secondt=NULL;
$dayt=NULL;
}
return "$dayt$hourt$minutet$secondt";
     }
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html>';
echo '<head>';
	echo '<title>LowRaceClub</title>';
	echo '<meta http-equiv="Content-Type" content="text/html" charset="windows-1251" />';
	echo '<meta name="description" content="Мобильные онлайн гонки">';
if(empty($data_user['theme']) or $data_user['theme'] == 'default')
{
$style="/style/twotheme/mobile.css";
}
if($data_user['theme'] == "twotheme")
{
$style="/style/twotheme/mobile.css";
}
echo '<link rel="stylesheet" href="'.$style.'" type="text/css" />';
?>
<div class="inform">
	<div class="block"><img src="img/benz.png" alt="Бензин"/> <?=$data_user['fuel']?></div>
	<div class="block"><img src="img/speed.png" alt="Скорость" /> <?=$data_user['speed']?> л.с</div>
	<div class="block"><img src="img/money2.png" alt="Золото" /> <?=$data_user['money2']?></div>
	<div class="block"><img src="img/money.png" alt="Баксы" /> <?=$data_user['money']?></div><br><br>
	</div>
<div class='title'>Вы забанены</div>
	 <div class="menu">

<b></b>Вы забанены до <b><?=date("d.m.y, H:i:s",$data_user['banned']);?><br/>
<br></b>Причина:<b> <?=$data_user['prich'];
echo "<br><br></b>Осталось:<b> ".ban_time($data_user['banned']-time())."";
?>
</div>
<?php
echo "</b><div class='title'>&copy; LowRaceClub ".date("Y")." </div><br>";
echo "<center>";
echo "Ваш игровой ID: <font color='yellow'>".$data_user['id']."</font><br><br>";
echo "Вы вошли как <b>".$data_user['nick']."</b><br><br>";
echo "<b>Текущее время</b> - ".date("H:i:s");
echo "</center>";
?>
</body>
</html>
	 <?
	 
	 if($data_user['banned'] < time()) {
     if($data_user['banned'] != 0){
	     mysql_query("update `users` set `banned` = '0', `prich` = '' where `id` = '$data_user[id]'");
		 header("location: ?");
	 }
}
	 
	 exit;
}
$swlevel = $data_user['level'];
switch($swlevel){
	case 1: $swleveln = 26; break; 
	case 2: $swleveln = 48; break; 
	case 3: $swleveln = 72; break; 
	case 4: $swleveln = 104; break; 
	case 5: $swleveln = 137; break; 
	case 6: $swleveln = 163; break; 
	case 7: $swleveln = 192; break; 
	case 8: $swleveln = 244; break; 
	case 9: $swleveln = 312; break; 
	case 10: $swleveln = 378; break;
	case 11: $swleveln = 429; break;
	case 12: $swleveln = 501; break;
	case 13: $swleveln = 596; break;
	case 14: $swleveln = 647; break;
	case 15: $swleveln = 724; break;
	case 16: $swleveln = 836; break;
	case 17: $swleveln = 952; break;
	case 18: $swleveln = 1137; break;
	case 19: $swleveln = 1204; break;
	case 20: $swleveln = 1269; break;
	case 21: $swleveln = 1325; break;
	case 22: $swleveln = 1404; break;
	case 23: $swleveln = 1486; break;
	case 24: $swleveln = 1531; break;
	case 25: $swleveln = 1598; break; 
	case 26: $swleveln = 1663; break; 
	case 27: $swleveln = 1752; break;
	case 28: $swleveln = 1810; break; 
	case 29: $swleveln = 1996; break; 
	case 30: $swleveln = 2104; break;
	case 31: $swleveln = 2218; break; 
	case 32: $swleveln = 2279; break; 
	case 33: $swleveln = 2358; break; 
	case 34: $swleveln = 2412; break;
	case 35: $swleveln = 2487; break; 
	case 36: $swleveln = 2569; break; 
	case 37: $swleveln = 2647; break; 
	case 38: $swleveln = 2707; break; 
	case 39: $swleveln = 2791; break; 
	case 40: $swleveln = 2934; break;
	case 41: $swleveln = 3087; break; 
	case 42: $swleveln = 3175; break; 
	case 43: $swleveln = 3261; break; 
	case 44: $swleveln = 3347; break; 
	case 45: $swleveln = 3469; break; 
	case 46: $swleveln = 3514; break; 
	case 47: $swleveln = 3726; break; 
	case 48: $swleveln = 3838; break; 
	case 49: $swleveln = 3902; break; 
	case 50: $swleveln = 5000; break;
}
$levelimg = ceil($data_user['opit']*100/$swleveln);
	if($data_user['opit'] >= $swleveln){
	$newlvl = $data_user['level']+1;
	$resm = $data_user['money']+2500;
	$resm2 = $data_user['money2']+1;
	$resr = $data_user['raiting']+10;
	mysql_query("UPDATE `users` SET `opit`='0', `level`= '$newlvl',`money`='$resm',`money2`='$resm2',`raiting`='$resr',`fuel`='100' WHERE nick='".$_SESSION['user']."'");
}
}
}

mysql_query("UPDATE `users` SET `fuel`=(`fuel`+2) WHERE `id`='$user[id]' ");

// функция для контроля уровня бензина по времени
// 28.06.13
function setFuel($user)
{
    // узнаем текущее юник время
    $currentDate = time();
    $dateDiff = $currentDate - $user['fuel_change'];
    $newFuel = $user['fuel'];
    //30000 сек - время полной заправки...
    if ($dateDiff < 15000 && $newFuel < 100)
    {
        // крутим цикл с пошаговым обновлением количества бензина
        // в соответсвии с временем простоя после последнего апдейта
         while ($dateDiff > 150)
        {
            $newFuel++;
            if ($newFuel >= 100)
            {
                break;
            }
            $dateDiff = $dateDiff - 150; //300 сек == 5 мин
        }
    }
    else
    {
       $newFuel = 100;
    }
    if ($newFuel != $user['fuel'])
    {
       mysql_query("UPDATE `users` SET `fuel`='$newFuel' , `fuel_change`='$currentDate' WHERE nick='".$_SESSION['user']."'");
       //die(mysql_error());
    }
}

// ALTER TABLE `users` ADD `fuel_change` INT( 11 ) NOT NULL DEFAULT '0' COMMENT 'время последнего обновления бенза' AFTER `fuel`
// Это запрос в БД
?>