<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';


$set['title']='Моя ферма - Грядка';
error_reporting (0);
include_once '../sys/inc/thead.php';
title();
err();
$int=intval($_GET['id']);
$post = mysql_fetch_array(mysql_query("select * from `fermer_gr` WHERE  `id` = '$int'  LIMIT 1")); 
if(isset($_GET['ok']))msg('Новое растение посажено!');
if(isset($_GET['sob_ok']))msg('Урожай собран!');

if(isset($_POST['sadit']) && $post && $user['id']==$post['id_user'] && $post['semen']==0)
{
$res = mysql_fetch_array(mysql_query("select * from `fermer_semen` WHERE `id` = '$_POST[sadit]' ")); 
$semen = mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE `id` = '$res[semen]' "));
$t=$time+$semen['time'];
mysql_query("UPDATE `fermer_gr` SET `semen` = $res[semen] WHERE `id` = $int LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `time` = '$t' WHERE `id` = $int LIMIT 1");
if($res['kol']>=2){
mysql_query("UPDATE `fermer_semen` SET `kol` = `kol`-'1' WHERE `id` = $_POST[sadit] LIMIT 1");
}else{
mysql_query("DELETE FROM `fermer_semen` WHERE `id` = $_POST[sadit] ");
}
header("Location: inc/header.php?gr=".$int."");
}
if(isset($_GET['get']) && $user['id']==$post['id_user'] && $post['semen']!=0 && $post['time']<$time)
{
$semen = mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE `id` = '$post[semen]' "));
mysql_query("INSERT INTO `fermer_sclad` (`kol` , `semen`, `id_user`) VALUES  ('".$post['kol']."', '".$post['semen']."', '".$user['id']."') ");
mysql_query("UPDATE `user` SET `fermer_oput` = `fermer_oput`+ '".$semen['oput']."' WHERE `id` = $user[id] LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `semen` = '0' WHERE `id` = $int LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `time` = NULL WHERE `id` = $int LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `water` = '0' WHERE `id` = $int LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `kol` = '0' WHERE `id` = $int LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `water` = '0' WHERE `id` = $int LIMIT 1");
header("Location: inc/header.php?gr2=".$int."");
}
if(isset($_POST['udobr']) && $post && $user['id']==$post['id_user'] && $post['semen']!=0)
{
$res = mysql_fetch_array(mysql_query("select * from `fermer_udobr` WHERE `id` = '$_POST[udobr]' ")); 
$semen = mysql_fetch_array(mysql_query("select * from `fermer_udobr_name` WHERE `id` = '$res[udobr]' "));
mysql_query("UPDATE `fermer_gr` SET `time` = `time`- $semen[time] WHERE `id` = $int LIMIT 1");
if($res['kol']>=2){
mysql_query("UPDATE `fermer_udobr` SET `kol` = `kol`-'1' WHERE `id` = $_POST[udobr] LIMIT 1");
}else{
mysql_query("DELETE FROM `fermer_udobr` WHERE `id` = $_POST[udobr] ");
}
header("Location: my.php?udobr_ok");
}
if(isset($_GET['woter']) && $post['woter']!=1){
mysql_query("UPDATE `fermer_gr` SET `woter` = '1' WHERE `id` = $int LIMIT 1");
msg('Успешно полито!!!');
}
aut();
//header("Content-type: application/vnd.wap.xhtml+xml");
header("Content-type: text/html");
echo "<link rel='stylesheet' href='style.css' type='text/css' /><center>";
echo "<div class='ferm1'><img src='fermer.gif'><br/>";
include 'inc/str.php';
echo '</div><div class="ferm4">.</div>';
echo'<div class="ferm2">';



if($post){
if($user['id']==$post['id_user']){


include 'inc/gr.php';


}else{echo "<div class='err'>Это не ваша грядка!</div>";}
}else{echo "<div class='err'>Такой грядки не существует!!!</div>";}

echo "<div class='foot'>";
echo "&laquo; <a href='my.php'>Назад</a><br/>";
echo "&laquo; <a href='index.php'>На ферму</a><br/>";
echo "</div></div>";

include_once '../sys/inc/tfoot.php';

?>

