38873-vm/discover.php
Flatlogic Bot 00a4b21825 v10
2026-02-28 17:04:46 +00:00

417 lines
17 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
require_once __DIR__ . '/db/config.php';
$current_user_id = $_SESSION['user_id'];
$user_role = $_SESSION['role'];
// Check if onboarding is completed (for founders)
if ($user_role === 'founder') {
$stmt = db()->prepare("SELECT onboarding_completed FROM users WHERE id = ?");
$stmt->execute([$current_user_id]);
$user_onboard = $stmt->fetch();
if (!$user_onboard['onboarding_completed']) {
header("Location: founder_onboarding.php");
exit;
}
}
// Handle Swipe via AJAX/POST (only for founders)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'swipe' && $user_role === 'founder') {
$swiped_id = (int)$_POST['swiped_id'];
$direction = $_POST['direction']; // 'like' or 'dislike'
if ($swiped_id > 0 && in_array($direction, ['like', 'dislike'])) {
$stmt = db()->prepare("INSERT IGNORE INTO swipes (swiper_id, swiped_id, direction) VALUES (?, ?, ?)");
$stmt->execute([$current_user_id, $swiped_id, $direction]);
// Check for match
if ($direction === 'like') {
$stmt = db()->prepare("SELECT id FROM swipes WHERE swiper_id = ? AND swiped_id = ? AND direction = 'like'");
$stmt->execute([$swiped_id, $current_user_id]);
if ($stmt->fetch()) {
// It's a match!
$stmt = db()->prepare("INSERT IGNORE INTO matches (user1_id, user2_id) VALUES (?, ?)");
$u1 = min($current_user_id, $swiped_id);
$u2 = max($current_user_id, $swiped_id);
$stmt->execute([$u1, $u2]);
// Add notification
$stmt = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)");
$stmt->execute([$swiped_id, "You have a new match!"]);
$stmt->execute([$current_user_id, "You have a new match!"]);
echo json_encode(['status' => 'success', 'match' => true]);
exit;
}
}
echo json_encode(['status' => 'success', 'match' => false]);
exit;
}
}
// Fetch founders to swipe on (if founder)
$founders = [];
if ($user_role === 'founder') {
$stmt = db()->prepare("
SELECT * FROM users
WHERE role = 'founder'
AND id != ?
AND onboarding_completed = 1
AND id NOT IN (SELECT swiped_id FROM swipes WHERE swiper_id = ?)
LIMIT 10
");
$stmt->execute([$current_user_id, $current_user_id]);
$founders = $stmt->fetchAll();
}
// Leaderboard: Most Followed This Week
$stmt = db()->prepare("
SELECT s.id, s.name, u.full_name as founder_name, COUNT(sf.id) as followers_count
FROM startups s
JOIN users u ON s.founder_id = u.id
JOIN startup_followers sf ON s.id = sf.startup_id
WHERE sf.created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
GROUP BY s.id
ORDER BY followers_count DESC
LIMIT 5
");
$stmt->execute();
$mostFollowed = $stmt->fetchAll();
// Leaderboard: Most Funded This Week
$stmt = db()->prepare("
SELECT s.id, s.name, u.full_name as founder_name, SUM(i.amount) as funded_amount
FROM startups s
JOIN users u ON s.founder_id = u.id
JOIN investments i ON s.id = i.startup_id
WHERE i.status = 'approved' AND i.created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
GROUP BY s.id
ORDER BY funded_amount DESC
LIMIT 5
");
$stmt->execute();
$mostFunded = $stmt->fetchAll();
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Discover — <?= htmlspecialchars($platformName) ?></title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&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>
.discover-container {
max-width: 400px;
margin: 0 auto;
position: relative;
height: 600px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.swipe-card {
position: absolute;
width: 100%;
height: 500px;
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 20px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
transition: transform 0.4s ease, opacity 0.4s ease;
user-select: none;
cursor: grab;
display: flex;
flex-direction: column;
}
.swipe-card:active { cursor: grabbing; }
.card-img {
height: 250px;
background: linear-gradient(45deg, #2c3e50, #000000);
display: flex;
align-items: center;
justify-content: center;
font-size: 80px;
color: rgba(255,255,255,0.1);
}
.card-body { padding: 20px; flex-grow: 1; }
.card-name { font-size: 24px; font-weight: 700; margin-bottom: 5px; }
.card-meta { color: var(--text-secondary); font-size: 14px; margin-bottom: 15px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; }
.tag { background: rgba(255,255,255,0.05); padding: 4px 10px; border-radius: 6px; font-size: 12px; }
.card-bio { font-size: 14px; color: var(--text-secondary); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.swipe-actions {
display: flex;
gap: 20px;
margin-top: 550px;
z-index: 10;
}
.swipe-btn {
width: 60px;
height: 60px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
cursor: pointer;
transition: transform 0.2s;
border: none;
}
.swipe-btn:hover { transform: scale(1.1); }
.btn-dislike { background: #ff4d4d; color: #fff; }
.btn-like { background: #2ecc71; color: #fff; }
#match-modal {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.9);
z-index: 1000;
display: none;
align-items: center;
justify-content: center;
text-align: center;
flex-direction: column;
}
/* Leaderboard Styling */
.leaderboard-section {
margin-top: 50px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
@media (max-width: 900px) {
.leaderboard-section { grid-template-columns: 1fr; }
}
.leaderboard-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 20px;
padding: 25px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.leaderboard-title {
font-size: 20px;
font-weight: 700;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.leaderboard-item {
display: flex;
align-items: center;
gap: 15px;
padding: 12px 0;
border-bottom: 1px solid rgba(255,255,255,0.05);
transition: transform 0.2s;
cursor: pointer;
text-decoration: none;
color: inherit;
}
.leaderboard-item:hover { transform: translateX(5px); }
.leaderboard-item:last-child { border-bottom: none; }
.rank {
width: 30px;
height: 30px;
border-radius: 50%;
background: rgba(255,255,255,0.05);
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 700;
color: var(--accent-blue);
}
.rank-1 { background: gold; color: #000; }
.rank-2 { background: silver; color: #000; }
.rank-3 { background: #cd7f32; color: #000; }
.item-info { flex-grow: 1; }
.item-name { font-weight: 600; font-size: 15px; }
.item-meta { font-size: 12px; color: var(--text-secondary); }
.item-stat { font-weight: 700; font-size: 14px; color: var(--accent-blue); }
</style>
</head>
<body>
<div class="sidebar">
<div class="logo"><?= htmlspecialchars($platformName) ?></div>
<nav>
<a href="dashboard.php"><i class="fas fa-home"></i> Dashboard</a>
<?php if ($user_role === 'founder'): ?>
<a href="discover.php" class="active"><i class="fas fa-search"></i> Partner Matching</a>
<?php else: ?>
<a href="discover.php" class="active"><i class="fas fa-search"></i> Discovery</a>
<?php endif; ?>
<a href="startups.php"><i class="fas fa-rocket"></i> <?= $user_role === 'founder' ? 'My Startups' : 'Browse Startups' ?></a>
<a href="portfolio.php"><i class="fas fa-chart-line"></i> Portfolio</a>
<a href="messages.php"><i class="fas fa-comment"></i> Messages</a>
<a href="notifications.php"><i class="fas fa-bell"></i> Notifications</a>
</nav>
<div style="margin-top: auto; padding: 20px;">
<a href="logout.php" style="color: #ff5555;"><i class="fas fa-sign-out-alt"></i> Log Out</a>
</div>
</div>
<div class="main-content">
<div class="header">
<h1><?= $user_role === 'founder' ? 'Partner Matching' : 'Discovery Hub' ?></h1>
<div class="user-profile">
<span><?= htmlspecialchars($_SESSION['full_name']) ?></span>
<div class="avatar"><?= strtoupper(substr($_SESSION['full_name'], 0, 1)) ?></div>
</div>
</div>
<?php if ($user_role === 'founder'): ?>
<div class="discover-container" id="card-stack">
<?php if (empty($founders)): ?>
<div style="text-align: center; color: var(--text-secondary);">
<i class="fas fa-user-friends" style="font-size: 48px; margin-bottom: 20px;"></i>
<p>No more founders found for now.<br>Check back later!</p>
</div>
<?php else: ?>
<?php foreach (array_reverse($founders) as $f): ?>
<div class="swipe-card" data-id="<?= $f['id'] ?>">
<div class="card-img"><i class="fas fa-user"></i></div>
<div class="card-body">
<div class="card-name"><?= htmlspecialchars($f['full_name']) ?></div>
<div class="card-meta"><?= htmlspecialchars($f['university']) ?> • <?= htmlspecialchars($f['degree_program']) ?> '<?= substr($f['graduation_year'], -2) ?></div>
<div class="card-tags">
<?php
$skills = explode(',', $f['skills']);
foreach (array_slice($skills, 0, 3) as $skill):
?>
<span class="tag"><?= htmlspecialchars(trim($skill)) ?></span>
<?php endforeach; ?>
</div>
<div class="card-bio"><?= htmlspecialchars($f['bio']) ?></div>
<div style="margin-top: 15px; font-size: 12px; color: var(--accent-blue);">
<i class="fas fa-bolt"></i> Interested in: <?= htmlspecialchars($f['startup_industries']) ?>
</div>
</div>
</div>
<?php endforeach; ?>
<div class="swipe-actions">
<button class="swipe-btn btn-dislike" onclick="swipe('dislike')"><i class="fas fa-times"></i></button>
<button class="swipe-btn btn-like" onclick="swipe('like')"><i class="fas fa-heart"></i></button>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<!-- Leaderboards -->
<div class="leaderboard-section">
<!-- Most Followed -->
<div class="leaderboard-card">
<div class="leaderboard-title">
<i class="fas fa-users" style="color: var(--accent-blue);"></i>
Most Followed This Week
</div>
<?php if (empty($mostFollowed)): ?>
<p style="color: var(--text-secondary); font-size: 14px;">No data for this week yet.</p>
<?php else: ?>
<?php foreach ($mostFollowed as $index => $item): ?>
<a href="startup_details.php?id=<?= $item['id'] ?>" class="leaderboard-item">
<div class="rank rank-<?= $index + 1 ?>"><?= $index + 1 ?></div>
<div class="item-info">
<div class="item-name"><?= htmlspecialchars($item['name']) ?></div>
<div class="item-meta">by <?= htmlspecialchars($item['founder_name']) ?></div>
</div>
<div class="item-stat"><?= number_format($item['followers_count']) ?> <i class="fas fa-heart" style="font-size: 10px; opacity: 0.7;"></i></div>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Most Funded -->
<div class="leaderboard-card">
<div class="leaderboard-title">
<i class="fas fa-chart-line" style="color: #2ecc71;"></i>
Most Funded This Week
</div>
<?php if (empty($mostFunded)): ?>
<p style="color: var(--text-secondary); font-size: 14px;">No investments this week yet.</p>
<?php else: ?>
<?php foreach ($mostFunded as $index => $item): ?>
<a href="startup_details.php?id=<?= $item['id'] ?>" class="leaderboard-item">
<div class="rank rank-<?= $index + 1 ?>"><?= $index + 1 ?></div>
<div class="item-info">
<div class="item-name"><?= htmlspecialchars($item['name']) ?></div>
<div class="item-meta">by <?= htmlspecialchars($item['founder_name']) ?></div>
</div>
<div class="item-stat">£<?= number_format($item['funded_amount']) ?></div>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<div id="match-modal">
<h1 style="font-size: 60px; color: var(--accent-blue); margin-bottom: 20px;">IT'S A MATCH!</h1>
<p style="font-size: 20px; margin-bottom: 40px;">You and this founder both swiped right on each other.</p>
<div style="display: flex; gap: 20px;">
<button class="btn btn-primary" onclick="window.location.href='messages.php'">Send a Message</button>
<button class="btn" style="border: 1px solid #fff;" onclick="closeMatch()">Keep Swiping</button>
</div>
</div>
<script>
function swipe(direction) {
const stack = document.getElementById('card-stack');
const cards = stack.querySelectorAll('.swipe-card');
if (cards.length === 0) return;
const topCard = cards[cards.length - 1];
const swipedId = topCard.getAttribute('data-id');
// Animation
if (direction === 'like') {
topCard.style.transform = 'translateX(500px) rotate(20deg)';
} else {
topCard.style.transform = 'translateX(-500px) rotate(-20deg)';
}
topCard.style.opacity = '0';
// Logic
fetch('discover.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `action=swipe&swiped_id=${swipedId}&direction=${direction}`
})
.then(r => r.json())
.then(data => {
if (data.match) {
document.getElementById('match-modal').style.display = 'flex';
}
setTimeout(() => {
topCard.remove();
if (stack.querySelectorAll('.swipe-card').length === 0) {
location.reload(); // Refresh to show empty state or new batch
}
}, 400);
});
}
function closeMatch() {
document.getElementById('match-modal').style.display = 'none';
}
</script>
</body>
</html>