<?php
//Грядки
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_ground` WHERE `id_user` = '$ku[id]'" ), 0 ) == 0 )
		{
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_ground` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_ground` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_ground` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_ground` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				header( "Location:?myfarm&" . passgen() );
				exit;
		}
//Загоны
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_petground` WHERE `id_user` = '$ku[id]'" ), 0 ) < 4 && $ku[ 'level' ] >= 10 )
		{
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_petground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_petground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_petground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_petground` SET `id_user` = '$ku[id]'" );
		}
//Пруды
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_pond` WHERE `id_user` = '$ku[id]'" ), 0 ) == 0 )
		{
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_pond` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_pond` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_pond` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_pond` SET `id_user` = '$ku[id]', `cultivator` = '1'" );
		}
//Сад
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_treeground` WHERE `id_user` = '$ku[id]'" ), 0 ) == 0 )
		{
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_treeground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_treeground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_treeground` SET `id_user` = '$ku[id]'" );
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_treeground` SET `id_user` = '$ku[id]'" );
		}
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_mest` WHERE `id_user` = '$ku[id]'" ), 0 ) < 1 && $ku[ 'level' ] >= 1 )
		{
				mysql_query( "INSERT INTO `$db_base`.`kolhoz_mest` SET `id_user` = '$ku[id]'" );
		}
if ( empty( $ku[ 'ikonka' ] ) )
		{
				$ku[ 'ikonka' ] = 2;
		}
mysql_query( "DELETE FROM `$db_base`.`kolhoz_mail` WHERE `time` < '" . ( $time - ( 3600 * 24 * 30 ) ) . "'" );
mysql_query( "DELETE FROM `$db_base`.`kolhoz_warehouse` WHERE `count` = '0'" );
mysql_query( "UPDATE `$db_base`.`kolhoz_user` SET `date_last` = '$time' WHERE `id` = '$ku[id]' LIMIT 1" );
$timeactiv = $time - $ku[ 'date_last' ];
if ( $timeactiv < 120 )
		{
				$newtimeactiv = $ku[ 'time' ] + $timeactiv;
				mysql_query( "UPDATE `$db_base`.`kolhoz_user` SET `time` ='$newtimeactiv' WHERE `id` = '$ku[id]' LIMIT 1" );
		}
//Загоны
$q = mysql_query( "SELECT * FROM `$db_base`.`kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'" );
while ( $post = mysql_fetch_array( $q ) )
		{
				if ( $post[ 'time' ] >= $time )
						{
								$nt = $time - $post[ 'last_rf' ];
						}
				else
						{
								$nt = $post[ 'time' ] - $post[ 'last_rf' ];
						}
				if ( $nt < 0 )
								$nt = 0;
				mysql_query( "UPDATE `$db_base`.`kolhoz_petground` SET `time_money2` = '" . ( $post[ 'time_money2' ] + $nt ) . "', `last_rf` = '$time' WHERE `id` = '$post[id]'" );
		}
// Collective
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`kolhoz_collective_user` WHERE `id_user` = '$ku[id]'" ), 0 ) != 0 )
		{
				$mcu                   = mysql_fetch_array( mysql_query( "SELECT * FROM `$db_base`.`kolhoz_collective_user` WHERE `id_user` = '$ku[id]'" ) );
				$mc                    = mysql_fetch_array( mysql_query( "SELECT * FROM `$db_base`.`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 `$db_base`.`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 `$db_base`.`kolhoz_user` SET `expdouble` = '$day' WHERE `id` = '$ku[id]'" );
				$ku[ 'expdouble' ] = $day;
		}
//Двойной опыт
if ( $ku[ 'expdouble' ] == date( "D" ) )
				$dexp = 1;
//БАН
if ( mysql_result( mysql_query( "SELECT COUNT(*) FROM `$db_base`.`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 `$db_base`.`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 `$db_base`.`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 `$db_base`.`kolhoz_user` WHERE `id` = '$ban[id_who]'" ) );
?>