148 lines
7.5 KiB
PHP
148 lines
7.5 KiB
PHP
<?php
|
|
include 'db/config.php';
|
|
include 'layout_header.php';
|
|
$db = db();
|
|
|
|
// Obtener todos los assets
|
|
$stmt = $db->query("SELECT * FROM marketing_assets ORDER BY categoria ASC, nombre ASC");
|
|
$assets = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Agrupar por categoría
|
|
$categorias = [
|
|
'Logo' => [],
|
|
'Intro/Outro' => [],
|
|
'Música' => [],
|
|
'Gráficos' => [],
|
|
'Otros' => []
|
|
];
|
|
|
|
foreach ($assets as $asset) {
|
|
$categorias[$asset['categoria']][] = $asset;
|
|
}
|
|
?>
|
|
|
|
<main id="main" class="main">
|
|
<div class="pagetitle d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h1>Biblioteca de Assets</h1>
|
|
<nav>
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
|
|
<li class="breadcrumb-item">Marketing</li>
|
|
<li class="breadcrumb-item active">Assets</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#subirAssetModal">
|
|
<i class="bi bi-cloud-arrow-up"></i> Subir Nuevo Recurso
|
|
</button>
|
|
</div>
|
|
|
|
<section class="section">
|
|
<div class="row">
|
|
<?php foreach ($categorias as $cat => $items): ?>
|
|
<div class="col-12 mb-4">
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center bg-light">
|
|
<h5 class="card-title mb-0 py-0"><?php echo $cat; ?> <span class="badge bg-secondary ms-2"><?php echo count($items); ?></span></h5>
|
|
</div>
|
|
<div class="card-body pt-3">
|
|
<?php if (empty($items)): ?>
|
|
<p class="text-muted mb-0">No hay archivos en esta categoría.</p>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Nombre</th>
|
|
<th>Fecha</th>
|
|
<th class="text-end">Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($items as $item): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="d-flex align-items-center">
|
|
<?php
|
|
$ext = pathinfo($item['archivo_path'], PATHINFO_EXTENSION);
|
|
$icon = 'bi-file-earmark';
|
|
if (in_array($ext, ['jpg', 'jpeg', 'png', 'svg'])) $icon = 'bi-image';
|
|
if (in_array($ext, ['mp4', 'mov', 'avi'])) $icon = 'bi-play-btn';
|
|
if (in_array($ext, ['mp3', 'wav'])) $icon = 'bi-music-note-beamed';
|
|
?>
|
|
<i class="bi <?php echo $icon; ?> fs-4 me-3 text-primary"></i>
|
|
<span><?php echo htmlspecialchars($item['nombre']); ?></span>
|
|
</div>
|
|
</td>
|
|
<td><?php echo date('d/m/Y', strtotime($item['fecha_subida'])); ?></td>
|
|
<td class="text-end">
|
|
<a href="<?php echo $item['archivo_path']; ?>" download class="btn btn-sm btn-outline-success" title="Descargar">
|
|
<i class="bi bi-download"></i>
|
|
</a>
|
|
<button class="btn btn-sm btn-outline-danger" onclick="eliminarAsset(<?php echo $item['id']; ?>)" title="Eliminar">
|
|
<i class="bi bi-trash"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Modal Subir Asset -->
|
|
<div class="modal fade" id="subirAssetModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form action="save_marketing_asset.php" method="POST" enctype="multipart/form-data">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Subir Recurso</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label class="form-label">Nombre del Recurso</label>
|
|
<input type="text" name="nombre" class="form-control" placeholder="Ej: Logo Principal Blanco" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Categoría</label>
|
|
<select name="categoria" class="form-select" required>
|
|
<option value="Logo">Logo</option>
|
|
<option value="Intro/Outro">Intro/Outro</option>
|
|
<option value="Música">Música</option>
|
|
<option value="Gráficos">Gráficos</option>
|
|
<option value="Otros">Otros</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Archivo</label>
|
|
<input type="file" name="archivo" class="form-control" required>
|
|
<div class="form-text">Soporta imágenes, videos y audio.</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
|
|
<button type="submit" class="btn btn-primary">Subir Archivo</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
function eliminarAsset(id) {
|
|
if (confirm('¿Estás seguro de que deseas eliminar este recurso?')) {
|
|
window.location.href = 'delete_marketing_asset.php?id=' + id;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<?php include 'layout_footer.php'; ?>
|