Panel/modules/billing/my_servers.php
copilot-swe-agent[bot] 1247e5e7ca
fix: harden billing module for standalone portability
- config_loader.php: prefer local billing config FIRST (root cause fix)
  - was: panel config loaded first, overriding local config with wrong db name
  - now: local modules/billing/includes/config.inc.php always wins when present
- config.inc.php: add $db_port="3306"
- config.example.php: new example config with all variables documented
- menu.php: add $db_port to mysqli_connect
- admin_auth.php: add $db_port; remove hardcoded /_website path detection
- bootstrap.php billing_get_db(): add $db_port
- login.php: fix /_website path detection
- adminserverlist.php: add $db_port; fix hardcoded /modules/billing/ URL
- All other mysqli_connect calls: add isset($db_port) port parameter
  (my_servers, forgot_password, serverlist, server_status, order, register,
   reset_password, payment_success, my_account, admin_invoices, admin_payments,
   diag_remote, admin_coupons, test_db_connection, tools/check_db_user,
   renew_server)
- timestamp.txt: updated

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/a3e1e4bb-8eb1-4e6e-b1f8-7f3952301231

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
2026-05-02 13:15:50 +00:00

161 lines
6.8 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Servers - GameServers.World</title>
</head>
<body>
<?php
// Require login for this page
require_once(__DIR__ . '/includes/login_required.php');
// Include billing bootstrap (loads config and DB helper)
require_once(__DIR__ . '/bootstrap.php');
// Variables from config.inc.php (helps IDEs understand scope)
/** @var string $db_host Database host */
/** @var string $db_user Database user */
/** @var string $db_pass Database password */
/** @var string $db_name Database name */
/** @var string $table_prefix Table prefix for database tables */
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name, isset($db_port) ? (int)$db_port : null);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Include top bar and menu
include(__DIR__ . '/includes/top.php');
include(__DIR__ . '/includes/menu.php');
// Get user ID from session
$user_id = intval($_SESSION['website_user_id']);
// Fetch user's active servers
// We'll look for homes assigned to this user
// The relationship is: {table_prefix}billing_orders -> user_id and contains home_id references
// We need to join with {table_prefix}home to get server details
$query = "SELECT
h.home_id,
h.home_name,
h.enabled,
h.billing_status,
h.server_expiration_date,
rs.remote_server_name,
gc.game_name,
o.order_id,
o.status,
o.invoice_duration,
o.end_date AS expiration_date,
bs.service_name,
bs.price_monthly,
o.price,
o.discount_amount,
o.coupon_id,
bc.code AS coupon_code,
bc.discount_percent AS coupon_discount_percent
FROM {$table_prefix}home h
LEFT JOIN {$table_prefix}remote_servers rs ON h.remote_server_id = rs.remote_server_id
LEFT JOIN {$table_prefix}game_configs gc ON h.home_cfg_id = gc.home_cfg_id
LEFT JOIN {$table_prefix}billing_orders o ON h.user_id = o.user_id
LEFT JOIN {$table_prefix}billing_services bs ON o.service_id = bs.service_id
LEFT JOIN {$table_prefix}billing_coupons bc ON o.coupon_id = bc.coupon_id
WHERE h.user_id = $user_id
ORDER BY h.home_id DESC";
$result = mysqli_query($db, $query);
?>
<div class="site-panel">
<div class="site-panel-title">My Game Servers</div>
<?php if ($result && mysqli_num_rows($result) > 0): ?>
<table class="cart-table">
<thead>
<tr>
<th>Server Name</th>
<th>Game</th>
<th>Location</th>
<th>Status</th>
<th>Expiration Date</th>
<th>Monthly Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($server = mysqli_fetch_assoc($result)): ?>
<?php
// Use billing_status from server_homes (set by migration + cron).
// Falls back to computing from expiration date for legacy rows.
$billing_status = $server['billing_status'] ?? null;
if (!$billing_status) {
$exp_ts = !empty($server['server_expiration_date']) ? strtotime($server['server_expiration_date']) : false;
if ($exp_ts && $exp_ts < time()) {
$billing_status = 'Expired';
} else {
$billing_status = 'Active';
}
}
$status_class_map = [
'Active' => 'text-success',
'Invoiced' => 'text-warning',
'Expired' => 'text-danger',
];
$status_class = $status_class_map[$billing_status] ?? 'text-secondary';
$exp_date = $server['server_expiration_date'] ?? $server['expiration_date'];
?>
<tr>
<td><?php echo htmlspecialchars($server['home_name'] ?? 'Unknown'); ?></td>
<td><?php echo htmlspecialchars($server['game_name'] ?? $server['service_name'] ?? 'Unknown'); ?></td>
<td><?php echo htmlspecialchars($server['remote_server_name'] ?? 'Unknown'); ?></td>
<td class="<?php echo $status_class; ?>"><?php echo htmlspecialchars($billing_status); ?></td>
<td><?php echo $exp_date ? date('M d, Y', strtotime($exp_date)) : 'N/A'; ?></td>
<td>
<?php
$price = $server['price'] ?? $server['price_monthly'];
$discount = floatval($server['discount_amount'] ?? 0);
if ($price) {
if ($discount > 0 && $server['coupon_code']) {
echo '<span style="text-decoration: line-through; color: #999;">$' . number_format($price + $discount, 2) . '</span><br>';
echo '<strong>$' . number_format($price, 2) . '</strong>';
echo '<br><small style="color: #28a745;">(' . htmlspecialchars($server['coupon_code']) . ' -' . number_format($server['coupon_discount_percent'], 0) . '%)</small>';
} else {
echo '$' . number_format($price, 2);
}
} else {
echo 'N/A';
}
?>
</td>
<td>
<?php if ($server['order_id']): ?>
<a href="renew_server.php?order_id=<?php echo urlencode($server['order_id']); ?>" class="gsw-btn">Renew</a>
<?php else: ?>
<span class="muted">N/A</span>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<div class="panel no-data">
<p style="font-size:1.2rem;margin-bottom:20px;">You don't have any game servers yet.</p>
<a href="serverlist.php" class="gsw-btn">Browse Game Servers</a>
</div>
<?php endif; ?>
</div>
<?php
// Close database connection
billing_maybe_close_db($db);
?>
</body>
<?php include(__DIR__ . '/includes/footer.php'); ?>
</html>