| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/auth.php';
- require_once '../includes/publication.php';
- $auth = new Auth();
- $auth->requireAuth();
- $publication = new Publication();
- $user = $auth->getUser();
- // Handle actions
- $action = $_GET['action'] ?? '';
- $message = '';
- if ($action === 'delete' && isset($_GET['id'])) {
- $id = (int)$_GET['id'];
- try {
- $publication->delete($id);
- $message = 'Publication deleted successfully';
- } catch (Exception $e) {
- $message = 'Error deleting publication: ' . $e->getMessage();
- }
- }
- // Get statistics
- $stats = $publication->getStats();
- // Get recent publications
- $recentPublications = $publication->getAll('all', 10);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Admin Dashboard - <?php echo SITE_TITLE; ?></title>
- <link rel="stylesheet" href="../css/style.css">
- </head>
- <body>
- <div class="admin-layout">
- <header class="admin-header">
- <div class="header-content">
- <h1><?php echo SITE_TITLE; ?></h1>
- <nav class="admin-nav">
- <a href="index.php" class="nav-link active">Dashboard</a>
- <a href="publications.php" class="nav-link">Publications</a>
- <a href="categories.php" class="nav-link">Categories</a>
- <a href="logout.php" class="nav-link">Logout</a>
- </nav>
- <div class="user-info">
- Welcome, <?php echo htmlspecialchars($user['username']); ?>
- </div>
- </div>
- </header>
- <main class="admin-main">
- <?php if ($message): ?>
- <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
- <?php echo htmlspecialchars($message); ?>
- </div>
- <?php endif; ?>
- <section class="dashboard-stats">
- <h2>Overview</h2>
- <div class="stats-grid">
- <div class="stat-card">
- <h3>Total Publications</h3>
- <p class="stat-number"><?php echo $stats['total']; ?></p>
- </div>
- <div class="stat-card">
- <h3>Published</h3>
- <p class="stat-number"><?php echo $stats['published']; ?></p>
- </div>
- <div class="stat-card">
- <h3>Drafts</h3>
- <p class="stat-number"><?php echo $stats['draft']; ?></p>
- </div>
- <div class="stat-card">
- <h3>Archived</h3>
- <p class="stat-number"><?php echo $stats['archived']; ?></p>
- </div>
- </div>
- </section>
- <section class="recent-publications">
- <h2>Recent Publications</h2>
- <div class="table-container">
- <table class="admin-table">
- <thead>
- <tr>
- <th>Title</th>
- <th>Author</th>
- <th>Status</th>
- <th>Created</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($recentPublications as $pub): ?>
- <tr>
- <td>
- <a href="edit.php?id=<?php echo $pub['id']; ?>">
- <?php echo htmlspecialchars($pub['title']); ?>
- </a>
- </td>
- <td><?php echo htmlspecialchars($pub['author']); ?></td>
- <td>
- <span class="status-badge status-<?php echo $pub['status']; ?>">
- <?php echo ucfirst($pub['status']); ?>
- </span>
- </td>
- <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
- <td>
- <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm">Edit</a>
- <a href="index.php?action=delete&id=<?php echo $pub['id']; ?>"
- class="btn btn-sm btn-danger"
- onclick="return confirm('Are you sure you want to delete this publication?')">
- Delete
- </a>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
-
- <div class="actions">
- <a href="edit.php" class="btn btn-primary">Create New Publication</a>
- </div>
- </section>
- </main>
- </div>
- </body>
- </html>
|