100 lines
5.3 KiB
PHP
100 lines
5.3 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch products for the dropdown
|
|
$stmt_productos = $pdo->query('SELECT id, nombre FROM productos ORDER BY nombre ASC');
|
|
$productos = $stmt_productos->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch Kanban columns for the dropdown
|
|
$stmt_columns = $pdo->query('SELECT id, nombre FROM kanban_columns ORDER BY orden ASC');
|
|
$columns = $stmt_columns->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// If no columns exist, create default ones to ensure the dropdown is never empty
|
|
if (empty($columns)) {
|
|
$default_columns = ['Para empezar', 'En proceso', 'Terminado'];
|
|
$stmt_insert = $pdo->prepare('INSERT INTO kanban_columns (nombre, orden) VALUES (?, ?)');
|
|
foreach ($default_columns as $index => $name) {
|
|
$stmt_insert->execute([$name, $index + 1]);
|
|
}
|
|
// Re-fetch columns so they appear on this page load
|
|
$stmt_columns = $pdo->query('SELECT id, nombre FROM kanban_columns ORDER BY orden ASC');
|
|
$columns = $stmt_columns->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
// Fetch existing info cards
|
|
$stmt_info = $pdo->query('SELECT info_productos.id, productos.nombre as producto_nombre, info_productos.imagen_url, info_productos.texto_informativo, kanban_columns.nombre as columna_nombre FROM info_productos JOIN productos ON info_productos.producto_id = productos.id LEFT JOIN kanban_columns ON info_productos.column_id = kanban_columns.id ORDER BY info_productos.created_at DESC');
|
|
$info_cards = $stmt_info->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
|
|
<div class="container mt-4">
|
|
<h2>Info de Productos</h2>
|
|
<p>Crea y gestiona tarjetas con información y fotos de tus productos.</p>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header">Agregar Nueva Tarjeta de Información</div>
|
|
<div class="card-body">
|
|
<form action="handle_agregar_info_producto.php" method="POST" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="producto_id">Producto</label>
|
|
<select class="form-control" id="producto_id" name="producto_id" required>
|
|
<option value="">Selecciona un producto</option>
|
|
<?php foreach ($productos as $producto): ?>
|
|
<option value="<?php echo htmlspecialchars($producto['id']); ?>">
|
|
<?php echo htmlspecialchars($producto['nombre']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group mt-3">
|
|
<label for="column_id">Columna Kanban</label>
|
|
<select class="form-control" id="column_id" name="column_id" required>
|
|
<option value="">Selecciona una columna</option>
|
|
<?php foreach ($columns as $column): ?>
|
|
<option value="<?php echo htmlspecialchars($column['id']); ?>">
|
|
<?php echo htmlspecialchars($column['nombre']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group mt-3">
|
|
<label for="imagen">Imagen del Producto</label>
|
|
<input type="file" class="form-control-file" id="imagen" name="imagen" accept="image/*" required>
|
|
</div>
|
|
<div class="form-group mt-3">
|
|
<label for="texto_informativo">Texto Informativo</label>
|
|
<textarea class="form-control" id="texto_informativo" name="texto_informativo" rows="3" required></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-3">Guardar Tarjeta</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<?php if (empty($info_cards)): ?>
|
|
<div class="col">
|
|
<p class="text-center">Aún no has creado ninguna tarjeta de información.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($info_cards as $card): ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100">
|
|
<img src="<?php echo htmlspecialchars($card['imagen_url']); ?>" class="card-img-top" alt="Imagen de <?php echo htmlspecialchars($card['producto_nombre']); ?>">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($card['producto_nombre']); ?></h5>
|
|
<p class="card-text"><small class="text-muted">Columna: <?php echo htmlspecialchars($card['columna_nombre'] ?? 'Sin asignar'); ?></small></p>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($card['texto_informativo'])); ?></p>
|
|
</div>
|
|
<div class="card-footer">
|
|
<a href="eliminar_info_producto.php?id=<?php echo $card['id']; ?>" class="btn btn-danger btn-sm" onclick="return confirm('¿Estás seguro de que quieres eliminar esta tarjeta?');">Eliminar</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|