<?
require "../../configmain.php";
require "../../global.php";
connectdb();?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<?
if ($banner == '1'){
echo $bannercode;
}
?><?
global $bupgrad;
$useram = mysql_query("SELECT * FROM usr WHERE usr ='$user'");
$usera = mysql_fetch_array($useram);
$buildl = mysql_query("SELECT * FROM buildinglocation WHERE horz='$horz' and vert='$vert' and town ='$town'");
$buildloc = mysql_fetch_array($buildl);
$costm = mysql_query("SELECT cost, name, upgradeid, lc, mc, hc, fa, level FROM buildingtype WHERE buid ='$buildloc[3]'");
$cost = mysql_fetch_array($costm);
$ucostm = mysql_query("SELECT cost, name, upgradeid, lc, mc, hc, fa, level FROM buildingtype WHERE buid ='$bupgrad'");
$ucost = mysql_fetch_array($ucostm);
if ($usera[1] != $password){
echo "incorrect password please log in again";
}
if($usera[8]<$ucost[7]){
echo"you are not a high enough level to build this, sorry<br>";
}
if($usera[8]>=$ucost[7]){
if ($usera[1] == $password){
if ($cost[2] != '0'){
// upgrade bit
echo "upgrade building to required level and remove money from users account<br>";
$tcost = $ucost[0] - ($cost[0]*2/3);
if ($usera[9] <= $tcost){
echo "Not enough money to upgrade building<br>You have $usera[9] money but the upgrade costs $tcost<br>";
}
$cb='1';//check to see if there are enough workers
$townm = mysql_query("SELECT * FROM towns WHERE tid ='$town'");
$towna = mysql_fetch_array($townm);
$uneploylc=$towna[10]-$towna[11];
$uneploymc=$towna[12]-$towna[13];
$uneployhc=$towna[14]-$towna[15];
$uneployfa=$towna[16]-$towna[17];
if($uneploylc<($ucost[3]-$cost[3]) OR $uneploymc<($ucost[4]-$cost[4]) OR $uneployhc<($ucost[5]-$cost[5]) OR $uneployfa<($ucost[6]-$cost[6])){
$cb='0';
echo"Not enough workers in the town<br>";
}
if($cb=='1'){
if ($usera[9] >= $tcost){
echo "You have enough money to upgrade to $ucost[1]<br>";
$owner=$buildloc[4];
$owner2 = $owner;
if ($owner2 == $user){
echo "You own this land and can upgrade this building<br>";
$res = mysql_query("UPDATE buildinglocation SET buid ='$bupgrad' where town='$town' and vert='$vert' and horz='$horz'");
$umoney = $usera[9] - $tcost;
$res2 = mysql_query("UPDATE usr SET money='$umoney' where usr='$user'");
$newlc=$towna[11]+$cost[2];
$newlc=$towna[11]+$ucost[3]-$cost[3];
$newmc=$towna[13]+$ucost[4]-$cost[4];
$newhc=$towna[15]+$ucost[5]-$cost[5];
$newfa=$towna[17]+$ucost[6]-$cost[6];
$res2 = mysql_query("UPDATE towns SET lce='$newlc' where tid='$town'");
$res2 = mysql_query("UPDATE towns SET mce='$newmc' where tid='$town'");
$res2 = mysql_query("UPDATE towns SET hce='$newhc' where tid='$town'");
$res2 = mysql_query("UPDATE towns SET fae='$newfa' where tid='$town'");
echo "Congratulations, you have upgraded to $ucost[1] (id is $bupgrad)<br>";
}
}
if ($owner2 != $user){
echo "Some one else owns this land, you can not build here<br>";
}}}}}
?>
</body>
</html>