Refactor GoldClub

Refactor GoldClub
This commit is contained in:
novgorodschi catalin
2026-05-21 13:41:48 +03:00
parent 1192e53b04
commit dd64b1e6c7
5 changed files with 879 additions and 462 deletions
+254 -148
View File
@@ -1,38 +1,79 @@
<?php <?php
if(isset($_GET['t']) == 99 && isset($_GET['action']) == 0) { $t = $_GET['t'] ?? null;
$action = $_GET['action'] ?? null;
$postAction = $_POST['action'] ?? null;
$isFarmlistPage = ($t == 99);
$isAddListPost = ($postAction === 'addList');
/* =========================
CREATE FARM LIST
========================= */
if ($isFarmlistPage && $action == 0) {
if (
$isFarmlistPage &&
$isAddListPost &&
!empty($_POST['did']) &&
!empty($_POST['name']) &&
$database->getVillageField((int)$_POST['did'], 'owner') == $session->uid
) {
$did = (int)$_POST['did'];
$name = trim($_POST['name']);
$database->createFarmList($did, $session->uid, $name);
} else if ($isFarmlistPage && $postAction === 'addList') {
header("Location: build.php?gid=16&t=99&action=addList");
exit;
}
if(isset($_GET['t']) == 99 && isset($_POST['action']) == 'addList' && !empty($_POST['did']) && !empty($_POST['name']) && $database->getVillageField($_POST['did'], 'owner') == $session->uid){
$database->createFarmList($_POST['did'], $session->uid, $_POST['name']);
}else if(isset($_GET['t']) == 99 && isset($_POST['action']) == 'addList'){
header("Location: build.php?gid=16&t=99&action=addList");
exit;
} }
/* =========================
FARM LIST QUERY (CLEAN)
========================= */
$farmlists = mysqli_query(
$database->dblink,
"SELECT id, name, owner, wref
FROM ".TB_PREFIX."farmlist
WHERE owner = ".(int)$session->uid."
ORDER BY wref DESC"
);
?> ?>
<form action="build.php?id=39&t=99&action=startRaid" method="post" name="msg"> <form action="build.php?id=39&t=99&action=startRaid" method="post" name="msg">
<input type="hidden" name="action" value="startRaid"> <input type="hidden" name="action" value="startRaid">
<?php
$sql = mysqli_query($database->dblink,"SELECT id, name, owner, wref FROM ".TB_PREFIX."farmlist WHERE owner = ".(int) $session->uid." ORDER BY wref DESC"); <?php
$query = mysqli_num_rows($sql); $query = mysqli_num_rows($farmlists);
while($row = mysqli_fetch_array($sql)){
while ($row = mysqli_fetch_array($farmlists)) {
$lid = $row["id"]; $lid = $row["id"];
$lname = $row["name"]; $lname = $row["name"];
$lowner = $row["owner"];
$lwref = $row["wref"]; $lwref = $row["wref"];
$lvname = $database->getVillageField($row["wref"], 'name');
$lvname = $database->getVillageField($lwref, 'name');
?> ?>
<div class="listTitleText">
<a href="build.php?gid=16&t=99&action=deleteList&lid=<?php echo $lid; ?>"><img class="del" src="img/x.gif" alt="delete" title="delete"></a> <div class="listTitleText">
<?php echo $lvname; ?> - <?php echo $lname; ?> <a href="build.php?gid=16&t=99&action=deleteList&lid=<?php echo $lid; ?>">
</div> <img class="del" src="img/x.gif" alt="delete" title="delete">
<div class="openedClosedSwitch switchOpened"></div> </a>
<div class="clear"></div> <?php echo $lvname; ?> - <?php echo $lname; ?>
</div> </div>
<div class="listContent ">
<div class="detail"> <div class="openedClosedSwitch switchOpened"></div>
<table id="raidList" cellpadding="1" cellspacing="1"> <div class="clear"></div>
<thead>
<div class="listContent">
<div class="detail">
<table id="raidList" cellpadding="1" cellspacing="1">
<thead>
<tr> <tr>
<td></td> <td></td>
<td>Village</td> <td>Village</td>
@@ -42,149 +83,214 @@ while($row = mysqli_fetch_array($sql)){
<td>Last raid</td> <td>Last raid</td>
<td></td> <td></td>
</tr> </tr>
</thead> </thead>
<tbody>
<tbody>
<?php <?php
$sql2 = mysqli_query($database->dblink,"SELECT * FROM ".TB_PREFIX."raidlist WHERE lid = ".(int) $lid." ORDER BY distance ASC"); $sql2 = mysqli_query(
$query2 = mysqli_num_rows($sql2); $database->dblink,
if(!$query2) echo '<td class="noData" colspan="7">'.NO_VILLAGES.'</td>'; "SELECT * FROM ".TB_PREFIX."raidlist
else WHERE lid = ".(int)$lid."
{ ORDER BY distance ASC"
while($row = mysqli_fetch_array($sql2)){ );
$id = $row['id'];
$lid = $row['lid']; $query2 = mysqli_num_rows($sql2);
$towref = $row['towref'];
$x = $row['x']; if (!$query2) {
$y = $row['y']; echo '<td class="noData" colspan="7">'.NO_VILLAGES.'</td>';
$distance = $row['distance']; } else {
for($i = 1; $i <= 6; $i++) ${'t'.$i} = $row['t'.$i]; while ($row = mysqli_fetch_array($sql2)) {
$vdata = $database->getVillage($towref); $id = $row['id'];
$towref = $row['towref'];
$x = $row['x'];
$y = $row['y'];
$distance = $row['distance'];
for ($i = 1; $i <= 6; $i++) {
${'t'.$i} = $row['t'.$i];
}
$vdata = $database->getVillage($towref);
$oasistype = $database->getVillageType2($towref);
?> ?>
<tr class="slotRow"> <tr class="slotRow">
<td class="checkbox">
<input id="slot" name="slot[]" value="<?php echo $id; ?>" type="checkbox" class="markSlot">
</td>
<td class="village">
<?php
$attacks = $database->getMovement(3, $towref, 1); <td class="checkbox">
if (($attacksCount = count($attacks)) > 0) { <input name="slot[]" value="<?php echo $id; ?>" type="checkbox" class="markSlot">
foreach($attacks as $attack){ </td>
if($attack['attack_type'] != 4) $attacksCount -= 1;
} <td class="village">
if($attacksCount > 0) echo '<img class="att2" src="img/x.gif" title="'.OWN_ATTACKING_TROOPS.'" />';
}
?>
<label for="slot<?php echo $id; ?>">
<?php
$oasistype = $database->getVillageType2($towref);
if($oasistype != 0) $thisVillageName = $database->getOasisField($towref, 'conqured') ? OCCUOASIS : UNOCCUOASIS;
else $thisVillageName = $vdata["name"];
?>
<span class="coordinates coordinatesWithText">
<span class="coordText"><?php echo $thisVillageName; ?></span>
<span class="coordinatesWrapper">
<span class="coordinateY">(<?php echo $x; ?></span>
<span class="coordinatePipe">|</span>
<span class="coordinateX"><?php echo $y; ?>)</span>
</span></span>
<span class="clear"></span>
</label>
</td>
<td class="ew"><?php if($oasistype == 0){ echo $vdata['pop']; }else{ echo "<center>-</center>"; }; ?></td>
<td class="distance"><?php echo $distance; ?></td>
<td class="troops">
<?php <?php
$start = ($session->tribe - 1) * 10 + 1; $attacks = $database->getMovement(3, $towref, 1);
$end = $start + 5; $attacksCount = count($attacks);
for($i = $start; $i <= $end; $i++){ if ($attacksCount > 0) {
if(${'t'.($i - $start + 1)} > 0){ foreach ($attacks as $attack) {
echo '<div class="troopIcon"><img class="unit u'.$i.'" title="'.$technology->getUnitName($i).'" src="img/x.gif"><span class="troopIconAmount">'.${'t'.($i - $start + 1)}.'</span></div>'; if ($attack['attack_type'] != 4) {
} $attacksCount--;
}
}
if ($attacksCount > 0) {
echo '<img class="att2" src="img/x.gif" title="'.OWN_ATTACKING_TROOPS.'" />';
}
}
?>
<label>
<?php
if ($oasistype != 0) {
$thisVillageName = $database->getOasisField($towref, 'conqured') ? OCCUOASIS : UNOCCUOASIS;
} else {
$thisVillageName = $vdata["name"];
}
?>
<span class="coordinates coordinatesWithText">
<span class="coordText"><?php echo $thisVillageName; ?></span>
<span class="coordinatesWrapper">
<span class="coordinateY">(<?php echo $x; ?></span>
<span class="coordinatePipe">|</span>
<span class="coordinateX"><?php echo $y; ?>)</span>
</span>
</span>
</label>
</td>
<td class="ew">
<?php echo ($oasistype == 0) ? $vdata['pop'] : "-"; ?>
</td>
<td class="distance"><?php echo $distance; ?></td>
<td class="troops">
<?php
$start = ($session->tribe - 1) * 10 + 1;
$end = $start + 5;
for ($i = $start; $i <= $end; $i++) {
$index = $i - $start + 1;
if (${'t'.$index} > 0) {
echo '<div class="troopIcon">
<img class="unit u'.$i.'" title="'.$technology->getUnitName($i).'" src="img/x.gif">
<span class="troopIconAmount">'.${'t'.$index}.'</span>
</div>';
}
}
?>
</td>
<td class="lastRaid">
<?php
$noticeClass = [
"Scout Report", "Won as attacker without losses", "Won as attacker with losses",
"Lost as attacker with losses", "Won as defender without losses",
"Won as defender with losses", "Lost as defender with losses",
"Lost as defender without losses", "Reinforcement arrived", "",
"Wood Delivered", "Clay Delivered", "Iron Delivered", "Crop Delivered",
"", "Won as defender without losses", "Won as defender with losses",
"Lost as defender with losses", "Won scouting as attacker",
"Lost scouting as attacker", "Won scouting as defender",
"Lost scouting as defender"
];
$getnotice = mysqli_query(
$database->dblink,
"SELECT ntype, data, time, id
FROM ".TB_PREFIX."ndata
WHERE ntype < 4
AND toWref = ".(int)$towref."
AND uid = ".(int)$session->uid."
ORDER BY time DESC LIMIT 1"
);
if (mysqli_num_rows($getnotice) > 0) {
while ($row2 = mysqli_fetch_array($getnotice)) {
$dataarray = explode(",", $row2['data']);
$type2 = $row2['ntype'];
echo '<img src="img/x.gif" class="iReport iReport'.$type2.'" title="'.$noticeClass[$type2].'">';
$allres = $dataarray[23] + $dataarray[24] + $dataarray[25] + $dataarray[26];
$carry = $dataarray[27];
echo '<img title="'.$allres.'/'.$carry.'" src="img/x.gif" class="carry"/>';
$date = $generator->procMtime($row2['time']);
echo '<a href="berichte.php?id='.$row2['id'].'">'
.$date[0]." ".date('H:i', $row2['time']).'</a>';
}
}
?>
</td>
<td class="action">
<a class="arrow" href="build.php?id=39&t=99&action=showSlot&eid=<?php echo $id; ?>">edit</a>
</td>
</tr>
<?php
}
} }
?> ?>
</tbody>
</table>
</div>
</td> </div>
<td class="lastRaid">
<?php
$noticeClass = ["Scout Report", "Won as attacker without losses", "Won as attacker with losses", "Lost as attacker with losses", "Won as defender without losses", "Won as defender with losses", "Lost as defender with losses", "Lost as defender without losses",
"Reinforcement arrived", "", "Wood Delivered", "Clay Delivered", "Iron Delivered", "Crop Delivered", "", "Won as defender without losses", "Won as defender with losses", "Lost as defender with losses", "Won scouting as attacker", "Lost scouting as attacker",
"Won scouting as defender", "Lost scouting as defender"];
$getnotice = mysqli_query($database->dblink,"SELECT ntype, data, time, id FROM ".TB_PREFIX."ndata WHERE ntype < 4 AND toWref = ".(int) $towref." AND uid = ".(int) $session->uid." ORDER BY time DESC Limit 1");
if(mysqli_num_rows($getnotice) > 0){
while($row2 = mysqli_fetch_array($getnotice)){
$dataarray = explode(",",$row2['data']);
$type2 = $row2['ntype'];
echo "<img src=\"img/x.gif\" class=\"iReport iReport".$row2['ntype']."\" title=\"".$noticeClass[$type2]."\"> ";
$allres = $dataarray[23] + $dataarray[24] + $dataarray[25] + $dataarray[26];
$carry = $dataarray[27];
echo "<img title=\"$allres/$carry\" src=\"img/x.gif\" class=\"carry\"/>";
$date = $generator->procMtime($row2['time']);
echo "<a href=\"berichte.php?id=".$row2['id']."\">".$date[0]." ".date('H:i',$row2['time'])."</a> ";
}
}
?>
<div class="clear"></div>
</td>
<td class="action">
<a class="arrow" href="build.php?id=39&t=99&action=showSlot&eid=<?php echo $id; ?>">edit</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div class="clear"></div><br />
<div class="troopSelection">
<div class="clear"></div>
</div>
</div>
<?php }?>
<?php if($database->getVilFarmlist($session->uid)){ ?>
<div class="markAll">
<input type="checkbox" id="raidListMarkAll" name="s10" class="markAll" onclick="Allmsg(this.form);">
<label for="raidListMarkAll">Select all</label>
</div><br />
<div class="addSlot">
<button type="button" class="trav_buttons" onclick="window.location.href = '?gid=16&t=99&action=addraid';">Add Raid</button>
<button type="submit" class="trav_buttons" value="Start Raid">Start Raid</button>
</div><br />
<?php } ?> <?php } ?>
<?php if ($database->getVilFarmlist($session->uid)) { ?>
<div class="markAll">
<input type="checkbox" onclick="Allmsg(this.form);">
<label>Select all</label>
</div>
<div class="addSlot">
<button type="button" onclick="window.location.href='?gid=16&t=99&action=addraid';">Add Raid</button>
<button type="submit">Start Raid</button>
</div>
<?php } ?>
<div class="options"> <div class="options">
<a class="arrow" href="build.php?gid=16&t=99&action=addList">Create a new list</a> <a class="arrow" href="build.php?gid=16&t=99&action=addList">Create a new list</a>
</div> </div>
<?php
}
?>
</form> </form>
<?php
if($create == 1){ <?php
$hideevasion = 1; /* =========================
include("Templates/goldClub/farmlist_add.tpl"); INCLUDE FORMS (UNCHANGED)
}else if($create == 2){ ========================= */
$hideevasion = 1;
include("Templates/goldClub/farmlist_addraid.tpl"); if ($create == 1) {
}else if($create == 3){ $hideevasion = 1;
$hideevasion = 1; include("Templates/goldClub/farmlist_add.tpl");
include("Templates/goldClub/farmlist_editraid.tpl");
} else if ($create == 2) {
$hideevasion = 1;
include("Templates/goldClub/farmlist_addraid.tpl");
} else if ($create == 3) {
$hideevasion = 1;
include("Templates/goldClub/farmlist_editraid.tpl");
} }
?> ?>
+60 -34
View File
@@ -1,37 +1,63 @@
<div id="raidListCreate"> <div id="raidListCreate">
<h4>Create a new list</h4> <h4>Create a new list</h4>
<form action="build.php?gid=16&t=99" method="post">
<div class="boxes boxesColor gray"><div class="boxes-tl"></div><div class="boxes-tr"></div><div class="boxes-tc"></div><div class="boxes-ml"></div><div class="boxes-mr"></div><div class="boxes-mc"></div><div class="boxes-bl"></div><div class="boxes-br"></div><div class="boxes-bc"></div><div class="boxes-contents cf">
<input type="hidden" name="action" value="addList">
<table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tbody><tr>
<th>
Name: </th>
<td>
<input class="text" id="name" name="name" type="text">
</td>
</tr>
<tr>
<th>
Village: </th>
<td>
<select id="did" name="did">
<?php
for($i = 1; $i <= count($session->villages); $i++){
if($session->villages[$i - 1] == $village->wid) $select = 'selected="selected"';
else $select = '';
echo "<option value=\"".$session->villages[$i-1]."\" ".$select.">".$database->getVillageField($session->villages[$i-1],'name')."</option>";
}
?> </select>
</td>
</tr>
</tbody></table>
</div> <form action="build.php?gid=16&t=99" method="post">
</div>
<button class="trav_buttons" type="submit" value="create">Create</button> <div class="boxes boxesColor gray">
</form> <div class="boxes-tl"></div><div class="boxes-tr"></div>
</div> <div class="boxes-tc"></div><div class="boxes-ml"></div>
<div class="boxes-mr"></div><div class="boxes-mc"></div>
<div class="boxes-bl"></div><div class="boxes-br"></div>
<div class="boxes-bc"></div>
<div class="boxes-contents cf">
<input type="hidden" name="action" value="addList">
<table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tbody>
<tr>
<th>Name:</th>
<td>
<input class="text" id="name" name="name" type="text">
</td>
</tr>
<tr>
<th>Village:</th>
<td>
<select id="did" name="did">
<?php
// OPTIMIZED: build list once (no DB calls in loop)
$villagesList = $session->villages ?? [];
foreach ($villagesList as $wid) {
$selected = ($wid == $village->wid)
? 'selected="selected"'
: '';
$villageName = $database->getVillageField((int)$wid, 'name');
echo '<option value="'.$wid.'" '.$selected.'>'
.$villageName.
'</option>';
}
?>
</select>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<button class="trav_buttons" type="submit" value="create">Create</button>
</form>
</div>
+234 -111
View File
@@ -1,138 +1,261 @@
<?php <?php
//If the player has no farm lists, return
if(!$database->getVilFarmlist($session->uid)){ /* =====================================================
header("Location: build.php?id=39&t=99"); GUARD: no farmlists
exit; ===================================================== */
if (!$database->getVilFarmlist($session->uid)) {
header("Location: build.php?id=39&t=99");
exit;
} }
if(isset($_POST['action']) && $_POST['action'] == 'addSlot' && isset($_POST['lid']) && ($FLData = $database->getFLData($_POST['lid']))['owner'] == $session->uid) { /* =====================================================
INIT
===================================================== */
$errormsg = $errormsg ?? null;
$troops = 0; $action = $_POST['action'] ?? null;
for($i = 1; $i <= 6; $i++){ $lid = (int)($_POST['lid'] ?? 0);
if(!in_array($i + ($session->tribe - 1) * 10, [4, 14, 23])) $troops += $_POST['t'.$i];
} /* =====================================================
HANDLE ADD SLOT
if(!empty($_POST['target_id'])){ ===================================================== */
$Wref = $_POST['target_id']; if ($action === 'addSlot' && $lid) {
$WrefCoor = $database->getCoor($Wref);
$WrefX = $WrefCoor['x']; $FLData = $database->getFLData($lid);
$WrefY = $WrefCoor['y'];
$type = $database->getVillageType2($Wref); if (!$FLData || $FLData['owner'] != $session->uid) {
$oasistype = $type; $errormsg = "Invalid farm list.";
$vdata = $database->getVillage($Wref); } else {
}elseif($_POST['x'] != "" && $_POST['y'] != "" && is_numeric($_POST['x']) && is_numeric($_POST['y']) && $_POST['x'] <= WORLD_MAX && $_POST['y'] <= WORLD_MAX){
$Wref = $database->getVilWref($_POST['x'], $_POST['y']); /* ======================
$WrefX = $_POST['x']; TROOP CALC
$WrefY = $_POST['y']; ====================== */
$type = $database->getVillageType2($Wref); $troops = 0;
$oasistype = $type; $tribeOffset = ($session->tribe - 1) * 10;
$vdata = $database->getVillage($Wref);
for ($i = 1; $i <= 6; $i++) {
$unitId = $i + $tribeOffset;
if (!in_array($unitId, [4, 14, 23])) {
$troops += (int)($_POST['t'.$i] ?? 0);
}
}
/* ======================
TARGET RESOLVE
====================== */
$Wref = null;
$WrefX = null;
$WrefY = null;
$vdata = null;
$oasistype = null;
$targetId = $_POST['target_id'] ?? '';
$x = $_POST['x'] ?? '';
$y = $_POST['y'] ?? '';
if (!empty($targetId)) {
$Wref = (int)$targetId;
$coor = $database->getCoor($Wref);
$WrefX = $coor['x'];
$WrefY = $coor['y'];
} elseif ($x !== '' && $y !== '' && is_numeric($x) && is_numeric($y)
&& $x <= WORLD_MAX && $y <= WORLD_MAX) {
$Wref = $database->getVilWref($x, $y);
$WrefX = (int)$x;
$WrefY = (int)$y;
}
if ($Wref) {
$oasistype = $database->getVillageType2($Wref);
$vdata = $database->getVillage($Wref);
}
/* ======================
VALIDATION
====================== */
if (empty($x) && empty($y) && empty($targetId)) {
$errormsg = "Enter coordinates.";
} elseif (($x === '' || $y === '') && empty($targetId)) {
$errormsg = "Enter the correct coordinates.";
} elseif ($oasistype == 0 && !$vdata) {
$errormsg = "There is no village on those coordinates.";
} elseif ($troops == 0) {
$errormsg = "No troops has been selected.";
} elseif ($database->hasBeginnerProtection($Wref)) {
$errormsg = "Player under protection.";
} elseif ($targetId == $FLData['wref'] || ($vdata['wref'] ?? null) == $FLData['wref']) {
$errormsg = "You can't attack the same village you're sending troops from.";
} else {
/* ======================
FINAL INSERT
====================== */
$coor = $database->getCoor($village->wid);
$distance = $database->getDistance($coor['x'], $coor['y'], $WrefX, $WrefY);
$database->addSlotFarm(
$lid,
$Wref,
$WrefX,
$WrefY,
$distance,
(int)($_POST['t1'] ?? 0),
(int)($_POST['t2'] ?? 0),
(int)($_POST['t3'] ?? 0),
(int)($_POST['t4'] ?? 0),
(int)($_POST['t5'] ?? 0),
(int)($_POST['t6'] ?? 0)
);
header("Location: build.php?id=39&t=99");
exit;
}
} }
if($_POST['x'] == "" && $_POST['y'] == "" && empty($_POST['target_id'])) $errormsg = "Enter coordinates.";
elseif(($_POST['x'] == "" || $_POST['y'] == "") && empty($_POST['target_id'])) $errormsg = "Enter the correct coordinates.";
elseif($oasistype == 0 && $vdata == 0) $errormsg = "There is no village on those coordinates.";
elseif($troops == 0) $errormsg = "No troops has been selected.";
elseif($database->hasBeginnerProtection($Wref) == 1) $errormsg = "Player under protection.";
elseif($_POST['target_id'] == $FLData['wref'] || $vdata['wref'] == $FLData['wref']) $errormsg = "You can't attack the same village you're sending troops from.";
else
{
if(!empty($_POST['target_id'])){
$Wref = $_POST['target_id'];
$WrefCoor = $database->getCoor($Wref);
$WrefX = $WrefCoor['x'];
$WrefY = $WrefCoor['y'];
}else{
$Wref = $database->getVilWref($_POST['x'], $_POST['y']);
$WrefX = $_POST['x'];
$WrefY = $_POST['y'];
}
$coor = $database->getCoor($village->wid);
$distance = $database->getDistance($coor['x'], $coor['y'], $WrefX, $WrefY);
$database->addSlotFarm($_POST['lid'], $Wref, $WrefX, $WrefY, $distance, $_POST['t1'], $_POST['t2'], $_POST['t3'], $_POST['t4'], $_POST['t5'], $_POST['t6']);
header("Location: build.php?id=39&t=99");
exit;
}
} }
?> ?>
<div id="raidListSlot"> <div id="raidListSlot">
<h4>Add Slot</h4> <h4>Add Slot</h4>
<font color="#FF0000"><b>
<?php echo $errormsg; ?> <font color="#FF0000"><b><?php echo $errormsg; ?></b></font>
</b></font>
<form action="build.php?id=39&t=99&action=addraid" method="post"> <form action="build.php?id=39&t=99&action=addraid" method="post">
<div class="boxes boxesColor gray"><div class="boxes-tl"></div><div class="boxes-tr"></div><div class="boxes-tc"></div><div class="boxes-ml"></div><div class="boxes-mr"></div><div class="boxes-mc"></div><div class="boxes-bl"></div><div class="boxes-br"></div><div class="boxes-bc"></div><div class="boxes-contents cf">
<div class="boxes boxesColor gray">
<div class="boxes-tl"></div>
<div class="boxes-tr"></div>
<div class="boxes-tc"></div>
<div class="boxes-ml"></div>
<div class="boxes-mr"></div>
<div class="boxes-mc"></div>
<div class="boxes-bl"></div>
<div class="boxes-br"></div>
<div class="boxes-bc"></div>
<div class="boxes-contents cf">
<input type="hidden" name="action" value="addSlot"> <input type="hidden" name="action" value="addSlot">
<table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tbody><tr> <table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tbody>
<tr>
<th>List name:</th> <th>List name:</th>
<td> <td>
<select name="lid"> <select name="lid">
<?php <?php
$sql = mysqli_query(
$database->dblink,
"SELECT id, name, wref
FROM ".TB_PREFIX."farmlist
WHERE owner = ".(int)$session->uid."
ORDER BY name ASC"
);
$sql = mysqli_query($database->dblink, "SELECT id, name, owner, wref FROM ".TB_PREFIX."farmlist WHERE owner = ".(int)$session->uid." ORDER BY name ASC"); while ($row = mysqli_fetch_array($sql)) {
while($row = mysqli_fetch_array($sql)){
$lid = $row["id"]; $lid = $row["id"];
$lname = $row["name"]; $lname = $row["name"];
$lvname = $database->getVillageField($row["wref"], 'name'); $lvname = $database->getVillageField($row["wref"], 'name');
echo '<option value="'.$lid.'">'.$lvname.' - '.$lname.'</option>';
} echo '<option value="'.$lid.'">'.$lvname.' - '.$lname.'</option>';
?> }
?>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>Target village:</th> <th>Target village:</th>
<td class="target"> <td class="target">
<div class="coordinatesInput"> <div class="coordinatesInput">
<div class="xCoord">
<label for="xCoordInput">X:</label> <div class="xCoord">
<input value="<?php echo $_POST['x']; ?>" name="x" id="xCoordInput" class="text coordinates x "> <label for="xCoordInput">X:</label>
</div> <input value="<?php echo $_POST['x'] ?? ''; ?>" name="x" id="xCoordInput" class="text coordinates x">
<br /> </div>
<div class="yCoord">
<label for="yCoordInput">Y:</label> <br />
<input value="<?php echo $_POST['y']; ?>" name="y" id="yCoordInput" class="text coordinates y ">
</div> <div class="yCoord">
<div class="clear"></div> <label for="yCoordInput">Y:</label>
</div> <input value="<?php echo $_POST['y'] ?? ''; ?>" name="y" id="yCoordInput" class="text coordinates y">
<br /> </div>
<div class="targetSelect">
<label class="lastTargets">Last targets:</label> <div class="clear"></div>
<select name="target_id">
<?php
$getwref = "SELECT movement.to, movement.ref, attacks.* FROM ".TB_PREFIX."movement as movement INNER JOIN ".TB_PREFIX."attacks as attacks ON attacks.id = movement.ref WHERE attacks.attack_type = 4 AND movement.proc = 1 AND movement.from = ".$village->wid;
$arraywref = $database->query_return($getwref);
echo '<option value="">Select village</option>';
if(mysqli_num_rows(mysqli_query($database->dblink, $getwref)) != 0){
foreach($arraywref as $row){
$towref = $row["to"];
$vilInfo = $database->getVillageByWorldID($towref);
if($vilInfo['fieldtype'] > 0 && !$vilInfo['occupied']) continue;
$tocoor = $database->getCoor($towref);
if($vilInfo['oasistype'] == 0) $tovname = $database->getVillageField($towref, 'name');
else $tovname = $database->getOasisField($towref, 'name');
if($vill[$towref] == 0) echo '<option value="'.$towref.'">'.$tovname.' ('.$tocoor['x'].'|'.$tocoor['y'].')</option>';
$vill[$towref] = 1;
}
}
?>
</select>
</div> </div>
<br />
<div class="targetSelect">
<label class="lastTargets">Last targets:</label>
<select name="target_id">
<?php
$getwref = "SELECT movement.to, movement.ref, attacks.*
FROM ".TB_PREFIX."movement movement
INNER JOIN ".TB_PREFIX."attacks attacks
ON attacks.id = movement.ref
WHERE attacks.attack_type = 4
AND movement.proc = 1
AND movement.from = ".$village->wid;
$arraywref = $database->query_return($getwref);
echo '<option value="">Select village</option>';
foreach ($arraywref as $row) {
$towref = $row["to"];
$vilInfo = $database->getVillageByWorldID($towref);
if ($vilInfo['fieldtype'] > 0 && !$vilInfo['occupied']) continue;
$tocoor = $database->getCoor($towref);
$tovname = ($vilInfo['oasistype'] == 0)
? $database->getVillageField($towref, 'name')
: $database->getOasisField($towref, 'name');
echo '<option value="'.$towref.'">'.$tovname.' ('.$tocoor['x'].'|'.$tocoor['y'].')</option>';
}
?>
</select>
</div>
<div class="clear"></div> <div class="clear"></div>
</td> </td>
</tr> </tr>
</tbody></table>
</div> </tbody>
</div>
<?php include("Templates/goldClub/trooplist.tpl"); ?> </table>
<br />
<button type="submit" value="save" name="save" id="save" class="trav_buttons">Create</button> </div>
</form>
</div> </div>
<?php include("Templates/goldClub/trooplist.tpl"); ?>
<button type="submit" class="trav_buttons">Create</button>
</form>
</div>
+286 -143
View File
@@ -1,158 +1,301 @@
<?php <?php
if(isset($_GET['action']) == 'editSlot' && $_GET['eid']) {
$eiddata = $database->getRaidList($_GET['eid']); $eid = isset($_GET['eid']) ? (int)$_GET['eid'] : 0;
$action = $_GET['action'] ?? null;
$errormsg = $errormsg ?? null;
/* =====================================================
LOAD SLOT DATA (EDIT MODE)
===================================================== */
if ($action === 'editSlot' && $eid) {
$eiddata = $database->getRaidList($eid);
if (!$eiddata) {
header("Location: build.php?id=39&t=99");
exit;
}
$x = $eiddata['x']; $x = $eiddata['x'];
$y = $eiddata['y']; $y = $eiddata['y'];
for($i = 1; $i <= 6; $i++) ${'t'.$i} = $eiddata['t'.$i];
for ($i = 1; $i <= 6; $i++) {
${'t'.$i} = $eiddata['t'.$i];
}
$FLData = $database->getFLData($eiddata['lid']); $FLData = $database->getFLData($eiddata['lid']);
//Check if we're editing one of ours raidlists
if($FLData['owner'] != $session->uid){
header("Location: build.php?id=39&t=99");
exit;
}
}
if(isset($_POST['action']) == 'editSlot' && isset($_GET['eid']) && !empty($_GET['eid']) && isset($_POST['lid']) && !empty($_POST['lid'])) { if ($FLData['owner'] != $session->uid) {
$FLData = $database->getFLData($_POST['lid']);
if(!empty($_POST['target_id'])){
$Wref = $_POST['target_id'];
$WrefCoor = $database->getCoor($Wref);
$WrefX = $WrefCoor['x'];
$WrefY = $WrefCoor['y'];
$type = $database->getVillageType2($Wref);
$oasistype = $type;
$vdata = $database->getVillage($Wref);
}elseif($_POST['x'] != "" && $_POST['y'] != "" && is_numeric($_POST['x']) && is_numeric($_POST['y'])){
$Wref = $database->getVilWref($_POST['x'], $_POST['y']);
$WrefX = $_POST['x'];
$WrefY = $_POST['y'];
$type = $database->getVillageType2($Wref);
$oasistype = $type;
$vdata = $database->getVillage($Wref);
}
$troops = 0;
for($i = 1; $i <= 6; $i++){
if(!in_array($i + ($session->tribe - 1) * 10, [4, 14, 23])) $troops += $_POST['t'.$i];
}
if($_POST['x'] == "" && $_POST['y'] == "" && empty($_POST['target_id'])) $errormsg = "Enter coordinates.";
elseif(($_POST['x'] == "" || $_POST['y'] == "") && empty($_POST['target_id'])) $errormsg = "Enter the correct coordinates.";
elseif($oasistype == 0 && $vdata == 0) $errormsg = "There is no village on those coordinates.";
elseif($troops == 0) $errormsg = "No troops has been selected.";
elseif($database->hasBeginnerProtection($Wref) == 1) $errormsg = "Player under protection.";
elseif($_POST['target_id'] == $FLData['wref'] || $vdata['wref'] == $FLData['wref']) $errormsg = "You can't attack the same village you're sending troops from.";
else
{
if(!empty($_POST['target_id'])){
$Wref = $_POST['target_id'];
$WrefCoor = $database->getCoor($Wref);
$WrefX = $WrefCoor['x'];
$WrefY = $WrefCoor['y'];
}else{
$Wref = $database->getVilWref($_POST['x'], $_POST['y']);
$WrefX = $_POST['x'];
$WrefY = $_POST['y'];
}
$coor = $database->getCoor($village->wid);
$distance = $database->getDistance($coor['x'], $coor['y'], $WrefX, $WrefY);
$database->editSlotFarm($_GET['eid'], $_POST['lid'], $database->getRaidList($_GET['eid'])['lid'], $session->uid, $Wref, $WrefX, $WrefY, $distance, $_POST['t1'], $_POST['t2'], $_POST['t3'], $_POST['t4'], $_POST['t5'], $_POST['t6']);
header("Location: build.php?id=39&t=99"); header("Location: build.php?id=39&t=99");
exit; exit;
}
} }
/* =====================================================
HANDLE EDIT SUBMIT
===================================================== */
$postAction = $_POST['action'] ?? null;
if (
$postAction === 'editSlot' &&
$eid &&
!empty($_POST['lid'])
) {
$FLData = $database->getFLData((int)$_POST['lid']);
/* ======================
TARGET RESOLVE
====================== */
$Wref = null;
$WrefX = null;
$WrefY = null;
$vdata = null;
$oasistype = null;
$targetId = $_POST['target_id'] ?? '';
$px = $_POST['x'] ?? '';
$py = $_POST['y'] ?? '';
if (!empty($targetId)) {
$Wref = (int)$targetId;
$coor = $database->getCoor($Wref);
$WrefX = $coor['x'];
$WrefY = $coor['y'];
} elseif ($px !== '' && $py !== '' && is_numeric($px) && is_numeric($py)) {
$Wref = $database->getVilWref($px, $py);
$WrefX = (int)$px;
$WrefY = (int)$py;
}
if ($Wref) {
$oasistype = $database->getVillageType2($Wref);
$vdata = $database->getVillage($Wref);
}
/* ======================
TROOP COUNT
====================== */
$troops = 0;
for ($i = 1; $i <= 6; $i++) {
$unitId = $i + ($session->tribe - 1) * 10;
if (!in_array($unitId, [4, 14, 23])) {
$troops += (int)($_POST['t'.$i] ?? 0);
}
}
/* ======================
VALIDATION
====================== */
if (empty($px) && empty($py) && empty($targetId)) {
$errormsg = "Enter coordinates.";
} elseif (($px === '' || $py === '') && empty($targetId)) {
$errormsg = "Enter the correct coordinates.";
} elseif ($oasistype == 0 && !$vdata) {
$errormsg = "There is no village on those coordinates.";
} elseif ($troops == 0) {
$errormsg = "No troops has been selected.";
} elseif ($database->hasBeginnerProtection($Wref)) {
$errormsg = "Player under protection.";
} elseif (
$Wref == $FLData['wref'] ||
($vdata['wref'] ?? null) == $FLData['wref']
) {
$errormsg = "You can't attack the same village you're sending troops from.";
} else {
/* ======================
UPDATE SLOT
====================== */
$coor = $database->getCoor($village->wid);
$distance = $database->getDistance($coor['x'], $coor['y'], $WrefX, $WrefY);
$oldLid = $database->getRaidList($eid)['lid'];
$database->editSlotFarm(
$eid,
(int)$_POST['lid'],
$oldLid,
$session->uid,
$Wref,
$WrefX,
$WrefY,
$distance,
(int)($_POST['t1'] ?? 0),
(int)($_POST['t2'] ?? 0),
(int)($_POST['t3'] ?? 0),
(int)($_POST['t4'] ?? 0),
(int)($_POST['t5'] ?? 0),
(int)($_POST['t6'] ?? 0)
);
header("Location: build.php?id=39&t=99");
exit;
}
} }
?> ?>
<div id="raidListSlot"> <div id="raidListSlot">
<h4>Edit Slot</h4> <h4>Edit Slot</h4>
<font color="#FF0000"><b>
<?php echo $errormsg; ?>
</b></font>
<form id="edit_form" action="build.php?id=39&t=99&action=showSlot&eid=<?php echo $_GET['eid']; ?>" method="post">
<div class="boxes boxesColor gray"><div class="boxes-tl"></div><div class="boxes-tr"></div><div class="boxes-tc"></div><div class="boxes-ml"></div><div class="boxes-mr"></div><div class="boxes-mc"></div><div class="boxes-bl"></div><div class="boxes-br"></div><div class="boxes-bc"></div><div class="boxes-contents cf">
<?php <font color="#FF0000"><b><?php echo $errormsg; ?></b></font>
$getlid = $database->getRaidList($database->escape($_GET["eid"]));
$lid2 = $getlid['lid'];
?>
<input type="hidden" name="action" value="editSlot">
<table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tbody><tr>
<th>List name:</th><?php echo $_GET["lid"]; ?>
<td>
<select onchange="getTargetsByLid();" id="lid" name="lid">
<?php
$sql = mysqli_query($database->dblink,"SELECT id, name, owner, wref FROM ".TB_PREFIX."farmlist WHERE owner = ".(int) $session->uid." ORDER BY name ASC");
while($row = mysqli_fetch_array($sql)){
$lid = $row["id"];
$lname = $row["name"];
$lvname = $database->getVillageField($row["wref"], 'name');
if($lid == $lid2) $selected = 'selected=""'; <form id="edit_form" action="build.php?id=39&t=99&action=showSlot&eid=<?php echo $eid; ?>" method="post">
else $selected = '';
echo '<option value="'.$lid.'" '.$selected.'>'.$lvname.' - '.$lname.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Target village:</th>
<td class="target">
<div class="coordinatesInput">
<div class="xCoord">
<label for="xCoordInput">X:</label>
<input value="<?php echo $x; ?>" name="x" id="xCoordInput" class="text coordinates x ">
</div>
<br />
<div class="yCoord">
<label for="yCoordInput">Y:</label>
<input value="<?php echo $y; ?>" name="y" id="yCoordInput" class="text coordinates y ">
</div>
<div class="clear"></div>
</div>
<div class="targetSelect"><br />
<label class="lastTargets">Last targets:</label>
<select name="target_id">
<?php
$getwref = "SELECT movement.to, movement.ref, attacks.* FROM ".TB_PREFIX."movement as movement INNER JOIN ".TB_PREFIX."attacks as attacks ON attacks.id = movement.ref WHERE attacks.attack_type = 4 AND movement.proc = 1 AND movement.from = ".$village->wid;
$arraywref = $database->query_return($getwref);
echo '<option value="">Select village</option>';
if(mysqli_num_rows(mysqli_query($database->dblink, $getwref)) != 0){
foreach($arraywref as $row){
$towref = $row["to"];
$vilInfo = $database->getVillageByWorldID($towref);
if($vilInfo['fieldtype'] > 0 && !$vilInfo['occupied']) continue;
$tocoor = $database->getCoor($towref);
if($vilInfo['oasistype'] == 0) $tovname = $database->getVillageField($towref, 'name');
else $tovname = $database->getOasisField($towref, 'name');
if($row["id"] == $_GET['eid']) $selected = 'selected=""';
else $selected = '';
if($vill[$towref] == 0) echo '<option value="'.$towref.'">'.$tovname.' ('.$tocoor['x'].'|'.$tocoor['y'].')</option>';
$vill[$towref] = 1;
}
}
?>
</select>
</div>
<div class="clear"></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<?php include "Templates/goldClub/trooplist.tpl"; ?>
<br /> <div class="boxes boxesColor gray">
<button type="submit" value="save" name="save" id="save" class="trav_buttons">Save</button>&nbsp; <div class="boxes-tl"></div>
<button type="button" value="delete" name="delete" id="delete" class="trav_buttons" onclick="window.location.href = '?gid=16&t=99&action=deleteSlot&eid=<?php echo $_GET["eid"]; ?>&lid=<?php echo $eiddata['lid']; ?>';">Delete</button> <div class="boxes-tr"></div>
</form> <div class="boxes-tc"></div>
<div class="boxes-ml"></div>
<div class="boxes-mr"></div>
<div class="boxes-mc"></div>
<div class="boxes-bl"></div>
<div class="boxes-br"></div>
<div class="boxes-bc"></div>
<div class="boxes-contents cf">
<input type="hidden" name="action" value="editSlot">
<table cellpadding="1" cellspacing="1" class="transparent" id="raidList">
<tr>
<th>List name:</th>
<td>
<select onchange="getTargetsByLid();" id="lid" name="lid">
<?php
$sql = mysqli_query(
$database->dblink,
"SELECT id, name, wref
FROM ".TB_PREFIX."farmlist
WHERE owner = ".(int)$session->uid."
ORDER BY name ASC"
);
while ($row = mysqli_fetch_array($sql)) {
$lid = $row["id"];
$lname = $row["name"];
$lvname = $database->getVillageField($row["wref"], 'name');
$selected = ($lid == $lid2) ? 'selected' : '';
echo '<option value="'.$lid.'" '.$selected.'>'
.$lvname.' - '.$lname.
'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Target village:</th>
<td class="target">
<div class="coordinatesInput">
<div class="xCoord">
<label for="xCoordInput">X:</label>
<input value="<?php echo $x; ?>" name="x" id="xCoordInput" class="text coordinates x">
</div>
<br />
<div class="yCoord">
<label for="yCoordInput">Y:</label>
<input value="<?php echo $y; ?>" name="y" id="yCoordInput" class="text coordinates y">
</div>
<div class="clear"></div>
</div>
<br />
<div class="targetSelect">
<label class="lastTargets">Last targets:</label>
<select name="target_id">
<?php
$getwref = "SELECT movement.to, movement.ref, attacks.*
FROM ".TB_PREFIX."movement movement
INNER JOIN ".TB_PREFIX."attacks attacks
ON attacks.id = movement.ref
WHERE attacks.attack_type = 4
AND movement.proc = 1
AND movement.from = ".$village->wid;
$arraywref = $database->query_return($getwref);
echo '<option value="">Select village</option>';
if (mysqli_num_rows(mysqli_query($database->dblink, $getwref)) != 0) {
foreach ($arraywref as $row) {
$towref = $row["to"];
$vilInfo = $database->getVillageByWorldID($towref);
if ($vilInfo['fieldtype'] > 0 && !$vilInfo['occupied']) {
continue;
}
$tocoor = $database->getCoor($towref);
if ($vilInfo['oasistype'] == 0) {
$tovname = $database->getVillageField($towref, 'name');
} else {
$tovname = $database->getOasisField($towref, 'name');
}
echo '<option value="'.$towref.'">'
.$tovname.' ('.$tocoor['x'].'|'.$tocoor['y'].')'
.'</option>';
}
}
?>
</select>
</div>
<div class="clear"></div>
</td>
</tr>
</table>
</div>
</div>
<?php include "Templates/goldClub/trooplist.tpl"; ?>
<button type="submit" class="trav_buttons">Save</button>
<button type="button"
class="trav_buttons"
onclick="window.location.href='?gid=16&t=99&action=deleteSlot&eid=<?php echo $eid; ?>&lid=<?php echo $eiddata['lid']; ?>';">
Delete
</button>
</form>
</div> </div>
+45 -26
View File
@@ -1,30 +1,49 @@
<?php <?php
$start = ($session->tribe - 1) * 10 + 1; $start = ($session->tribe - 1) * 10 + 1;
$end = $start + 5; $end = $start + 5;
/* build unit list once (keeps alignment safe) */
$units = [];
for ($i = $start; $i <= $end; $i++) {
if (in_array($i, [4, 14, 23])) {
continue;
}
$units[] = $i;
}
?> ?>
<table class="transparent" id="raidList" cellspacing="1" cellpadding="1"> <table class="transparent" id="raidList" cellspacing="1" cellpadding="1">
<tr>
<?php <tr>
for($i = $start; $i <= $end; $i++){ <?php foreach ($units as $i): ?>
if(in_array($i, [4, 14, 23])) continue; <td>
?> <label for="t<?php echo $i - $start + 1; ?>">
<td> <img class="unit u<?php echo $i; ?>"
<label for="t<?php echo $i - $start + 1; ?>"><img class="unit u<?php echo $i; ?>" title="<?php echo $technology->getUnitName($i) ?>" src="img/x.gif"></label> title="<?php echo $technology->getUnitName($i); ?>"
</td> src="img/x.gif">
<?php </label>
} </td>
?> <?php endforeach; ?>
</tr> </tr>
<tr>
<?php <tr>
for($i = $start; $i <= $end; $i++){ <?php foreach ($units as $i): ?>
if(in_array($i, [4, 14, 23])) continue; <?php $index = $i - $start + 1; ?>
?>
<td> <td>
<input class="text" id="t<?php echo $i - $start + 1; ?>" type="text" name="t<?php echo $i - $start + 1; ?>" value="<?php echo (${'t'.($i - $start + 1)} > 0) ? ${'t'.($i - $start + 1)} : 0; ?>"> <input class="text"
</td> id="t<?php echo $index; ?>"
<?php type="text"
} name="t<?php echo $index; ?>"
?> value="<?php echo (isset(${'t'.$index}) && ${'t'.$index} > 0) ? ${'t'.$index} : 0; ?>">
</tr> </td>
</table>
<?php endforeach; ?>
</tr>
</table>