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
+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;
?>
?>