38873-vm/startup_details.php
Flatlogic Bot 3575e4a095 v70
2026-02-28 23:27:55 +00:00

645 lines
33 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_id = $_SESSION['user_id'];
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();
$startupId = $_GET['id'] ?? null;
if (!$startupId) {
header('Location: startups.php');
exit;
}
$stmt = db()->prepare("
SELECT s.*, fr.id as round_id, fr.funding_goal as active_goal, fr.funding_raised as active_raised, fr.status as round_status
FROM startups s
LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active'
WHERE s.id = ?
");
$stmt->execute([$startupId]);
$startup = $stmt->fetch();
if (!$startup) {
die("Startup not found.");
}
// Check if user is the founder or an investor
$isFounder = ($_SESSION['user_id'] == $startup['founder_id']);
$isInvestor = ($user['role'] == 'investor');
// Basic permissions check
if (!$isFounder && $startup['status'] === 'private' && !$isInvestor) {
die("You do not have permission to view this profile.");
}
// Fetch funding history
$canSeeHistory = $isFounder || $isInvestor;
$fundingHistory = [];
if ($canSeeHistory) {
$stmt = db()->prepare("
SELECT i.*, u.full_name as investor_name, u.id as investor_user_id
FROM investments i
LEFT JOIN users u ON i.investor_id = u.id
WHERE i.startup_id = ? AND i.status != 'rejected'
ORDER BY i.created_at DESC
");
$stmt->execute([$startupId]);
$fundingHistory = $stmt->fetchAll();
}
// Fetch approved investments for dividends calculation (Founder only)
$approvedInvestments = [];
if ($isFounder) {
$stmt = db()->prepare("
SELECT i.*, u.full_name as investor_name
FROM investments i
JOIN users u ON i.investor_id = u.id
WHERE i.startup_id = ? AND i.status = 'approved'
");
$stmt->execute([$startupId]);
$approvedInvestments = $stmt->fetchAll();
}
// Fetch founders
$stmt = db()->prepare("SELECT id, full_name FROM users WHERE id = ?");
$stmt->execute([$startup['founder_id']]);
$founder = $stmt->fetch();
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
// Calculate progress
$goal = $startup['active_goal'] ?: 0;
$raised = $startup['active_raised'] ?: 0;
$progress = ($goal > 0) ? round(($raised / $goal) * 100) : 0;
/**
* Helper to calculate time left for next dividend
*/
function getNextDividendInfo($createdAt) {
$created = new DateTime($createdAt);
$day = $created->format('d');
$now = new DateTime();
$thisMonth = new DateTime($now->format('Y-m-') . $day);
// If today is past the day, next is next month
if ($thisMonth <= $now) {
$next = clone $thisMonth;
$next->modify('+1 month');
} else {
$next = $thisMonth;
}
$interval = $now->diff($next);
$days = $interval->days;
return [
'date' => $next->format('M d, Y'),
'days_left' => $days
];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?= htmlspecialchars($startup['name']) ?> | Startup Details</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=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
.section-title {
font-size: 20px;
font-weight: 800;
margin-bottom: 25px;
display: flex; align-items: center;
gap: 12px;
}
.data-label {
font-size: 12px;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-secondary);
margin-bottom: 8px;
}
.doc-link {
background: var(--elevated-color);
padding: 12px 20px;
border-radius: 12px;
text-decoration: none;
color: #fff;
display: flex;
align-items: center;
gap: 10px;
font-size: 14px;
transition: all 0.2s;
border: 1px solid var(--border-color);
}
.doc-link:hover {
border-color: var(--accent-primary);
transform: translateY(-2px);
}
.invest-btn {
background: var(--accent-primary);
color: #000;
padding: 16px 32px;
border-radius: 999px;
text-decoration: none;
font-weight: 800;
display: inline-flex;
align-items: center;
gap: 10px;
transition: all 0.3s;
text-transform: uppercase;
font-size: 14px;
letter-spacing: 0.5px;
}
.invest-btn:hover {
background: var(--accent-secondary);
transform: scale(1.05);
}
.progress-bar-container {
width: 100%;
height: 10px;
background: var(--bg-color);
border-radius: 100px;
overflow: hidden;
margin: 20px 0;
border: 1px solid var(--border-color);
}
.progress-bar-fill {
height: 100%;
background: var(--accent-primary);
border-radius: 100px;
}
.dividend-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
background: var(--elevated-color);
border-radius: 12px;
border: 1px solid var(--border-color);
margin-bottom: 10px;
}
.btn-status-small {
padding: 10px 15px;
font-size: 12px;
font-weight: 700;
border-radius: 999px;
border: 1px solid transparent;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 6px;
background: transparent;
text-decoration: none;
text-transform: uppercase;
}
.btn-cancel-small {
border-color: var(--error-color);
color: var(--error-color);
}
.btn-cancel-small:hover {
background: var(--error-color);
color: #fff;
}
.btn-finish-small {
border-color: var(--success-color);
color: var(--success-color);
}
.btn-finish-small:hover {
background: var(--success-color);
color: #000;
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 2000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.9);
backdrop-filter: blur(4px);
}
</style>
</head>
<body style="background: var(--bg-color); color: var(--text-primary);">
<header>
<div class="container" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<a href="dashboard.php" class="logo-container">
<img src="assets/images/logo.svg?v=<?php echo time(); ?>" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img">
<span class="logo-text"><?= htmlspecialchars($platformName) ?></span>
</a>
<nav class="nav-links">
<?php if ($user['role'] === 'founder'): ?>
<a href="startups.php">My Startups</a>
<a href="partners.php">Find Partners</a>
<?php else: ?>
<a href="funding_rounds.php">Founding Rounds</a>
<a href="portfolio.php">Portfolio</a>
<a href="discover.php">Discovery Hub</a>
<?php endif; ?>
<a href="messages.php">Messages</a>
</nav>
<div style="display: flex; align-items: center; gap: 15px;">
<div onclick="openWalletModal('add')" style="cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: var(--surface-color); border-radius: 50px; border: 1px solid var(--border-color);">
<i class="fas fa-wallet" style="color: var(--accent-primary); font-size: 14px;"></i>
<span id="header-wallet-balance" style="font-size: 14px; font-weight: 800; color: #fff;">£<?= number_format($user['balance'], 2) ?></span>
</div>
<div style="display: flex; align-items: center; gap: 10px; padding: 6px 14px; background: var(--surface-color); border-radius: 50px; border: 1px solid var(--border-color);">
<div style="width: 24px; height: 24px; background: var(--accent-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #000; font-weight: 800;">
<?= substr($user['full_name'], 0, 1) ?>
</div>
<span style="font-size: 13px; font-weight: 600;"><?= htmlspecialchars(explode(' ', $user['full_name'])[0]) ?></span>
</div>
<a href="logout.php" class="btn btn-secondary" style="padding: 8px 16px; font-size: 12px;">Log Out</a>
</div>
</div>
</header>
<div class="container" style="padding: 60px 20px;">
<div style="max-width: 900px; margin: 0 auto;">
<?php if (isset($_GET['success'])): ?>
<div style="background: rgba(0, 200, 83, 0.1); border: 1px solid var(--success-color); color: var(--success-color); padding: 15px; border-radius: 12px; margin-bottom: 25px; font-size: 14px; text-align: center; font-weight: 600;">
Round status updated successfully!
</div>
<?php endif; ?>
<!-- Header Section -->
<div style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 50px;">
<div>
<div style="display: flex; align-items: center; gap: 15px; margin-bottom: 15px;">
<span style="background: var(--surface-color); color: var(--accent-primary); padding: 6px 14px; border-radius: 100px; font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; border: 1px solid var(--border-color);">
<?= htmlspecialchars($startup['industry']) ?>
</span>
<span style="color: var(--text-secondary); font-size: 13px;">
<i class="fas fa-map-marker-alt"></i> <?= htmlspecialchars($startup['country']) ?>
</span>
</div>
<h1 style="font-size: 48px; font-weight: 900; margin: 0; line-height: 1.1; letter-spacing: -1px;">
<?= htmlspecialchars($startup['name']) ?>
</h1>
<p style="color: var(--text-secondary); margin-top: 10px; font-size: 16px;">
Founded by <a href="profile.php?id=<?= $founder['id'] ?>" style="color: var(--accent-primary); font-weight: 700; text-decoration: none; border-bottom: 1px dashed var(--accent-primary);"><?= htmlspecialchars($founder['full_name']) ?></a>
</p>
</div>
<?php if ($isInvestor): ?>
<div style="display: flex; gap: 15px;">
<a href="messages.php?chat_with=<?= $startup['founder_id'] ?>" class="btn btn-secondary" style="padding: 16px 24px;">
<i class="far fa-comment-dots"></i> Message Founder
</a>
<a href="invest.php?id=<?= $startup['id'] ?>" class="invest-btn">
<i class="fas fa-rocket"></i> Invest Now
</a>
</div>
<?php elseif ($isFounder): ?>
<a href="create_startup.php?id=<?= $startup['id'] ?>" class="btn btn-secondary" style="padding: 16px 24px;">
<i class="fas fa-edit"></i> Edit Profile
</a>
<?php endif; ?>
</div>
<?php if ($startup['round_status'] === 'Active'): ?>
<!-- Funding Progress -->
<section class="card" style="margin-bottom: 40px; border-color: var(--accent-primary) !important;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<h2 class="section-title" style="margin-bottom: 0;"><i class="fas fa-chart-pie" style="color: var(--accent-primary);"></i> Active Funding Round</h2>
<span style="font-weight: 800; color: var(--accent-primary);"><?= $progress ?>% Complete</span>
</div>
<div class="progress-bar-container">
<div class="progress-bar-fill" style="width: <?= min(100, $progress) ?>%;"></div>
</div>
<div style="display: flex; justify-content: space-between; font-weight: 700;">
<div>
<div style="font-size: 11px; color: var(--text-secondary); text-transform: uppercase;">Raised</div>
<div style="font-size: 20px;">£<?= number_format($raised) ?></div>
</div>
<div style="text-align: right;">
<div style="font-size: 11px; color: var(--text-secondary); text-transform: uppercase;">Goal</div>
<div style="font-size: 20px;">£<?= number_format($goal) ?></div>
</div>
</div>
<?php if ($isFounder): ?>
<div style="display: flex; gap: 15px; margin-top: 30px; border-top: 1px solid var(--border-color); padding-top: 25px;">
<form action="update_round_status.php" method="POST" style="margin: 0;" onsubmit="return confirm('Finish this round early?');">
<input type="hidden" name="round_id" value="<?= $startup['round_id'] ?>">
<input type="hidden" name="status" value="Closed">
<button type="submit" class="btn-status-small btn-finish-small">
<i class="fas fa-check-circle"></i> Finish Round Early
</button>
</form>
<form action="update_round_status.php" method="POST" style="margin: 0;" onsubmit="return confirm('Cancel this funding round?');">
<input type="hidden" name="round_id" value="<?= $startup['round_id'] ?>">
<input type="hidden" name="status" value="Cancelled">
<button type="submit" class="btn-status-small btn-cancel-small">
<i class="fas fa-times-circle"></i> Cancel Round
</button>
</form>
</div>
<?php endif; ?>
</section>
<?php endif; ?>
<?php if ($isFounder): ?>
<!-- Money Pot (Founder View) -->
<section class="card" style="margin-bottom: 40px; background: var(--elevated-color) !important;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;">
<h2 class="section-title" style="margin-bottom: 0;"><i class="fas fa-wallet" style="color: var(--accent-primary);"></i> Startup Money Pot</h2>
<div style="display: flex; gap: 10px;">
<button onclick="openWalletModal('add')" class="btn btn-primary" style="padding: 10px 20px; font-size: 13px;">Add Funds</button>
<button onclick="openWalletModal('withdraw')" class="btn btn-secondary" style="padding: 10px 20px; font-size: 13px;">Withdraw</button>
</div>
</div>
<div style="display: flex; align-items: center; gap: 30px;">
<div>
<div style="font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px;">Available Capital</div>
<div id="startup-wallet-balance" style="font-size: 36px; font-weight: 900; color: #fff; margin-top: 5px;">£<?= number_format($user['balance'], 2) ?></div>
</div>
<div style="padding-left: 30px; border-left: 1px solid var(--border-color);">
<div style="font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px;">Total Investments Received</div>
<div style="font-size: 24px; font-weight: 900; color: var(--accent-primary); margin-top: 5px;">£<?= number_format($startup['funding_raised'], 2) ?></div>
</div>
</div>
<p style="margin-top: 20px; color: var(--text-secondary); font-size: 13px; opacity: 0.8;">
<i class="fas fa-info-circle"></i> This pot holds all investments received. You can withdraw funds for business operations or add funds to cover investor dividends.
</p>
</section>
<?php endif; ?>
<?php if ($isFounder && !empty($approvedInvestments)): ?>
<!-- Dividend Management (Founder Only) -->
<section class="card" style="margin-bottom: 40px; border-color: var(--success-color) !important;">
<h2 class="section-title"><i class="fas fa-hand-holding-usd" style="color: var(--success-color);"></i> Monthly Dividends Due</h2>
<div style="margin-bottom: 20px;">
<p style="color: var(--text-secondary); font-size: 14px;">Track upcoming monthly payments to your investors based on your <strong><?= number_format($startup['founder_return_rate'] ?? 0, 1) ?>%</strong> offered return.</p>
</div>
<?php foreach ($approvedInvestments as $inv):
$monthlyYield = ($inv['amount'] * ($startup['founder_return_rate'] ?? 0) / 100) / 12;
$nextPay = getNextDividendInfo($inv['created_at']);
?>
<div class="dividend-item">
<div>
<div style="font-weight: 700; font-size: 15px;"><?= htmlspecialchars($inv['investor_name']) ?></div>
<div style="font-size: 12px; color: var(--text-secondary);">Invested £<?= number_format($inv['amount']) ?></div>
</div>
<div style="text-align: right;">
<div style="font-size: 18px; font-weight: 900; color: #fff;">£<?= number_format($monthlyYield, 2) ?></div>
<div style="font-size: 11px; color: <?= $nextPay['days_left'] < 7 ? 'var(--error-color)' : 'var(--success-color)' ?>; font-weight: 700;">
<i class="far fa-clock"></i> <?= $nextPay['days_left'] ?> days left
</div>
</div>
</div>
<?php endforeach; ?>
</section>
<?php endif; ?>
<!-- Product & Vision -->
<section class="card" style="margin-bottom: 40px;">
<h2 class="section-title"><i class="fas fa-eye" style="color: var(--accent-primary);"></i> Product & Vision</h2>
<p style="font-size: 18px; line-height: 1.6; color: var(--text-primary);">
<?= nl2br(htmlspecialchars($startup['product_service'])) ?>
</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px;">
<div>
<h4 style="color: var(--text-secondary); text-transform: uppercase; font-size: 12px; letter-spacing: 1px;">Business Model</h4>
<p style="font-weight: 700; font-size: 16px; color: var(--text-primary);"><?= htmlspecialchars($startup['business_model']) ?></p>
</div>
<div>
<h4 style="color: var(--text-secondary); text-transform: uppercase; font-size: 12px; letter-spacing: 1px;">Operational Stage</h4>
<p style="font-weight: 700; font-size: 16px; color: var(--text-primary);"><?= htmlspecialchars($startup['operational_stage']) ?></p>
</div>
</div>
</section>
<section class="card" style="margin-bottom: 40px;">
<h2 class="section-title"><i class="fas fa-chart-line" style="color: var(--accent-primary);"></i> Financial Health</h2>
<div style="background: var(--bg-color); padding: 25px; border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 25px;">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div>
<div class="data-label">Cash on Hand</div>
<div style="font-size: 24px; font-weight: 900; color: var(--success-color);">£<?= number_format($startup['current_cash_balance']) ?></div>
</div>
<div>
<div class="data-label">Monthly Burn</div>
<div style="font-size: 24px; font-weight: 900; color: var(--error-color);">£<?= number_format($startup['burn_rate']) ?></div>
</div>
</div>
</div>
<div style="background: var(--bg-color); padding: 15px; border-radius: 12px; margin-bottom: 25px; border: 1px solid var(--border-color);">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
<div>
<div class="data-label" style="font-size: 10px;">Outstanding Debt</div>
<div style="font-size: 14px; color: var(--text-primary);"><?= htmlspecialchars($startup['outstanding_debt'] ?: 'None') ?></div>
</div>
<div>
<div class="data-label" style="font-size: 10px;">Accounts Receivable/Payable</div>
<div style="font-size: 14px; color: var(--text-primary);"><?= htmlspecialchars($startup['accounts_receivable_payable'] ?: 'N/A') ?></div>
</div>
</div>
</div>
<h4 style="margin-bottom: 15px; font-size: 14px; text-transform: uppercase; color: var(--text-secondary); opacity: 0.7;">Historical Documentation</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<?php
$docs = [
'Income Statements' => $startup['doc_income_statements'],
'Balance Sheets' => $startup['doc_balance_sheets'],
'Cash Flow' => $startup['doc_cash_flow_statements'],
'Revenue Breakdown' => $startup['doc_revenue_breakdown'],
'Gross Margin' => $startup['doc_gross_margin']
];
foreach ($docs as $label => $path): if ($path):
?>
<a href="<?= htmlspecialchars($path) ?>" target="_blank" class="doc-link">
<i class="fas fa-file-pdf"></i> <?= $label ?>
</a>
<?php endif; endforeach; ?>
</div>
</section>
<!-- Return Rates Comparison -->
<section class="card" style="margin-bottom: 40px; border-color: var(--accent-primary) !important;">
<h2 style="margin-top: 0; margin-bottom: 25px; display: flex; align-items: center; gap: 12px;">
<i class="fas fa-percentage" style="color: var(--accent-primary);"></i> Expected Investor Returns
</h2>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div style="padding: 20px; background: var(--bg-color); border-radius: 12px; border: 1px solid var(--border-color); text-align: center;">
<div style="font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;">Platform Recommendation</div>
<div style="font-size: 32px; font-weight: 900; color: var(--accent-primary);"><?= number_format($startup['recommended_return_rate'] ?? 5.0, 1) ?>%</div>
<div style="font-size: 11px; color: var(--text-secondary); margin-top: 5px;">AI analysis based on uploaded financials</div>
</div>
<div style="padding: 20px; background: var(--bg-color); border-radius: 12px; border: 1px solid var(--border-color); text-align: center;">
<div style="font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;">Founder's Proposal</div>
<div style="font-size: 32px; font-weight: 900; color: #fff;">
<?= $startup['founder_return_rate'] !== null ? number_format($startup['founder_return_rate'], 1) . '%' : 'N/A' ?>
</div>
<div style="font-size: 11px; color: var(--text-secondary); margin-top: 5px;">Target annual dividend yield set by founder</div>
</div>
</div>
<?php if (!empty($startup['recommended_return_reasoning'])): ?>
<div style="margin-top: 20px; padding: 15px; background: var(--surface-color); border-radius: 12px; border: 1px solid var(--border-color); font-size: 13px; line-height: 1.5; color: var(--text-secondary);">
<div style="font-weight: 700; margin-bottom: 5px; color: var(--accent-primary); text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px;">Calculation Reasoning</div>
<?= htmlspecialchars($startup['recommended_return_reasoning']) ?>
</div>
<?php endif; ?>
</section>
<!-- Funding History Section -->
<?php if ($canSeeHistory): ?>
<section class="card" style="margin-bottom: 40px;">
<h2 class="section-title"><i class="fas fa-history" style="color: var(--accent-primary);"></i> Funding History</h2>
<?php if (empty($fundingHistory)): ?>
<div style="padding: 40px; text-align: center; background: var(--bg-color); border-radius: 12px; border: 1px dashed var(--border-color);">
<p style="color: var(--text-secondary); margin: 0;">No investment history available yet.</p>
</div>
<?php else: ?>
<div style="display: flex; flex-direction: column; gap: 15px;">
<?php foreach ($fundingHistory as $inv):
$investorName = $inv['investor_name'] ?: 'Verified Investor';
?>
<div style="display: flex; align-items: center; justify-content: space-between; padding: 20px; background: var(--elevated-color); border-radius: 12px; border: 1px solid var(--border-color);">
<div style="display: flex; align-items: center; gap: 15px;">
<?php if ($inv['investor_user_id']): ?>
<a href="profile.php?id=<?= $inv['investor_user_id'] ?>" style="text-decoration: none;">
<div style="width: 45px; height: 45px; border-radius: 8px; background: var(--surface-color); display: flex; align-items: center; justify-content: center;">
<span style="font-weight: 800; color: var(--accent-primary);"><?= substr($investorName, 0, 1) ?></span>
</div>
</a>
<?php else: ?>
<div style="width: 45px; height: 45px; border-radius: 8px; background: var(--surface-color); display: flex; align-items: center; justify-content: center;">
<span style="font-weight: 800; color: var(--accent-primary);"><?= substr($investorName, 0, 1) ?></span>
</div>
<?php endif; ?>
<div>
<div style="font-weight: 700; color: var(--text-primary);">
<?php if ($inv['investor_user_id']): ?>
<a href="profile.php?id=<?= $inv['investor_user_id'] ?>" style="color: inherit; text-decoration: none;"><?= htmlspecialchars($investorName) ?></a>
<?php else: ?>
<?= htmlspecialchars($investorName) ?>
<?php endif; ?>
</div>
<div style="font-size: 12px; color: var(--text-secondary);"><?= date('M d, Y', strtotime($inv['created_at'])) ?></div>
</div>
</div>
<div style="text-align: right;">
<div style="font-weight: 900; color: var(--text-primary); font-size: 18px;">£<?= number_format($inv['amount']) ?></div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section>
<?php endif; ?>
</div>
</div>
<!-- Wallet Modal -->
<div id="wallet-modal" class="modal">
<div class="modal-content" style="max-width: 420px; margin: 10% auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
<h2 id="modal-title" style="margin: 0; font-size: 24px; font-weight: 900; color: #fff;">Add Funds</h2>
<button onclick="closeWalletModal()" style="background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 20px;"><i class="fas fa-times"></i></button>
</div>
<form id="wallet-form">
<input type="hidden" id="wallet-action" name="action" value="add">
<div style="margin-bottom: 25px;">
<label style="display: block; margin-bottom: 12px; font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; font-weight: 700;">Amount (£)</label>
<input type="number" id="wallet-amount" name="amount" min="1" step="0.01" required placeholder="0.00"
style="width: 100%; padding: 18px; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 12px; color: #fff; font-size: 24px; font-weight: 800;">
</div>
<button type="submit" id="wallet-submit-btn" class="btn btn-primary" style="width: 100%; padding: 18px; font-size: 16px;">Confirm</button>
</form>
</div>
</div>
<footer style="padding: 60px 0; border-top: 1px solid var(--border-color); margin-top: 100px; text-align: center;">
<p style="color: var(--text-secondary); font-size: 14px;">&copy; <?= date('Y') ?> <?= htmlspecialchars($platformName) ?>. All rights reserved.</p>
</footer>
<script>
function openWalletModal(action) {
const modal = document.getElementById('wallet-modal');
const title = document.getElementById('modal-title');
const actionInput = document.getElementById('wallet-action');
const submitBtn = document.getElementById('wallet-submit-btn');
actionInput.value = action;
if (action === 'add') {
title.innerText = 'Add Funds';
submitBtn.innerText = 'Confirm Deposit';
submitBtn.className = 'btn btn-primary';
} else {
title.innerText = 'Withdraw Funds';
submitBtn.innerText = 'Confirm Withdrawal';
submitBtn.className = 'btn btn-secondary';
}
modal.style.display = 'block';
}
function closeWalletModal() {
document.getElementById('wallet-modal').style.display = 'none';
}
document.getElementById('wallet-form').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
fetch('api/wallet_transaction.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
const formattedBalance = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('header-wallet-balance').innerText = formattedBalance;
if (document.getElementById('startup-wallet-balance')) {
document.getElementById('startup-wallet-balance').innerText = formattedBalance;
}
closeWalletModal();
alert(formData.get('action') === 'add' ? 'Funds added successfully!' : 'Withdrawal successful!');
} else {
alert('Error: ' + data.error);
}
})
.catch(error => {
console.error('Error:', error);
alert('An unexpected error occurred.');
});
});
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('wallet-modal');
if (event.target == modal) {
closeWalletModal();
}
}
</script>
</body>
</html>