<?
$time=time();
include_once '../inc/start_sess.php';
$x=mysql_query("SELECT * FROM `kolhoz_user` WHERE `gard` = '4' AND `gard_time` = '$time' ");
while($ku=mysql_fetch_array($x))
{
include_once '../inc/functions.php';
include_once '../inc/tehnika.php';
/////вскопать//////
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` = '0' AND (`time` = '$time' OR `time` < '$time') AND `plug` = '0'"),0)!=0)
{
$rat=5;
$rat_drakon_act=0;
$rat_sc_act=0;
$rat_lib_act=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
$rat_cultivator_act=(($rat/100)*$cultivator_act);
if(isset($drakon_act))$rat_drakon_act=((2/100)*300);
if(isset($lib_act))$rat_lib_act=$rat*2;
if(isset($shmel_act))$rat_cultivator_act=$rat_cultivator_act*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_cultivator_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_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` = '0' AND (`time` = '$time' OR `time` < '$time') AND `plug` = '0'");
while($post=mysql_fetch_array($q))
{
mysql_query("UPDATE `kolhoz_sad` SET `plug` = '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(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` = '0' AND `plug` = '1'"),0)!=0)
{
$tree=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '$ku[last_tree]'"));
$cg=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` = '0'"),0);
$mon=($tree['cena']/100)*$seeder_act_skid;
$money=floor($tree['cena']-$mon);
$sc=$money*$cg;
$rat=$tree['rating'];
$rat_sc_act=0;
$rat_drakon_act=0;
$rat_seeder_act=0;
$rat_school_act=0;
$rat_lib_act=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($tree['rating']/100)*300);
if(isset($seeder_act))$rat_seeder_act=(($rat/100)*$seeder_act);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat*2;
if(isset($shmel_act))$rat_seeder_act=$rat_seeder_act*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_seeder_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

if($gos['id_tree']==$tree['id'] && $gos['type']=='rating' && isset($mc))$rat=$rat*2;
if($ku['money']>=$sc)
{
$q=mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` = '0' AND `plug` = '1'");
$orat=0;
while($post=mysql_fetch_array($q))
{
$orat=$rat+$orat;
mysql_query("UPDATE `kolhoz_sad` SET `id_tree` = '$tree[id]', `time_soil` = '".($time+$tree['time_soil'])."', `time_sbor` = '".($time+1800)."', `soil` = '0', `time` = '".($tree['time']+$time)."' WHERE `id` = '$post[id]' LIMIT 1");
}
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']-$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_money']=$sc-$ku['money'];
}
}

////////полить///////
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `id_tree` != '0' AND (`time_sbor` = '$time' OR `time_sbor` < '$time') AND `time` > '$time' AND (`soil` = '0' AND `time_soil` > '$time' OR `soil` = '1')"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND (`time_sbor` < '$time' OR `time_sbor` = '$time') AND `id_tree` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$tree=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '$post[id_tree]'"));
$nt=2925;
$rat=10;
$rat_hp_act=0; //гидра
$rat_mc_hp_act=0; //ороситель
$rat_sc_act=0; //пугало
$rat_drakon_act=0; //дракон
$rat_irregate_act=0; //оПроситель
$rat_school_act=0; //школа
$rat_lib_act=0;
if(isset($hp_act))$rat_hp_act=(($rat/100)*$hp_ps);
if(isset($mc_hp_act))$rat_mc_hp_act=(($rat/100)*$mc_hp_ps);
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($irregate_act))$rat_irregate_act=(($rat/100)*$irregate_act);
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_irregate_act=$rat_irregate_act*2;
if(isset($shmel_act))$rat_hp_act=$rat_hp_act*2;
$ratt=$rat_hp_act+$rat_sc_act+$rat_drakon_act+$rat_irregate_act+$rat_mc_hp_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;
$count=$tree['count'];
$count_harvester_act=0;
$count_yastreb_act=0;
$count_greenhouse_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($greenhouse_act))$count_greenhouse_act=(($count/100)*$greenhouse_ps);
$count=$count_harvester_act+$count_yastreb_act+$count+$count_greenhouse_act;
$count=floor($count);
$ntt=15*60;
$ntt_hp_act=0;
$ntt_mc_hp_act=0;
if(isset($hp_act))$ntt_hp_act=(($ntt/100)*$hp_ps);
if(isset($mc_hp_act))$ntt_mc_hp_act=(($ntt/100)*$mc_hp_ps);
$ntt=$ntt_hp_act+$ntt_mc_hp_act;
if(isset($irregate_act))
if($pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_mmarket` WHERE `id_user` = '$ku[id]' AND `id_tree` = '$tree[id]' AND `arena` = '0'")))
{
mysql_query("UPDATE `kolhoz_mmarket` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
$nt=$nt-($irregate_act_mnp*30);
$ntt=$ntt+($irregate_act_m*60);
}
else mysql_query("INSERT INTO `kolhoz_mmarket` SET `id_tree` = '$tree[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
mysql_query("UPDATE `kolhoz_sad` SET `time_sbor` = '".($time+$nt)."', `time` = '".($post['time']-$ntt)."' WHERE `id` = '$post[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_journal` SET `works` = 'собрал плоды в амбар', `id_user` = '$ku[id]', `garden` = 'Дмитрий', `time` = '$time'");
$ohv=$ohv+$count;
}
$_SESSION['rating']=$rat;
$_SESSION['harvest']=$count;
update_mc($rat);
}
//////////удобрить///////////
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `soil` = '0' AND (`time_soil` = '$time' OR `time_soil` < '$time') AND `id_tree` != '0' AND `time` > '$time'"),0)!=0)
{
$soil=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_soil` WHERE `id` = '$ku[last_soil3]'"));
$cg=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `soil` = '0' AND (`time_soil` = '$time' OR `time_soil` < '$time') AND `id_tree` != '0' AND `time` > '$time'"),0);
$sc=$cg*$soil['cena'];
if($ku['money']>=$sc)
{
$rat=$soil['rating'];
$rat_sc_act=0;
$rat_hp_act=0;
$rat_mc_hp_act=0;
$rat_drakon_act=0;
$rat_school_act=0;
$rat_lib_act=0;
if(isset($hp_act))$rat_hp_act=(($rat/100)*$hp_ps);
if(isset($mc_hp_act))$rat_mc_hp_act=(($rat/100)*$mc_hp_ps);
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_soiler_act=$rat_soiler_act*2;
if(isset($shmel_act))$rat_hp_act=$rat_hp_act*2;
$ratt=$rat_mc_hp_act+$rat_sc_act+$rat_hp_act+$rat_drakon_act+$rat_soiler_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

$st=$soil['time'];
$st_hp_act=0;
$st_mc_hp_act=0;
$st_soiler_act=0;
if(isset($hp_act))$st_hp_act=($st/100)*$hp_ps;
if(isset($mc_hp_act))$st_mc_hp_act=($st/100)*$mc_hp_ps;
if($soiler_act)$st_soiler_act=($st/100)*$soiler_act;
$st=$st_hp_act+$st_soiler_act+$st+$st_mc_hp_act;

$q=mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND `soil` = '0' AND (`time_soil` = '$time' OR `time_soil` < '$time') AND `id_tree` != '0' AND `time` > '$time'");
$orat=0;
$vc=0;
while($post=mysql_fetch_array($q))
{
$orat=$orat+$rat;
mysql_query("UPDATE `kolhoz_sad` SET `time` = '".($post['time']-$st)."', `soil` = '1' WHERE `id` = '$post[id]' LIMIT 1");
$vc=$vc+1;
}
mysql_query("UPDATE `kolhoz_user` SET `agronom` = '".($ku['agronom']+$vc)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']-$sc)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$orat;
update_mc($orat);
}
else 
$_SESSION['no_money']=$sc-$ku['money'];
}
/////////собрать//////////
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_tree` != '0'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_tree` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$tree=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '$post[id_tree]'"));
if($tree['id']==$gos['id_tree'] && $mc)
{
$harv=(isset($harvester2_act)?$harvester2_act/100:0);
$hawk=(isset($yastreb2_act)?3:0);
$exp=$tree['time_soil']+($tree['time_soil']*$harv)+($tree['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'");
}
$count=$tree['count'];
$count=$count_harvester2_act+$count_yastreb2_act+$count+$count_greenhouse_act;
$money=($ohv*$tree['money']);
mysql_query("UPDATE `kolhoz_sad` SET `id_tree` = '0', `soil` = '0', `plug` = '0' WHERE `id` = '".intval($_GET['sbor_all'])."' LIMIT 1");
{
}
mysql_query("UPDATE `kolhoz_sad` SET `id_tree` = '0', `soil` = '0', `plug` = '0' WHERE `id` = '$post[id]' LIMIT 1");
$ohv=$ohv+$count;
}
$_SESSION['mon']=$money;
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$money)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_sad` SET `id_tree` = '0', `soil` = '0', `plug` = '0' WHERE `id` = '".intval($_GET['sbor_all'])."' LIMIT 1");
}
}
?>