<?
if(isset($_GET['myfarm']) && isset($_GET['harvest_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant` != '0'"),0)!=0 && $ku['harvester']>0)
{
$q=mysql_query("SELECT * FROM `kolhoz_ground` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
if($plant['id']==$gos['id_plant'] && $mc)
{
$harv=(isset($harvester_act)?$harvester_act/100:0);
$hawk=(isset($yastreb_act)?3:0);
$exp=$plant['time_soil']+($plant['time_soil']*$harv)+($plant['time_soil']*$hawk);
if($gos['type']=='harvest')$exp=$exp*2;
mysql_query("INSERT INTO `kolhoz_collective_rating_gos` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$exp', `time` = '$time'");
}
$id=$plant[id]-4;
$labo=mysql_fetch_array(mysql_query("SELECT *  FROM `kolhoz_lab_m` WHERE `id_user` = '$ku[id]'"));
$count=($plant[count]/100)*$labo[$id]*5+$plant[count];
$count_harvester_act=0;
$count_yastreb_act=0;
$count_greenhouse_act=0;
$count_rusalka_act=0;
$count_poseidon_act=0;
$rat_acva_act=0;
if(isset($harvester_act))$count_harvester_act=floor(($count/100)*$harvester_act);
if(isset($yastreb_act))$count_yastreb_act=(($count/100)*300);
if(isset($rusalka_act))$count_rusalka_act=(($count/100)*500);
if(isset($poseidon_act))$count_poseidon_act=(($count/100)*1000);

if(isset($greenhouse_act))$count_greenhouse_act=(($count/100)*$greenhouse_ps);
if(isset($acva_act))$rat_acva_act=$rat*5;
if(isset($expcount))$count=$count*2;

$count=$count_harvester_act+$count_yastreb_act+$count+$count_greenhouse_act+$count_poseidon_act+$count_rusalka_act+$rat_acva_act;
$count=floor($count);

if($pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '0'")))
{
mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
if($plant['id_plant']==15)
mysql_query("UPDATE `kolhoz_user` SET `cvest1` = '".($ku['cvest1']+$ohv)."' WHERE `id` = '$ku[id]'");
if($plant['id_plant']==28)
mysql_query("UPDATE `kolhoz_user` SET `cvest2` = '".($ku['cvest2']+$ohv)."' WHERE `id` = '$ku[id]'");
}
else mysql_query("INSERT INTO `kolhoz_warehouse` SET `id_plant` = '$plant[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
mysql_query("UPDATE `kolhoz_ground` SET `id_plant` = '0', `soil` = '0', `cultivator` = '0' WHERE `id` = '$post[id]' LIMIT 1");
$ohv=$ohv+$count;
}
$rand=rand(1,10);
if($rand==1 || $rand==5  || $rand==20)
{
mysql_query("UPDATE `kolhoz_user` SET `almaz` = '".($ku['almaz']+1)."' WHERE `id` = '$ku[id]'");
}
$_SESSION['harvest']=$ohv;
mysql_query("UPDATE `kolhoz_user` SET `sadovod` = '".($ku['sadovod']+$ohv)."' WHERE `id` = '$ku[id]'");
header("Location:?myfarm&".passgen());
exit;
}
?>