67 lines
3.0 KiB
PHP
67 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$search_term = $_GET['search'] ?? '';
|
|
$pdo = db();
|
|
|
|
$query = "SELECT * FROM books";
|
|
$params = [];
|
|
|
|
if (!empty($search_term)) {
|
|
$query .= " WHERE title LIKE :search OR author LIKE :search OR isbn LIKE :search";
|
|
$params[':search'] = '%' . $search_term . '%';
|
|
}
|
|
|
|
$stmt = $pdo->prepare($query);
|
|
$stmt->execute($params);
|
|
$books = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<?php require_once __DIR__ . '/includes/header.php'; ?>
|
|
|
|
<main class="container my-5">
|
|
<section>
|
|
<h1 class="mb-4">Book Catalog</h1>
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<form action="catalog.php" method="GET">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" name="search" placeholder="Search by title, author, or ISBN..." value="<?php echo htmlspecialchars($search_term); ?>">
|
|
<button class="btn btn-primary" type="submit"><i class="bi bi-search"></i> Search</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<?php if (empty($books)): ?>
|
|
<div class="col">
|
|
<div class="alert alert-info">No books found matching your search criteria.</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($books as $book): ?>
|
|
<div class="col-md-6 col-lg-4 mb-4">
|
|
<div class="card h-100 book-card">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title fw-bold"><?php echo htmlspecialchars($book['title']); ?></h5>
|
|
<h6 class="card-subtitle mb-2 text-muted"><?php echo htmlspecialchars($book['author']); ?></h6>
|
|
<p class="card-text flex-grow-1"><?php echo htmlspecialchars(substr($book['description'], 0, 100)) . '...'; ?></p>
|
|
<div class="mt-auto">
|
|
<p class="mb-1"><small class="text-muted">ISBN: <?php echo htmlspecialchars($book['isbn']); ?></small></p>
|
|
<p class="mb-0">
|
|
Status:
|
|
<span class="status-<?php echo htmlspecialchars($book['status']); ?>">
|
|
<?php echo htmlspecialchars(ucfirst($book['status'])); ?>
|
|
</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|