38873-vm/dashboard.php
Flatlogic Bot 378fa008c6 v51
2026-02-28 22:42:56 +00:00

397 lines
24 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
require_once __DIR__ . '/db/config.php';
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if (!$user) {
session_destroy();
header("Location: login.php");
exit;
}
// Security: Check if verified
if ($user['verified'] == 0) {
session_destroy();
header("Location: login.php?error=not_verified");
exit;
}
// Check if onboarding is complete
if ($user['role'] === 'founder' && $user['onboarding_completed'] == 0) {
header("Location: founder_onboarding.php");
exit;
}
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
// Identify Trending Startups (Top 3 in followers or funding)
$trendingIds = [];
// Top 3 Followed
$stmt = db()->prepare("
SELECT s.id
FROM startups s
LEFT JOIN startup_followers sf ON s.id = sf.startup_id
GROUP BY s.id
ORDER BY COUNT(sf.id) DESC
LIMIT 3
");
$stmt->execute();
$topFollowed = $stmt->fetchAll(PDO::FETCH_COLUMN);
$trendingIds = array_merge($trendingIds, $topFollowed);
// Top 3 Funded (Total)
$stmt = db()->prepare("
SELECT id
FROM startups
ORDER BY funding_raised DESC
LIMIT 3
");
$stmt->execute();
$topFunded = $stmt->fetchAll(PDO::FETCH_COLUMN);
$trendingIds = array_unique(array_merge($trendingIds, $topFunded));
// Fetch user's data based on role
$myStartups = [];
$myInvestments = [];
if ($user['role'] === 'founder') {
$stmt = db()->prepare("
SELECT s.*, fr.funding_goal as active_goal, fr.funding_raised as active_raised, fr.status as round_status, fr.id as round_id
FROM startups s
LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active'
WHERE s.founder_id = ?
ORDER BY s.created_at DESC
");
$stmt->execute([$_SESSION['user_id']]);
$myStartups = $stmt->fetchAll();
} else {
$stmt = db()->prepare("SELECT i.*, s.name as startup_name FROM investments i JOIN startups s ON i.startup_id = s.id WHERE i.investor_id = ? ORDER BY i.created_at DESC");
$stmt->execute([$_SESSION['user_id']]);
$myInvestments = $stmt->fetchAll();
}
function number_get_formatted($num) {
return number_format((float)$num, 0, '.', ',');
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dashboard — <?= htmlspecialchars($platformName) ?></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.4.0/css/all.min.css">
</head>
<body style="background: #000; color: #fff; font-family: 'Inter', sans-serif;">
<nav style="padding: 20px 40px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); background: rgba(0,0,0,0.8); backdrop-filter: blur(20px); position: sticky; top: 0; z-index: 1000;">
<div style="display: flex; align-items: center; gap: 40px;">
<a href="index.php" style="text-decoration: none; display: flex; align-items: center; gap: 10px;">
<div style="width: 32px; height: 32px; background: var(--gradient-primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 900; font-size: 18px;">G</div>
<span style="font-weight: 900; font-size: 22px; letter-spacing: -1px; color: #fff;"><?= htmlspecialchars($platformName) ?></span>
</a>
<div style="display: flex; gap: 25px;">
<a href="dashboard.php" style="color: #fff; text-decoration: none; font-size: 14px; font-weight: 700; opacity: 1;">Dashboard</a>
<a href="discover.php" style="color: #fff; text-decoration: none; font-size: 14px; font-weight: 600; opacity: 0.6;">Discover</a>
<a href="messages.php" style="color: #fff; text-decoration: none; font-size: 14px; font-weight: 600; opacity: 0.6;">Messages</a>
</div>
</div>
<div style="display: flex; align-items: center; gap: 20px;">
<div style="background: rgba(255,255,255,0.05); padding: 8px 16px; border-radius: 50px; border: 1px solid var(--border-color); display: flex; align-items: center; gap: 10px;">
<i class="fas fa-wallet" style="color: var(--accent-blue); font-size: 12px;"></i>
<span id="header-wallet-balance" style="font-weight: 800; font-size: 13px;">£<?= number_format($user['balance'], 2) ?></span>
</div>
<a href="logout.php" style="color: #ff3b30; text-decoration: none; font-size: 13px; font-weight: 700;">Logout</a>
</div>
</nav>
<main style="max-width: 1400px; margin: 40px auto; padding: 0 40px;">
<div style="margin-bottom: 40px;">
<h1 style="font-size: 42px; font-weight: 900; margin: 0; letter-spacing: -1.5px;">Welcome back, <?= explode(' ', htmlspecialchars($user['full_name']))[0] ?>!</h1>
<p style="color: var(--text-secondary); font-size: 18px; margin-top: 10px;">Here's what's happening in your venture ecosystem.</p>
</div>
<div style="display: grid; grid-template-columns: 1fr 380px; gap: 40px;">
<div>
<?php if ($user['role'] === 'founder'): ?>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;">
<h3 style="margin: 0; font-size: 24px; font-weight: 800;">My Ventures</h3>
<a href="create_startup.php" class="btn btn-primary" style="padding: 12px 24px; font-size: 14px;">+ Register New Startup</a>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 25px; margin-bottom: 40px;">
<?php if (empty($myStartups)): ?>
<div class="card" style="grid-column: span 2; padding: 60px; text-align: center; border-style: dashed;">
<div class="card-icon" style="margin: 0 auto 20px; background: rgba(0, 242, 255, 0.1);"><i class="fas fa-rocket"></i></div>
<h3 style="font-size: 22px; font-weight: 800; margin-bottom: 10px;">No startups registered</h3>
<p style="color: var(--text-secondary); margin-bottom: 25px;">Ready to change the world? Start by registering your venture.</p>
<a href="create_startup.php" class="btn btn-primary">Get Started</a>
</div>
<?php else: ?>
<?php foreach ($myStartups as $startup): ?>
<div class="candidate-card" style="padding: 30px; cursor: pointer;" onclick="window.location.href='startup_details.php?id=<?= $startup['id'] ?>'">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px;">
<div style="width: 64px; height: 64px; background: var(--surface-color); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 28px; border: 1px solid var(--border-color);">
<i class="fas fa-building" style="opacity: 0.5;"></i>
</div>
<span class="status-pill status-active" style="background: <?= $startup['status'] === 'public' ? 'rgba(76, 217, 100, 0.1)' : 'rgba(255, 255, 255, 0.05)' ?>; color: <?= $startup['status'] === 'public' ? '#4cd964' : '#999' ?>;">
<?= strtoupper($startup['status']) ?>
</span>
</div>
<h3 style="margin: 0 0 8px; font-size: 22px; font-weight: 900;"><?= htmlspecialchars($startup['name']) ?></h3>
<p style="color: var(--text-secondary); font-size: 14px; margin-bottom: 25px; line-height: 1.5; height: 42px; overflow: hidden;"><?= htmlspecialchars($startup['description']) ?></p>
<?php if ($startup['active_goal'] > 0): ?>
<div style="background: rgba(255,255,255,0.03); padding: 15px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.05);">
<div style="display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;">
<span style="color: var(--accent-blue);">Active Funding Round</span>
<span><?= round(($startup['active_raised'] / $startup['active_goal']) * 100) ?>%</span>
</div>
<div class="progress-bar" style="height: 6px; margin-bottom: 10px;">
<div class="progress-fill" style="width: <?= min(100, ($startup['active_raised'] / $startup['active_goal']) * 100) ?>%;"></div>
</div>
<div style="display: flex; justify-content: space-between; font-size: 14px; font-weight: 800;">
<span>£<?= number_get_formatted($startup['active_raised']) ?></span>
<span style="color: var(--text-secondary);">Target: £<?= number_get_formatted($startup['active_goal']) ?></span>
</div>
</div>
<?php else: ?>
<a href="start_funding_round.php?startup_id=<?= $startup['id'] ?>" class="btn" style="width: 100%; padding: 12px; font-size: 13px; font-weight: 800; background: rgba(0, 242, 255, 0.1); color: var(--accent-blue); border-radius: 12px; text-decoration: none; display: inline-block; text-align: center;">Start Funding Round</a>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php else: ?>
<div class="card" style="margin-bottom: 40px; padding: 35px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
<h3 style="margin: 0; font-size: 24px; font-weight: 800;">Portfolio Overview</h3>
<a href="funding_rounds.php" class="btn btn-primary" style="padding: 12px 24px; font-size: 14px;">Find New Deals</a>
</div>
<?php if (empty($myInvestments)): ?>
<div style="text-align: center; padding: 60px 0; background: rgba(255,255,255,0.02); border-radius: 32px; border: 1px dashed var(--border-color);">
<div class="card-icon" style="margin: 0 auto 20px; background: rgba(0, 242, 255, 0.1);"><i class="fas fa-chart-line"></i></div>
<p style="color: var(--text-secondary); margin-bottom: 25px; font-size: 18px;">Start backing the next generation of founders.</p>
<a href="funding_rounds.php" class="btn btn-primary">Start Investing</a>
</div>
<?php else: ?>
<div style="display: grid; grid-template-columns: 1fr; gap: 20px;">
<?php foreach ($myInvestments as $inv): ?>
<div class="candidate-card" style="padding: 25px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;" onclick="window.location.href='startup_details.php?id=<?= $inv['startup_id'] ?>'">
<div style="display: flex; align-items: center; gap: 20px;">
<div style="width: 60px; height: 60px; background: var(--surface-color); border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 24px; border: 1px solid var(--border-color);">
<i class="fas fa-building" style="opacity: 0.5;"></i>
</div>
<div>
<div style="font-weight: 800; font-size: 20px; margin-bottom: 6px;"><?= htmlspecialchars($inv['startup_name']) ?></div>
<div style="font-size: 14px; color: var(--text-secondary);">Committed on <?= date('M d, Y', strtotime($inv['created_at'])) ?></div>
</div>
</div>
<div style="text-align: right;">
<div style="font-size: 22px; font-weight: 900; color: var(--accent-blue);">£<?= number_get_formatted($inv['amount']) ?></div>
<div style="font-size: 13px; font-weight: 800; color: <?= $inv['status'] === 'approved' ? '#4cd964' : ($inv['status'] === 'rejected' ? '#ff3b30' : '#ffcc00') ?>; letter-spacing: 1px;">
<?= strtoupper($inv['status']) ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="card" style="padding: 40px; text-align: center; border-style: dashed;">
<h3 style="font-size: 22px; font-weight: 800; margin-bottom: 10px;">Ecosystem Activity</h3>
<p style="color: var(--text-secondary); font-size: 16px;">Insights from your network and trending matches will appear here.</p>
</div>
</div>
<div>
<!-- Money Pot Section -->
<div class="card" style="margin-bottom: 30px; padding: 30px; background: linear-gradient(135deg, #1a1a24 0%, #101018 100%); border: 1px solid rgba(0, 242, 255, 0.1);">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3 style="margin: 0; font-size: 18px; font-weight: 800; color: var(--accent-blue);">My Money Pot</h3>
<i class="fas fa-wallet" style="color: var(--accent-blue); opacity: 0.5;"></i>
</div>
<div style="margin-bottom: 25px;">
<span style="font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; font-weight: 700;">Available Balance</span>
<div id="wallet-balance" style="font-size: 36px; font-weight: 900; color: #fff; margin-top: 5px;">£<?= number_format($user['balance'], 2) ?></div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">
<button onclick="openWalletModal('add')" class="btn btn-primary" style="padding: 12px; font-size: 13px; font-weight: 800; background: var(--accent-blue); color: #000; border-radius: 12px;">
<i class="fas fa-plus-circle" style="margin-right: 5px;"></i> Add Funds
</button>
<button onclick="openWalletModal('withdraw')" class="btn btn-secondary" style="padding: 12px; font-size: 13px; font-weight: 800; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;">
<i class="fas fa-minus-circle" style="margin-right: 5px;"></i> Withdraw
</button>
</div>
<p style="font-size: 11px; color: var(--text-secondary); margin-top: 15px; text-align: center; opacity: 0.6;">
<?php if ($user['role'] === 'founder'): ?>
Manage your startup capital and dividend funds.
<?php else: ?>
Manage your investment capital and earnings.
<?php endif; ?>
</p>
</div>
<div class="card" style="margin-bottom: 30px; padding: 30px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;">
<h3 style="margin: 0; font-size: 20px; font-weight: 800;">My Profile</h3>
<a href="edit_profile.php" style="color: var(--accent-blue); font-size: 13px; font-weight: 700; text-decoration: none; padding: 6px 14px; background: rgba(0, 242, 255, 0.1); border-radius: 50px;">Edit</a>
</div>
<a href="profile.php?id=<?= $user['id'] ?>" class="profile-link-card">
<div style="display: flex; align-items: center; gap: 20px; margin-bottom: 25px;">
<div style="width: 80px; height: 80px; background: var(--gradient-primary); border-radius: 24px; display: flex; align-items: center; justify-content: center; font-size: 32px; color: #fff; font-weight: 900; box-shadow: 0 15px 30px rgba(0, 122, 255, 0.2);">
<?= substr($user['full_name'] ?? 'U', 0, 1) ?>
</div>
<div>
<div style="font-weight: 900; font-size: 22px; letter-spacing: -0.5px;"><?= htmlspecialchars($user['full_name'] ?? 'User') ?></div>
<div style="font-size: 14px; color: var(--accent-blue); font-weight: 700; opacity: 0.8;"><?= htmlspecialchars($user['university'] ?? 'Student') ?></div>
</div>
</div>
</a>
<div style="margin-bottom: 25px; font-size: 15px; line-height: 1.6; color: var(--text-secondary);">
<?= htmlspecialchars($user['bio'] ?: 'No bio provided yet.') ?>
</div>
<?php if ($user['role'] === 'founder'): ?>
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<?php
$skills = explode(',', $user['skills'] ?? '');
foreach (array_slice($skills, 0, 3) as $skill): if(empty(trim($skill))) continue; ?>
<span style="font-size: 11px; padding: 6px 14px; background: rgba(255,255,255,0.04); border-radius: 50px; border: 1px solid var(--border-color); font-weight: 600; color: var(--text-secondary);"><?= htmlspecialchars(trim($skill)) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="card" style="background: var(--gradient-primary); color: #fff; border: none; margin-bottom: 30px; padding: 30px; position: relative; overflow: hidden;">
<div style="position: absolute; top: -50px; right: -50px; width: 150px; height: 150px; background: rgba(255,255,255,0.1); border-radius: 50%; blur: 20px;"></div>
<h3 style="color: #fff; margin-bottom: 12px; font-size: 22px; font-weight: 800; position: relative;"><?= $user['role'] === 'founder' ? 'Find Your Team' : 'Discover Talent' ?></h3>
<p style="font-size: 15px; opacity: 0.9; margin-bottom: 25px; font-weight: 400; position: relative;">
<?= $user['role'] === 'founder' ? 'Start swiping to find co-founders with complementary skills.' : 'Explore the most promising student startups today.' ?>
</p>
<a href="<?= $user['role'] === 'founder' ? 'partners.php' : 'discover.php' ?>" class="btn" style="width: 100%; background: #fff; color: #1a1a24; font-weight: 800; text-align: center; border-radius: 16px; position: relative;">
<?= $user['role'] === 'founder' ? 'Launch Matching' : 'Go to Discovery Hub' ?>
</a>
</div>
</div>
</div>
</main>
<!-- Wallet Modal -->
<div id="wallet-modal" class="modal">
<div class="modal-content">
<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: #999; 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: 10px; font-size: 12px; color: #999; 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: #000; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; 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; font-weight: 800; border-radius: 16px; background: var(--accent-blue); color: #000;">Confirm</button>
</form>
</div>
</div>
<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.style.background = 'var(--accent-blue)';
} else {
title.innerText = 'Withdraw Funds';
submitBtn.innerText = 'Confirm Withdrawal';
submitBtn.style.background = '#fff';
}
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('wallet-balance').innerText = formattedBalance;
document.getElementById('header-wallet-balance').innerText = formattedBalance;
closeWalletModal();
} else {
alert('Error: ' + data.error);
}
})
.catch(error => {
console.error('Error:', error);
alert('An unexpected error occurred.');
});
});
function updateRound(roundId, status) {
if (confirm('Are you sure you want to ' + status.toLowerCase() + ' this funding round?')) {
const formData = new FormData();
formData.append('round_id', roundId);
formData.append('status', status);
fetch('update_round_status.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert('Error: ' + data.error);
}
});
}
}
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('wallet-modal');
if (event.target == modal) {
closeWalletModal();
}
}
</script>
</body>
</html>