fix: add_to_cart SQL mismatch, Browse Servers routing, canonical game dedup, OS-aware locations, XML editor improvements

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/aecffd5d-b644-4e4d-b13e-b392e78d4606

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-06 23:45:27 +00:00 committed by GitHub
parent 7ff7adca9d
commit acbb850e21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 495 additions and 352 deletions

View file

@ -7,10 +7,6 @@
</head>
<body>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Include database configuration
require_once(__DIR__ . '/bootstrap.php');
@ -37,23 +33,59 @@ if (isset($_POST['save']) && !empty($_POST['description'])) {
$stmt->close();
}
// Fetch services
// Fetch services, joining config_homes to get canonical game_name and game_key for OS detection.
// LEFT JOIN so services without a linked config_homes entry still appear.
$service_id = isset($_REQUEST['service_id']) ? intval($_REQUEST['service_id']) : 0;
$where_service_id = $service_id !== 0
? "WHERE enabled = 1 AND service_id = $service_id AND remote_server_id != '' AND remote_server_id IS NOT NULL"
: "WHERE enabled = 1 AND remote_server_id != '' AND remote_server_id IS NOT NULL";
$qry_services = "SELECT * FROM {$table_prefix}billing_services $where_service_id ORDER BY service_name";
if ($service_id !== 0) {
$where_clause = "WHERE bs.enabled = 1 AND bs.service_id = {$service_id} AND bs.remote_server_id != '' AND bs.remote_server_id IS NOT NULL";
} else {
$where_clause = "WHERE bs.enabled = 1 AND bs.remote_server_id != '' AND bs.remote_server_id IS NOT NULL";
}
$qry_services = "SELECT bs.*, ch.game_name AS cfg_game_name, ch.game_key AS cfg_game_key
FROM {$table_prefix}billing_services bs
LEFT JOIN {$table_prefix}config_homes ch ON ch.home_cfg_id = bs.home_cfg_id
{$where_clause}
ORDER BY bs.service_name";
$result_services = $db->query($qry_services);
if (!$result_services) {
// config_homes join may not exist on all installs; fall back to services-only query
$where_clause_fallback = str_replace('bs.', '', $where_clause);
$qry_services_fallback = "SELECT *, NULL AS cfg_game_name, NULL AS cfg_game_key
FROM {$table_prefix}billing_services
{$where_clause_fallback}
ORDER BY service_name";
$result_services = $db->query($qry_services_fallback);
}
if (!$result_services) {
echo "<meta http-equiv='refresh' content='1'>";
billing_maybe_close_db($db);
return;
}
// Fetch all service rows into an array so the template foreach works correctly
// Fetch all service rows and deduplicate by canonical game name so that
// arma3_linux64 and arma3_win64 (both named "Arma 3") appear only once.
// When a specific service_id is requested we skip deduplication.
$serviceRows = [];
$seenCanonical = [];
while ($row = $result_services->fetch_assoc()) {
if ($service_id !== 0) {
// Single-service detail view: always include without deduplication
$serviceRows[] = $row;
continue;
}
// Derive canonical display name: prefer config_homes game_name (consistent across OS
// variants), fall back to service_name.
$canonicalName = !empty($row['cfg_game_name'])
? $row['cfg_game_name']
: $row['service_name'];
if (isset($seenCanonical[$canonicalName])) {
// Already have this game — skip the duplicate OS variant
continue;
}
$seenCanonical[$canonicalName] = true;
$serviceRows[] = $row;
}
$result_services->free();
@ -69,13 +101,18 @@ include(__DIR__ . '/includes/menu.php');
<?php if (!isset($_REQUEST['service_id'])): ?>
<!-- Service listing (all) -->
<div class="float-left p-30-20">
<?php $imgSrc = billing_image_url((string)($row['img_url'] ?? '')); ?>
<?php if ($imgSrc !== ''): ?>
<img src="<?php echo htmlspecialchars($imgSrc, ENT_QUOTES, 'UTF-8'); ?>" width="460" height="225"><br>
<?php endif; ?>
<strong><?php echo htmlspecialchars((string)$row['service_name'], ENT_QUOTES, 'UTF-8'); ?></strong><br>
<?php
echo ($row['price_monthly'] == 0.0) ? "FREE" : "$" . number_format(floatval($row['price_monthly']), 2) . " Monthly";
$imgSrc = billing_image_url((string)($row['img_url'] ?? ''));
// Use a generic fallback image when the service has no image configured
if ($imgSrc === '') {
$imgSrc = '/images/games/default_server.png';
}
?>
<img src="<?php echo htmlspecialchars($imgSrc, ENT_QUOTES, 'UTF-8'); ?>" width="460" height="225"
onerror="this.src='/images/games/default_server.png'; this.onerror=null;"><br>
<strong><?php echo htmlspecialchars((string)($row['cfg_game_name'] ?? $row['service_name']), ENT_QUOTES, 'UTF-8'); ?></strong><br>
<?php
echo (floatval($row['price_monthly']) == 0.0) ? "FREE" : "$" . number_format(floatval($row['price_monthly']), 2) . " Monthly";
?>
<br>
@ -84,44 +121,48 @@ include(__DIR__ . '/includes/menu.php');
<?php else: ?>
<!-- Single service detail view -->
<div class="float-left decorative-bottom">
<?php $imgSrc = billing_image_url((string)($row['img_url'] ?? '')); ?>
<?php if ($imgSrc !== ''): ?>
<img src="<?php echo htmlspecialchars($imgSrc, ENT_QUOTES, 'UTF-8'); ?>" width="230" height="112"><br>
<?php endif; ?>
<center><b><?php echo htmlspecialchars((string)$row['service_name'], ENT_QUOTES, 'UTF-8'); ?></b></center>
<?php
$imgSrc = billing_image_url((string)($row['img_url'] ?? ''));
if ($imgSrc === '') {
$imgSrc = '/images/games/default_server.png';
}
?>
<img src="<?php echo htmlspecialchars($imgSrc, ENT_QUOTES, 'UTF-8'); ?>" width="230" height="112"
onerror="this.src='/images/games/default_server.png'; this.onerror=null;"><br>
<center><b><?php echo htmlspecialchars((string)($row['cfg_game_name'] ?? $row['service_name']), ENT_QUOTES, 'UTF-8'); ?></b></center>
<?php
$isAdmin = false; // change to actual check, e.g. current_user_can('administrator')
$isAdmin = false;
if ($isAdmin) {
if (!isset($_POST['edit'])) {
echo "<p style='color:gray;width:230px;'>{$row['description']}</p>";
echo "<p style='color:gray;width:230px;'>" . htmlspecialchars((string)($row['description'] ?? ''), ENT_QUOTES, 'UTF-8') . "</p>";
echo "<form method='post'>
<input type='hidden' name='service_id' value='{$row['servioce_id']}'>
<input type='hidden' name='service_id' value='" . intval($row['service_id']) . "'>
<input type='submit' name='edit' value='Edit'>
</form>";
} else {
$desc = str_replace("<br>", "\r\n", $row['description']);
$desc = htmlspecialchars(str_replace("<br>", "\r\n", (string)($row['description'] ?? '')), ENT_QUOTES, 'UTF-8');
echo "<form method='post'>
<textarea style='resize:none;width:230px;height:132px;' name='description'>$desc</textarea><br>
<input type='hidden' name='service_id' value='{$row['service_id']}'>
<textarea style='resize:none;width:230px;height:132px;' name='description'>{$desc}</textarea><br>
<input type='hidden' name='service_id' value='" . intval($row['service_id']) . "'>
<input type='submit' name='save' value='Save'>
</form>";
}
} else {
echo "<p style='color:gray;width:280px;'>{$row['description']}</p>";
echo "<p style='color:gray;width:280px;'>" . htmlspecialchars((string)($row['description'] ?? ''), ENT_QUOTES, 'UTF-8') . "</p>";
}
?>
</div>
<!-- Order Form -->
<form method="post" action="order_server.php">
<input type="hidden" name="service_id" value="<?php echo $row['service_id']; ?>">
<input type="hidden" name="service_id" value="<?php echo intval($row['service_id']); ?>">
<input type="hidden" name="remote_control_password" value="">
<input type="hidden" name="ftp_password" value="">
<table class="float-left">
<tr>
<td align="right"><b>Game Server Name</b></td>
<td><input type="text" name="home_name" size="40" value="<?php echo $row['service_name']; ?>"></td>
<td><input type="text" name="home_name" size="40" value="<?php echo htmlspecialchars((string)($row['service_name'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>"></td>
</tr>
<!-- Add other form fields as needed -->
<tr>