<?
# Автор движка: InstalScript
# vk.com/k.karamin  - Я Вк
# bymas.ru/id3741  - Я на бумасе
# Специально для обитателей bymas.ru
# Ток на бумасе можно найти моды для данного движка


{
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `nick` = '".check($_SESSION['nick'])."' AND `pass` = '".check($_SESSION['pass'])."'  "));
if($user != null){
if($_SESSION['nick'] != $_COOKIE['nick']){setcookie('nick',$_SESSION['nick'],time()+31536000);}
if($_SESSION['pass'] != $_COOKIE['pass']){setcookie('pass',$_SESSION['pass'],time()+31536000);}
}
if($user == null){$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `nick` = '".check($_COOKIE['nick'])."' AND `pass` = '".check($_COOKIE['pass'])."'  "));}
$uid = abs($user['id']);




$my_tank = mysql_fetch_assoc(mysql_query("SELECT * FROM `utank` WHERE `uid` = '".$uid."' AND `act` = '1' "));
$tid = abs($my_tank['tid']);



if($uid == '0' && $auth_null == null){header("Location:/");exit();}

$msg_new = mysql_fetch_assoc(mysql_query("SELECT * FROM `umsg` WHERE `idu` = '".$uid."' AND `act` = '1' "));
}




function userfuel($uid){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));

if(strripos($_SERVER['REQUEST_URI'],'battle') == null){

if(empty($user['time_fuel'])){mysql_query("UPDATE `users` SET `time_fuel` = '".(time())."' WHERE `id` = '".$uid."' ");}
$is_time_regen = '10'; # Чем больше число тем дольше восстанавливается топливо
if($user['fuel']<$user['fuel_max'] && ($user['time_fuel']+$is_time_regen)<time()){

$rfuel = mt_rand((($user['fuel_max']/100 )*1),(($user['fuel_max']/100*2)));
$rfue = $user['fuel']+(time()-$user['time_fuel'])*$rfuel;
if($rfue > $user['fuel_max']){$rfue = $user['fuel_max'];}
mysql_query("UPDATE `users` SET `fuel` = '".($rfue)."',`time_fuel` = '".(time())."' WHERE `id` = '".$uid."' "); #or die(mysql_error());
}else{
if($user['fuel'] == $user['fuel_max']){mysql_query("UPDATE `users` SET `time_fuel` = '".(time())."' WHERE `id` = '".$uid."' ");}
}
}else{
mysql_query("UPDATE `users` SET `time_fuel` = '".(time())."' WHERE `id` = '".$uid."' "); #or die(mysql_error());
}

if($user['fuel'] > $user['fuel_max']){mysql_query("UPDATE `users` SET `fuel` = '".$user['fuel_max']."' ");}
mysql_query("UPDATE `users` SET `time` = '".(time())."' WHERE `id` = '".$uid."' ");
}


function head($title,$uid){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));
if(empty($user['ava'])){mysql_query("UPDATE `users` SET `ava` = 'empty.png' WHERE `id` = '".$user['id']."' ");}

echo"<!DOCTYPE html PUBLIC '-//WAPFORUM//DTD XHTML Mobile 1.0//EN' 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd'>";
echo "<html xmlns = 'http://www.w3.org/1999/xhtml' xmlns:w = 'http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd'>";
echo "<head>";
echo "<script src = '/instalscript/jquery/jquery-1.6.4.min.js' type='text/javascript'></script>";
echo "<meta http-equiv = 'Content-Type' content = 'text/html; charset=UTF-8'>";
echo "<meta name = 'SKYPE_TOOLBAR' content = 'SKYPE_TOOLBAR_PARSER_COMPATIBLE'>";
echo "<link rel = 'icon' href = '/instalscript/main/favicon.ico' type = 'image/x-icon'>";
echo "<link rel = 'shortcut icon' href = '/instalscript/main/favicon.ico'>";
echo "<link rel = 'stylesheet' type = 'text/css' href = '/instalscript/main/style.css'>";
echo "<title>Танки";if(!empty($title)){echo " | ".$title."";}echo"</title>";
echo "</head>";
echo "<body>";

if($user!=null){
userfuel($uid);




# Уровни и опыт на них
function userlevel($level){
if($level  == '1'){$exp = '3000000';}
if($level  == '2'){$exp = '4000000';}
if($level  == '3'){$exp = '5000000';}
if($level  == '4'){$exp = '10000000';}
if($level  == '5'){$exp = '20000000';}
if($level  == '6'){$exp = '30000000';}
if($level  == '7'){$exp = '40000000';}
if($level  == '8'){$exp = '50000000';}
if($level  == '9'){$exp = '60000000';}
if($level  == '10'){$exp  = '100000000';}
return $exp;
}

$expr = round(abs($user['exp']/userlevel($user['level'])));
if($expr > '100'){$expr = '100';}
if($expr < '0'){$expr = '0';}






echo "
<div class = 'round-panel'>
<div class = 'wrp1'><div class = 'wrp2'>
<table class = 'count bold'>
<tbody><tr>
<td class = 'small lh1 bgn'>
<img title = 'Топливо' alt = 'Топливо' src = '/instalscript/images/icons/fuel.png'> ".$user['fuel']."
</td>
<td class = 'small lh1 pl12'>
<img title = 'Золото' alt = 'Золото' src = '/instalscript/images/icons/gold.png'> ".$user['gold']."
</td>
<td class = 'small lh1 pl12'>
<img title = 'Серебро' alt = 'Серебро' src = '/instalscript/images/icons/silver.png'> ".$user['silver']."
</td>
</tr>
</tbody></table>
</div></div>
</div>

<table class = 'rblock blue esmall'>
<tbody><tr>
<td><div class = 'value-block lh1'><span><span><img height = '14' width = '14' src = '/instalscript/images/icons/exp.png'>".$user['level']."</span></span></div></td>
<td class = 'progr'><div class = 'scale-block'><div class = 'scale' style = 'width:".$expr."%;'>&nbsp;</div></div></td>
<td><div class = 'value-block lh1'><span><span>".$expr."%</span></span></div></td>
</tr>
</tbody></table>

<table>
<tbody><tr>
<td style = 'width:33%;padding-right:4px;'>
<div style = 'position:relative;'>
<a class = 'simple-but border gray mb1' href = '/angar/'><span><span>Ангар</span></span></a>";
/*
echo "<span class = 'digit esmall'><span class = 'l'>&nbsp;</span><span class = 'm'>+</span><span class = 'r'>&nbsp;</span></span>";
*/

echo "</div>
</td>
<td style = 'width:33%;padding:0 4px;'>
<div style = 'position:relative;'>
<a class = 'simple-but border mb1' href = '/battle/'><span><span>В бой!</span></span></a>";
if($user['fuel'] >= '30'){echo "<span class = 'digit esmall'><span class = 'l'>&nbsp;</span><span class = 'm'>+</span><span class = 'r'>&nbsp;</span></span>";}
echo "</div></td>";


echo "<td style = 'width:33%;padding-left:4px;'>
<div style = 'position:relative;'>
<a class = 'simple-but gray border mb1' href = '/buildings/'><span><span>База</span></span></a>";
/*
echo "<span class = 'digit esmall'><span class = 'l'>&nbsp;</span><span class = 'm'>+</span><span class = 'r'>&nbsp;</span></span>";
*/


echo "</div>
</td>
</tr>
</tbody></table>
";
}



echo "<div class = 'p5'>";
}


function body($uid){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));




if($user == null){


echo "
<div class = 'cntr mb2'>
<img style = 'max-width:300px;width:100%;' w:id = 'logo' src = '/instalscript/images/GameLogo_World_of_Tanks.png'><br>
</div>
<a class = 'simple-but border' w:id = 'startLink' href = '/start/'><span><span>Начать новую игру</span></span></a>
<form w:id = 'loginForm' id = 'id1' method = 'post' action = '/auth'><div style = 'width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden'><input type = 'hidden' name = 'id1_hf_0' id = 'id1_hf_0'></div>
<div class = 'trnt-block'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'wrap-content'>
<div class = 'cntr white small sh_b bold mb10'>
Вход для зарегистрированных пользователей<br>";


echo logs();logn();
echo "
<br>
Логин:<br>

<input type = 'text' name = 'nick' value = '' class = 'fld-chng' size = '20' maxlength = '32' w:id = 'login'><br>
Пароль:<br>
<input type = 'password' name = 'pass' value = '' class = 'fld-chng' size = '20' maxlength = '32' w:id = 'password'>
</div>
<div class = 'bot'><span class = 'input-but border'><span><input class = 'w100' type = 'submit' w:message = 'value:LoginPage.submit' value = 'Вход'></span></span></div>
</form>

</div>
</div></div></div></div></div></div></div></div>
</div>

<div class = 'small cntr mb10'><a class = 'gray1' href = '/remindPassword' w:id = 'remindPassword'>Забыли пароль?</a></div>
";

}else{


header("Location:/angar/");



}
}


function foot($uid){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".abs($uid)."' "));
$online = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `time` > '".(time()-300)."' "),0);
echo "
<div class = 'footer'>";
if($user != null){
echo "<div class = 'trnt-block mb2'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'wrap-content-mini'>";
$viinfo = mysql_fetch_assoc(mysql_query("SELECT * FROM `info` ORDER BY RAND() "));

echo "<div class = 'mt5 mb5 small green1 cntr'>".$viinfo['text']."</div>";

echo "</div>
</div></div></div></div></div></div></div></div>
</div><div class = 'round-panel'>
<div class = 'wrp1'><div class = 'wrp2'>
<table class = 'esmall bold'>
<tbody><tr>
<td class = 'w50'><a class = 'yellow1' href = '/profile/'>".$user['nick']."</a></td>
<td class = 'w50 ta_r'>

<a class = 'yellow1' href = '/company/'>Дивизия</a>
</td>
</tr>
</tbody></table>
</div></div>
</div>";
echo "<div class = 'medium cntr mb5'><a class = 'yellow1' href = '/forum/'>Форум</a> | <a class = 'yellow1' href = '/chat/'>Чат</a></div>";
echo "<div class = 'esmall cntr mb5 cD2'><a href = '/about/'>Об игре</a> | <a href = '/settings/'>Настройки</a></div>";
echo "<div class = 'esmall cntr cD2'><a href = '/support/'>Помощь</a> | <a href = '/exit'>Выход</a>";



}







echo "
<div class = 'esmall cntr mb5 cD2'>
<span><em>Онлайн</em></span>: <span class = 'green1'>".$online."</span>
</div>
";


echo "
<div class = 'esmall cntr mb5 cD2'>
<a href = '/'>".$_SERVER['HTTP_HOST']."</a> @ <a href = 'http://vk.com/k.karamin' title = 'Автор движка, InstalScript (Николай Карамышев)'>InstalScript</a> 2015, 16+
</div>
</div>
</div>
</body></html>
";
}



?>