<?php

include 'sql.php';
include 'dbc.php';
include 'func_user.php';


	$expLevel = array (0,100,100,200,500,800,1000,		2000,2400,2800,3300,6000,7000,8000,10000,11000,27000,28000,28000,29000,30000,41000,52000,63000,74000,85000,99000,100000,100000,100000,100000,100000,100000,100000,120000,130000,140000,150000,13170000,180000,190000,200000,250000,300000,300000,350000,400000,400000,500000,600000,700000,100000000);






function Oput($the){ global $user;
global  $expLevel;
global $dbc; if($user['vip']== 1){ $the = $the*2;}if($user['clan']<=0){ $dbc->query("update `users` set `oput` = `oput` + ".$the.", `exp` = `exp`+".$the." where id = '".$user['id']."'");}else{ $plan = $the*10/100; $dbc->query("update `users` set `clan_oput` = `clan_oput`+".$plan.",`oput`=`oput`+".$the." , `exp`=`exp`+".$the." where id = '".$user['id']."'"); 

$dbc->query("update `clan` set `clan_oput` = `clan_oput` + ".$plan." where id = '".$user['clan']."'"); }if ($user['exp']>=$expLevel[$user['level']]){




$dbc->query("update `dop` set `boi`=`boi`+5 where `user`='".$user['id']."' ");


$dbc->query("UPDATE `users` SET 
`level`=`level`+1,

`train`=`train`+1, `exp`=0

 WHERE `id`='".$user['id']."'");
$_SESSION['message']='<center><span class="info">Вы получили новый уровень!</span></br>Боев в охоте +5';


}}




if ($user['oput']>=$expLevel[$user['level']]){ $_SESSION['message']='<center><img src="img/stat/up.png">Вы получили новый уровень!<img src="img/stat/up.png">'; }
function head($title){


global $expLevel;
global $dbc;
global $user;

include 'head.php';
/* Записываем где пользователь */
if($user['id']>0){



if($title!=$user['title']){

$dbc->query("UPDATE `users` SET `where`='".$title."' WHERE `id`='".$user['id']."'");
}
}
}

list ( $ms , $s ) = explode ( chr ( 32 ) , microtime ( ) );
$g = $s + $ms;
$time_beg=microtime();

date_default_timezone_set('Europe/Moscow');


define('TIME', time());
session_start();
/* Настройки системы */
/* Проверяем бан, если да дропаем куки*/
if($user['ban']==1)
{
head('Бан');
echo '<div class="main">
<div class="block_zero center">Ваш персонаж был заблокирован!<br>
Причина: <b>'.$user['ban_why'].'</b>
</div></div>';
include 'foot.php';
exit;
}
function Sec2Time($time){
  if(is_numeric($time)){
    $value = array(
      "years" => 0, "days" => 0, "hours" => 0,
      "minutes" => 0, "seconds" => 0,
    );
    if($time >= 31556926){
      $value["years"] = floor($time/31556926);
      $time = ($time%31556926);
    }
    if($time >= 691200){
      $value["days"] = floor($time/691200);
      $time = ($time%691200);
    }
    if($time >= 3600){
      $value["hours"] = floor($time/3600);
      $time = ($time%3600);
    }
    if($time >= 60){
      $value["minutes"] = floor($time/60);
      $time = ($time%60);
    }
    $value["seconds"] = floor($time);
	
	if($value["seconds"]>0){
	$time3 = $value["seconds"].' сек. ';
	}else{
	$time3='';
	}
	if($value["minutes"]>0){
	$time2 = $value["minutes"].' мин. ';
	}else{
	$time2='';
	}
	if($value["hours"]>0){
	$time1 = $value["hours"].' ч. ';
	}else{
	$time1='';
	}
	if($value["years"]>0){
	$time_y = $value["years"].' лет ';
	}else{
	$time_y='';
	}
    return $time_y.$time1.$time2.$time3;
   ## return (array) $value;
  }else{
    return (bool) FALSE;
  }
}

    function nifa($i) {    if($i >= 10000 && $i < 1000000) {      $i = number_format($i, 0, '', '.'); $i =  floor($i);     $i = round($i,3).'k';}elseif($i >= 1000000) {      $i = number_format($i, 0, '', '.');      $i = round($i,3).'M'; }   else    {      $i = number_format($i, 0, '', '\'');  }    return $i;    }








/* Функция отфильтровки чисел */
function int($int)
{
	return abs(intval($int));
}
/* Функция защиты от нежелательных действий */
function protect($text)
{
	$text=str_replace('%','-%-',$text);
	return trim(mysql_real_escape_string(htmlspecialchars($text, ENT_QUOTES, 'utf-8')));
}

/* Проверка GET данных */
foreach ($_GET as $check_url)
{
    if (is_array($check_url) and !preg_match('#^(?:[a-z0-9_\-/]+|\.+(?!/))*$#i', $check_url))
    {
    	session_start();
        $_SESSION['note'] = 'ERROR 403. Недопустимый запрос!';
        header ("Location: ../index.php");
        exit;
    }
}
unset($check_url);

/* Время */
function clock($time)
{
global $user;
$timep= date("j M Y год H:i:s", $time);
$time_p[0]=date("j n Y", $time);
$time_p[1]=date("H:i:s", $time);
if ($time_p[0]==date("j n Y", time()))$timep='Сегодня  '.$time_p['1'];
if ($time_p[0]==date("j n Y", time()-86400))$timep='Вчера  '.$time_p['1'];
if ($time_p[0]==date("j n Y", time()-172800))$timep='Позавчера  '.$time_p['1'];
if ($time_p[0]==date("j n Y", time()-259200))$timep='3 дня назад  '.$time_p['1'];
if ($time_p[0]==date("j n Y", time()-604800))$timep='Неделю назад  '.$time_p['1'];
if ($time_p[0]==date("j n Y", time()-1209600))$timep='2 недели назад  '.$time_p['1'];
$months_eng = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$months_rus = array('Января','Февраля','Марта','Апреля','Мая','Июня','Июля','Августа','Сентября','Октября','Ноября','Декабря');
$timep = str_replace($months_eng,$months_rus,$timep);
return $timep;
}

/* Время */
function clock2($time)
{
global $user;
$timep= date("j:M:Y H:i:s", $time);
$time_p[0]=date("j:n:Y", $time);
$time_p[1]=date("H:i:s", $time);
if ($time_p[0]==date("j:n:Y", time()))$timep=''.$time_p['1'];
if ($time_p[0]==date("j:n:Y", time()-86400))$timep=''.$time_p['1'];
if ($time_p[0]==date("j:n:Y", time()-172800))$timep=''.$time_p['1'];
if ($time_p[0]==date("j:n:Y", time()-259200))$timep=''.$time_p['1'];
if ($time_p[0]==date("j:n:Y", time()-604800))$timep=''.$time_p['1'];
if ($time_p[0]==date("j:n:Y", time()-1209600))$timep=''.$time_p['1'];
$months_eng = array('01','02','03','04','05','06','07','08','09','10','11','12');
$months_rus = array('01','02','03','04','05','06','07','08','09','10','11','12');
$timep = str_replace($months_eng,$months_rus,$timep);
return $timep;
}

/* Функция постраничной навигации */
if($user['id']>0){
$page = isset($_GET['page']) ? int($_GET['page']) : 0; $i=0;
if($user['str'] != 0){
$set['str'] = $user['str'];
}
while($i<$page+$set['str'] or $i==0) $i = $i+100;
if($page+$set['str']>100) $pagefile = $page-$i+100;
else $pagefile = $page;

function pages($page, $total, $href, $num)
{
    echo '<div class="text">';
    if ($page) echo '<a class="page" href="'.$href.'page='.($page-$num).'"><center>&larr;</center></a> ';
    else echo '<span class="page">&larr;</span>';

    {  

    $minus = $page-($num*3);
    $plus = $page+($num*4);
    if($minus<$total && $minus>0) echo ' <a class="page" href="'.$href.'page=0">1</a> ... ';

    for($i=$minus; $i<$plus;)
    {
        if($i<$total && $i>=0)     {
            $ii = floor(1+$i/$num);
            if ($page==$i) echo ' <span class="page"><center>'.$ii.'</center></span>';
            else echo ' <a class="page" href="'.$href.'page='.$i.'"><center>'.$ii.'</center></a>';
        }
        $i=$i+$num;
    }
    if ($total > $page + $num)
    echo ' <a class="page" href="'.$href.'page='.($page + $num).'"><center>&rarr;</center></a>';
    else echo '&rarr;';
    if($plus<$total)    {
        $whole = ceil($total/$num);
        echo ' ... <a class="page" href="'.$href.'page='.($whole*$num-$num).'"><center>'.$whole.'</center></a>';
    }
  	if(isset($_GET['end'])){
	     $whole = ceil($total/$num);
	header('Location: '.$href.'&page='.($whole*$num-$num).'');}}
echo '</div>';}
}











/* Функция только для  НЕ зарегистрированных пользователей */
function unreg()
{
	global $user;
	if($user)
	{
		header("Location: ../index.php");
	}
}
/* Функция для зарегистрированных */
function reg(){
	global $user;
if(empty($user['login']) and empty($user['password'])){
header("Location: ../sign.php");
			exit;
	}
}
/* Функция для определения уровня пользователя */
function only_admin($level)
{
    global $user;
 	if (!isset($user) or $user['admins'] < $level)
	{
  		header("Location: ../index.php");exit;
	}
}

/* Функция безопасного шифрования в MD5 */
function md5_sault($text)
{
	return md5(md5('Game').md5(md5($text)));
}
if($user['id']>0){
	/*Время в игре*/
		
		
	
	
	
	





 



	
	
 



}
/* Функция отображения низа */
function foot(){
 global $user;
include 'foot.php';
}
function mesto($the){ return header('location: '.$the.'');}







$bili = $user['regen'] + $user['health'];
	$prov = abs(intval(31)) + TIME;
if($user['dobav']>=1 AND $user['am1_time'] <= $prov){ $dbc->query('UPDATE `users` SET `strength` =`strength`-"'.$user['dobav'].'",`dobav`=0 WHERE `id` = "' . $user['id'] . '"');}

	$unti = abs(intval(5)) + TIME;
        if($user['health']< $user['max_health'] AND $user['time_a'] < time()) {
if($bili>= $user['max_health']){
$dbc->query("update `users` set `time_a` = ".$unti.",`health`='".$user['max_health']."' where id = '".$user['id']."'");}else{$dbc->query("update `users` set `time_a` = ".$unti.",`health`=`health`+'".$user['regen']."' where id = '".$user['id']."'");}}


$ab = $user['daytovip'] -time();
if(Sec2Time($ab) == 0 and $user['vip']==1){
$dbc->query("update `users` set `vip` = '0' where id = '".$user['id']."'");

}
function am_off(){ global $user; if($user['dobav']>=1){ $dbc->query('UPDATE `users` SET `strength` =`strength`-"'.$user['dobav'].'",`dobav`=0 WHERE `id` = "' . $user['id'] . '"');} }
function err($text) {
$_SESSION['err']="<center><font color=red>$text</font></center>";


header('location:?');exit; }
?>