67 lines
2.9 KiB
PHP
67 lines
2.9 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
require_once 'layout_header.php';
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT * FROM products ORDER BY order_position ASC");
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
echo "<div class='alert alert-danger'>Error al conectar con la base de datos: " . $e->getMessage() . "</div>";
|
|
// Consider logging the error and showing a more user-friendly message
|
|
// For now, we stop execution if the database connection fails.
|
|
die();
|
|
}
|
|
?>
|
|
|
|
<div class="container-fluid mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1 class="m-0">Inventario General</h1>
|
|
<a href="edit_product.php" class="btn btn-primary">Añadir Producto</a>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Nombre</th>
|
|
<th>SKU</th>
|
|
<th>Precio</th>
|
|
<th class="text-center">Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($products)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center">No hay productos en el inventario. <a href="edit_product.php">Agrega el primero</a>.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($products as $product): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($product['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($product['nombre']); ?></td>
|
|
<td><?php echo htmlspecialchars($product['sku']); ?></td>
|
|
<td>S/ <?php echo htmlspecialchars(number_format($product['precio'], 2)); ?></td>
|
|
<td class="text-center">
|
|
<a href="edit_product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-warning">Editar</a>
|
|
<a href="delete_product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este producto?');">Eliminar</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'layout_footer.php'; ?>
|