38873-vm/discover.php
Flatlogic Bot 844a54704c v4
2026-02-28 16:01:57 +00:00

272 lines
11 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'founder') {
header("Location: dashboard.php");
exit;
}
require_once __DIR__ . '/db/config.php';
// Check if onboarding is completed
$stmt = db()->prepare("SELECT onboarding_completed FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if (!$user['onboarding_completed']) {
header("Location: founder_onboarding.php");
exit;
}
$current_user_id = $_SESSION['user_id'];
// Handle Swipe via AJAX/POST
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'swipe') {
$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
$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();
$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;
}
</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>
<a href="discover.php" class="active"><i class="fas fa-search"></i> Partner Matching</a>
<a href="startups.php"><i class="fas fa-rocket"></i> My 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>Partner Matching</h1>
<div class="user-profile">
<span><?= htmlspecialchars($_SESSION['full_name']) ?></span>
<div class="avatar"><?= strtoupper(substr($_SESSION['full_name'], 0, 1)) ?></div>
</div>
</div>
<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>
</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>