diff --git a/modules/billing/add_remote_server_enabled_column.sql b/modules/billing/add_remote_server_enabled_column.sql new file mode 100644 index 00000000..dc158104 --- /dev/null +++ b/modules/billing/add_remote_server_enabled_column.sql @@ -0,0 +1,31 @@ +-- Migration: add `enabled` column to gsp_remote_servers +-- +-- The original panel schema (panel.sql / ogp_remote_servers) includes an `enabled` +-- INT(11) column. Installations that were created from an older schema, or whose +-- table was renamed without carrying the column forward, may be missing it. +-- +-- Run this once against your panel database (replace `gsp_` with your prefix if +-- different). Safe to skip if the column already exists — just check with: +-- SHOW COLUMNS FROM `gsp_remote_servers` LIKE 'enabled'; +-- +-- Usage: +-- mysql -u -p < modules/billing/add_remote_server_enabled_column.sql + +SET @table_name = 'gsp_remote_servers'; +SET @col_name = 'enabled'; + +SET @sql = IF( + ( + SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = @table_name + AND COLUMN_NAME = @col_name + ) = 0, + CONCAT('ALTER TABLE `', @table_name, '` ADD COLUMN `enabled` INT(11) NOT NULL DEFAULT 1'), + 'SELECT "Column already exists — nothing to do" AS note' +); + +PREPARE stmt FROM @sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/modules/billing/admin_config.php b/modules/billing/admin_config.php index dbbe2fea..8cf3aa15 100644 --- a/modules/billing/admin_config.php +++ b/modules/billing/admin_config.php @@ -5,7 +5,10 @@ require_once(__DIR__ . '/includes/config_loader.php'); include(__DIR__ . '/includes/top.php'); include(__DIR__ . '/includes/menu.php'); -session_start(); +if (session_status() === PHP_SESSION_NONE) { + session_name('opengamepanel_web'); + session_start(); +} if (empty($_SESSION['admin_csrf'])) $_SESSION['admin_csrf'] = bin2hex(random_bytes(16)); $csrf = $_SESSION['admin_csrf']; diff --git a/modules/billing/admin_invoices.php b/modules/billing/admin_invoices.php index adf3425e..1d1abcd2 100644 --- a/modules/billing/admin_invoices.php +++ b/modules/billing/admin_invoices.php @@ -66,6 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'], $_POST['inv if (!headers_sent()) { header('Location: admin_invoices.php?msg=' . urlencode($message) . '&type=' . $msgType); mysqli_close($db); + $db = null; exit; } } @@ -81,6 +82,7 @@ $res = $db->query( ); if ($res) $invoices = $res->fetch_all(MYSQLI_ASSOC); mysqli_close($db); +$db = null; if (isset($_GET['msg'])) $message = $_GET['msg']; if (isset($_GET['type'])) $msgType = $_GET['type']; diff --git a/modules/billing/admin_payments.php b/modules/billing/admin_payments.php index d53be759..5ab18c86 100644 --- a/modules/billing/admin_payments.php +++ b/modules/billing/admin_payments.php @@ -28,6 +28,7 @@ if (!$db) { $transactions = $repo->getTransactions($filter, 200, 0); mysqli_close($db); + $db = null; } ?> diff --git a/modules/billing/adminserverlist.php b/modules/billing/adminserverlist.php index d7b38b74..8c05448a 100644 --- a/modules/billing/adminserverlist.php +++ b/modules/billing/adminserverlist.php @@ -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"); ?>
".h($m)."
"; ?> -
".h($m)."
"; ?> + + + +
+ ⚠ Schema notice: The table is missing the enabled column. + Server location enable/disable is currently non-functional. + Run modules/billing/add_remote_server_enabled_column.sql to add the column. +

Enable/Disable Server Locations (Global)

@@ -170,7 +183,6 @@ $services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locat
-

diff --git a/modules/billing/includes/menu.php b/modules/billing/includes/menu.php index 5908f399..113269e7 100644 --- a/modules/billing/includes/menu.php +++ b/modules/billing/includes/menu.php @@ -55,7 +55,9 @@ if ($is_logged_in) { // Prefer reusing an existing $db if present, otherwise open a local connection $menu_db = null; $menu_db_opened = false; - if (isset($db) && $db instanceof mysqli) { + // Only reuse $db if it is still an open (non-closed) connection. + // mysqli_thread_id() returns 0 on a closed handle, so guard against that. + if (isset($db) && $db instanceof mysqli && @mysqli_thread_id($db)) { $menu_db = $db; } else { $menu_db_port = isset($db_port) ? (int)$db_port : null;