<?

if($ku['id']==1)
{
error_reporting(E_ALL); // включаем показ ошибок
ini_set('display_errors',true); // включаем показ ошибок
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]'"),0)==0)
{
mysql_query("INSERT INTO `kolhoz_ground` (`id_user`,`cultivator`) VALUES ('$ku[id]','1'),('$ku[id]','1'),('$ku[id]','1'),('$ku[id]','1')");
//mysql_query("INSERT INTO `kolhoz_ground` SET `id_user` = '$ku[id]', `cultivator` = '1'");
header("Location:/myfarm/".passgen());
exit;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mest` WHERE `id_user` = '$ku[id]'"),0)<1 && $ku['level']>=15)
{
mysql_query("INSERT INTO `kolhoz_mest` SET `id_user` = '$ku[id]'");
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0)<4 && $ku['level']>=10)
{
mysql_query("INSERT INTO `kolhoz_petground` (`id_user`) VALUES ('$ku[id]'),('$ku[id]'),('$ku[id]'),('$ku[id]')");
//mysql_query("INSERT INTO `kolhoz_petground` SET `id_user` = '$ku[id]'");
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_garden` WHERE `id_user` = '$ku[id]'"),0)<4 && $ku['level']>=45)
{
mysql_query("INSERT INTO `kolhoz_garden` (`id_user`) VALUES ('$ku[id]'),('$ku[id]'),('$ku[id]'),('$ku[id]')");
//mysql_query("INSERT INTO `kolhoz_sad` SET `id_user` = '$ku[id]'");
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_pond` WHERE `id_user` = '$ku[id]'"),0)==0)
{
mysql_query("INSERT INTO `kolhoz_pond` (`id_user`,`cultivator`) VALUES ('$ku[id]','1'),('$ku[id]','1'),('$ku[id]','1'),('$ku[id]','1')");
//mysql_query("INSERT INTO `kolhoz_pond` SET `id_user` = '$ku[id]', `cultivator` = '1'");
}

//mysql_query("DELETE FROM `kolhoz_mail` WHERE `time` < '".($time-(3600*24*15))."'");

//mysql_query("DELETE FROM `kolhoz_warehouse` WHERE `count` = '0'");
//$tim2=microtime(1);
mysql_query("UPDATE `kolhoz_user` SET `date_last` = '$time' WHERE `id` = '$ku[id]' LIMIT 1");
//if($ku['id']==1)echo '<br/> #'.number_format(microtime(1)-$tim2,5).' сек. start#';
$activ=time()-$ku['date_last'];
if($activ < 240)
{
$newactiv=$ku['time']+$activ;
mysql_query("UPDATE `kolhoz_user` SET `time` ='$newactiv' WHERE `id` = '$ku[id]' LIMIT 1");
}
/*$tim2=microtime(1);
include_once 'inc/q_animals.php';
if($ku['id']==1)echo '<br/> '.number_format(microtime(1)-$tim2,5).' сек. start';*/
// Collective
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
$mcu=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_user` WHERE `id_user` = '$ku[id]'"));
$mc=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective` WHERE `id` = '$mcu[id_collective]'"));
$mc['next_level']=$mc['level']+1;
$mc['flowerbed_max']=$mc['level']*10;
$mc['users_max']=($mc['level']*5)+10+$mc['users_add'];
$mc['users']=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_collective` = '$mc[id]'"),0);
}

include_once 'inc/gos_start.php';
if($ku['expdouble']==NULL)
{
$rand=rand(1,7);
if($rand==1)$day='Mon';elseif($rand==2)$day='Tue';elseif($rand==3)$day='Wed';elseif($rand==4)$day='Thu';elseif($rand==5)$day='Fri';elseif($rand==6)$day='Sat';else $day='Sun';
mysql_query("UPDATE `kolhoz_user` SET `expdouble` = '$day' WHERE `id` = '$ku[id]'");
$ku['expdouble']=$day;
}
if($ku['expdouble']==date("D"))$dexp=1;
//$dexp=1;////////Двойной опыт
$dexp3=1;////////Тройной опыт
if($ku['action_time']>time()){$id_actio = mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_action` "));$id_action = $id_actio['id_action'];}
$ku['mdp']=md5($ku['password']);

if(isset($_GET['outlogin']) && hsc($_GET['outlogin'])==$ku['mdp'])
{
setcookie('log_id', '');
setcookie('pass', '');
unset($_SESSION['id_user']);
header("Location: http://$_SERVER[HTTP_HOST]");
exit;
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ban` WHERE `id_user` = '$ku[id]' AND `izg` = '1' LIMIT 1"),0)!=0 && (!isset($_GET['user']) || isset($_GET['user']) && $_GET['user']!=$ku['id'])){header("Location:/user-$ku[id]/bans");exit;}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ban` WHERE `id_user` = '$ku[id]' AND `time` > '$time' AND `izg` = '0' LIMIT 1"),0)!=0)$molchi=1;
$ban=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$ku[id]' AND `time` > '$time' AND `izg` = '0' ORDER BY `id` DESC LIMIT 1"));
$us_ban=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$ban[id_who]'"));

?>