<?php
require_once 'db.php';
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$current_id = (int)$_SESSION['user_id'];
if (is_banned($current_id)) {
include 'header.php';
echo '<p>Ваш аккаунт заблокирован. Обратитесь в поддержку.</p>';
include 'footer.php';
exit;
}
/* ==== лайк с карточки ==== */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['like_user_id'])) {
$liked_id = (int)$_POST['like_user_id'];
if ($liked_id > 0 && $liked_id !== $current_id) {
$stmt = $mysqli->prepare("INSERT IGNORE INTO likes (from_user_id, to_user_id) VALUES (?, ?)");
$stmt->bind_param('ii', $current_id, $liked_id);
$stmt->execute();
$stmt->close();
}
// чтобы не дублировать отправку по F5 – редирект обратно на список
$qs = $_SERVER['QUERY_STRING'] ? ('?' . $_SERVER['QUERY_STRING']) : '';
header('Location: browse.php' . $qs);
exit;
}
/* ==== фильтры ==== */
$city = trim($_GET['city'] ?? '');
$gender = $_GET['gender'] ?? 'any';
$age_from = isset($_GET['age_from']) ? (int)$_GET['age_from'] : 0;
$age_to = isset($_GET['age_to']) ? (int)$_GET['age_to'] : 0;
$gender_in = ['m','f','other','any'];
if (!in_array($gender, $gender_in, true)) {
$gender = 'any';
}
/* ==== выборка анкет ==== */
$sql = "
SELECT u.id, u.name, u.city, u.about, u.photo,
TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) AS age
FROM users u
WHERE u.id <> {$current_id}
AND u.is_banned = 0
";
if ($city !== '') {
$city_esc = $mysqli->real_escape_string($city);
$sql .= " AND u.city LIKE '%{$city_esc}%'";
}
if ($gender !== 'any') {
$gender_esc = $mysqli->real_escape_string($gender);
$sql .= " AND u.gender = '{$gender_esc}'";
}
if ($age_from > 0) {
$sql .= " AND TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) >= {$age_from}";
}
if ($age_to > 0) {
$sql .= " AND TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) <= {$age_to}";
}
$sql .= " ORDER BY u.created_at DESC";
$result = $mysqli->query($sql);
include 'header.php';
?>
<style>
/* локальные стили для browse.php */
.browse-page { margin-top: 18px; }
.filter-card {
background:#ffffff;
border-radius:22px;
padding:14px 16px 16px;
box-shadow:0 10px 30px rgba(0,0,0,0.06);
margin-bottom:16px;
}
.filter-row {
display:flex;
flex-wrap:wrap;
gap:10px;
margin-bottom:10px;
}
.filter-row label {
font-size:13px;
margin-bottom:4px;
display:block;
}
.filter-field {
flex:1 1 130px;
min-width:120px;
}
.filter-actions {
display:flex;
gap:10px;
flex-wrap:wrap;
}
/* карточки */
.profile-list {
display:flex;
flex-direction:column;
gap:14px;
margin-bottom:80px; /* запас над нижним меню */
}
.profile-card {
background:#ffffff;
border-radius:28px;
padding:20px 20px 16px;
box-shadow:0 14px 40px rgba(0,0,0,0.08);
text-align:center;
}
.profile-card-main-link {
display:block;
text-decoration:none;
color:inherit;
padding-bottom:12px;
border-bottom:1px solid rgba(0,0,0,0.04);
margin-bottom:12px;
}
.profile-avatar-circle {
width:120px;
height:120px;
border-radius:999px;
object-fit:cover;
margin:0 auto 10px;
}
.profile-avatar-placeholder {
width:120px;
height:120px;
border-radius:999px;
background:linear-gradient(135deg,#ffe5f0,#f5ebff);
display:flex;align-items:center;justify-content:center;
font-size:40px;margin:0 auto 10px;
}
.profile-name-large {
font-size:20px;
font-weight:700;
margin-bottom:2px;
}
.profile-age-small {
font-size:13px;
color:#ff6b9c;
margin-left:4px;
}
.profile-city-small {
font-size:14px;
color:#7b7287;
margin-bottom:6px;
}
.profile-about-preview {
font-size:13px;
color:#4a4257;
}
.profile-card-actions {
display:flex;
justify-content:center;
flex-wrap:wrap;
gap:10px;
}
/* немного адаптива */
@media (max-width:768px){
.filter-card{margin:0 -4px 14px;border-radius:18px;}
.profile-card{margin:0 -4px;border-radius:22px;}
}
</style>
<div class="browse-page">
<h1>Анкеты</h1>
<!-- Фильтры -->
<div class="filter-card">
<form method="get">
<div class="filter-row">
<div class="filter-field">
<label>Город</label>
<input type="text" name="city" placeholder="Например, Москва"
value="<?= htmlspecialchars($city) ?>">
</div>
<div class="filter-field">
<label>Пол</label>
<select name="gender">
<option value="any" <?= $gender === 'any' ? 'selected' : '' ?>>Любой</option>
<option value="m" <?= $gender === 'm' ? 'selected' : '' ?>>Мужчина</option>
<option value="f" <?= $gender === 'f' ? 'selected' : '' ?>>Женщина</option>
<option value="other" <?= $gender === 'other' ? 'selected' : '' ?>>Другое</option>
</select>
</div>
<div class="filter-field">
<label>Возраст от</label>
<input type="number" name="age_from" min="18" max="99"
value="<?= $age_from ?: '' ?>">
</div>
<div class="filter-field">
<label>до</label>
<input type="number" name="age_to" min="18" max="99"
value="<?= $age_to ?: '' ?>">
</div>
</div>
<div class="filter-actions">
<button type="submit" class="btn-primary" style="flex:1 1 140px;">Фильтровать</button>
<a href="browse.php" class="btn-outline" style="flex:1 1 100px;text-align:center;">Сбросить</a>
</div>
</form>
</div>
<!-- Список анкет -->
<div class="profile-list">
<?php if (!$result || $result->num_rows === 0): ?>
<p>Пока нет анкет, подходящих под фильтр.</p>
<?php else: ?>
<?php while ($u = $result->fetch_assoc()): ?>
<article class="profile-card">
<!-- КЛИКАБЕЛЬНАЯ ЧАСТЬ КАРТОЧКИ: переходим на user.php -->
<a href="user.php?user_id=<?= (int)$u['id'] ?>" class="profile-card-main-link">
<?php if ($u['photo']): ?>
<img src="/assets/img/<?= htmlspecialchars($u['photo']) ?>"
alt=""
class="profile-avatar-circle">
<?php else: ?>
<div class="profile-avatar-placeholder">🙂</div>
<?php endif; ?>
<div class="profile-name-large">
<?= htmlspecialchars($u['name'] ?: 'Без имени') ?>
<?php if (!empty($u['age'])): ?>
<span class="profile-age-small"><?= (int)$u['age'] ?> лет</span>
<?php endif; ?>
</div>
<?php if (!empty($u['city'])): ?>
<div class="profile-city-small">
<?= htmlspecialchars($u['city']) ?>
</div>
<?php endif; ?>
<?php if (!empty($u['about'])): ?>
<div class="profile-about-preview">
<?= htmlspecialchars(mb_strimwidth($u['about'], 0, 90, '…')) ?>
</div>
<?php endif; ?>
</a>
<!-- КНОПКИ ДЕЙСТВИЙ -->
<div class="profile-card-actions">
<form method="post">
<input type="hidden" name="like_user_id" value="<?= (int)$u['id'] ?>">
<button type="submit" class="btn-primary">❤ Нравится</button>
</form>
<a href="messages.php?user_id=<?= (int)$u['id'] ?>" class="btn-outline">
Написать
</a>
<a href="send_gift.php?user_id=<?= (int)$u['id'] ?>" class="btn-outline">
Подарок 🎁
</a>
</div>
</article>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php include 'footer.php'; ?>