<?php
#Файл конфигурации
#Автор FeST [ICQ 3452223]
#функции

 function sims_in($str)
    {
        $str = htmlentities(trim($str), ENT_QUOTES, 'UTF-8');
        $str = nl2br($str);
        $str = strtr($str, array(
                                chr(0) => '',
                                chr(1) => '',
                                chr(2) => '',
                                chr(3) => '',
                                chr(4) => '',
                                chr(5) => '',
                                chr(6) => '',
                                chr(7) => '',
                                chr(8) => '',
                                chr(9) => '',
                                chr(10) => '',
                                chr(11) => '',
                                chr(12) => '',
                                chr(13) => '',
                                chr(14) => '',
                                chr(15) => '',
                                chr(16) => '',
                                chr(17) => '',
                                chr(18) => '',
                                chr(19) => '',
                                chr(20) => '',
                                chr(21) => '',
                                chr(22) => '',
                                chr(23) => '',
                                chr(24) => '',
                                chr(25) => '',
                                chr(26) => '',
                                chr(27) => '',
                                chr(28) => '',
                                chr(29) => '',
                                chr(30) => '',
                                chr(31) => ''
                           ));
        $str = str_replace("'", "&#39;", $str);
        $str = str_replace('\\', "&#92;", $str);
        $str = str_replace("|", "I", $str);
        $str = str_replace("||", "I", $str);
        $str = str_replace("/\\\$/", "&#36;", $str);
        $str = mysql_real_escape_string($str);
        return $str;
    }

function sims_date($time=NULL)
{

if ($time==NULL)$time=time();
$timep="".date("j M Y в H:i", $time)."";
$time_p[0]=date("j n Y", $time);
$time_p[1]=date("H:i", $time);
if ($time_p[0]==date("j n Y"))$timep=date("H:i:s", $time);

if ($time_p[0]==date("j n Y"))$timep=date("H:i:s", $time);
if ($time_p[0]==date("j n Y", time()-60*60*24))$timep="Вчера в $time_p[1]";
$timep=str_replace("Jan","Янв",$timep);
$timep=str_replace("Feb","Фев",$timep);
$timep=str_replace("Mar","Марта",$timep);
$timep=str_replace("May","Мая",$timep);
$timep=str_replace("Apr","Апр",$timep);
$timep=str_replace("Jun","Июня",$timep);
$timep=str_replace("Jul","Июля",$timep);
$timep=str_replace("Aug","Авг",$timep);
$timep=str_replace("Sep","Сент",$timep);
$timep=str_replace("Oct","Окт",$timep);
$timep=str_replace("Nov","Ноября",$timep);
$timep=str_replace("Dec","Дек",$timep);
return $timep;
}

function sims_pagenav($base_url, $start, $max_value, $num_per_page) {
    ////////////////////////////////////////////////////////////
    // Функция постраничной навигации                         //
    ////////////////////////////////////////////////////////////
    // За основу взята аналогичная функция от форума SMF2.0   //
    ////////////////////////////////////////////////////////////
    $pgcont = 4;
    $pgcont = (int)($pgcont - ($pgcont % 2)) / 2;
    if ($start >= $max_value)
        $start = max(0, (int)$max_value - (((int)$max_value % (int)$num_per_page) == 0 ? $num_per_page : ((int)$max_value % (int)$num_per_page)));
    else
        $start = max(0, (int)$start - ((int)$start % (int)$num_per_page));
    $base_link = '<a class="navpg" href="' . strtr($base_url, array ('%' => '%%')) . 'start=%d' . '">%s</a> ';
    $pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '&lt;-');
    if ($start > $num_per_page * $pgcont)
        $pageindex .= sprintf($base_link, 0, '1');
    if ($start > $num_per_page * ($pgcont + 1))
        $pageindex .= '<span style="font-weight: bold;"> ... </span>';
    for ($nCont = $pgcont; $nCont >= 1; $nCont--)
        if ($start >= $num_per_page * $nCont) {
            $tmpStart = $start - $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    $pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
    $tmpMaxPages = (int)(($max_value - 1) / $num_per_page) * $num_per_page;
    for ($nCont = 1; $nCont <= $pgcont; $nCont++)
        if ($start + $num_per_page * $nCont <= $tmpMaxPages) {
            $tmpStart = $start + $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
        $pageindex .= '<span style="font-weight: bold;"> ... </span>';
    if ($start + $num_per_page * $pgcont < $tmpMaxPages)
        $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
    if ($start + $num_per_page < $max_value) {
        $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
        $pageindex .= sprintf($base_link, $display_page, '-&gt;');
    }
    return $pageindex;
}

function sims_timer($timediff){

$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
if($hourfield>0)$hourfield="$hourfield часов";else$hourfield='';
$time_1="$hourfield $minutefield минут $secondfield секунд";
return $time_1;
}
function sims_msg($div,$txt){
echo "<div class='".$div."'>".$txt."</div>";
}
function sims_ret($div,$txt,$link){
echo "<div class='".$div."'><img src='i/ret.png' /> <a href='".$link."'>".$txt."</a></div>";
}



$user_id=$user['id'];
$user_login=$user['nick'];

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `sims_user` WHERE `id_u`='".$user_id."'"),0)==0 && $_SERVER['PHP_SELF']!='/sims/new.php'){

header("Location:new.php");
exit;
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `sims_user` WHERE `id_u`='".$user_id."'"),0)!=0 && $_SERVER['PHP_SELF']=='/sims/new.php'){

header("Location:index.php");
exit;
}



$diz=array('a'=>'sims_a','main'=>'sims_main','title2'=>'cat_title2','title'=>'cat_title','msg'=>'sims_msg','ret'=>'sims_ret','post_1'=>'sims_post_1','post_2'=>'sims_post_2','err'=>'cat_err');
?>
<style type="text/css">
.sims_main { background-color:#fff;color:#000; padding:3px;}
.cat_main {background:#2167AF; color:#ffffff;}
.cat_title2 {background: #0090C4;padding: 4px 2px;border: 1px solid #fff;}
.sims_post_1 {background: #5572B4;padding: 4px 2px;border: 1px solid #5363A0;color:#fff}
.sims_post_1 a{color:#fff;}
.sims_post_2 {background: #7996E1;padding: 4px 2px;border-top: 1px solid #5363A0;color:#fff}
.sims_post_2 a{color:#fff;}
.sims_msg {background: #0090C4;color:#fff;padding: 4px 2px;border: 1px solid #fff;}
.sims_ret {background: #0090C4;padding: 4px 2px;border-bottom: 1px solid #fff;}
.sims_ret a{color:#fff;}
</style>
<?

$page = isset ($_REQUEST['page']) && $_REQUEST['page'] > 0 ? intval($_REQUEST['page']) : 1;
$start = isset ($_GET['start']) ? abs(intval($_GET['start'])) : 0;

$start = isset ($_REQUEST['page']) ? $page * $kmess - $kmess : $start;

if(isset($_GET['place']))
{	
	$array = sims_in($_GET['place']);
	$array2 = array('kitchen','guest','room','toilet');
	if(in_array($array,$array2) && mysql_result(mysql_query("SELECT COUNT(*) FROM `sims_user` WHERE `id_u`='".$user_id."'"),0)!=0)
	{

	mysql_query("UPDATE `sims_user` SET `place`='".$array."' WHERE `id_u`='".$user_id."'");

	}


}
function get_file_type_sims($file,$arrays){
	$arr=explode(';',$arrays);
	$count=count($arr);
	$isset=0;
		for($i=0;$i<$count;$i++){
		if($arr[$i]==$file && $arr[$i]!='')
		$isset++;
		}
	if($isset!=0)
	return true;
	else
	return false;
	}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `sims_user` WHERE `id_u`='".$user_id."'"),0)!=0)
{
	include_once 'Sims.class.php';
	$sims = new Sims;
	$sims->id = $user_id;
	if($_SESSION['sims_time'] == 0)$_SESSION['sims_time'] = time();
	$sims_user = mysql_fetch_array(mysql_query("SELECT * FROM `sims_user` WHERE `id_u`='".$user_id."'"));
	mysql_query("UPDATE `sims_user` SET `last_visit`='".time()."',`in_game`=`in_game`+".(time()-$_SESSION['sims_time'])." WHERE `id_u`='".$user_id."'");
	$_SESSION['sims_time'] = time();
	$sims->life();
	}
function sims_translit2($name)
{
	
	switch($name)
	{
	
		case'culinaria':
		return 'Кулинария';
		break;
		case'medicina':
		return 'Медицина';
		break;
		case'tehnika':
		return 'Техника';
		break;
		case'obayanie':
		return 'Обаяние';
		break;
		case'culture':
		return 'Культура тела';
		break;
		case'logika':
		return 'Логика';
		break;
		case'tvorchesto':
		return 'Творчество';
		break;
		case'uborka':
		return 'Уборка';
		break;
		
	}
}

function sims_translit($name)
{
	
	switch($name)
	{
	
		case'bed':
		return 'Отдых';
		break;
		case'cabinet':
		return 'Использование';
		break;
		case'chair':
		return 'Отдых';
		break;
		case'enter':
		return 'Развлечение';
		break;
		case'chair':
		return 'Отдых';
		break;
		case'divan':
		return 'Отдых';
		break;
		case'jac':
		return 'Использование';
		break;
		case'ykr':
		return 'Использование';
		break;
		case'bit':
		return 'Использование';
		break;
	case'osv':
		return 'Использование';
		break;
	case'polki':
		return 'Использование';
		break;
	case'dush':
		return 'Использование';
		break;
	case'tumb':
		return 'Использование';
		break;
	case'stol':
		return 'Использование';
		break;
	case'teh':
		return 'Использование';
		break;
	case'toilet':
		return 'Использование';
		break;
	case'moi':
		return 'Использование';
		break;
	}
}

if(isset($_GET['end']))
{
	
	mysql_query("UPDATE `sims_user` SET `last_id`='0',`last_update`='0' WHERE `id_u`='".$user_id."'");

	header("Location:house.php");
	exit;

}
function sims_color($value)
{
if($value>80)$color='#AFEA00';
elseif($value<81 && $value>30)$color='#FF9900';
else $color='#D20000';

$msg = "<span style='color:".$color."'>$value</span>";
return $msg;
}
function sims_get_skill($skill)
{
	switch($skill)
	{
	case'k':
	return 'culinaria';
	break;
case't':
	return 'tehnika';
	break;
case'o':
	return 'obayanie';
	break;
case'c':
	return 'culture';
	break;
case'l':
	return 'logika';
	break;
case'te':
	return 'tvorchesto';
	break;
case'y':
	return 'uborka';
	break;
	}

}
if(isset($sims_user))
{	
  

  

	$array_skill = array('0'=>'23','1'=>'60','2'=>'151','3'=>'377','4'=>'937','5'=>'2325','6'=>'5768','7'=>'14308','8'=>'35485','9'=>'88006');
	
		$exp_skill = $sims_user['tehnika'];
		$level_skill = $sims_user['tehnika_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `tehnika_level`=`tehnika_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['obayanie'];
		$level_skill = $sims_user['obayanie_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `obayanie_level`=`obayanie_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['culture'];
		$level_skill = $sims_user['culture_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `culture_level`=`culture_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['logika'];
		$level_skill = $sims_user['logika_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `logika_level`=`logika_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['medicina'];
		$level_skill = $sims_user['medicina_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `medicina_level`=`medicinaa_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['tvorchesto'];
		$level_skill = $sims_user['tvorchesto_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `tvorchesto_level`=`tvorchesto_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['uborka'];
		$level_skill = $sims_user['uborka_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `uborka_level`=`uborka_level`+1 WHERE `id_u`='".$user_id."'");
		$exp_skill = $sims_user['culinaria'];
		$level_skill = $sims_user['culinaria_level'];
	if($array_skill[$level_skill]<$exp_skill)
	mysql_query("UPDATE `sims_user` SET `culinaria_level`=`culinaria_level`+1 WHERE `id_u`='".$user_id."'");
	

		
	if($sims_user['ybor_time']!=0)
	{
		
		if($sims_user['ybor_update']<(time()-60*3))
		{
		$gig = (($sims_user['gigiena']+1)<100 ? $sims_user['gigiena']+1 : 100);
		mysql_query("UPDATE `sims_user` SET `ybor_update`='".time()."',`gigiena`='".$gig."' WHERE `id_u`='".$user_id."'");
		}
	
	}	
	if($sims_user['gor_time']!=0)
	{
		
		if($sims_user['gor_update']<(time()-60*3))
		{
		$gig = (($sims_user['gigiena']+1)<100 ? $sims_user['gigiena']+1 : 100);
		$p = (($sims_user['culinar']+1)<100 ? $sims_user['culinar']+1 : 100);
		mysql_query("UPDATE `sims_user` SET `gor_update`='".time()."',`gigiena`='".$gig."',`culinar`='".$p."' WHERE `id_u`='".$user_id."'");
		}
	
	}	
	if($sims_user['dvor_time']!=0)
	{
		
		if($sims_user['dvor_update']<(time()-60*3))
		{
		$gig = (($sims_user['gigiena']+1)<100 ? $sims_user['gigiena']+1 : 100);
			$p = (($sims_user['culinar']+1)<100 ? $sims_user['culinar']+1 : 100);
				$d = (($sims_user['dosug']+1)<100 ? $sims_user['dosug']+1 : 100);
		mysql_query("UPDATE `sims_user` SET `dvor_update`='".time()."',`gigiena`='".$gig."',`culinar`='".$p."',`dosug`='".$d."' WHERE `id_u`='".$user_id."'");
		}
	
	}
$repair_item = mysql_result(mysql_query("SELECT COUNT(*) FROM `sims_i` WHERE `id_u`='".$user_id."' AND `iznos`>='100'"),0);
	
	if($repair_item!=0)
	{
		mysql_query("DELETE FROM `sims_i` WHERE `iznos`>='100' AND `id_u`='".$user_id."'");
	
	}
	
}
?>
