0) { $query = "SELECT user_id, users_login, users_email, users_fname, users_lname FROM {$table_prefix}users WHERE user_id = $user_id LIMIT 1"; $result = mysqli_query($db, $query); if ($result && mysqli_num_rows($result) === 1) { $user_info = mysqli_fetch_assoc($result); } } // Handle password change if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password'])) { $current_password = $_POST['current_password'] ?? ''; $new_password = $_POST['new_password'] ?? ''; $confirm_password = $_POST['confirm_password'] ?? ''; if (empty($current_password) || empty($new_password) || empty($confirm_password)) { $error_message = 'All password fields are required.'; } elseif ($new_password !== $confirm_password) { $error_message = 'New passwords do not match.'; } elseif (strlen($new_password) < 6) { $error_message = 'New password must be at least 6 characters long.'; } else { // Verify current password (using MD5 as per panel legacy) $current_hash = md5($current_password); $verify_query = "SELECT user_id FROM {$table_prefix}users WHERE user_id = $user_id AND users_passwd = '$current_hash' LIMIT 1"; $verify_result = mysqli_query($db, $verify_query); if ($verify_result && mysqli_num_rows($verify_result) === 1) { // Update password $new_hash = md5($new_password); $update_query = "UPDATE {$table_prefix}users SET users_passwd = '$new_hash' WHERE user_id = $user_id LIMIT 1"; if (mysqli_query($db, $update_query)) { $success_message = 'Password changed successfully!'; } else { $error_message = 'Failed to update password. Please try again.'; } } else { $error_message = 'Current password is incorrect.'; } } } // Handle account info update if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_info'])) { $fname = mysqli_real_escape_string($db, trim($_POST['fname'] ?? '')); $lname = mysqli_real_escape_string($db, trim($_POST['lname'] ?? '')); $email = mysqli_real_escape_string($db, trim($_POST['email'] ?? '')); if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message = 'Invalid email address.'; } else { $update_query = "UPDATE {$table_prefix}users SET users_fname = '$fname', users_lname = '$lname', users_email = '$email' WHERE user_id = $user_id LIMIT 1"; if (mysqli_query($db, $update_query)) { $success_message = 'Account information updated successfully!'; // Refresh user info $query = "SELECT user_id, users_login, users_email, users_fname, users_lname FROM {$table_prefix}users WHERE user_id = $user_id LIMIT 1"; $result = mysqli_query($db, $query); if ($result && mysqli_num_rows($result) === 1) { $user_info = mysqli_fetch_assoc($result); } } else { $error_message = 'Failed to update account information. Please try again.'; } } } // Fetch user's orders from billing_orders. Keep this simple: select orders for the user and join service name. // Avoid joins to remote server fields that do not exist on the orders table. $servers_query = "SELECT o.order_id, o.home_name, o.status, o.price, o.invoice_duration, o.home_id, o.end_date, bs.service_name FROM {$table_prefix}billing_orders o LEFT JOIN {$table_prefix}billing_services bs ON o.service_id = bs.service_id WHERE o.user_id = $user_id ORDER BY o.order_id DESC"; $servers_result = mysqli_query($db, $servers_query); // Debug: Log query execution and errors if (!$servers_result) { error_log("My Account Error - User ID: $user_id, Query failed: " . mysqli_error($db)); } else { error_log("My Account Debug - User ID: $user_id, Servers Found: " . mysqli_num_rows($servers_result)); } // Fetch invoices (from data directory JSON files) $dataDir = (isset($SITE_DATA_DIR) && $SITE_DATA_DIR) ? $SITE_DATA_DIR : realpath(__DIR__ . '/') . DIRECTORY_SEPARATOR . 'data'; $invoices = []; if (is_dir($dataDir)) { foreach (glob($dataDir . '/*.json') as $file) { $j = json_decode(file_get_contents($file), true); if (!$j || !is_array($j)) continue; // Try to match by user email or user_id in custom field $match = false; if ($user_info && !empty($user_info['users_email'])) { if (!empty($j['payer']) && stripos($j['payer'], $user_info['users_email']) !== false) $match = true; if (!$match && !empty($j['custom']) && stripos($j['custom'], $user_info['users_email']) !== false) $match = true; } if ($match) { $invoices[] = $j; } } } // Sort invoices by invoice/order id (newest order id first) when available, // otherwise fall back to timestamp (newest first). usort($invoices, function($a, $b) { $getOrderId = function($inv) { if (!empty($inv['invoice']) && is_numeric($inv['invoice'])) return intval($inv['invoice']); if (!empty($inv['custom']) && is_numeric($inv['custom'])) return intval($inv['custom']); return null; }; $aId = $getOrderId($a); $bId = $getOrderId($b); if ($aId !== null || $bId !== null) { // If either has a numeric order id, prefer numeric comparison (desc) if ($aId === $bId) { return strtotime($b['ts'] ?? 0) - strtotime($a['ts'] ?? 0); } if ($aId === null) return 1; // b has id -> b before a if ($bId === null) return -1; // a has id -> a before b return $bId - $aId; // numeric desc } // Fallback: newest timestamp first return strtotime($b['ts'] ?? 0) - strtotime($a['ts'] ?? 0); }); // Organize invoices by status $invoices_by_status = []; foreach ($invoices as $inv) { $status = strtolower($inv['status'] ?? 'pending'); if (!isset($invoices_by_status[$status])) { $invoices_by_status[$status] = []; } $invoices_by_status[$status][] = $inv; } // Define status display order and labels $status_config = [ 'pending' => ['label' => 'Pending Invoices', 'class' => 'pending'], 'paid' => ['label' => 'Paid Invoices', 'class' => 'paid'], 'completed' => ['label' => 'Completed Invoices', 'class' => 'paid'], 'in-cart' => ['label' => 'In Cart', 'class' => 'pending'], 'installed' => ['label' => 'Installed/Active', 'class' => 'paid'], 'expired' => ['label' => 'Expired Invoices', 'class' => 'expired'], 'cancelled' => ['label' => 'Cancelled Invoices', 'class' => 'expired'], ]; ?>
My Account
Logout
Account Information
Username
Email
First Name
Last Name
Edit Account Information
First Name
Last Name
Email
Update Information
Unable to load account information.
Change Password
Current Password
New Password
Confirm New Password
Change Password
My Game Servers
0): ?>
Game:
Location / Home ID:
Status:
Price:
$/
Order ID:
#
Expires:
Renew
You don't have any game servers yet.
Browse Game Servers
$status_info): ?>
Invoice #
Invoices
No invoices found.