<?php
$pageTitle = "Seven O'Clock Dinner Club";
// Fetch only approved uploads for the gallery; admins can remove or unapprove entries from the uploads admin page
$uploadsStmt = $db->prepare('
SELECT
u.id,
u.image_url,
u.quote_text,
u.attribution,
u.created_at,
m.display_name,
(SELECT COUNT(*) FROM upload_reactions r WHERE r.upload_id = u.id AND r.reaction = "like") AS like_count,
(SELECT COUNT(*) FROM upload_reactions r WHERE r.upload_id = u.id AND r.reaction = "dislike") AS dislike_count,
(SELECT COUNT(*) FROM upload_comments c WHERE c.upload_id = u.id) AS comment_count,
0 AS my_reaction_unused
FROM uploads u
JOIN member_profiles m ON m.user_id = u.user_id
WHERE u.is_approved = 1
ORDER BY u.created_at DESC
');
$uid = currentUserId();
// Query contains no placeholders now; nothing to bind.
$uploadsStmt->execute();
$uploads = $uploadsStmt->get_result()->fetch_all(MYSQLI_ASSOC);
?>
<section class="page-grid">
<div class="card" data-animate-initial>
<div class="muted" style="font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; margin-bottom: 10px;">
Evenings at seven
</div>
<?php if (isLoggedIn()): ?>
<h1 style="font-family: 'Georgia', 'Times New Roman', serif; font-weight: 400; font-size: 30px; line-height: 1.3; margin: 0 0 14px;">
Welcome back.
</h1>
<div style="margin-top: 18px; display: flex; flex-wrap: wrap; gap: 10px;">
<a href="<?= url('upload') ?>" class="pill pill-accent">Upload</a>
<a href="<?= url('schedule?rsvp=today#rsvp-today') ?>" class="pill">
RSVP
</a>
<a href="<?= url('profile') ?>" class="pill">Profile</a>
</div>
<?php else: ?>
<h1 style="font-family: 'Georgia', 'Times New Roman', serif; font-weight: 400; font-size: 34px; line-height: 1.2; margin: 0 0 14px;">
The hottest dinner club around.
</h1>
<div style="margin-top: 22px; display: flex; flex-wrap: wrap; gap: 10px;">
<a href="<?= url('register') ?>" class="pill pill-accent">Join</a>
<a href="<?= url('members') ?>" class="pill">Members</a>
<a href="<?= url('schedule') ?>" class="pill">Schedule</a>
</div>
<?php endif; ?>
</div>
<div class="card" data-animate>
<div class="muted" style="font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; margin-bottom: 10px;">
Recent dinners
</div>
<?php if ($uploads): ?>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px;">
<?php foreach ($uploads as $upload): ?>
<figure id="upload-<?= (int)($upload['id'] ?? 0) ?>" style="margin: 0; overflow: hidden; border-radius: 14px; border: 1px solid rgba(0,0,0,0.06); background: var(--bg-elevated);">
<button type="button" data-image-full="<?= htmlspecialchars($upload['image_url'], ENT_QUOTES, 'UTF-8') ?>" style="all: unset; display: block; width: 100%; cursor: zoom-in;">
<img src="<?= htmlspecialchars($upload['image_url'], ENT_QUOTES, 'UTF-8') ?>" alt="" style="display:block; width:100%; height:auto; aspect-ratio:4 / 5; object-fit:cover; object-position:center center; filter:grayscale(30%); border-radius: 14px 14px 0 0;">
</button>
<figcaption style="padding: 10px 12px 12px; background: #ffffff; font-size: 13px; line-height: 1.5;">
<div style="font-size: 13px; margin-bottom: 4px;">
“<?= htmlspecialchars($upload['quote_text'], ENT_QUOTES, 'UTF-8') ?>”
</div>
<?php if (!empty($upload['attribution'])): ?>
<div class="muted" style="font-size: 12px; margin-bottom: 4px;">
<?= htmlspecialchars($upload['attribution'], ENT_QUOTES, 'UTF-8') ?>
</div>
<?php else: ?>
<div style="font-size: 12px; margin-bottom: 4px;"> </div>
<?php endif; ?>
<div class="muted" style="margin-top: 4px; font-size: 11px;">
Uploaded by <?= htmlspecialchars($upload['display_name'], ENT_QUOTES, 'UTF-8') ?>
· <?= htmlspecialchars(date('M j, Y', strtotime($upload['created_at'])), ENT_QUOTES, 'UTF-8') ?>
</div>
<div style="margin-top: 10px; display:flex; gap: 8px; flex-wrap: nowrap; align-items:center; justify-content: space-between; width: 100%;">
<div style="display:flex; gap: 8px; align-items:center;">
<button
type="button"
class="pill"
style="font-size: 12px; padding: 6px 12px;"
aria-label="Upvote"
data-open-upload-interactions
data-upload-id="<?= htmlspecialchars((string)($upload['id'] ?? ''), ENT_QUOTES, 'UTF-8') ?>"
data-reaction="like"
>
▲ <?= (int)($upload['like_count'] ?? 0) ?>
</button>
<button
type="button"
class="pill"
style="font-size: 12px; padding: 6px 12px;"
aria-label="Downvote"
data-open-upload-interactions
data-upload-id="<?= htmlspecialchars((string)($upload['id'] ?? ''), ENT_QUOTES, 'UTF-8') ?>"
data-reaction="dislike"
>
▼ <?= (int)($upload['dislike_count'] ?? 0) ?>
</button>
</div>
<button
type="button"
class="pill"
style="font-size: 11px; padding: 6px 12px;"
data-open-upload-interactions
data-upload-id="<?= htmlspecialchars((string)($upload['id'] ?? ''), ENT_QUOTES, 'UTF-8') ?>"
data-open-comments="1"
>
Comments (<?= (int)($upload['comment_count'] ?? 0) ?>)
</button>
</div>
</figcaption>
</figure>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="muted" style="font-size: 13px;">
Nothing yet.
</p>
<?php endif; ?>
</div>
</section>