<?php


$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($post['semen']!=0){ 
if($time<$post['time'])$time_1=$day.$hourfield."ч. ".$minutefield."м.";
else$time_1=0;
}
echo "<img src='img/$post[semen].gif' alt=''><br/>&raquo; <b>".$name_gr."</b>";
if($post['semen']!=0){
if($time>$post['time']){
if($post['semen']!=0 && $post['kol']!=0)echo " <b>[<a href='?id=".$int."&amp;get'>Собрать</a>]</b>";
elseif($post['semen']!=0 &&  $post['kol']==0)echo " <b>[Ошибка! Обновите страницу!]</b>";
}

if($post['semen']!=0 && $time>$post['time'] && $post['kol']==0)
{
$pt=rand($semen['rand1'],$semen['rand2']);
if($post['woter']==0)$pt=floor($pt/2);
mysql_query("UPDATE `fermer_gr` SET `kol` = $pt WHERE `id` = $int LIMIT 1");
}

if($time<$post['time']){

$k2=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_udobr` WHERE `id_user` = '$user[id]'"),0);
if($k2!=0){
$res2 = mysql_query("select * from `fermer_udobr` WHERE `id_user` = '$user[id]' "); 
echo "<form method='post' action='?id=".$int."&amp;$passgen'>\n";
echo "&raquo; Удобрения:<br />\n<select name='udobr'>";
while ($post2 = mysql_fetch_array($res2)){
$semen2=mysql_fetch_array(mysql_query("select * from `fermer_udobr_name` WHERE  `id` = '$post2[udobr]'  LIMIT 1")); 
echo "<option value='".$post2['id']."'>".$semen2['name']." [".$post2['kol']."]</option>";
}
echo "</select><br />\n";
echo "<input type='submit' name='save' value='Удобрить' />\n";
echo "</form>\n";
}else{
echo '
<select name="cad" disabled="disabled" >
<option value="0" selected="selected">На складе удобрений нет!</option>
</select><br />';
}

echo "&raquo; До сбора осталось: <b>".$time_1."</b>";
if($post['woter']==1){$w='Да';}else{$w='Нет';}
echo "<br />&raquo; Полито: <b>".$w."</b>";
if($post['woter']==0){echo "<b> [<a href='?id=".$int."&amp;woter'>Полить</a>]</b>";}
}else{
echo "<br/>&raquo; Опит: <b>+".$semen['oput']."</b> <br/>";
echo "&raquo; Количество урожая: <b>".$post['kol']."</b> <br/>";
if($post['woter']==0)echo "<span class='off'>*Вы потеряли половину урожая, не полив ферму!!!</span><br />";
echo "&raquo; Цена за единицу: <b>".$semen['dohod']."</b> <br/>";
$dohod=$post['kol']*$semen['dohod'];
echo "&raquo; Общий доход: <b>".$dohod."</b> <br/>";
}
}else{


$k=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_semen` WHERE `id_user` = '$user[id]'"),0);
if($k!=0){
$res = mysql_query("select * from `fermer_semen` WHERE `id_user` = '$user[id]' "); 
echo "<form method='post' action='?id=".$int."&amp;$passgen'>\n";
echo "Семена:<br />\n<select name='sadit'>";


while ($post = mysql_fetch_array($res)){
$semen=mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE  `id` = '$post[semen]'  LIMIT 1")); 
$name_gr=$semen['name'];
echo "<option value='".$post['id']."'>".$name_gr." [".$post['kol']."]</option>";


}
echo "</select><br />\n";
echo "<input type='submit' name='save' value='Посадить' />\n";
echo "</form>\n";
}else{
echo '
<select name="cad" disabled="disabled" ><br />
<option value="0" selected="selected">На складе семян нет!</option>
</select><br />';
}

}

?>