176 lines
5.8 KiB
PHP
176 lines
5.8 KiB
PHP
<?php
|
|
require_once '../config/db.php';
|
|
require_once 'auth.php';
|
|
verificarAuth();
|
|
|
|
// Obtener todos los artículos
|
|
$stmt = $pdo->prepare("
|
|
SELECT p.*, u.nombre as autor_nombre
|
|
FROM blog_posts p
|
|
LEFT JOIN admin_users u ON p.autor_id = u.id
|
|
ORDER BY p.created_at DESC
|
|
");
|
|
$stmt->execute();
|
|
$posts = $stmt->fetchAll();
|
|
|
|
$admin = getAdminActual();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard - Blog Amor y Roma</title>
|
|
<link rel="stylesheet" href="../style/main.css">
|
|
<style>
|
|
.admin-header {
|
|
background: white;
|
|
padding: 1.5rem 2rem;
|
|
border-bottom: 1px solid rgba(0, 63, 82, 0.12);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.admin-container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
}
|
|
.btn-nuevo {
|
|
background: #ba124d;
|
|
color: white;
|
|
padding: 0.75rem 1.5rem;
|
|
border-radius: 24px;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
.btn-nuevo:hover {
|
|
background: #9c0f40;
|
|
}
|
|
.posts-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 2rem;
|
|
background: white;
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
|
|
}
|
|
.posts-table th,
|
|
.posts-table td {
|
|
padding: 1rem;
|
|
text-align: left;
|
|
border-bottom: 1px solid rgba(0, 63, 82, 0.12);
|
|
}
|
|
.posts-table th {
|
|
background: #f5f9f8;
|
|
font-weight: 600;
|
|
color: #003f52;
|
|
font-size: 0.85rem;
|
|
text-transform: uppercase;
|
|
}
|
|
.posts-table tr:hover {
|
|
background: #f9f9f9;
|
|
}
|
|
.estado-badge {
|
|
padding: 0.25rem 0.75rem;
|
|
border-radius: 999px;
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
}
|
|
.estado-publicado {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
.estado-borrador {
|
|
background: #fff3cd;
|
|
color: #856404;
|
|
}
|
|
.acciones {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
}
|
|
.btn-accion {
|
|
padding: 0.4rem 0.8rem;
|
|
border-radius: 6px;
|
|
text-decoration: none;
|
|
font-size: 0.85rem;
|
|
font-weight: 600;
|
|
}
|
|
.btn-editar {
|
|
background: #003f52;
|
|
color: white;
|
|
}
|
|
.btn-eliminar {
|
|
background: #dc3545;
|
|
color: white;
|
|
}
|
|
.logout-link {
|
|
color: #ba124d;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="admin-header">
|
|
<div>
|
|
<h2 style="margin: 0; font-family: 'Literata', serif;">Hola, <?= htmlspecialchars($admin['nombre']) ?></h2>
|
|
<p style="margin: 0.25rem 0 0; color: #666; font-size: 0.9rem;">Gestión de artículos del blog</p>
|
|
</div>
|
|
<div style="display: flex; gap: 1rem; align-items: center;">
|
|
<a href="../blog.php" target="_blank" class="btn-accion" style="background: #eaf0ee; color: #003f52;">Ver Blog</a>
|
|
<a href="editor.php" class="btn-nuevo">+ Nuevo Artículo</a>
|
|
<a href="logout.php" class="logout-link">Cerrar sesión</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-container">
|
|
<table class="posts-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Título</th>
|
|
<th>Categoría</th>
|
|
<th>Autor</th>
|
|
<th>Estado</th>
|
|
<th>Fecha</th>
|
|
<th>Vistas</th>
|
|
<th>Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($posts)): ?>
|
|
<tr>
|
|
<td colspan="7" style="text-align: center; padding: 3rem; color: #666;">
|
|
No hay artículos creados aún. <a href="editor.php" style="color: #ba124d;">Crear el primero</a>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($posts as $post): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($post['titulo']) ?></td>
|
|
<td><?= htmlspecialchars($post['categoria']) ?></td>
|
|
<td><?= htmlspecialchars($post['autor_nombre']) ?></td>
|
|
<td>
|
|
<span class="estado-badge estado-<?= $post['estado'] ?>">
|
|
<?= $post['estado'] ?>
|
|
</span>
|
|
</td>
|
|
<td><?= date('d/m/Y', strtotime($post['created_at'])) ?></td>
|
|
<td><?= $post['vistas'] ?></td>
|
|
<td class="acciones">
|
|
<a href="editor.php?id=<?= $post['id'] ?>" class="btn-accion btn-editar">Editar</a>
|
|
<a href="eliminar.php?id=<?= $post['id'] ?>" class="btn-accion btn-eliminar" onclick="return confirm('¿Eliminar este artículo?')">Eliminar</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</body>
|
|
</html>
|