diff --git a/Templates/goldClub/farmlist.tpl b/Templates/goldClub/farmlist.tpl index 4549aee6..15cc9fc9 100644 --- a/Templates/goldClub/farmlist.tpl +++ b/Templates/goldClub/farmlist.tpl @@ -1,38 +1,79 @@ 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" +); + ?> +
-dblink,"SELECT id, name, owner, wref FROM ".TB_PREFIX."farmlist WHERE owner = ".(int) $session->uid." ORDER BY wref DESC"); -$query = mysqli_num_rows($sql); -while($row = mysqli_fetch_array($sql)){ + +getVillageField($row["wref"], 'name'); + + $lvname = $database->getVillageField($lwref, 'name'); ?> -
- delete - - -
-
-
- -
-
- - + +
+ + delete + + - +
+ +
+
+ +
+
+ +
+ @@ -42,149 +83,214 @@ while($row = mysqli_fetch_array($sql)){ - - + + + dblink,"SELECT * FROM ".TB_PREFIX."raidlist WHERE lid = ".(int) $lid." ORDER BY distance ASC"); -$query2 = mysqli_num_rows($sql2); -if(!$query2) echo ''; -else -{ - while($row = mysqli_fetch_array($sql2)){ - $id = $row['id']; - $lid = $row['lid']; - $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); + $sql2 = mysqli_query( + $database->dblink, + "SELECT * FROM ".TB_PREFIX."raidlist + WHERE lid = ".(int)$lid." + ORDER BY distance ASC" + ); + + $query2 = mysqli_num_rows($sql2); + + if (!$query2) { + echo ''; + } else { + + while ($row = mysqli_fetch_array($sql2)) { + + $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); ?> - - - - - + + + + + + + + + + + + + + + + - + +
VillageLast raid
'.NO_VILLAGES.''.NO_VILLAGES.'
- - - getMovement(3, $towref, 1); - if (($attacksCount = count($attacks)) > 0) { - foreach($attacks as $attack){ - if($attack['attack_type'] != 4) $attacksCount -= 1; - } - if($attacksCount > 0) echo ''; - } - ?> - - -"; }; ?> + + + tribe - 1) * 10 + 1; - $end = $start + 5; - - for($i = $start; $i <= $end; $i++){ - if(${'t'.($i - $start + 1)} > 0){ - echo '
'.${'t'.($i - $start + 1)}.'
'; - } +$attacks = $database->getMovement(3, $towref, 1); +$attacksCount = count($attacks); + +if ($attacksCount > 0) { + foreach ($attacks as $attack) { + if ($attack['attack_type'] != 4) { + $attacksCount--; + } + } + + if ($attacksCount > 0) { + echo ''; + } +} +?> + + + +
+ + + +tribe - 1) * 10 + 1; +$end = $start + 5; + +for ($i = $start; $i <= $end; $i++) { + $index = $i - $start + 1; + + if (${'t'.$index} > 0) { + echo '
+ + '.${'t'.$index}.' +
'; + } +} +?> + +
+ +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 ''; + + $allres = $dataarray[23] + $dataarray[24] + $dataarray[25] + $dataarray[26]; + $carry = $dataarray[27]; + + echo ''; + + $date = $generator->procMtime($row2['time']); + echo '' + .$date[0]." ".date('H:i', $row2['time']).''; + } +} +?> + + + edit +
- - - - +
-$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 " "; - - $allres = $dataarray[23] + $dataarray[24] + $dataarray[25] + $dataarray[26]; - $carry = $dataarray[27]; - - echo ""; - - $date = $generator->procMtime($row2['time']); - echo "".$date[0]." ".date('H:i',$row2['time'])." "; -} -} -?> -
- - - edit - - - - - - -

-
-
-
-
- - - -getVilFarmlist($session->uid)){ ?> -
- - -

-
- - -

+ +getVilFarmlist($session->uid)) { ?> + +
+ + +
+ +
+ + +
+ + +
Create a new list
-
- \ No newline at end of file diff --git a/Templates/goldClub/farmlist_add.tpl b/Templates/goldClub/farmlist_add.tpl index d491c4ed..232061ec 100644 --- a/Templates/goldClub/farmlist_add.tpl +++ b/Templates/goldClub/farmlist_add.tpl @@ -1,37 +1,63 @@
-

Create a new list

-
-
- - - - - - - - - - -
- Name: - -
- Village: - - -
+

Create a new list

-
-
+ - -
-
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + +
Name: + +
Village: + +
+ +
+
+ + + + + \ No newline at end of file diff --git a/Templates/goldClub/farmlist_addraid.tpl b/Templates/goldClub/farmlist_addraid.tpl index 194359f3..0c87abef 100644 --- a/Templates/goldClub/farmlist_addraid.tpl +++ b/Templates/goldClub/farmlist_addraid.tpl @@ -1,138 +1,261 @@ getVilFarmlist($session->uid)){ - header("Location: build.php?id=39&t=99"); - exit; + +/* ===================================================== + GUARD: no farmlists +===================================================== */ +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; - for($i = 1; $i <= 6; $i++){ - if(!in_array($i + ($session->tribe - 1) * 10, [4, 14, 23])) $troops += $_POST['t'.$i]; - } - - 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']) && $_POST['x'] <= WORLD_MAX && $_POST['y'] <= WORLD_MAX){ - $Wref = $database->getVilWref($_POST['x'], $_POST['y']); - $WrefX = $_POST['x']; - $WrefY = $_POST['y']; - $type = $database->getVillageType2($Wref); - $oasistype = $type; - $vdata = $database->getVillage($Wref); +$action = $_POST['action'] ?? null; +$lid = (int)($_POST['lid'] ?? 0); + +/* ===================================================== + HANDLE ADD SLOT +===================================================== */ +if ($action === 'addSlot' && $lid) { + + $FLData = $database->getFLData($lid); + + if (!$FLData || $FLData['owner'] != $session->uid) { + $errormsg = "Invalid farm list."; + } else { + + /* ====================== + TROOP CALC + ====================== */ + $troops = 0; + $tribeOffset = ($session->tribe - 1) * 10; + + 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; -} } + ?>

Add Slot

- - - - + + +
-
+ +
+
+
+
+
+
+
+
+
+
+ +
+ - - + +
+ + + + + -
List name:
Target village: - -
-
- - -
-
-
- - -
-
-
-
-
- - + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+
+ +
+ +
+ + + + + +
+
+
-
-
- -
- - + + + + + +
+ + + + + + +
\ No newline at end of file diff --git a/Templates/goldClub/farmlist_editraid.tpl b/Templates/goldClub/farmlist_editraid.tpl index 62994e17..89c04488 100644 --- a/Templates/goldClub/farmlist_editraid.tpl +++ b/Templates/goldClub/farmlist_editraid.tpl @@ -1,158 +1,301 @@ 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']; $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']); - - //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'])) { - - $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']); - + if ($FLData['owner'] != $session->uid) { 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; + } } + ?>
-

Edit Slot

- - - - -
-
+

Edit Slot

-getRaidList($database->escape($_GET["eid"])); -$lid2 = $getlid['lid']; -?> - - - - - - - - - - -
List name: - -
Target village: - -
-
- - -
-
-
- - -
-
-
-

- - -
-
-
-
-
- + -
-  - -
+
+
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + +
List name: + +
Target village: + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ + + + + +
+ +
+ +
+ +
+
+ + + + + + +
\ No newline at end of file diff --git a/Templates/goldClub/trooplist.tpl b/Templates/goldClub/trooplist.tpl index 88758d0a..0ef26f99 100644 --- a/Templates/goldClub/trooplist.tpl +++ b/Templates/goldClub/trooplist.tpl @@ -1,30 +1,49 @@ -tribe - 1) * 10 + 1; $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; +} + ?> + - - - - - - - - - - -
- -
- -
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file