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, '.', ',');
}
?>