71 lines
3.0 KiB
PHP
71 lines
3.0 KiB
PHP
<?php
|
|
require_once '../db/config.php';
|
|
include 'partials/header.php';
|
|
|
|
$status = $_GET['status'] ?? '';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT id, name, price, stock, images FROM products ORDER BY created_at DESC');
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
die("Erro ao buscar produtos: " . $e->getMessage());
|
|
}
|
|
?>
|
|
|
|
<?php if ($status === 'deleted'): ?>
|
|
<div class="alert alert-success">Produto excluído com sucesso!</div>
|
|
<?php elseif ($status === 'error'): ?>
|
|
<div class="alert alert-danger">Ocorreu um erro ao processar sua solicitação.</div>
|
|
<?php elseif ($status === 'saved'): ?>
|
|
<div class="alert alert-success">Produto salvo com sucesso!</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<h1>Gerenciar Produtos</h1>
|
|
<a href="product-edit.php" class="btn btn-primary">Adicionar Novo Produto</a>
|
|
</div>
|
|
|
|
<div class="table-responsive mt-4">
|
|
<table class="table table-striped table-bordered">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Imagem</th>
|
|
<th>ID</th>
|
|
<th>Nome</th>
|
|
<th>Preço</th>
|
|
<th>Estoque</th>
|
|
<th>Ações</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($products)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center">Nenhum produto cadastrado.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($products as $product): ?>
|
|
<tr>
|
|
<td>
|
|
<?php if (!empty($product['images']) && file_exists('../' . $product['images'])): ?>
|
|
<img src="../<?php echo htmlspecialchars($product['images']); ?>" alt="<?php echo htmlspecialchars($product['name']); ?>" style="width: 50px; height: 50px; object-fit: cover;">
|
|
<?php else: ?>
|
|
<img src="../assets/images/placeholder.png" alt="Sem imagem" style="width: 50px; height: 50px; object-fit: cover;">
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($product['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($product['name']); ?></td>
|
|
<td>R$ <?php echo number_format($product['price'], 2, ',', '.'); ?></td>
|
|
<td><?php echo htmlspecialchars($product['stock']); ?></td>
|
|
<td>
|
|
<a href="product-edit.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-warning">Editar</a>
|
|
<a href="product-delete.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Tem certeza que deseja excluir este produto?');">Excluir</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<?php include 'partials/footer.php'; ?>
|