<?php

if(isset($_GET['add_ok']))msg('Грядка приобретена!');
if(isset($_GET['udobr_ok']))msg('Растение удобрено!');
if(isset($_GET['add_no']))echo '<div class="err">Ваш уровень должен быть больше 5!</div>';
if(isset($_GET['gr_add']) && $user['fermer_money']>=5000)
{
if($user['fermer_oput']>=3000){
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money`- '5000' WHERE `id` = $user[id] LIMIT 1");
mysql_query("INSERT INTO `fermer_gr` (`semen`, `id_user`) VALUES  ( '0', '".$user['id']."') ");
header('Location: my.php?add_ok');
}else{header('Location: my.php?add_no');}
}


$doggy=$user['fermer_doggy'];

include 'inc/str.php';
include 'inc/popular.php';

if($karma==0){echo '<a href="original_appearance.php"><img src="blog.png"></a> : 0<br />';}else{echo '<a href="original_appearance.php"><img src="blog.png"></a> : '.$karma.' %<br />';}
include_once 'inc/pop.php';

if($socstatus>=0 && $socstatus<=499){echo '<a href="area.php"><img src="chart.png"></a> : Колхозник ('.$socstatus.' %)<br />';}
elseif($socstatus>=500 && $socstatus<=999){echo '<a href="area.php"><img src="chart.png"></a> : Продвинутый ('.$socstatus.' %)<br />';}
elseif($socstatus>=1000 && $socstatus<=1499){echo '<a href="area.php"><img src="chart.png"></a> : Первый на деревне ('.$socstatus.' %)<br />';}
echo '</div><div class="ferm4">.</div>';
echo'<div class="ferm2">';
if($doggy==1){echo '<a href="dog.php"><img src="dog3.png"></a>
<a href="reeltor.php?p=house"><img src="imghouse/house.gif"></a>
<a href="storage.php"><img src="sklad.png"></a>
<br />';}else{echo '
<a href="dog.php"><img src="dog1.png"></a>
<a href="reeltor.php?p=house"><img src="imghouse/house.gif"></a>
<a href="storage.php"><img src="sklad.png"></a>
<br />';}
echo'';
if(isset($_GET['add'])){

echo "Стоимость одной грядки составляет 5000";
echo "<form method='post' action='?gr_add'>\n";
echo "<input type='submit' name='save' value='Приобрести!' />\n";
echo "</form>\n";

}else{





$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_gr` WHERE `id_user` = '$user[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];



$res = mysql_query("select * from `fermer_gr` WHERE `id_user` = '$user[id]'  LIMIT $start, $set[p_str];");

while ($post = mysql_fetch_array($res)){
$semen=mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE  `id` = '$post[semen]'  LIMIT 1"));
if($post['semen']==0){$name_gr='Пустая грядка';}else{$name_gr=$semen['name'];}

$vremja=$post['time']-$time;

$timediff=$vremja;
$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
if($dayfield>0)$day=$dayfield.'д. ';

if($time<$post['time'])$time_1="(".$day.$hourfield."ч. ".$minutefield."м.)";
else$time_1=" (<span class='off'>Пора собирать!</span>)";

if($post['semen']!=0 && $time>$post['time'] && $post['kol']==0)
{
$pt=rand($semen['rand1'],$semen['rand2']);
mysql_query("UPDATE `fermer_gr` SET `kol` = $pt WHERE `id` = $int LIMIT 1");
}
echo "
<b></b> <a href='gr.php?id=$post[id]'><img src='img/$post[semen].gif' ></a>";
if($post['semen']!=0)
echo"";
echo "\n";
}


if ($k_page>1)str('?',$k_page,$page); // Вывод страниц
}
echo "<a href='my.php?add'><img src='2_0_0_0(01).gif' ></a>";
echo "<div class='ferm6'>.</div></div>";

?>

