<?
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']='My villa'; // заголовок страницы

include_once '../sys/inc/thead.php';
title();
err();
aut();
echo '<center><img src="/villa/images/villa1.gif" /> </center>';


if(isset($user)){


$action=htmlspecialchars(trim($_GET['action']));

switch ($action){



default:

$x=mysql_query("SELECT * FROM `ferma` WHERE `id`='".$user['id']."' LIMIT 1");
if(!mysql_num_rows($x)){echo 'You do not have a villa =(<a href="ferma.php?action=reg">Buy land for villa!</a>';
include_once "kto.php";
include_once '../sys/inc/tfoot.php';break;};
$x=mysql_fetch_assoc($x);
$q=$x['dohod_1'];
$w=$x['dohod_2'];
$e=$x['dohod_3'];
$r=$x['dohod_4'];
$t=$x['dohod_5'];
$y=$x['dohod_6'];
$u=$x['dohod_7'];
$a=$x['dohod_8'];
$s=$x['dohod_9'];
$d=$x['dohod_10'];
$f=$x['dohod_11'];
$g=$x['dohod_12'];
$dohod=$q+$w+$e+$r+$t+$y+$u+$a+$s+$d+$f+$g;
$level=$x['level']+1;
if($x['um']>7500 && $x['level']==0){echo "Your level is increased to 2!!!<br/>";
mysql_query("UPDATE `ferma` SET `level`='1' WHERE `id`='".$user['id']."'");};
if($x['um']>25000 && $x['level']==1){echo "Your level is increased to 3!!!<br/>";
mysql_query("UPDATE `ferma` SET `level`='2' WHERE `id`='".$user['id']."'");};
if($x['um']>75000 && $x['level']==2){echo "Your level is increased to 4!!!<br/>";
mysql_query("UPDATE `ferma` SET `level`='3' WHERE `id`='".$user['id']."'");};
if($x['um']>150000 && $x['level']==3){echo "Your level is increased to 5!!!<br/>";
mysql_query("UPDATE `ferma` SET `level`='4' WHERE `id`='".$user['id']."'");};
echo 'Name of the villa: <font color="red">'.$x['name'].'</font><br/>';
echo 'Date of construction:<font color="red"> '.date("d-m-Y",$x['date']).'</font><br/>';
echo 'Your experience Florist: <font color="green">'.$x['um'].'</font><br/>';
echo 'The level of craftsmanship: <font color="green">'.$level.'</font><br/>';
echo 'Income from greenhouse: <font color="red">'.$dohod.'</font> руб.<br/>';
if (time()>=$x['dohod_time']){
echo 'You can sell seedlings! <a href="ferma.php?action=deneg">Sell!</a><br/>';};

echo '<a href="ferma.php?action=uch">Greenhouses</a><br/>';





echo '<a href="ferma.php?action=faq">Reference</a><br/>';

break;
case 'reg':
if(!empty($user['ferma'])){echo 'You already have a villa!';break;};
echo '<form action="ferma.php?action=save" method="post">';
echo 'Name of the villa:<br/>';
echo '<input name="name" type="text" value=""/><br/>';
echo '<input type="submit" value="Submit"/>';
echo '</form>';
break;


case 'save':
$name=htmlspecialchars(mysql_real_escape_string(trim($_POST['name'])));
if(!$name){echo 'empty options!';break;};
mysql_query("INSERT INTO `ferma` (`id`,`name`,`user`,`date`,`dohod_time`)VALUES('".$user['id']."','$name','".$user['nick']."','".time()."','".time()."')");
mysql_query("UPDATE `user` SET `ferma`='$name' WHERE `id`='".$user['id']."'");
mysql_query("INSERT INTO `lenta` (`tekst`, `time`) values('$user[nick] acquired land and built a villa', '$time')");
echo 'You built a villa =)!<br/>';
echo '<a href="ferma.php">In the menu</a>';
break;


case 'faq':
echo'Info:<Br/>
Get yourself a vacation home, villa, divorce her flowers in greenhouses, sell seedlings plants! Whether iskustno florist!!!';
break;


case 'uch':
$x=mysql_query("SELECT * FROM `ferma` WHERE `id`='".$user['id']."' LIMIT 1");
if(!mysql_num_rows($x)){echo 'You do not have a villa =(<a href="pit.php?action=reg">Buy land for villa!</a>';
include_once "kto.php";
include_once '../sys/inc/tfoot.php';break;};
$x=mysql_fetch_assoc($x);
$level=$x['level']+1;
echo "It is your greenhouse! The higher the level, the more you can plant the flower greenhouses!!!<br/>";
if($level==1){
if($x['mesto_1']==0){echo "<a href='zemli.php?action=1'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=1'>$x[name_1]</a><br/>";};
if($x['mesto_2']==0){echo "<a href='zemli.php?action=2'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=2'>$x[name_2]</a><br/>";};
if($x['mesto_3']==0){echo "<a href='zemli.php?action=3'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=3'>$x[name_3]</a><br/>";};
if($x['mesto_4']==0){echo "<a href='zemli.php?action=4'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=4'>$x[name_4]</a><br/>";};
if($x['mesto_5']==0){echo "<a href='zemli.php?action=5'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=5'>$x[name_5]</a><br/>";};
};
if($level==2){
if($x['mesto_1']==0){echo "<a href='zemli.php?action=1'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=1'>$x[name_1]</a><br/>";};
if($x['mesto_2']==0){echo "<a href='zemli.php?action=2'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=2'>$x[name_2]</a><br/>";};
if($x['mesto_3']==0){echo "<a href='zemli.php?action=3'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=3'>$x[name_3]</a><br/>";};
if($x['mesto_4']==0){echo "<a href='zemli.php?action=4'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=4'>$x[name_4]</a><br/>";};
if($x['mesto_5']==0){echo "<a href='zemli.php?action=5'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=5'>$x[name_5]</a><br/>";};
if($x['mesto_6']==0){echo "<a href='zemli.php?action=6'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=6'>$x[name_6]</a><br/>";};
if($x['mesto_7']==0){echo "<a href='zemli.php?action=7'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=7'>$x[name_7]</a><br/>";};

};
if($level==3){
if($x['mesto_1']==0){echo "<a href='zemli.php?action=1'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=1'>$x[name_1]</a><br/>";};
if($x['mesto_2']==0){echo "<a href='zemli.php?action=2'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=2'>$x[name_2]</a><br/>";};
if($x['mesto_3']==0){echo "<a href='zemli.php?action=3'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=3'>$x[name_3]</a><br/>";};
if($x['mesto_4']==0){echo "<a href='zemli.php?action=4'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=4'>$x[name_4]</a><br/>";};
if($x['mesto_5']==0){echo "<a href='zemli.php?action=5'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=5'>$x[name_5]</a><br/>";};
if($x['mesto_6']==0){echo "<a href='zemli.php?action=6'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=6'>$x[name_6]</a><br/>";};
if($x['mesto_7']==0){echo "<a href='zemli.php?action=7'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=7'>$x[name_7]</a><br/>";};
if($x['mesto_8']==0){echo "<a href='zemli.php?action=8'>Empty</a><br/>";}else{echo "<a href='zemli.php?action=8'>$x[name_8]</a><br/>";};

};
break;


case 'deneg':
$x=mysql_query("SELECT * FROM `ferma` WHERE `id`='".$user['id']."' LIMIT 1");
if(!mysql_num_rows($x)){echo 'You do not have a villa =(<a href="pit.php?action=reg">Buy land for villa!</a>';
include_once "kto.php";
include_once '../sys/inc/tfoot.php';break;};
$x=mysql_fetch_assoc($x);
$q=$x['dohod_1'];
$w=$x['dohod_2'];
$e=$x['dohod_3'];
$r=$x['dohod_4'];
$t=$x['dohod_5'];
$y=$x['dohod_6'];
$u=$x['dohod_7'];
$a=$x['dohod_8'];
$s=$x['dohod_9'];
$d=$x['dohod_10'];
$f=$x['dohod_11'];
$g=$x['dohod_12'];
$dohod=$q+$w+$e+$r+$t+$y+$u+$a+$s+$d+$f+$g;
$summa=$dohod*0.95;
$opit=$summa*0.27;
if (time()>=$x['dohod_time']){
echo 'You grow and sell seedlings of flowers, you get '.$summa.' Money '.$opit.' Experience';
mysql_query("UPDATE `ferma` SET `um`=`um`+'$opit' WHERE `user`='".$user['nick']."'");
mysql_query("UPDATE `ferma` SET `dohod_time`='".(time()+12000)."' WHERE `user`='".$user['nick']."'");
mysql_query("UPDATE `user` SET `gorod_money`=`gorod_money`+'$summa' WHERE `id`='".$user['id']."'");
}else{echo 'You have not grown seedlings to sell them =)';};
break;

};



echo '<div class="msg"><a href="index.php">Home Page</a></div>';

}else{
echo '<div class="msg">The game is available only to authorized users!</div>';
};
include_once "kto.php";
include_once '../sys/inc/tfoot.php';
?>