<?php
/*
Автор скрипта: MoD
ICQ: 3536335
Скрипт нельзя 
кидать в паблик, 
барыжить(продавать) им, 
давать друзьям!
*/
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';

$int=intval($_GET['id']);
$set['title']='Ферма!';
include_once '../sys/inc/thead.php';
title();
err();
aut();
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id`= $int LIMIT 1")); 
if($_GET['id']==$user['id'])header('Location: my.php');
include 'inc/str.php';

if(isset($_GET['vor'])){
$gr = mysql_fetch_array(mysql_query("select * from `fermer_gr` WHERE `id` = $_GET[vor] ")); 
$semen = mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE `id` = '$gr[semen]' "));
$qi = mysql_fetch_assoc(mysql_query("SELECT * FROM `fermer_vor` WHERE `id_user` = '$user[id]'  AND `gr` = $_GET[vor] LIMIT 1"));
if($qi['time']<$time){
$rand1=floor($semen['rand1']/5);
$rand2=floor($semen['rand2']/5);
$rand=rand($rand1,$rand2);
$dog=mysql_fetch_array(mysql_query("select * from `fermer_dog` WHERE `id_user` = '$ank[id]' "));
if($dog['time']<$time){
$t=$time+86400;
mysql_query("INSERT INTO `fermer_vor` (`id_user` , `gr`, `time`) VALUES  ('".$user['id']."', '".$_GET['vor']."', '".$t."') ");
mysql_query("UPDATE `user` SET `fermer_oput` = `fermer_karma`- '1' WHERE `id` = $user[id] LIMIT 1");
if($gr['kol']>$rand){
mysql_query("UPDATE `fermer_gr` SET `kol` = `kol`- $rand WHERE `id` = $_GET[vor] LIMIT 1");
mysql_query("INSERT INTO `fermer_sclad` (`kol` , `semen`, `id_user`) VALUES  ('".$rand."', '".$gr['semen']."', '".$user['id']."') ");
}else{
$rand=mysql_result(mysql_query("SELECT `kol` FROM `fermer_gr` WHERE `id` = $_GET[vor] "),0);
mysql_query("UPDATE `fermer_gr` SET `semen` = '0' WHERE `id` = $_GET[vor] LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `time` = NULL WHERE `id` = $_GET[vor] LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `kol` = NULL WHERE `id` = $_GET[vor] LIMIT 1");
mysql_query("INSERT INTO `fermer_sclad` (`kol` , `semen`, `id_user`) VALUES  ('".$rand."', '".$gr['semen']."', '".$user['id']."') ");
}
msg('Украдено '.$rand.'!!!');

}else{

mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money` - $rand WHERE `id` = $user[id] LIMIT 1");
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money` + $rand WHERE `id` = $ank[id] LIMIT 1");
$rand=rand(1,100);
echo '<div class="err">На вас напала собака фермера! При побеге вы потеряли '.$rand.' монет!!!</div>';
}
}else{echo "<div class='err'>С этой грядки больше воровать нелзя!!!</div>";}
}
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_gr` WHERE `id_user` = '".$int."'"),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` =  '".$int."' 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'];}

echo "<img src='img/$post[semen].gif' height='20' width='20'><b>&raquo;</b> ".$name_gr."";
if($post['semen']!=0 && $post['time']<$time){
echo " (".$post['kol'].") ";
$qi = mysql_fetch_array(mysql_query("SELECT * FROM `fermer_vor` WHERE `id_user` = '$user[id]'  AND `gr` = '$post[id]' LIMIT 1"));
if($qi['time']<$time)
echo "<a href='?id=".$int."&amp;vor=".$post['id']."'>[Воровать!]</a>";


}else{if($post['semen']!=0)echo " (Созревает)";}
echo "<br/>";

}



if ($k_page>1)str('?',$k_page,$page); // Вывод страниц

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

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

?>