38873-vm/discover.php
Flatlogic Bot 0053cb8830 v74
2026-03-01 09:49:02 +00:00

312 lines
16 KiB
PHP

<?php
require_once 'db/config.php';
session_start();
$user_id = $_SESSION['user_id'] ?? null;
if (!$user_id) { header('Location: login.php'); exit; }
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();
if (!$user) { header('Location: login.php'); exit; }
$user_role = $user['role'];
if ($user_role === 'founder') {
header('Location: dashboard.php');
exit;
}
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
// Get user's followed startups
$stmt = db()->prepare("SELECT startup_id FROM startup_followers WHERE user_id = ?");
$stmt->execute([$user_id]);
$followedStartups = $stmt->fetchAll(PDO::FETCH_COLUMN);
// Leaderboard: Most Followed
$stmt = db()->query("
SELECT s.*, u.full_name as founder_name
FROM startups s
JOIN users u ON s.founder_id = u.id
ORDER BY s.followers_count DESC
LIMIT 3
");
$mostFollowed = $stmt->fetchAll();
// Leaderboard: Most Funded (Total funding raised)
$stmt = db()->query("
SELECT s.id, s.name, u.full_name as founder_name, s.funding_raised as funded_amount
FROM startups s
JOIN users u ON s.founder_id = u.id
ORDER BY s.funding_raised DESC
LIMIT 3
");
$mostFunded = $stmt->fetchAll();
// General Browse - ONLY Founding Rounds (Active)
$q = $_GET['q'] ?? '';
$where = "fr.status = 'Active'";
$params = [];
if ($q) {
$where .= " AND (s.name LIKE ? OR s.description LIKE ? OR s.industry LIKE ?)";
$params[] = "%$q%";
$params[] = "%$q%";
$params[] = "%$q%";
}
$stmt = db()->prepare("
SELECT s.*, u.full_name as founder_name, fr.funding_goal as active_goal, fr.funding_raised as active_raised
FROM funding_rounds fr
JOIN startups s ON fr.startup_id = s.id
JOIN users u ON s.founder_id = u.id
WHERE $where
ORDER BY fr.created_at DESC
LIMIT 12
");
$stmt->execute($params);
$browseStartups = $stmt->fetchAll();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Discovery Hub — <?= 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>
.hub-header { padding: 60px 0 40px; text-align: center; }
.hub-header h1 { font-size: 56px; font-weight: 900; margin-bottom: 12px; color: var(--text-primary); }
.hub-header p { color: var(--text-secondary); font-size: 20px; }
.leaderboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-bottom: 60px; }
@media (max-width: 900px) { .leaderboard-grid { grid-template-columns: 1fr; } }
.lb-card { background: var(--surface-color); border: 1px solid var(--border-color); border-radius: 16px; padding: 30px; }
.lb-title { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; font-size: 20px; font-weight: 800; color: var(--text-primary); }
.lb-item { display: flex; align-items: center; gap: 15px; padding: 15px; background: var(--elevated-color); border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 12px; transition: all 0.3s; text-decoration: none; color: inherit; position: relative; }
.lb-item:hover { transform: translateX(8px); border-color: var(--accent-primary); }
.lb-rank { width: 32px; height: 32px; background: var(--bg-color); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent-primary); font-size: 14px; border: 1px solid var(--border-color); }
.rank-1 { background: var(--warning-color); color: #000; border-color: var(--warning-color); }
.rank-2 { background: var(--text-secondary); color: #000; border-color: var(--text-secondary); }
.rank-3 { background: #cd7f32; color: #000; border-color: #cd7f32; }
.startup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 25px; }
.follow-btn {
background: var(--surface-color);
border: 1px solid var(--border-color);
color: var(--text-primary);
padding: 8px 16px;
border-radius: 50px;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 6px;
z-index: 2;
}
.follow-btn:hover {
border-color: var(--accent-primary);
color: var(--accent-primary);
}
.follow-btn.active {
background: var(--accent-primary);
color: #000;
border-color: var(--accent-primary);
}
.follow-btn i { font-size: 14px; }
</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?v=<?php echo time(); ?>" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img">
<span class="logo-text"><?= htmlspecialchars($platformName) ?></span>
</a>
<nav class="nav-links">
<a href="funding_rounds.php">Founding Rounds</a>
<a href="portfolio.php">Portfolio</a>
<a href="discover.php" class="active">Discovery Hub</a>
<a href="messages.php">Messages</a>
</nav>
<div style="display: flex; align-items: center; gap: 15px;">
<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: 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>
<main class="container">
<div class="hub-header">
<h1>Discovery <span style="color: var(--accent-primary);">Hub.</span></h1>
<p>Explore the best student-led innovation across the network.</p>
</div>
<div class="leaderboard-grid">
<div class="lb-card">
<div class="lb-title"><i class="fas fa-heart" style="color: var(--error-color);"></i> Top Followed</div>
<?php foreach ($mostFollowed as $i => $s):
$isFollowing = in_array($s['id'], $followedStartups);
?>
<div class="lb-item-wrapper" style="position: relative; margin-bottom: 12px;">
<a href="startup_details.php?id=<?= $s['id'] ?>" class="lb-item" style="margin-bottom: 0;">
<div class="lb-rank rank-<?= $i+1 ?>"><?= $i+1 ?></div>
<div style="flex: 1;">
<div style="font-weight: 700; color: var(--text-primary);"><?= htmlspecialchars($s['name']) ?></div>
<div style="font-size: 12px; color: var(--text-secondary);">by <?= htmlspecialchars($s['founder_name']) ?></div>
</div>
<div style="display: flex; align-items: center; gap: 15px;">
<div style="font-weight: 800; color: var(--accent-primary); min-width: 40px; text-align: right;" id="follower-count-<?= $s['id'] ?>"><?= number_format($s['followers_count']) ?></div>
</div>
</a>
<button class="follow-btn <?= $isFollowing ? 'active' : '' ?>"
data-id="<?= $s['id'] ?>"
data-action="<?= $isFollowing ? 'unfollow' : 'follow' ?>"
style="position: absolute; right: 80px; top: 50%; transform: translateY(-50%);">
<i class="<?= $isFollowing ? 'fas' : 'far' ?> fa-heart"></i>
<?= $isFollowing ? 'Following' : 'Follow' ?>
</button>
</div>
<?php endforeach; ?>
</div>
<div class="lb-card">
<div class="lb-title"><i class="fas fa-rocket" style="color: var(--accent-primary);"></i> Most Funded</div>
<?php foreach ($mostFunded as $i => $s): ?>
<a href="startup_details.php?id=<?= $s['id'] ?>" class="lb-item">
<div class="lb-rank rank-<?= $i+1 ?>"><?= $i+1 ?></div>
<div style="flex: 1;">
<div style="font-weight: 700; color: var(--text-primary);"><?= htmlspecialchars($s['name']) ?></div>
<div style="font-size: 12px; color: var(--text-secondary);">by <?= htmlspecialchars($s['founder_name']) ?></div>
</div>
<div style="font-weight: 800; color: var(--success-color);">£<?= number_format($s['funded_amount']) ?></div>
</a>
<?php endforeach; ?>
</div>
</div>
<div style="margin-bottom: 40px; text-align: center;">
<h2 style="margin-bottom: 25px; color: var(--text-primary);">Founding Rounds</h2>
<form method="GET" style="display: flex; gap: 10px; max-width: 600px; margin: 0 auto;">
<input type="text" name="q" value="<?= htmlspecialchars($q) ?>" placeholder="Search founding rounds..." class="form-control" style="flex: 1;">
<button type="submit" class="btn btn-primary">Filter</button>
</form>
</div>
<div class="startup-grid">
<?php foreach ($browseStartups as $s):
$isFollowing = in_array($s['id'], $followedStartups);
?>
<div class="card" onclick="location.href='startup_details.php?id=<?= $s['id'] ?>'" style="cursor: pointer; position: relative;">
<div style="display: flex; gap: 20px; align-items: center; margin-bottom: 20px;">
<div style="width: 50px; height: 50px; background: var(--accent-primary); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 900; color: #000;">
<?= substr($s['name'], 0, 1) ?>
</div>
<div style="flex: 1;">
<div style="font-weight: 800; font-size: 18px; color: var(--text-primary);"><?= htmlspecialchars($s['name']) ?></div>
<div style="font-size: 12px; color: var(--text-secondary);">by <?= htmlspecialchars($s['founder_name']) ?></div>
</div>
<button class="follow-btn <?= $isFollowing ? 'active' : '' ?>"
data-id="<?= $s['id'] ?>"
data-action="<?= $isFollowing ? 'unfollow' : 'follow' ?>"
onclick="event.stopPropagation();">
<i class="<?= $isFollowing ? 'fas' : 'far' ?> fa-heart"></i>
</button>
</div>
<p style="color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; line-height: 1.5; height: 39px; overflow: hidden;">
<?= htmlspecialchars(substr($s['description'], 0, 100)) ?>...
</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px;">
<div style="background: rgba(255,255,255,0.03); padding: 8px; border-radius: 8px; border: 1px solid var(--border-color); text-align: center;">
<div style="font-size: 9px; color: var(--text-secondary); text-transform: uppercase;">Rate</div>
<div style="font-size: 13px; font-weight: 800; color: var(--accent-primary);"><?= number_format($s['founder_return_rate'] ?? 0, 1) ?>%</div>
</div>
<div style="background: rgba(255,255,255,0.03); padding: 8px; border-radius: 8px; border: 1px solid var(--border-color); text-align: center;">
<div style="font-size: 9px; color: var(--text-secondary); text-transform: uppercase;">Term</div>
<div style="font-size: 13px; font-weight: 800; color: #fff;"><?= $s['repayment_term'] ?? 12 ?> Mo</div>
</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 15px;">
<span style="font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase;"><?= htmlspecialchars($s['industry']) ?></span>
<span style="font-weight: 900; color: var(--text-primary);">£<?= number_format($s['active_raised']) ?> Raised</span>
</div>
</div>
<?php endforeach; ?>
</div>
</main>
<footer style="margin-top: 80px; padding: 60px 0; border-top: 1px solid var(--border-color);">
<div class="container" style="text-align: center;">
<div class="logo-container" style="justify-content: center; margin-bottom: 25px;">
<img src="assets/images/logo.svg?v=<?php echo time(); ?>" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img" style="width: 30px; height: 30px;">
<span class="logo-text" style="font-size: 20px;"><?= htmlspecialchars($platformName) ?></span>
</div>
<p style="color: var(--text-secondary); font-size: 14px;">&copy; <?= date('Y') ?> <?= htmlspecialchars($platformName) ?>. All rights reserved.</p>
</div>
</footer>
<script>
document.querySelectorAll('.follow-btn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
const startupId = this.dataset.id;
const action = this.dataset.action;
const formData = new FormData();
formData.append('startup_id', startupId);
formData.append('action', action);
fetch('api/follow_startup.php', {
method: 'POST',
body: formData
})
.then(res => res.json())
.then(data => {
if (data.success) {
// Update all buttons for this startup
document.querySelectorAll(`.follow-btn[data-id="${startupId}"]`).forEach(b => {
if (action === 'follow') {
b.classList.add('active');
b.dataset.action = 'unfollow';
b.querySelector('i').className = 'fas fa-heart';
if (b.innerText.trim() !== '') {
b.innerHTML = '<i class="fas fa-heart"></i> Following';
}
} else {
b.classList.remove('active');
b.dataset.action = 'follow';
b.querySelector('i').className = 'far fa-heart';
if (b.innerText.trim() !== '') {
b.innerHTML = '<i class="far fa-heart"></i> Follow';
}
}
});
// Update follower count if exists
const countDisplay = document.getElementById(`follower-count-${startupId}`);
if (countDisplay) {
countDisplay.innerText = data.new_count.toLocaleString();
}
}
});
});
});
</script>
<script src="assets/js/main.js"></script>
</body>
</html>