<?php
defined('PROTECTOR') OR die('Ошибка: нет доступа');

$t=time();
$req = mysql_query("SELECT * FROM `ban` WHERE `usr` = '$log' LIMIT 1");
$avtob = mysql_num_rows($req);
if ($avtob == 1) {
 $ban = mysql_fetch_array($req);
if($ban['ban_time']<$t){
mysql_query("DELETE FROM `ban` WHERE `usr` = '$log'");
}else{
if($ban['block']==1){
$vrem=$ban['ban_time']-time();
echo'<div class="block_zero"><span style="color: #ff3434;">Ваш персонаж заблокирован!<br>Причина: '.$ban['text'].'<br>Осталось: '.Sec2Time($vrem).'<br>Забанил: '.$ban['admin'].'</span></div>';
exit();
}
}
}


if ($user_id=='1'){
include('lvl.php');
/*
echo'<layer name="lenta" top=0 right=0 >
<nolayer>
<div id="lenta" style="position:absolute; top:0; right:0;">
</nolayer>
<a href="index.html" target="_blank"><img border="0" src="http://likiliks.ru/images/georg-lenta.gif" align="right"></a>
<nolayer>
</div>
</nolayer>
</layer>';
*/

if(empty($header)){
$udata = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `usr` = '$log'"));
echo'<div class="foot"><img src="image/icon/health.png" alt="*"> '.$udata['hp'].'   <img src="image/icon/mana.png" alt="*"> '.$udata['mp'].'<span style="float: right;">'.$head.'</span></div>';

if(isset($ol) AND isset($op)){
$exp=round((($udata['exp']-$ol)/($op-$ol))*100);
}else{
$ol=false;
$op=false;
$exp=false;
}

echo '<div class="exp_bar"><div class="progress" style="height:1px; width: '.$exp.'%;"></div></div>';

/*if($udata['time_start']<=$time-86400 AND date("j")!==$conf['present_day']){
if($udata['level']>=1 AND $udata['level']<=5){$mkoef=100;$rkoef=1;}
if($udata['level']>=6 AND $udata['level']<=11){$mkoef=500;$rkoef=0.7;}
if($udata['level']>=12 AND $udata['level']<=20){$mkoef=1000;$rkoef=0.7;}
if($udata['level']>=21 AND $udata'level']<=29){$mkoef=5000;$rkoef=0.8;}
if($udata['level']>=30 AND $udata['level']<=36){$mkoef=10000;$rkoef=0.9;}
if($udata['level']>=37 AND $udata['level']<=40){$mkoef=50000;$rkoef=1;}
if($udata['level']>=41 AND $udata['level']<=45){$mkoef=100000;$rkoef=1;}
if($udata['level']>=46 AND $udata['level']<=50){$mkoef=200000;$rkoef=1;}
if($udata['level']>=51 AND $udata['level']<=60){$mkoef=1000000;$rkoef=1;}
if($udata['level']>=61 AND $udata['level']<=64){$mkoef=10000000;$rkoef=1.4;}
if($udata['level']>=65 AND $udata['level']<=70){$mkoef=100000000;$rkoef=1.6;}
//if($udata['level']>=71 AND $udata['level']<=80){$mkoef=1000000000;$rkoef=1.8;}

if($conf['present_time']>=$time-93600)$present_bon=$conf['present_bon']+1; else $present_bon=$conf['present_bon']-(3*round(($time-$conf['present_time'])/86400));
if($present_bon<=0)$present_bon=0;
$bons_money=$udata['level']*$mkoef;
if($present_bon>=40)$present_bon=40;
$bons_rubies=round($ku['level']*$rkoef+$present_bon);

mysql_query("UPDATE `users` SET `almaz` = '".($udata['almaz']+$bons_money)."',`money` = '".($udata['money']+$bons_rubies)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `users` SET `present_day` = '".(date("j"))."',`present_time` = '$time',`present_bon` = 'present_bon'+'$present_bon' WHERE `usr` = '$udata[usr]'");
$text = "Ваш ежедневный бонус: $bons_money рублей и $bons_rubies сигарет!";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Журнал', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
/*$_SESSION['msg']="Спасибо, что Вы играете в нашу игру.
Вам подарок:  $bons_money рублей и $bons_rubies сигарет
Бонус выдается каждый день.";
header("Location:/");
}*/

/*
$proc=($udata['hp']/$udata['hpall'])*100;
$proc2=($udata['mp']/$udata['mpall'])*100;
echo"<div class='stat_bar'><div class='progress blue' style='width:$proc%'></div></div>";
echo"<div class='stat_bar'><div class='progress blue' style='width:$proc2%'></div></div>";
*/

$on = mysql_fetch_array(mysql_query('SELECT * FROM `undying` WHERE `start` = "0"'));
if(time()>=$on['time'] AND $on['start']==0 AND $udata['lvl']>4){
echo'<div class="block_zero center"><a href="undying.php"><div class="head"><span style="color: #3c3;">На зоне начинается мятеж!</span></div></a></div>';
//mysql_query("UPDATE `undying` SET `start` = '1' WHERE `start` = '0'");
}


$set = mysql_fetch_assoc(mysql_query("SELECT * FROM `set` WHERE `usr` = '$log'"));
$time=time();
$ab = $set['viptime'] -$time;
if($set['vip']=='on'){
//echo'<div class="block_zero center"><a href="vip.php?"><div class="head"><span style="color: #939;">VIP, осталось '.Sec2Time($ab).'</span></div></a></div>';
}

//-----
$news=mysql_fetch_array(mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 1"));
$asd = mysql_query("SELECT COUNT(*) FROM `news` ORDER BY `id` DESC LIMIT 1");
$avto=mysql_result($asd, 0);
if ($avto > 0 AND $udata['news']==0) {
echo'<div class="block_zero center"><a href="posnews.php"><div class="head"><span style="color: #3c3;">Обновлены новости '.$news['time'].'</span></div></a></div>';
}

/*
$otkr=$udata['s1']+$udata['s2']+$udata['s3']+$udata['s4'];
$start=mysql_fetch_array(mysql_query("SELECT `sunduki` FROM `set` WHERE `usr`='$log'"));
if($start['sunduki']<=time() AND $otkr==4){
$time = date("H:i d.m.y");
$text = "Сундуки в тайнике обновлены";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Мастер ключей', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
}
*/


$req=mysql_query("SELECT * FROM `rydnik` WHERE `usr`='$log'");
$rydnik=mysql_fetch_array($req);
$avto=mysql_num_rows($req);
if($rydnik['over']<=time() AND $udata['s5']=='1'){
$time = date("H:i d.m.y");
$text = "Работа завершена!";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Журнал', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
mysql_query("UPDATE `users` SET `s5` = '0' WHERE `usr` = '$log'");
}

$pohod = mysql_fetch_array(mysql_query("SELECT * FROM `dozor` WHERE `usr` = '$log'"));
$mag = mysql_fetch_array(mysql_query("SELECT * FROM `mag` WHERE `usr` = '$log'"));
if($pohod['over']<=time() AND $mag['vihr2']=='1'){ 
$time = date("H:i d.m.y");
$text = "Прогулка завершена!";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Журнал', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
mysql_query("UPDATE `mag` SET `vihr2` = '0' WHERE `usr` = '$log'");
}

if (isset($_SESSION['message'])){
echo "<div class='ok center'><img src='/image/icon/ok.png'> $_SESSION[message]</div>";
$_SESSION['message']=NULL;
}
if (isset($_SESSION['err'])){
echo "<div class='error center'><img src='/image/icon/error.png'> $_SESSION[err]</div>";
$_SESSION['err']=NULL;
}

$q = mysql_query("SELECT COUNT(*) FROM `msg_r` WHERE `user_to` = '$log' AND `read` = '1';");
$new_mail = mysql_result($q, 0);
if($new_mail > 0){
echo'<div class="block_zero center"><a href="msg.php?mod=read"><div class="head"><span style="color: #3c3;">Тебе малява ('.$new_mail.')</span></div></a></div>';
}


$pri = mysql_query("SELECT * FROM `zametka` WHERE `id` = '1' AND `status`='on'");
$prim = mysql_num_rows($pri);
$prime = mysql_fetch_array($pri);
if($prim > 0 AND $set['prim']=='on'){
echo'<div class="block_zero center"><a href="index.php?mod=prim"><div class="head"><span style="color: #3c3;">Объява по зоне!</span></div></a></div>';
}
/*
if($dueli==1){
$req = mysql_query("SELECT `duid` FROM `userduel` WHERE `usr` = '$log' LIMIT 1");
$duel = mysql_fetch_array($req);
$redu = mysql_query("SELECT * FROM `duel` WHERE `id` = '$duel[duid]' LIMIT 1");
$due = mysql_fetch_array($redu);
if($due['status']=="sob" and $due['time']<$t){
mysql_query("UPDATE `duel` SET `status` = 'begin' WHERE `usr` = '$log' and `id`='$due[id]'") or die (mysql_error());
}
$reduk = mysql_query("SELECT * FROM `duel` WHERE `id` = '$due[id]' LIMIT 1");
$duel = mysql_fetch_array($reduk);
$vremya1=$duel['time']-$t;
$vremy=floor($vremya1/60);
$vremya=$vremya1-($vremy*60);
if($vremya<10){$vremya="0$vremya";}
$vrem="$vremy:$vremya";
if($vremya<1){
//header('Location: fiting.php');exit;
}
if($duel['status']=="sob"){ 
echo'<div class="block_zero center"><a href="duel.php?"><div class="head"><span style="color: #3c3;">Бой в Колизее через '.Sec2Time($vremya1).'</span></div></a></div>';
}
if($duel['status']=="begin" AND $head!=="duel"){ 
echo'<div class="block_zero center"><a href="duel.php?"><div class="head"><span style="color: #3c3;">Идёт бой в Колизее!</span></div></a></div>';
}
}
*/
//**********
/*$req = mysql_query("SELECT * FROM `item_aura` WHERE `usr` = '$log' and `status`='1'");
$avto=mysql_num_rows($req);
if($avto==1){
$aur = mysql_fetch_array($req);
$req = mysql_query("SELECT * FROM `aurs` WHERE `usr`='$log'");
$avto=mysql_num_rows($req);
$aro = mysql_fetch_array($req);

$ab = $aro['actimer'] -time();
echo'<div class="block_zero center"><a href="shopaura.php?"><div class="head"><span style="color: #999;">'.$aur['name'].': осталось '.Sec2Time($ab).'</span></div></a></div>';
echo'</div>';
}*/

echo'</div><div class="f_bg"></a>';
}
}else{
echo "<div class=\"f_bg\">Ошибка!Вы не авторизованы!<br><a href='/'>Авторизуйтесь</a>
<div>";
include('files/end.php');exit;
}
?>