105 lines
4.8 KiB
PHP
105 lines
4.8 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
// If user is not logged in or not a super_admin, redirect to login page
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'super_admin') {
|
|
header('Location: ../login.php');
|
|
exit;
|
|
}
|
|
|
|
// Fetch all products
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT * FROM products ORDER BY created_at DESC');
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin Dashboard - GiftShop</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="#">GiftShop Admin</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="logout.php">Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Product Management</h1>
|
|
<a href="edit_product.php" class="btn btn-primary">
|
|
<i class="bi bi-plus-lg"></i> Add New Product
|
|
</a>
|
|
</div>
|
|
|
|
<?php if (isset($_SESSION['success_message'])): ?>
|
|
<div class="alert alert-success">
|
|
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_SESSION['error_message'])): ?>
|
|
<div class="alert alert-danger">
|
|
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Price</th>
|
|
<th>Stock</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($products)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No products found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($products as $product): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($product['name']); ?></td>
|
|
<td>$<?php echo htmlspecialchars($product['price']); ?></td>
|
|
<td><?php echo htmlspecialchars($product['stock_quantity']); ?></td>
|
|
<td class="text-end">
|
|
<a href="edit_product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-outline-primary">
|
|
<i class="bi bi-pencil"></i> Edit
|
|
</a>
|
|
<form action="delete_product.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this product?');">
|
|
<input type="hidden" name="product_id" value="<?php echo $product['id']; ?>">
|
|
<button type="submit" class="btn btn-sm btn-outline-danger" <?php if ($product['stock_quantity'] > 0) echo 'disabled'; ?>>
|
|
<i class="bi bi-trash"></i> Delete
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|