<?
if(isset($_GET['mygarden']) && isset($_GET['sell_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` != '0' AND `time`<'$time'"),0)!=0)
{
$qyeru=mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` != '0' AND `time`<'$time'");
$money_sess=0;
WHILE($sad=mysql_fetch_array($qyeru)){
$recipes=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '$sad[id_tree]'"));
if($sad['time']<=$time)
{
/*
if($recipes['id']==$gos['id_recipes'] && isset($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_school_act=0;
$rat_kulinary_act=0;
$rat_lib_act=0;
if(isset($sc_act))$rat_sc_act=$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_kulinary_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;
$count=$recipes['count'];
$count_harvester2_act=0;
$count_yastreb_act=0;
if(isset($yastreb_act))$count_yastreb_act=(($count/100)*300);
$count=$count_harvester2_act+$count_yastreb_act+$count;
$money=($count*$recipes['money']);
mysql_query("UPDATE `kolhoz_sad` SET `time` = '$time'+'$recipes[time]', `time_soil` = '$time'+'120', `soil` = '0', `plug` = '1' WHERE `id` = '$sad[id]' LIMIT 1");
$_SESSION['km']=+1;
$_SESSION['rating']=$rat+$_SESSION['rating'];
$money_sess=$money_sess+$money;

//mysql_query("UPDATE `kolhoz_user` SET `cook_mas` = '".($ku['cook_mas']+1)."' WHERE `id` = '$ku[id]'");
}}

if($_SESSION['rating']>=1){mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$money_sess)."',`umoney` = '$money_sess',`rating` = '".($ku['rating']+$_SESSION['rating'])."' WHERE `id` = '$ku[id]'");

header("Location:/mygarden/".passgen());
}
}
//else {header("Location:/mygarden/".passgen());
//exit;}
?>