Alliance Bonuses — Admin Panel Update by @Sk4r7z issue #390

The admin panel now supports viewing and editing alliance bonus levels for Recruitment, Philosophy, Metallurgy, and Commerce.

Changes:
The alliance overview displays each bonus’s level, percentage, accumulated resources, and upgrade status.
The edit page allows administrators to select individual bonuses and set their levels from 0 to 5.
Changing a bonus level cancels its current upgrade while preserving accumulated resources. Setting level 5 clears the remaining resources.
Submitted levels are validated on the server, and bonus updates are recorded in the admin log.
Administrator identity is taken from the authenticated session.
Alliances without members can now be displayed.
This commit is contained in:
novgorodschi catalin
2026-09-09 14:10:49 +03:00
parent c55642e3c2
commit 52ff1c66e7
3 changed files with 116 additions and 5 deletions
+39 -2
View File
@@ -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']) {
</div>
</div>
<div class="card">
<h3><?php echo ADM_ALLIANCE_BONUSES; ?></h3>
<div class="body" style="overflow-x:auto;">
<?php require_once __DIR__ . '/../../GameEngine/AllianceBonus.php'; ?>
<?php if (AllianceBonus::enabled()): ?>
<table class="mini-table">
<thead><tr><th><?php echo ALLYBONUS_TAB; ?></th><th><?php echo ALLYBONUS_LEVEL; ?></th><th>Bonus</th><th>Resources in pool</th><th><?php echo ADM_STATUS; ?></th></tr></thead>
<tbody>
<?php foreach ((new AllianceBonus())->getState($aid) as $btype => $bonus):
$bonusType = AllianceBonus::types()[$btype];
?>
<tr>
<td><?php echo htmlspecialchars(constant($bonusType['lang'])); ?></td>
<td><?php echo $bonus['level'] . '/' . AllianceBonus::MAX_LEVEL; ?></td>
<td><?php echo AllianceBonus::percentFor($btype, $bonus['level']); ?>%</td>
<td><?php echo number_format($bonus['pool']); ?></td>
<td><?php
if ($bonus['level'] >= 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']));
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="btn-row"><a class="btn edit" href="?p=editAli&amp;aid=<?php echo $aid; ?>"><?php echo ADM_EDIT_ALLIANCE; ?></a></div>
<?php else: ?>
<p>Alliance bonuses are disabled or their database table is unavailable.</p>
<?php endif; ?>
</div>
</div>
<!-- ALLIANCE DESCRIPTION - ACUM SUB DETAILS -->
<div class="card">
<h3><?php echo ADM_ALLIANCE_DESCRIPTION; ?></h3>
@@ -301,4 +338,4 @@ if($_GET['aid']) {
echo "<div style='padding:30px;text-align:center;'>Alliance not found... <a href='javascript:history.go(-1)'>Back</a></div>";
}
}
?>
?>
+34 -1
View File
@@ -108,6 +108,39 @@ textarea{width:100%;box-sizing:border-box;min-height:120px;padding:8px;border:1p
</div>
</div>
<?php
require_once __DIR__ . '/../../GameEngine/AllianceBonus.php';
$bonusesEnabled = AllianceBonus::enabled();
?>
<div class="card">
<h3><?php echo ADM_ALLIANCE_BONUSES; ?></h3>
<div class="body">
<?php if ($bonusesEnabled): ?>
<p class="hint">Select the bonuses to update. Changing a level cancels its current upgrade and preserves accumulated resources. Level 5 clears remaining resources.</p>
<div class="form-grid">
<?php foreach ((new AllianceBonus())->getState($aid) as $btype => $bonus):
$bonusType = AllianceBonus::types()[$btype];
?>
<div class="form-row">
<label for="bonus-level-<?php echo $btype; ?>"><?php echo htmlspecialchars(constant($bonusType['lang'])); ?></label>
<label><input type="checkbox" name="bonus_apply[<?php echo $btype; ?>]" value="1"> Update this bonus</label>
<input id="bonus-level-<?php echo $btype; ?>" type="number" name="bonus_levels[<?php echo $btype; ?>]" min="0" max="<?php echo AllianceBonus::MAX_LEVEL; ?>" step="1" value="<?php echo $bonus['level']; ?>">
<div class="hint">
<?php echo ALLYBONUS_LEVEL . ': ' . $bonus['level'] . ' (' . AllianceBonus::percentFor($btype, $bonus['level']) . '%)'; ?><br>
Resources in pool: <?php echo number_format($bonus['pool']); ?>
<?php if ($bonus['upgrade_end'] > 0): ?><br>
<?php echo ALLYBONUS_UNLOCKING . ' ' . ($bonus['level'] + 1) . ' — ' . date('d.m.Y H:i:s', $bonus['upgrade_end']); ?>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="hint">Alliance bonuses are disabled or their database table is unavailable.</p>
<?php endif; ?>
</div>
</div>
<div class="actions">
<button type="submit" class="btn-save"><?php echo ADM_SAVE_ALLIANCE; ?></button>
<a href="admin.php?p=alliance&aid=<?php echo $aid; ?>" style="margin-left:12px;color:#555;text-decoration:none;"><?php echo ADM_CANCEL_2; ?></a>
@@ -116,4 +149,4 @@ textarea{width:100%;box-sizing:border-box;min-height:120px;padding:8px;border:1p
</div>
<?php
} // <- închide if($aid)
?>
?>
+43 -2
View File
@@ -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 <a href='admin.php?p=alliance&aid=$aid'>$tag</a>";
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;
?>
?>