37646-vm/index.php
Flatlogic Bot 0a39896c6c 0.0.3
2026-01-21 03:38:11 +00:00

188 lines
7.9 KiB
PHP

<?php
// index.php
declare(strict_types=1);
// --- SESSION & AUTHENTICATION ---
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'includes/helpers.php';
// --- LANGUAGE & TRANSLATION ---
$lang = $_SESSION['lang'] ?? 'en';
if (isset($_GET['lang']) && in_array($_GET['lang'], ['en', 'es'])) {
$lang = $_GET['lang'];
$_SESSION['lang'] = $lang;
}
require_once 'db/config.php';
$pdo = db();
$current_user_id = $_SESSION['user_id'];
$filterCity = $_GET['city'] ?? '';
$filterActivity = $_GET['activity'] ?? '';
// Fetch one companion that the user has not yet swiped on
$sql = "
SELECT p.*
FROM user_profiles p
JOIN users u ON p.user_id = u.id
WHERE u.role = 'companion'
AND p.user_id != :current_user_id
AND p.user_id NOT IN (
SELECT swiped_user_id FROM swipes WHERE swiper_user_id = :current_user_id
)
";
$params = [':current_user_id' => $current_user_id];
if ($filterCity) {
$sql .= " AND p.city LIKE :city";
$params[':city'] = '%' . $filterCity . '%';
}
if ($filterActivity) {
$sql .= " AND p.bio LIKE :activity";
$params[':activity'] = '%' . $filterActivity . '%';
}
$sql .= " ORDER BY RAND() LIMIT 1";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$companion = $stmt->fetch(PDO::FETCH_ASSOC);
// Fetch matches for the logged-in user
$stmt = $pdo->prepare("
SELECT p.*
FROM matches m
JOIN user_profiles p ON (m.user1_id = p.user_id OR m.user2_id = p.user_id)
WHERE (m.user1_id = :current_user_id OR m.user2_id = :current_user_id)
AND p.user_id != :current_user_id
");
$stmt->execute(['current_user_id' => $current_user_id]);
$matches = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($matches as &$m) {
$m['img'] = $m['profile_photo_path'] ?? 'assets/images/avatar_placeholder.svg';
}
unset($m);
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Find your perfect vetted companion for platonic experiences.';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<!doctype html>
<html lang="<?= $lang ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= t('page_title') ?></title>
<meta name="description" content="<?= htmlspecialchars($projectDescription) ?>">
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>">
<?php endif; ?>
<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&family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css?v=<?= time() ?>" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Compañía</a>
<div class="d-flex ms-auto align-items-center order-lg-2">
<div class="dropdown me-2">
<button class="btn btn-outline-secondary btn-sm dropdown-toggle" type="button" id="langDropdown" data-bs-toggle="dropdown" aria-expanded="false"><?= strtoupper($lang) ?></button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="langDropdown">
<li><a class="dropdown-item" href="?lang=en">EN (English)</a></li>
<li><a class="dropdown-item" href="?lang=es">ES (Español)</a></li>
</ul>
</div>
<ul class="navbar-nav flex-row">
<li class="nav-item ms-2"><a href="logout.php" class="btn btn-outline-primary btn-sm"><?= t('nav_logout') ?></a></li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="#"><?= t('nav_companions') ?></a></li>
<li class="nav-item"><a class="nav-link" href="#"><?= t('nav_how_it_works') ?></a></li>
<li class="nav-item"><a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#matchesModal"><?= t('nav_matches') ?></a></li>
</ul>
</div>
</div>
</nav>
<!-- Swiping UI -->
<main class="py-5 bg-light">
<div class="container text-center">
<h2 class="h3 mb-4"><?= t('featured_companions') ?></h2>
<div id="swipe-container" class="mx-auto" style="max-width: 400px; position: relative; height: 650px;">
<?= render_companion_card($companion) ?>
</div>
</div>
</main>
<!-- Matches Modal -->
<div class="modal fade" id="matchesModal" tabindex="-1" aria-labelledby="matchesModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header"><h5 class="modal-title" id="matchesModalLabel"><?= t('matches_title') ?></h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div>
<div class="modal-body">
<?php if (empty($matches)): ?>
<p class="text-center text-muted py-5"><?= t('matches_empty') ?></p>
<?php else: ?>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<?php foreach ($matches as $match): ?>
<div class="col">
<div class="card h-100 text-center">
<img src="<?= htmlspecialchars($match['img']) ?>" class="card-img-top" alt="<?= htmlspecialchars($match['name']) ?>" style="height: 200px; object-fit: cover;">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($match['name']) ?></h5>
<button class="btn btn-primary btn-sm">Message</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Match Notification Modal -->
<div class="modal fade" id="matchNotificationModal" tabindex="-1" aria-labelledby="matchNotificationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content text-center">
<div class="modal-body p-4">
<h2 class="modal-title" id="matchNotificationModalLabel"><?= t('match_modal_title') ?></h2>
<p id="match-notification-body" class="my-3"></p>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal"><?= t('match_modal_button') ?></button>
</div>
</div>
</div>
</div>
<footer>
<div class="container text-center py-4">
<p>&copy; <?= date('Y') ?> <?= t('footer_copyright') ?></p>
<p class="small text-muted"><?= t('footer_coc') ?> <a href="#"><?= t('footer_safety') ?></a>.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?= time() ?>"></script>
</body>
</html>