<?error_reporting(E_ALL^E_NOTICE);
if($ku['worker1_time']<=$time)
{
mysql_query("UPDATE `kolhoz_user` SET `worker1_time` = '',`worker1`='' WHERE `id` = '$ku[id]' LIMIT 1");
}
else
{
if($ku['worker1']==1)
{
$namew='Дарья';$clean=1;$sell=1;$put=1;$clean2=1;$sell2=1;$put2=1;
}

if(isset($clean) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND `id_recipes` = '0' AND (`time` = '$time' OR `time` < '$time') AND `clean` = '0'"),0)!=0)
{
$rat=1;
$rat_drakon_act=0;
$rat_sc_act=0;
$rat_school_act=0;
$rat_lib_act=0;
$rat_vetruk=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($vetruk))$rat_vetruk=$rat+$rat*2;
if(isset($drakon_act))$rat_drakon_act=((2/100)*300);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_vetruk+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;
$orat=0;
$q=mysql_query("SELECT * FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND `id_recipes` = '0' AND (`time` = '$time' OR `time` < '$time') AND `clean` = '0'");

while($post=mysql_fetch_array($q))
{
mysql_query("UPDATE `kolhoz_polka` SET `clean` = '1' WHERE `id` = '$post[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
$orat=$rat+$orat;
}
$_SESSION['rating']=$orat;
update_mc($orat);
}

if(isset($sell) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_recipes` != '0'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_recipes` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$recipes=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_recipes` WHERE `id` = '$post[id_recipes]'"));
if($recipes['id']==$gos['id_recipes'] && $mc)
{
$harv=(isset($harvester2_act)?$harvester2_act/100:0);
$hawk=(isset($yastreb2_act)?3:0);
$exp=$recipes['time_soil']+($recipes['time_soil']*$harv)+($recipes['time_soil']*$hawk);
if($gos['type']=='harvest2')$exp=$exp*2;
mysql_query("INSERT INTO `kolhoz_collective_rating_gos` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$exp', `time` = '$time'");
}
$rat=$recipes['rating'];
$rat_sc_act=0;
$rat_drakon_act=0;
$rat_kulinary_act=0;
$rat_school_act=0;
$rat_lib_act=0;
$rat_vetruk=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($vetruk))$rat_vetruk=$rat+$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($recipes['rating']/100)*300);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat*2;
if(isset($kulinary_act))$rat_kulinary_act=($rat/100)*$kulinary_ps_r;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_vetruk+$rat_kulinary_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;
$orat=$rat+$orat;
$count=$recipes['count'];
$count=$count_harvester2_act+$count_yastreb2_act+$count+$count_greenhouse_act;
$money=($ohv*$recipes['money']);
mysql_query("UPDATE `kolhoz_polka` SET `id_recipes` = '0', `soil` = '0', `clean` = '0' WHERE `id` = '".intval($_GET['sell_all'])."' LIMIT 1");
{
}
mysql_query("UPDATE `kolhoz_polka` SET `id_recipes` = '0', `soil` = '0', `clean` = '0' WHERE `id` = '$post[id]' LIMIT 1");
$ohv=$ohv+$count;
}
$_SESSION['km']=$ohv;
$_SESSION['mon']=$money;
$_SESSION['rating']=$orat;
mysql_query("UPDATE `kolhoz_user` SET `cook_mas` = '".($ku['cook_mas']+$ohv)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$money)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_polka` SET `id_recipes` = '0', `soil` = '0', `clean` = '0' WHERE `id` = '".intval($_GET['sell_all'])."' LIMIT 1");
}

if(isset($put) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND `id_recipes` = '0' AND `clean` = '1'"),0)!=0)
{
if($ku['last_recipes']!=0)
{
$recipes=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_recipes` WHERE `id` = '$ku[last_recipes]'"));
$cg=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND `id_recipes` = '0'"),0);
$mon=($recipes['cena']/100)*$seeder2_act_skid;
$money=floor($recipes['cena']-$mon);
$sc=$money*$cg;
$rat_sc_act=0;

if($gos['id_recipes']==$recipes['id'] && $gos['type']=='rating' && isset($mc))$rat=$rat*2;
if($ku['money']>=$sc)
{
$q=mysql_query("SELECT * FROM `kolhoz_polka` WHERE `id_user` = '$ku[id]' AND `id_recipes` = '0' AND `clean` = '1'");
$orat=0;
while($post=mysql_fetch_array($q))
{
$orat=$rat+$orat;
mysql_query("UPDATE `kolhoz_polka` SET `id_recipes` = '$recipes[id]', `time_soil` = '".($time+$recipes['time_soil'])."', `time_water` = '".($time+120)."', `soil` = '0', `time` = '".($recipes['time']+$time)."' WHERE `id` = '$post[id]' LIMIT 1");
}
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']-$sc)."' WHERE `id` = '$ku[id]'");
update_mc($orat);
}
else
{
$_SESSION['no_money']=$sc-$ku['money'];
}
}
}


//Рубиновый погреб
if($ku['time_key']>$time)
{
if(isset($put2) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant2` != '0'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant2` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));
if($plant2['id']==$gos['id_plant2'] && $mc)
{
$harv=(isset($harvester2_act)?$harvester2_act/100:0);
$hawk=(isset($yastreb2_act)?3:0);
$exp=$plant2['time_soil2']+($plant2['time_soil2']*$harv)+($plant2['time_soil2']*$hawk);
if($gos['type']=='harvest2')$exp=$exp*2;
mysql_query("INSERT INTO `kolhoz_collective_rating_gos` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$exp', `time` = '$time'");
}
$count=$plant2['count'];
$count_harvester2_act=0;
$count_yastreb2_act=0;
$count_greenhouse_act=0;
if(isset($harvester2_act))$count_harvester2_act=floor(($count/100)*$harvester2_act);
if(isset($yastreb2_act))$count_yastreb2_act=(($count/100)*300);
if(isset($greenhouse_act))$count_greenhouse_act=(($count/100)*$greenhouse_ps);
$count=$count_harvester2_act+$count_yastreb2_act+$count+$count_greenhouse_act;
$count=floor($count);

if($pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '$plant2[id]' AND `arena` = '0'")))
{
mysql_query("UPDATE `kolhoz_market` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_market` SET `id_plant2` = '$plant2[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
mysql_query("UPDATE `kolhoz_polka2` SET `id_plant2` = '0', `soil2` = '0', `cultivator2` = '0' WHERE `id` = '$post[id]' LIMIT 1");
$ohv=$ohv+$count;
}
$_SESSION['harvest2']=$ohv;
mysql_query("UPDATE `kolhoz_user` SET `sadovod` = '".($ku['sadovod']+$ohv)."' WHERE `id` = '$ku[id]'");
}

if(isset($clean2) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND (`time` = '$time' OR `time` < '$time') AND `cultivator2` = '0'"),0)!=0)
{
$rat=1;
$rat_drakon_act=0;
$rat_sc_act=0;
$rat_lib_act=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
$rat_cultivator2_act=(($rat/100)*$cultivator2_act);
if(isset($drakon_act))$rat_drakon_act=((2/100)*300);
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel2_act))$rat_cultivator2_act=$rat_cultivator2_act*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_cultivator2_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;
$orat=0;
$q=mysql_query("SELECT * FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND (`time` = '$time' OR `time` < '$time') AND `cultivator2` = '0'");
while($post=mysql_fetch_array($q))
{
mysql_query("UPDATE `kolhoz_polka2` SET `cultivator2` = '1' WHERE `id` = '$post[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
$orat=$rat+$orat;
}
$_SESSION['rating']=$orat;
update_mc($orat);
}

if(isset($sell2) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND `cultivator2` = '1'"),0)!=0)
{
if($ku['last_plant2']!=0)
{
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$ku[last_plant2]'"));
$cg=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0'"),0);
$mon=($plant2['cena']/100)*$seeder2_act_skid;
$rubies=floor($plant2['cena']-$mon);
$sc=$rubies*$cg;
$rat=$plant2['rating'];
$rat_sc_act=0;
$rat_drakon_act=0;
$rat_seeder2_act=0;
$rat_school_act=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($plant2['rating']/100)*300);
if(isset($seeder2_act))$rat_seeder2_act=(($rat/100)*$seeder2_act);
if(isset($school_act))$rat_school_act=$rat/2;
if(isset($shmel_act))$rat_seeder2_act=$rat_seeder2_act*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_seeder2_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

if($gos['id_plant2']==$plant2['id'] && $gos['type']=='rating' && isset($mc))$rat=$rat*2;
if($ku['rubies']>=$sc)
{
$q=mysql_query("SELECT * FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND `cultivator2` = '1'");
$orat=0;
while($post=mysql_fetch_array($q))
{
$orat=$rat+$orat;
mysql_query("UPDATE `kolhoz_polka2` SET `id_plant2` = '$plant2[id]', `time_soil2` = '".($time+$plant2['time_soil2'])."', `time_water2` = '".($time+120)."', `soil2` = '0', `time` = '".($plant2['time']+$time)."' WHERE `id` = '$post[id]' LIMIT 1");
}
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']-$sc)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
update_mc($orat);
$_SESSION['rating']=$orat;
}
else
{
$_SESSION['no_rubies']=$sc-$ku['rubies'];
}
}
}
}

}
?>