diff --git a/Admin/Templates/alliance.tpl b/Admin/Templates/alliance.tpl index 103c2a94..3a74643d 100644 --- a/Admin/Templates/alliance.tpl +++ b/Admin/Templates/alliance.tpl @@ -24,7 +24,8 @@ if($_GET['aid']) { $alidata = $database->getAlliance($aid); $aliusers = $database->getAllMember($aid); - if($alidata && $aliusers) { + if($alidata) { + $aliusers = $aliusers ?: array(); $memberIDs = array_column($aliusers, 'id'); $data = $database->getVSumField($memberIDs,"pop"); $totalpop = 0; @@ -185,6 +186,42 @@ if($_GET['aid']) { +
+

+
+ + + + + + getState($aid) as $btype => $bonus): + $bonusType = AllianceBonus::types()[$btype]; + ?> + + + + + + + + + +
BonusResources in pool
%= AllianceBonus::MAX_LEVEL) { + echo ALLYBONUS_MAXED; + } elseif ($bonus['upgrade_end'] > 0) { + echo ALLYBONUS_UNLOCKING . ' ' . ($bonus['level'] + 1) . ' — ' . date('d.m.Y H:i:s', $bonus['upgrade_end']); + } else { + echo ALLYBONUS_NEXT . ': ' . number_format(AllianceBonus::costFor($bonus['level'])); + } + ?>
+
+ +

Alliance bonuses are disabled or their database table is unavailable.

+ +
+
+

@@ -301,4 +338,4 @@ if($_GET['aid']) { echo "
Alliance not found... Back
"; } } -?> \ No newline at end of file +?> diff --git a/Admin/Templates/editAli.tpl b/Admin/Templates/editAli.tpl index 254f640e..0f521343 100644 --- a/Admin/Templates/editAli.tpl +++ b/Admin/Templates/editAli.tpl @@ -108,6 +108,39 @@ textarea{width:100%;box-sizing:border-box;min-height:120px;padding:8px;border:1p
+ +
+

+
+ +

Select the bonuses to update. Changing a level cancels its current upgrade and preserves accumulated resources. Level 5 clears remaining resources.

+
+ getState($aid) as $btype => $bonus): + $bonusType = AllianceBonus::types()[$btype]; + ?> +
+ + + +
+
+ Resources in pool: + 0): ?>
+ + +
+
+ +
+ +

Alliance bonuses are disabled or their database table is unavailable.

+ +
+
+
@@ -116,4 +149,4 @@ textarea{width:100%;box-sizing:border-box;min-height:120px;padding:8px;border:1p
\ No newline at end of file +?> diff --git a/GameEngine/Admin/Mods/editAli.php b/GameEngine/Admin/Mods/editAli.php index 9d97df1c..14ce8393 100644 --- a/GameEngine/Admin/Mods/editAli.php +++ b/GameEngine/Admin/Mods/editAli.php @@ -40,7 +40,7 @@ include_once($autoprefix . "GameEngine/Database.php"); // --------------------------------------------------------------------------- // Input // --------------------------------------------------------------------------- -$admid = (int)($_POST['admid'] ?? 0); +$admid = (int)($_SESSION['id'] ?? 0); $aid = (int)($_POST['aid'] ?? 0); if ($aid <= 0 || $admid <= 0) { @@ -59,6 +59,28 @@ if (!$admin || (int)$admin['access'] !== 9) { // --------------------------------------------------------------------------- // Câmpuri // --------------------------------------------------------------------------- +if (!$database->getAlliance($aid)) { + admin_deny('Alliance not found.'); +} + +require_once __DIR__ . '/../../AllianceBonus.php'; +$bonusUpdates = array(); +if (!empty($_POST['bonus_apply'])) { + if (!AllianceBonus::enabled() || !is_array($_POST['bonus_apply']) || + !isset($_POST['bonus_levels']) || !is_array($_POST['bonus_levels'])) { + admin_deny('Invalid alliance bonus settings.'); + } + $bonusTypes = AllianceBonus::types(); + foreach ($_POST['bonus_apply'] as $btype => $apply) { + $rawLevel = $_POST['bonus_levels'][$btype] ?? null; + if (!isset($bonusTypes[$btype]) || $apply !== '1' || !is_string($rawLevel) || + !preg_match('/^[0-5]$/D', $rawLevel)) { + admin_deny('Alliance bonus levels must be integers from 0 to 5.'); + } + $bonusUpdates[(int)$btype] = (int)$rawLevel; + } +} + $tag = $database->escape(substr(trim($_POST['tag'] ?? ''), 0, 8)); $name = $database->escape(substr(trim($_POST['name'] ?? ''), 0, 25)); $leader = (int)($_POST['leader'] ?? 0); @@ -84,8 +106,27 @@ $database->query( // --------------------------------------------------------------------------- // Log admin - aceeași structură ca editUser // --------------------------------------------------------------------------- +foreach ($bonusUpdates as $btype => $level) { + // Compare against the current database level, not a potentially stale form. + // Assignment order matters: preserve the old level until the final assignment. + $ok = $database->query( + "INSERT INTO " . TB_PREFIX . "alliance_bonus (aid, btype, level, pool, upgrade_end) + VALUES ($aid, $btype, $level, 0, 0) + ON DUPLICATE KEY UPDATE + upgrade_end = IF(level <> $level OR $level = " . AllianceBonus::MAX_LEVEL . ", 0, upgrade_end), + pool = IF($level = " . AllianceBonus::MAX_LEVEL . ", 0, pool), + level = $level" + ); + if (!$ok) { + admin_deny('Could not save alliance bonuses. Please reload the alliance and check its settings.'); + } +} + $time = time(); $logText = "Edited alliance $tag"; +if ($bonusUpdates) { + $logText .= ' | Alliance bonus levels: ' . json_encode($bonusUpdates); +} $logEsc = $database->escape($logText); $database->query( @@ -95,4 +136,4 @@ $database->query( header("Location: ../../../Admin/admin.php?p=alliance&aid=$aid&edited=1"); exit; -?> \ No newline at end of file +?>