35570-vm/index.php
Flatlogic Bot 9671081d9c 1
2025-11-08 12:20:22 +00:00

50 lines
2.3 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'header.php';
// Fetch recent books and their authors
$stmt = db()->query("SELECT b.id, b.title, b.author_name, b.added_by_user_id, u.username FROM books b LEFT JOIN users u ON b.added_by_user_id = u.id ORDER BY b.created_at DESC LIMIT 5");
$recent_books = $stmt->fetchAll();
?>
<div class="container my-5">
<div class="p-5 text-center bg-light rounded-3">
<h1 class="display-4">Welcome to the Virtual Library</h1>
<p class="lead">Your personal space to discover, organize, and share books.</p>
<?php if (!isset($_SESSION['user_id'])): ?>
<a class="btn btn-primary btn-lg" href="signup.php" role="button">Get Started</a>
<?php else: ?>
<a class="btn btn-primary btn-lg" href="library.php" role="button">Go to Your Library</a>
<?php endif; ?>
</div>
<div class="row mt-5">
<div class="col">
<h2 class="text-center mb-4">Recently Added Books</h2>
<?php if (count($recent_books) > 0): ?>
<div class="list-group">
<?php foreach ($recent_books as $book): ?>
<a href="book.php?id=<?php echo $book['id']; ?>" class="list-group-item list-group-item-action flex-column align-items-start">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"><?php echo htmlspecialchars($book['title']); ?></h5>
</div>
<p class="mb-1">by
<?php if ($book['added_by_user_id'] && $book['username']): ?>
<a href="author.php?id=<?php echo $book['added_by_user_id']; ?>"><?php echo htmlspecialchars($book['username']); ?></a>
<?php else: ?>
<?php echo htmlspecialchars($book['author_name']); ?>
<?php endif; ?>
</p>
</a>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="text-center">No books have been added yet. Be the first!</p>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once 'footer.php'; ?>