<?php
require_once 'db.php';
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_id = (int)$_SESSION['user_id'];
if (is_banned($user_id)) {
include 'header.php';
echo '<p>Ваш аккаунт заблокирован. Обратитесь в поддержку.</p>';
include 'footer.php';
exit;
}
// профиль
$stmt = $mysqli->prepare("
SELECT id, email, name, gender, birthday, city, about, photo,
TIMESTAMPDIFF(YEAR, birthday, CURDATE()) AS age
FROM users
WHERE id = ?
");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
if (!$user) {
include 'header.php';
echo '<p>Пользователь не найден.</p>';
include 'footer.php';
exit;
}
// интересы
$current_interests = [];
$stmt = $mysqli->prepare("SELECT interest FROM interests WHERE user_id = ?");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$res = $stmt->get_result();
while ($row = $res->fetch_assoc()) {
$current_interests[] = $row['interest'];
}
$stmt->close();
// альбом (последние 12)
$stmt = $mysqli->prepare("
SELECT id, filename
FROM user_photos
WHERE user_id = ?
ORDER BY created_at DESC
LIMIT 12
");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$album = $stmt->get_result();
$stmt->close();
/* 🔔 помечаем все непрочитанные подарки как прочитанные,
как только человек открыл свой профиль */
$upd = $mysqli->prepare("UPDATE user_gifts SET is_read = 1 WHERE to_user_id = ? AND is_read = 0");
$upd->bind_param('i', $user_id);
$upd->execute();
$upd->close();
// полученные подарки (последние 12)
$stmt = $mysqli->prepare("
SELECT ug.id, ug.message, ug.created_at,
g.title AS gift_title, g.image AS gift_image,
u.name AS from_name
FROM user_gifts ug
JOIN gifts g ON g.id = ug.gift_id
JOIN users u ON u.id = ug.from_user_id
WHERE ug.to_user_id = ?
ORDER BY ug.created_at DESC
LIMIT 12
");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$gifts = $stmt->get_result();
$stmt->close();
include 'header.php';
?>
<style>
/* стили профиля */
.profile-page { margin-top: 18px; }
.profile-layout {
display: grid;
grid-template-columns: 280px minmax(0, 1fr);
gap: 20px;
}
.profile-main-card {
text-align: center;
padding: 20px;
border-radius: 24px;
background: rgba(255,255,255,0.98);
box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.profile-avatar {
width: 140px;
height: 140px;
border-radius: 999px;
object-fit: cover;
margin-bottom: 10px;
}
.profile-avatar-placeholder {
width: 140px;
height: 140px;
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 {
font-size: 22px;
margin-bottom: 4px;
}
.profile-age {
font-size: 14px;
color: #ff6b9c;
}
.profile-city {
font-size: 14px;
color: #7b7287;
margin-top: 4px;
}
.profile-about-card {
padding: 18px 20px;
border-radius: 24px;
background: rgba(255,255,255,0.98);
box-shadow: 0 10px 30px rgba(0,0,0,0.06);
margin-bottom: 16px;
}
.profile-about-card h2 {
margin-top: 0;
margin-bottom: 6px;
font-size: 18px;
}
.profile-about-text {
font-size: 14px;
color: #4a4257;
white-space: pre-wrap;
}
.profile-interests {
margin-top: 8px;
}
.profile-chip {
display: inline-block;
padding: 4px 10px;
border-radius: 999px;
background: #ffe6f1;
color: #74415a;
font-size: 12px;
margin: 0 4px 4px 0;
}
/* альбом и подарки */
.album-card,
.gifts-card {
padding: 18px 20px;
border-radius: 24px;
background: rgba(255,255,255,0.98);
box-shadow: 0 10px 30px rgba(0,0,0,0.06);
margin-top: 12px;
}
.album-header,
.gifts-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.album-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
gap: 8px;
}
.album-photo {
width: 100%;
aspect-ratio: 1/1;
border-radius: 16px;
object-fit: cover;
}
.album-empty,
.gifts-empty {
font-size: 14px;
color: #7b7287;
}
/* подарки */
.gifts-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
gap: 10px;
}
.gift-card {
text-align: center;
font-size: 12px;
}
.gift-img {
width: 80px;
height: 80px;
object-fit: contain;
border-radius: 16px;
background: #fff7fb;
box-shadow: 0 4px 14px rgba(0,0,0,0.06);
margin: 0 auto 4px;
}
.gift-from {
font-weight: 600;
font-size: 12px;
}
.gift-meta {
font-size: 10px;
color: #a29ab4;
}
@media (max-width: 768px) {
.profile-layout {
grid-template-columns: 1fr;
}
.profile-main-card {
margin: 0 -4px;
border-radius: 18px;
}
.profile-about-card,
.album-card,
.gifts-card {
margin: 10px -4px 0;
border-radius: 18px;
}
}
</style>
<div class="profile-page">
<h1>Мой профиль</h1>
<div class="profile-layout">
<section class="profile-main-card">
<?php if ($user['photo']): ?>
<img src="/assets/img/<?= htmlspecialchars($user['photo']) ?>" class="profile-avatar" alt="">
<?php else: ?>
<div class="profile-avatar-placeholder">🙂</div>
<?php endif; ?>
<div class="profile-name">
<?= htmlspecialchars($user['name'] ?: 'Без имени') ?>
</div>
<?php if (!empty($user['age'])): ?>
<div class="profile-age"><?= (int)$user['age'] ?> лет</div>
<?php endif; ?>
<?php if (!empty($user['city'])): ?>
<div class="profile-city"><?= htmlspecialchars($user['city']) ?></div>
<?php endif; ?>
<div style="margin-top:16px;">
<a href="profile_edit.php" class="btn-primary">Редактировать профиль</a>
</div>
</section>
<section>
<div class="profile-about-card">
<h2>О себе</h2>
<div class="profile-about-text">
<?= nl2br(htmlspecialchars($user['about'] ?: 'Расскажите немного о себе, чтобы другим было легче начать диалог.')) ?>
</div>
<?php if ($current_interests): ?>
<div class="profile-interests">
<?php foreach ($current_interests as $interest): ?>
<span class="profile-chip"><?= htmlspecialchars($interest) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="album-card">
<div class="album-header">
<h2 style="margin:0;font-size:18px;">Фотоальбом</h2>
<div style="display:flex;gap:8px;flex-wrap:wrap;">
<a href="profile_edit.php#album" class="btn-outline btn-small">Добавить фото</a>
<a href="album.php" class="btn-outline btn-small">Управлять альбомом</a>
</div>
</div>
<?php if ($album->num_rows === 0): ?>
<p class="album-empty">
В альбоме пока нет фотографий. Добавьте несколько снимков – так легче найти «своих» людей 🙂
</p>
<?php else: ?>
<div class="album-grid">
<?php while ($p = $album->fetch_assoc()): ?>
<img src="/assets/img/<?= htmlspecialchars($p['filename']) ?>" class="album-photo" alt="">
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<div class="gifts-card" id="gifts">
<div class="gifts-header">
<h2 style="margin:0;font-size:18px;">Подарки</h2>
</div>
<?php if ($gifts->num_rows === 0): ?>
<p class="gifts-empty">
Пока вы не получали подарков. Но всё ещё впереди 💝
</p>
<?php else: ?>
<div class="gifts-grid">
<?php while ($g = $gifts->fetch_assoc()): ?>
<div class="gift-card">
<img src="/assets/gifts/<?= htmlspecialchars($g['gift_image']) ?>" class="gift-img" alt="">
<div><?= htmlspecialchars($g['gift_title']) ?></div>
<div class="gift-from">
от <?= htmlspecialchars($g['from_name']) ?>
</div>
<div class="gift-meta">
<?= htmlspecialchars(date('d.m H:i', strtotime($g['created_at']))) ?>
</div>
<?php if (!empty($g['message'])): ?>
<div style="font-size:11px;margin-top:2px;">
«<?= htmlspecialchars($g['message']) ?>»
</div>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
</section>
</div>
</div>
<?php include 'footer.php'; ?>