fix: resolve 3 billing admin errors and normalize remote_servers query

- admin_config.php: guard session_start() — was firing Notice because
  admin_auth.php → session_bridge.php already started the session
- includes/menu.php: check mysqli_thread_id() before reusing $db so a
  closed handle does not cause 'mysqli object is already closed' fatal
- admin_invoices.php / admin_payments.php: set $db = null after
  mysqli_close() so menu.php's reuse-check correctly falls through to
  opening a fresh connection
- adminserverlist.php: use col_exists() to detect missing 'enabled'
  column in gsp_remote_servers; fall back to constant 1 and display a
  schema-notice banner; guard UPDATE accordingly; also add missing
  price_daily / price_year columns to the services SELECT; remove
  duplicate 'Update Enabled Servers' button
- add_remote_server_enabled_column.sql: idempotent migration to add the
  'enabled' INT column to gsp_remote_servers on older installs

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/988997ed-7568-48bf-96ef-889fb5d91fec

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-02 13:40:10 +00:00 committed by GitHub
parent 59a7eef4bd
commit bb77620796
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 8 deletions

View file

@ -66,6 +66,9 @@ function join_base($base, $path){
$locationCol = col_exists($db, "{$table_prefix}billing_services", 'remote_server_id') ? 'remote_server_id' :
(col_exists($db, "{$table_prefix}billing_services", 'remote_server') ? 'remote_server' : 'remote_server_id');
/* whether gsp_remote_servers has an 'enabled' column (may be missing on older installs) */
$rsHasEnabled = col_exists($db, "{$table_prefix}remote_servers", 'enabled');
$flash = [];
/* A) Update global server location enable flags */
@ -76,9 +79,11 @@ if (isset($_POST['update_remote_servers'])) {
foreach ((array)$allIds as $row) {
$id = (int)$row['remote_server_id'];
$e = isset($enabledSet[$id]) ? 1 : 0;
$db->query("UPDATE {$table_prefix}remote_servers SET enabled={$e} WHERE remote_server_id={$id}");
if ($rsHasEnabled) {
$db->query("UPDATE {$table_prefix}remote_servers SET enabled={$e} WHERE remote_server_id={$id}");
}
}
$flash[] = "Server locations updated.";
$flash[] = $rsHasEnabled ? "Server locations updated." : "Server locations updated (note: 'enabled' column missing from remote_servers — run add_remote_server_enabled_column.sql migration).";
}
/* helper: update one service row from posted array */
@ -148,13 +153,21 @@ if (isset($_POST['remove_service'], $_POST['service_id_remove'])) {
}
/* fetch data for UI */
$remoteServers = fetch_all_assoc($db, "SELECT remote_server_id, remote_server_name, enabled FROM {$table_prefix}remote_servers ORDER BY remote_server_name");
$services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locationCol}` AS locs, slot_min_qty, slot_max_qty, price_monthly, img_url, enabled FROM {$table_prefix}billing_services ORDER BY service_name");
$rsEnabledExpr = $rsHasEnabled ? ', enabled' : ', 1 AS enabled';
$remoteServers = fetch_all_assoc($db, "SELECT remote_server_id, remote_server_name{$rsEnabledExpr} FROM {$table_prefix}remote_servers ORDER BY remote_server_name");
$services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locationCol}` AS locs, slot_min_qty, slot_max_qty, price_daily, price_monthly, price_year, img_url, enabled FROM {$table_prefix}billing_services ORDER BY service_name");
?>
<?php if ($flash): ?>
<div class="panel" style="margin-bottom:12px"><?php foreach ((array)$flash as $m) echo "<div>".h($m)."</div>"; ?></div>
<div class="panel mb-12"><?php foreach ((array)$flash as $m) echo "<div>".h($m)."</div>"; ?></div>
<?php endif; ?>
<?php if (!$rsHasEnabled): ?>
<div class="panel" style="margin-bottom:12px;background:#fff3cd;border:1px solid #ffc107;">
<strong> Schema notice:</strong> The <code><?php echo h("{$table_prefix}remote_servers"); ?></code> table is missing the <code>enabled</code> column.
Server location enable/disable is currently non-functional.
Run <code>modules/billing/add_remote_server_enabled_column.sql</code> to add the column.
</div>
<?php endif; ?>
<h2>Enable/Disable Server Locations (Global)</h2>
@ -170,7 +183,6 @@ $services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locat
<?php endforeach; ?>
</div>
<div style="margin-top:10px;"><button type="submit">Update Enabled Servers</button></div>
<div class="mt-10"><button type="submit">Update Enabled Servers</button></div>
</form>
<hr>