Location: PHPKode > projects > php Strategy Game Engine X > phpsgex/adm/buildings.php
<?php
$body.="<script type='text/javascript'>
function showHide(id) {
	if (id.style.display != 'block') id.style.display = 'block';
	else id.style.display = 'none';
}
</script>";

//add new build
$racsel="<select name='race'><option value='0'>All</option>";
$qrac= mysql_query("SELECT * FROM races");
while( $racr= mysql_fetch_array($qrac) ) $racsel.="<option value='".$racr['id']."'>".$racr['rname']."</option>"; 
$racsel.="</select>";

$prodsel="<select name='prod'><option value='0'>None</option>";
$qprod= mysql_query("SELECT * FROM resdata");
while( $rprod= mysql_fetch_array($qprod) ) $prodsel.="<option value='".$rprod['id']."'>".$rprod['name']."</option>"; 
$prodsel.="</select>";

$rescost="";
$qrres= mysql_query("SELECT * FROM resdata");
while( $ftr= mysql_fetch_array($qrres) ) $rescost.=$ftr['name'].": <input type='text' name='res".$ftr['id']."' value='0' size='3'> X: <input type='text' size='3' name='rmpl".$ftr['id']."' value='0'><br>";

//select for resource function
$bf= bud_func();
$budfunc="<select name='budfunc'>";
for( $i=0; $i< count($bf); $i++ ){
	$budfunc.= "<option value='".$bf[$i]."'>".$bf[$i]."</option>";	
}
$budfunc.="</select>";

$body.="<form method='post' action='?pg=buildings'></table> <h2>".$lang['adm_addbuild']."</h2> <table border='1' width='100%'> <tr> <td>".$lang['adm_name']."</td> <td>".$lang['reg_race']."</td> <td>".$lang['adm_prodres']."</td> <td>".$lang['adm_image']."</td> <td>Cost / Moltiplier per level</td> </tr>
<tr> <td><input type='text' name='name'></td> <td>".$lang['reg_race'].": $racsel <br>Function: $budfunc</td> <td>$prodsel</td> <td><input type='text' name='img' value='null.gif' size='9'></td> <td>$rescost Time: <input type='text' name='time' size='3' value='0'> X: <input type='text' name='timempl' value='0' size='3'></td> <td><input type='image' src='../img/icons/add-icon.png' onclick='document.thisform.submit()' name='addbuild' value=' ' /></td>  </tr>
</table></form>";

//edit builds
$body.= "<form method='get' action=''><input type='hidden' name='pg' value='buildings'>
<br><br>Show by race: <select name='srac'><option value='0'>All</option>";

$qrac= mysql_query("SELECT * FROM races");
while( $racr= mysql_fetch_array($qrac) ) $body.= "<option value='".$racr['id']."'>".$racr['rname']."</option>"; 

$body.="</select> <input type='submit' value='ok'></form><br>
<table border='1' width='105%'> <tr> <td>Name/Img/Race</td> <td>".$lang['adm_prodres']."</td> <td>Cost / Moltiplier</td> <td>".$lang['adm_requirements']."</td> </tr>";

if( isset($_GET['srac']) && $_GET['srac'] >0 ) $qr= mysql_query("SELECT * FROM t_builds WHERE arac =".(int)$_GET['srac']);
else $qr= mysql_query("SELECT * FROM t_builds");
while( $row= mysql_fetch_array($qr) ){
	//select for race
	$racsel="<select name='race'><option value='0'>All</option>";
	$qrac= mysql_query("SELECT * FROM races");
	while( $racr= mysql_fetch_array($qrac) ) { 
		$racsel.="<option value='".$racr['id']."'";
		if( $racr['id']==$row['arac'] ) $racsel.="selected";
		$racsel.=">".$racr['rname']."</option>"; 
	}
	$racsel.="</select>";
	//select for resource production
	$prodsel="<select name='prod'><option value='0'>None</option>";
	$qprod= mysql_query("SELECT * FROM resdata");
	while( $rprod= mysql_fetch_array($qprod) ) { 
		$prodsel.="<option value='".$rprod['id']."'";
		if( $rprod['id']==$row['produceres'] ) $prodsel.="selected";
		$prodsel.=">".$rprod['name']."</option>"; 
	}
	$prodsel.="</select>";
	//select for resource cost
	$rescost="";
	$qrres= mysql_query("SELECT * FROM resdata");
	while( $ftr= mysql_fetch_array($qrres) ){
		$qrcost= mysql_query("SELECT * FROM `t_build_resourcecost` WHERE `build` =".$row['id']." AND resource =".$ftr['id']);
		if( mysql_num_rows($qrcost) ==0 ) { $cost=0; $molt= 0; }
		else {
			$ar= mysql_fetch_array($qrcost);
			$cost= $ar['cost'];	
			$molt= $ar['moltiplier'];
		}
		$rescost.=$ftr['name'].": <input type='text' size='3' name='res".$ftr['id']."' value='$cost'>
		 X: <input type='text' size='3' name='rmpl".$ftr['id']."' value='".$molt."'><br>";
	}
	//select for resource function
	$bf= bud_func();
	$budfunc="<select name='budfunc'>";
	for( $i=0; $i< count($bf); $i++ ){
		$budfunc.= "<option ";
		if( $bf[$i]==$row['func'] ) $budfunc.="selected ";
		$budfunc.= "value='".$bf[$i]."'>".$bf[$i]."</option>";	
	}
	$budfunc.="</select>";
	
	$body.="<form method='post' action='?pg=buildings'><input type='hidden' name='editbuild' value='".$row['id']."' >
	<tr> <td style='text-align: left'>Name: <input type='text' name='name' value='".$row['name']."' size='15'> <br>".$lang['adm_image'].": <input type='text' name='img' value='".$row['img']."' size='9'> <br>".$lang['reg_race'].": $racsel</td> <td>".$lang['adm_prodres'].": $prodsel<br><br>Function: $budfunc</td> <td>$rescost Time: <input type='text' name='time' value='".$row['time']."' size='3'> X: <input type='text' size='3' name='timempl' value='".$row['time_mpl']."'></td> 
	<td><nobr>";
	
	$qrreqbud= mysql_query("SELECT * FROM `t_build_reqbuild` WHERE `build` =".$row['id']);
	$i=1;
	while( $arb= mysql_fetch_array($qrreqbud) ) {
		$body.="<select name='reqbud$i'>";
		
		$qrgetbuilds= mysql_query("SELECT * FROM t_builds");
		while( $gb= mysql_fetch_array($qrgetbuilds) ){
			if( $gb['id']!=$row['id'] ) {
				$body.="<option value='".$gb['id']."' ";
				if( $gb['id']==$arb['reqbuild'] ) $body.="selected";
				$body.=">".$gb['name']."</option>";
			}
		}
			
		$body.="</select>: <input type='text' name='levbud$i' value='".$arb['lev']."' size='1'></nobr> <br>";
		$i++;
	}
	
	$body.="<nobr> <div id='radd".$row['id']."' style='display:none;'><select name='reqbud$i'>";
	
	$qrgetbuilds= mysql_query("SELECT * FROM t_builds");
	while( $gb= mysql_fetch_array($qrgetbuilds) ) if( $gb['id']!=$row['id'] ) $body.="<option value='".$gb['id']."'>".$gb['name']."</option>";
	
	$body.="</select>: <input type='text' name='levbud$i' value='0' size='1'></div></nobr> <br><a href='#' onclick=\"javascript: showHide(radd".$row['id'].");\">".$lang['adm_add']."</a> </td>
	<td><input type='image' src='../img/icons/b_edit.png' onclick='document.thisform.submit()' />
	<a href='?pg=buildings&delbuild=".$row['id']."'><img src='../img/icons/x.png' /></a></td> </tr></form>";	
}

$body.="</table>";
?>
Return current item: php Strategy Game Engine X