38873-vm/dashboard.php
Flatlogic Bot cab62424f8 v56
2026-02-28 22:48:17 +00:00

482 lines
27 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">
<style>
.trending-pill {
background: linear-gradient(45deg, #FFD700, #FFA500);
color: #000;
padding: 2px 8px;
border-radius: 4px;
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
display: inline-flex;
align-items: center;
gap: 3px;
margin-left: 8px;
vertical-align: middle;
}
.profile-link-card {
text-decoration: none;
color: inherit;
transition: transform 0.2s;
display: block;
}
.profile-link-card:hover {
transform: translateY(-2px);
}
/* 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.85);
backdrop-filter: blur(8px);
}
.modal-content {
background-color: #1a1a24;
margin: 10% auto;
padding: 40px;
border: 1px solid var(--border-color);
width: 420px;
border-radius: 32px;
box-shadow: 0 25px 60px rgba(0,0,0,0.7);
}
</style>
</head>
<body>
<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" 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;">
<!-- Money Pot Widget in Header -->
<div onclick="openWalletModal('add')" style="cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 5px 12px; background: rgba(0, 242, 255, 0.1); border-radius: 50px; border: 1px solid rgba(0, 242, 255, 0.2);">
<i class="fas fa-wallet" style="color: var(--accent-blue); font-size: 12px;"></i>
<span id="header-wallet-balance" style="font-size: 13px; font-weight: 800; color: #fff;">£<?= number_format($user['balance'], 2) ?></span>
</div>
<a href="notifications.php" style="color: var(--text-secondary); position: relative; font-size: 18px;">
<i class="fas fa-bell"></i>
</a>
<div style="display: flex; align-items: center; gap: 10px; padding: 5px 12px; background: rgba(255,255,255,0.05); border-radius: 50px; border: 1px solid var(--border-color);">
<div style="width: 24px; height: 24px; background: var(--gradient-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; 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; border-radius: 10px;">Log Out</a>
</div>
</div>
</header>
<main class="container" style="padding-top: 60px; padding-bottom: 80px;">
<div class="hero-bg">
<div class="hero-blob" style="top: 5%; left: -15%;"></div>
<div class="hero-blob" style="bottom: 10%; right: -15%; width: 500px; height: 500px; background: radial-gradient(circle, rgba(138, 43, 226, 0.1) 0%, rgba(0, 242, 255, 0.1) 100%);"></div>
</div>
<div style="margin-bottom: 60px;">
<div class="match-score-pill" style="margin-bottom: 20px;"><i class="fas fa-rocket"></i> Launchpad Active</div>
<h1 style="font-size: 56px; font-weight: 900; letter-spacing: -2px; line-height: 1.1;">Welcome back, <span style="background: var(--gradient-primary); -webkit-background-clip: text; -webkit-text-fill-color: transparent;"><?= htmlspecialchars(explode(' ', $user['full_name'])[0]) ?>.</span></h1>
<p style="color: var(--text-secondary); font-size: 20px; margin-top: 10px;">Your command center for the next big thing.</p>
</div>
<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 40px;">
<div>
<?php if ($user['role'] === 'founder'): ?>
<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;">My Ventures</h3>
<div style="display: flex; gap: 10px;">
<a href="create_startup.php" class="btn btn-primary" style="padding: 12px 24px; font-size: 14px;">+ Launch Startup</a>
</div>
</div>
<?php if (empty($myStartups)): ?>
<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-rocket"></i></div>
<p style="color: var(--text-secondary); margin-bottom: 25px; font-size: 18px;">Ready to share your vision with the world?</p>
<a href="create_startup.php" class="btn btn-primary">Start Your First Round</a>
</div>
<?php else: ?>
<div style="display: grid; grid-template-columns: 1fr; gap: 20px;">
<?php foreach ($myStartups as $startup):
$goal = $startup['active_goal'] ?? $startup['funding_target'];
$raised = $startup['active_raised'] ?? $startup['funding_raised'];
$isTrending = in_array($startup['id'], $trendingIds);
?>
<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=<?= $startup['id'] ?>'">
<div style="display: flex; align-items: center; gap: 20px;">
<div style="width: 60px; height: 60px; background: var(--gradient-primary); border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: #fff; font-weight: 800;">
<?= substr($startup['name'], 0, 1) ?>
</div>
<div>
<div style="font-weight: 800; font-size: 20px; margin-bottom: 6px;">
<?= htmlspecialchars($startup['name']) ?>
<?php if ($isTrending): ?>
<span class="trending-pill"><i class="fas fa-fire"></i> Trending</span>
<?php endif; ?>
</div>
<div style="font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; gap: 12px;">
<span style="padding: 4px 10px; background: rgba(0, 242, 255, 0.1); color: var(--accent-blue); border-radius: 8px; font-weight: 700; font-size: 12px; letter-spacing: 0.5px;">
<?= strtoupper($startup['round_status'] ?? 'Draft') ?>
</span>
<span style="opacity: 0.7;">Target: £<?= number_get_formatted($goal) ?></span>
</div>
</div>
</div>
<div style="display: flex; gap: 20px; align-items: center;">
<div style="text-align: right;">
<div style="font-size: 22px; font-weight: 900; color: #fff;">£<?= number_get_formatted($raised) ?></div>
<div style="font-size: 13px; color: var(--text-secondary); opacity: 0.6;">Funds Raised</div>
</div>
<?php if ($startup['round_status'] === 'Active'): ?>
<div style="display: flex; gap: 8px;">
<button onclick="event.stopPropagation(); updateRound(<?= $startup['round_id'] ?>, 'Closed')" class="btn" style="padding: 8px 12px; font-size: 11px; background: #28a745; color: #fff; border: none; border-radius: 8px;">Finish</button>
<button onclick="event.stopPropagation(); updateRound(<?= $startup['round_id'] ?>, 'Cancelled')" class="btn" style="padding: 8px 12px; font-size: 11px; background: #dc3545; color: #fff; border: none; border-radius: 8px;">Cancel</button>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?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'], 0, 1) ?>
</div>
<div>
<div style="font-weight: 900; font-size: 22px; letter-spacing: -0.5px;"><?= htmlspecialchars($user['full_name']) ?></div>
<div style="font-size: 14px; color: var(--accent-blue); font-weight: 700; opacity: 0.8;"><?= htmlspecialchars($user['university']) ?></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});
if (document.getElementById('wallet-balance')) {
document.getElementById('wallet-balance').innerText = formattedBalance;
}
if (document.getElementById('header-wallet-balance')) {
document.getElementById('header-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.');
});
});
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>