mittus
Создатель
- Регистрация
- 12 Июл 2009
- Сообщения
- 73
- Реакции
- 11
- Автор темы
- #1
PHP:
<?php
if(!defined('INSIDE')){ die(header("location:../../"));}
global $phpEx, $lang;
$parse = $lang;
include($xgp_root . 'extension.inc.php');
include($xgp_root . 'common.' . $phpEx);
include($xgp_root . 'includes/donorvars.' . $phpEx);
$TargetPlanet = $user['current_planet'];
$TargetUser = $user['id'];
$AvailPoints = $user['darkmatter'];
$PlanetName = $planetrow['name'];
$PlayerName = $user['username'];
$mode = $_POST['mode'];
$levelcost1 = floor($donorcost['1'] * pow(1.5, $planetrow[$donorid['1']]));
$levelcost2 = floor($donorcost['2'] * pow(1.5, $planetrow[$donorid['2']]));
$levelcost3 = floor($donorcost['3'] * pow(1.5, $planetrow[$donorid['3']]));
$levelcost4 = floor($donorcost['4'] * pow(1.5, $planetrow[$donorid['4']]));
$levelcost12 = floor($donorcost['12'] * pow(1.5, $planetrow[$donorid['12']]));
$levelcost14 = floor($donorcost['14'] * pow(1.5, $planetrow[$donorid['14']]));
$levelcost15 = floor($donorcost['15'] * pow(1.5, $planetrow[$donorid['15']]));
$levelcost21 = floor($donorcost['21'] * pow(1.5, $planetrow[$donorid['21']]));
$levelcost22 = floor($donorcost['22'] * pow(1.5, $planetrow[$donorid['22']]));
$levelcost23 = floor($donorcost['23'] * pow(1.5, $planetrow[$donorid['23']]));
$levelcost24 = floor($donorcost['24'] * pow(1.5, $planetrow[$donorid['24']]));
$levelcost31 = floor($donorcost['31'] * pow(1.5, $planetrow[$donorid['31']]));
$levelcost33 = floor($donorcost['33'] * pow(1.5, $planetrow[$donorid['33']]));
$levelcost34 = floor($donorcost['34'] * pow(1.5, $planetrow[$donorid['34']]));
$levelcost44 = floor($donorcost['44'] * pow(1.5, $planetrow[$donorid['44']]));
if ($mode == 'addit') {
$id = $TargetPlanet;
$player = $TargetUser;
$metal_mine = $_POST['metal_mine'];
$crystal_mine = $_POST['crystal_mine'];
$deuterium_sintetizer = $_POST['deuterium_sintetizer'];
$solar_plant = $_POST['solar_plant'];
$fusion_plant = $_POST['fusion_plant'];
$robot_factory = $_POST['robot_factory'];
$nano_factory = $_POST['nano_factory'];
$hangar = $_POST['hangar'];
$metal_store = $_POST['metal_store'];
$crystal_store = $_POST['crystal_store'];
$deuterium_store = $_POST['deuterium_store'];
$laboratory = $_POST['laboratory'];
$terraformer = $_POST['terraformer'];
$ally_deposit = $_POST['ally_deposit'];
$silo = $_POST['silo'];
$TotalCost = (($metal_mine * $levelcost1)
+($crystal_mine * $levelcost2)
+($deuterium_sintetizer * $levelcost3)
+($solar_plant * $levelcost4)
+($fusion_plant * $levelcost12)
+($robot_factory * $levelcost14)
+($nano_factory * $levelcost15)
+($hangar * $levelcost21)
+($metal_store * $levelcost22)
+($crystal_store * $levelcost23)
+($deuterium_store * $levelcost24)
+($laboratory * $levelcost31)
+($terraformer * $levelcost33)
+($ally_deposit * $levelcost34)
+($silo * $levelcost44)
);
if ($TotalCost <= $AvailPoints) {
$QryUpdatePlanet = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`metal_mine` = `metal_mine` + '". $metal_mine ."', ";
$QryUpdatePlanet .= "`crystal_mine` = `crystal_mine` + '". $crystal_mine ."', ";
$QryUpdatePlanet .= "`deuterium_sintetizer` = `deuterium_sintetizer` + '". $deuterium_sintetizer ."', ";
$QryUpdatePlanet .= "`solar_plant` = `solar_plant` + '". $solar_plant ."', ";
$QryUpdatePlanet .= "`fusion_plant` = `fusion_plant` + '". $fusion_plant ."', ";
$QryUpdatePlanet .= "`robot_factory` = `robot_factory` + '". $robot_factory ."', ";
$QryUpdatePlanet .= "`nano_factory` = `nano_factory` + '". $nano_factory ."', ";
$QryUpdatePlanet .= "`hangar` = `hangar` + '". $hangar ."', ";
$QryUpdatePlanet .= "`metal_store` = `metal_store` + '". $metal_store ."', ";
$QryUpdatePlanet .= "`crystal_store` = `crystal_store` + '". $crystal_store ."', ";
$QryUpdatePlanet .= "`deuterium_store` = `deuterium_store` + '". $deuterium_store ."', ";
$QryUpdatePlanet .= "`laboratory` = `laboratory` + '". $laboratory ."', ";
$QryUpdatePlanet .= "`terraformer` = `terraformer` + '". $terraformer ."', ";
$QryUpdatePlanet .= "`ally_deposit` = `ally_deposit` + '". $ally_deposit ."', ";
$QryUpdatePlanet .= "`silo` = `silo` + '". $silo ."' ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '". $id ."' ";
doquery( $QryUpdatePlanet, "planets");
$QryUpdateUser = "UPDATE {{table}} SET ";
$QryUpdateUser .= "`darkmatter` = `darkmatter` - '". $TotalCost ."' ";
$QryUpdateUser .= "WHERE ";
$QryUpdateUser .= "`id` = '". $player ."' ";
doquery( $QryUpdateUser, "users");
Message ( "Покупка", "Покупка состоялась" );
} else {
Message ( "Покупка не состоялась", "У вас нет нужного кол-ва Темной материи" );
}
}
$Page .= "<br><br><h2></h2>";
$Page .= "<table width=404><tbody><tr>";
$Page .= "<td class=c colspan=3>Информация игрока</td></tr>";
$Page .= "<tr><th width=33%><font color=skyblue> ".$PlayerName."</font></th>";
$Page .= "<th width=33%><font color=skyblue> ".$PlanetName."</font></th>";
$Page .= "<th width=33%><font color=skyblue> ".$AvailPoints."</font> ТМ</th></tr>";
$Page .= "</tbody></table>";
$Page .= "<table width=404><tbody><tr>";
$Page .= "<tr><td class=c><div align=center><a href=\"/game.php?page=shop\"><font color=skyblue>Назад</font></a></div></td>";
$Page .= "</tbody></table>";
$Page .= "<form action=donorbuildings.php method=post><input type=\"hidden\" name=\"mode\" value=\"addit\">";
$Page .= "<table width=404><tbody><tr>";
$Page .= "<td class=c colspan=4>Покупка зданий</td></tr>";
$Page .= "<tr><th>Цена</th><th>Наименование</th><th>Кол-во</th><th>Уровень</th></tr>";
if ($planetrow['planet_type'] == 1) {
$Page .= "<tr><th>".$levelcost1."</th><th>".$donorname['1']."</th><th><input name=".$donorid['1']." type=checkbox value=1></th><th>".$planetrow[$donorid['1']]."</th></tr>";
$Page .= "<tr><th>".$levelcost2."</th><th>".$donorname['2']."</th><th><input name=".$donorid['2']." type=checkbox value=1></th><th>".$planetrow[$donorid['2']]."</th></tr>";
$Page .= "<tr><th>".$levelcost3."</th><th>".$donorname['3']."</th><th><input name=".$donorid['3']." type=checkbox value=1></th><th>".$planetrow[$donorid['3']]."</th></tr>";
$Page .= "<tr><th>".$levelcost4."</th><th>".$donorname['4']."</th><th><input name=".$donorid['4']." type=checkbox value=1></th><th>".$planetrow[$donorid['4']]."</th></tr>";
$Page .= "<tr><th>".$levelcost12."</th><th>".$donorname['12']."</th><th><input name=".$donorid['12']." type=checkbox value=1></th><th>".$planetrow[$donorid['12']]."</th></tr>";
$Page .= "<tr><th>".$levelcost14."</th><th>".$donorname['14']."</th><th><input name=".$donorid['14']." type=checkbox value=1></th><th>".$planetrow[$donorid['14']]."</th></tr>";
$Page .= "<tr><th>".$levelcost15."</th><th>".$donorname['15']."</th><th><input name=".$donorid['15']." type=checkbox value=1></th><th>".$planetrow[$donorid['15']]."</th></tr>";
$Page .= "<tr><th>".$levelcost21."</th><th>".$donorname['21']."</th><th><input name=".$donorid['21']." type=checkbox value=1></th><th>".$planetrow[$donorid['21']]."</th></tr>";
$Page .= "<tr><th>".$levelcost22."</th><th>".$donorname['22']."</th><th><input name=".$donorid['22']." type=checkbox value=1></th><th>".$planetrow[$donorid['22']]."</th></tr>";
$Page .= "<tr><th>".$levelcost23."</th><th>".$donorname['23']."</th><th><input name=".$donorid['23']." type=checkbox value=1></th><th>".$planetrow[$donorid['23']]."</th></tr>";
$Page .= "<tr><th>".$levelcost24."</th><th>".$donorname['24']."</th><th><input name=".$donorid['24']." type=checkbox value=1></th><th>".$planetrow[$donorid['24']]."</th></tr>";
$Page .= "<tr><th>".$levelcost31."</th><th>".$donorname['31']."</th><th><input name=".$donorid['31']." type=checkbox value=1></th><th>".$planetrow[$donorid['31']]."</th></tr>";
$Page .= "<tr><th>".$levelcost33."</th><th>".$donorname['33']."</th><th><input name=".$donorid['33']." type=checkbox value=1></th><th>".$planetrow[$donorid['33']]."</th></tr>";
$Page .= "<tr><th>".$levelcost34."</th><th>".$donorname['34']."</th><th><input name=".$donorid['34']." type=checkbox value=1></th><th>".$planetrow[$donorid['34']]."</th></tr>";
$Page .= "<tr><th>".$levelcost44."</th><th>".$donorname['44']."</th><th><input name=".$donorid['44']." type=checkbox value=1></th><th>".$planetrow[$donorid['44']]."</th></tr>";
}
else if ($planetrow['planet_type'] == 3) {
$Page .= "<tr><th>".$levelcost4."</th><th>".$donorname['4']."</th><th><input name=".$donorid['4']." type=checkbox value=1></th><th>".$planetrow[$donorid['4']]."</th></tr>";
$Page .= "<tr><th>".$levelcost12."</th><th>".$donorname['12']."</th><th><input name=".$donorid['12']." type=checkbox value=1></th><th>".$planetrow[$donorid['12']]."</th></tr>";
$Page .= "<tr><th>".$levelcost14."</th><th>".$donorname['14']."</th><th><input name=".$donorid['14']." type=checkbox value=1></th><th>".$planetrow[$donorid['14']]."</th></tr>";
$Page .= "<tr><th>".$levelcost15."</th><th>".$donorname['15']."</th><th><input name=".$donorid['15']." type=checkbox value=1></th><th>".$planetrow[$donorid['15']]."</th></tr>";
$Page .= "<tr><th>".$levelcost21."</th><th>".$donorname['21']."</th><th><input name=".$donorid['21']." type=checkbox value=1></th><th>".$planetrow[$donorid['21']]."</th></tr>";
$Page .= "<tr><th>".$levelcost22."</th><th>".$donorname['22']."</th><th><input name=".$donorid['22']." type=checkbox value=1></th><th>".$planetrow[$donorid['22']]."</th></tr>";
$Page .= "<tr><th>".$levelcost23."</th><th>".$donorname['23']."</th><th><input name=".$donorid['23']." type=checkbox value=1></th><th>".$planetrow[$donorid['23']]."</th></tr>";
$Page .= "<tr><th>".$levelcost24."</th><th>".$donorname['24']."</th><th><input name=".$donorid['24']." type=checkbox value=1></th><th>".$planetrow[$donorid['24']]."</th></tr>";
$Page .= "<tr><th>".$levelcost31."</th><th>".$donorname['31']."</th><th><input name=".$donorid['31']." type=checkbox value=1></th><th>".$planetrow[$donorid['31']]."</th></tr>";
$Page .= "<tr><th>".$levelcost33."</th><th>".$donorname['33']."</th><th><input name=".$donorid['33']." type=checkbox value=1></th><th>".$planetrow[$donorid['33']]."</th></tr>";
$Page .= "<tr><th>".$levelcost34."</th><th>".$donorname['34']."</th><th><input name=".$donorid['34']." type=checkbox value=1></th><th>".$planetrow[$donorid['34']]."</th></tr>";
$Page .= "<tr><th>".$levelcost44."</th><th>".$donorname['44']."</th><th><input name=".$donorid['44']." type=checkbox value=1></th><th>".$planetrow[$donorid['44']]."</th></tr>";
}
$Page .= "<tr><th colspan=3><input type=Submit value=Купить></th></tr>";
$Page .= "</tbody></tr></table></form>";
// Show Adsense Ad
if ($adsense_config['donorstore_on'] == 1) {
$Page .= "<div>".$adsense_config['overview_script']."</div>";
} else {
$Page .= "";
}
+
display($Page, $lang['donor'], true, '', false);
?>
Весь ХТМЛ код нужно занести в TPL файл и оттуда построить вывод в данный ПХП скрипт..
Приблизительно так выглядет TPL:
HTML:
<br />
<div id="content">
<form action="game.php?page=trader" method="post">
<input type="hidden" name="action" value="2">
<table width="600">
<tr>
<td class="c" colspan="4">123
</td>
</tr><tr>
<th>1</th>
<th>1</th>
<th>1</th>
<th>1</th>
</tr>
<tr>
<th>2</th>
<th>2</th>
<th>2</th>
<th><input name="submit" type="submit" value="{tr_call_trader_submit}" /></th>
</tr>
<tr>
<th colspan="4"><div align="left"><a href="#">{shop_back}</a></div></th>
</tr>
</table>
</form>
</div>
Вот пример нормально работающего скрипта такого типа:
PHP:
<?php
if(!defined('INSIDE')){ die(header("location:../../"));}
function ShowTraderPage($CurrentPlanet)
{
global $phpEx, $lang;
$parse = $lang;
if (isset($_POST['ress']) && $_POST['ress'] != '')
{
switch ($_POST['ress'])
{
case 'metal':
{
if ($_POST['cristal'] < 0 or $_POST['deut'] < 0)
{
message($lang['tr_only_positive_numbers'], "game." . $phpEx . "?page=trader",1);
}
else
{
$necessaire = (($_POST['cristal'] * 2) + ($_POST['deut'] * 4));
if ($CurrentPlanet['metal'] > $necessaire)
{
$QryUpdatePlanet = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`metal` = `metal` - ".round($necessaire).", ";
$QryUpdatePlanet .= "`crystal` = `crystal` + ".round($_POST['cristal']).", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` + ".round($_POST['deut'])." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '".$CurrentPlanet['id']."';";
doquery($QryUpdatePlanet , 'planets');
$planetrow['metal'] -= $necessaire;
$CurrentPlanet['cristal'] += $_POST['cristal'];
$CurrentPlanet['deuterium'] += $_POST['deut'];
}
else
{
message($lang['tr_not_enought_metal'], "game." . $phpEx . "?page=trader",1);
}
}
break;
}
case 'cristal':
{
if ($_POST['metal'] < 0 or $_POST['deut'] < 0)
{
message($lang['tr_only_positive_numbers'], "game." . $phpEx . "?page=trader",1);
}
else
{
$necessaire = ((abs($_POST['metal']) * 0.5) + (abs($_POST['deut']) * 2));
if ($CurrentPlanet['crystal'] > $necessaire)
{
$QryUpdatePlanet = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`metal` = `metal` + ".round($_POST['metal']).", ";
$QryUpdatePlanet .= "`crystal` = `crystal` - ".round($necessaire).", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` + ".round($_POST['deut'])." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '".$CurrentPlanet['id']."';";
doquery($QryUpdatePlanet , 'planets');
$CurrentPlanet['metal'] += $_POST['metal'];
$CurrentPlanet['cristal'] -= $necessaire;
$CurrentPlanet['deuterium'] += $_POST['deut'];
}
else
{
message($lang['tr_not_enought_crystal'], "game." . $phpEx . "?page=trader",1);
}
}
break;
}
case 'deuterium':
{
if ($_POST['cristal'] < 0 or $_POST['metal'] < 0)
{
message($lang['tr_only_positive_numbers'], "game." . $phpEx . "?page=trader",1);
}
else
{
$necessaire = ((abs($_POST['metal']) * 0.25) + (abs($_POST['cristal']) * 0.5));
if ($CurrentPlanet['deuterium'] > $necessaire)
{
$QryUpdatePlanet = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`metal` = `metal` + ".round($_POST['metal']).", ";
$QryUpdatePlanet .= "`crystal` = `crystal` + ".round($_POST['cristal']).", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` - ".round($necessaire)." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '".$CurrentPlanet['id']."';";
doquery($QryUpdatePlanet , 'planets');
$CurrentPlanet['metal'] += $_POST['metal'];
$CurrentPlanet['cristal'] += $_POST['cristal'];
$CurrentPlanet['deuterium'] -= $necessaire;
}
else
{
message($lang['tr_not_enought_deuterium'], "game." . $phpEx . "?page=trader",1);
}
}
break;
}
}
message($lang['tr_exchange_done'],"game." . $phpEx . "?page=trader",1);
}
else
{
if ($_POST['action'] != 2)
{
$template = gettemplate('trader/trader_main');
}
else
{
$parse['mod_ma_res'] = '1';
switch ($_POST['choix'])
{
case 'metal':
$template = gettemplate('trader/trader_metal');
$parse['mod_ma_res_a'] = '2';
$parse['mod_ma_res_b'] = '4';
break;
case 'cristal':
$template = gettemplate('trader/trader_cristal');
$parse['mod_ma_res_a'] = '0.5';
$parse['mod_ma_res_b'] = '2';
break;
case 'deut':
$template = gettemplate('trader/trader_deuterium');
$parse['mod_ma_res_a'] = '0.25';
$parse['mod_ma_res_b'] = '0.5';
break;
}
}
}
return display(parsetemplate($template,$parse));
}
?>
TPL файлы:
HTML:
<br />
<div id="content">
<form action="game.php?page=trader" method="post">
<input type="hidden" name="action" value="2">
<table width="600">
<tr>
<td class="c" colspan="2">{tr_call_trader}</td>
</tr><tr>
<th>{shop_ask}</th>
<th colspan="-7"><select name="choix" size="1">
<option value="metal">{Metal}</option>
<option value="cristal">{Crystal}</option>
<option value="deut">{Deuterium}</option>
</select></th>
</tr>
<tr>
<th>{shop_exchange}</th>
<th colspan="-7">{tr_exchange_quota}</th>
</tr>
<tr>
<th>{shop_cause}</th>
<th colspan="-7"><input name="submit" type="submit" value="{tr_call_trader_submit}" /></th>
</tr>
<tr>
<th colspan="2"><div align="left"><a href="/game.php?page=shop">{shop_back}</a></div></th>
</tr>
</table>
</form>
</div>
HTML:
<script type="text/javascript" >
function calcul() {
var Metal = document.forms['trader'].elements['metal'].value;
var Cristal = document.forms['trader'].elements['cristal'].value;
Metal = Metal * {mod_ma_res_a};
Cristal = Cristal * {mod_ma_res_b};
var Deuterium = Metal + Cristal;
document.getElementById("deuterio").innerHTML=Deuterium;
if (isNaN(document.forms['trader'].elements['metal'].value)) {
document.getElementById("deuterio").innerHTML="Sуlo nъmeros";
}
if (isNaN(document.forms['trader'].elements['cristal'].value)) {
document.getElementById("deuterio").innerHTML="Sуlo nъmeros";
}
}
</script>
<br />
<div id="content">
<form id="trader" action="" method="post">
<input type="hidden" name="ress" value="deuterium">
<table width="569">
<tr>
<td class="c" colspan="5"><b>{tr_sell_deuterium}</b></td>
</tr><tr>
<th>{tr_resource}</th>
<th>{tr_amount}</th>
<th>{tr_quota_exchange}</th>
</tr><tr>
<th>{Deuterium}</th>
<th><span id='deuterio'></span> </th>
<th>{mod_ma_res}</th>
</tr><tr>
<th>{Metal}</th>
<th><input name="metal" type="text" value="0" onkeyup="calcul()"/></th>
<th>{mod_ma_res_a}</th>
</tr><tr>
<th>{Crystal}</th>
<th><input name="cristal" type="text" value="0" onkeyup="calcul()"/></th>
<th>{mod_ma_res_b}</th>
</tr><tr>
<th colspan="6"><input type="submit" value="{tr_exchange}" /></th>
</tr>
<tr>
<th colspan="6"><div align="left"><a href="/game.php?page=trader">{shop_back}</a></div></th>
</tr>
</table>
</form>
</div>
Помогите пожалуйста разобраться!!