| Server IP : 3.111.61.48 / Your IP : 216.73.216.67 Web Server : Apache System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.2.31 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/vhost/book.gyaniguru.org/admin/ |
Upload File : |
<?php
require_once __DIR__ . '/../includes/db.php';
if (isset($_GET['delete'])) {
$id = (int)$_GET['delete'];
$conn->query("DELETE FROM books WHERE id = $id");
header("Location: books.php?msg=Book deleted successfully");
exit();
}
include 'includes/header.php';
$books = get_all("SELECT b.*, c.name as cat_name FROM books b LEFT JOIN categories c ON b.category_id = c.id ORDER BY b.created_at DESC");
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<div class="search-wrap" style="width: 300px;">
<div class="input-group">
<span class="input-group-text bg-transparent border-end-0" style="border-color: rgba(212,175,55,0.2);"><i class="bi bi-search text-muted"></i></span>
<input type="text" id="bookSearch" onkeyup="filterTable('bookSearch', 'booksTable')" class="form-control bg-transparent border-start-0" style="border-color: rgba(212,175,55,0.2); color: var(--text-dark)" placeholder="Search books...">
</div>
</div>
<a href="book-add.php" class="btn btn-saffron px-4">
<i class="bi bi-plus-lg me-2"></i> Add New Book
</a>
</div>
<?php if(isset($_GET['msg'])): ?>
<div class="alert alert-success py-2 mb-4" style="font-size: 0.9rem;">
<i class="bi bi-check-circle me-2"></i> <?php echo $_GET['msg']; ?>
</div>
<?php endif; ?>
<div class="admin-card">
<div class="table-responsive">
<table class="table table-custom" id="booksTable">
<thead>
<tr>
<th>Book Info</th>
<th>Category</th>
<th>Pricing</th>
<th>Attributes</th>
<th>Badges</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach($books as $book): ?>
<tr>
<td>
<div class="d-flex align-items-center gap-3">
<img src="../<?php echo $book['image']; ?>" alt="" style="width:45px; height:65px; object-fit:cover; border-radius:6px; box-shadow: 0 4px 10px rgba(0,0,0,0.1);" onerror="this.src='../images/placeholder.png'">
<div>
<div style="font-weight:700; color: var(--maroon);"><?php echo $book['title']; ?></div>
<div class="text-muted" style="font-size:0.8rem">by <?php echo $book['author']; ?></div>
</div>
</div>
</td>
<td><span class="badge py-2 px-3" style="background: var(--warm-white); border: 1px solid var(--cream-dark); color: var(--text-dark);"><?php echo $book['cat_name'] ?: 'Uncategorized'; ?></span></td>
<td>
<div style="font-weight:700; color: var(--gerua-deep)">₹<?php echo $book['price']; ?></div>
<del class="text-muted small">₹<?php echo $book['original_price']; ?></del>
</td>
<td style="font-size: 0.8rem">
<?php echo $book['pages']; ?> Pages<br>
<?php echo $book['language']; ?><br>
<?php echo $book['binding'] ?: 'Paperback'; ?>
</td>
<td>
<?php if($book['is_featured']): ?>
<span class="badge bg-warning text-dark" style="font-size:0.65rem">FEATURED</span>
<?php endif; ?>
<?php if($book['is_new']): ?>
<span class="badge bg-info text-dark" style="font-size:0.65rem">NEW</span>
<?php endif; ?>
<?php if($book['is_upcoming']): ?>
<span class="badge bg-dark text-warning border border-warning" style="font-size:0.65rem">UPCOMING</span>
<?php endif; ?>
</td>
<td>
<div class="d-flex gap-2">
<a href="book-edit.php?id=<?php echo $book['id']; ?>" class="btn-action bg-info bg-opacity-10 text-info" title="Edit">
<i class="bi bi-pencil-square"></i>
</a>
<a href="books.php?delete=<?php echo $book['id']; ?>" class="btn-action bg-danger bg-opacity-10 text-danger" title="Delete" onclick="return confirm('Are you sure you want to delete this book?')">
<i class="bi bi-trash"></i>
</a>
</div>
</td>
</tr>
<?php endforeach; if(empty($books)) echo '<tr><td colspan="6" class="text-center py-5">No books found in database.</td></tr>'; ?>
</tbody>
</table>
</div>
</div>
<?php include 'includes/footer.php'; ?>