index.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. require_once '../includes/config.php';
  3. require_once '../includes/database.php';
  4. require_once '../includes/auth.php';
  5. require_once '../includes/publication.php';
  6. $auth = new Auth();
  7. $auth->requireAuth();
  8. $publication = new Publication();
  9. $user = $auth->getUser();
  10. // Handle actions
  11. $action = $_GET['action'] ?? '';
  12. $message = '';
  13. if ($action === 'delete' && isset($_GET['id'])) {
  14. $id = (int)$_GET['id'];
  15. try {
  16. $publication->delete($id);
  17. $message = 'Publication deleted successfully';
  18. } catch (Exception $e) {
  19. $message = 'Error deleting publication: ' . $e->getMessage();
  20. }
  21. }
  22. // Get statistics
  23. $stats = $publication->getStats();
  24. // Get recent publications
  25. $recentPublications = $publication->getAll('all', 10);
  26. ?>
  27. <!DOCTYPE html>
  28. <html lang="en">
  29. <head>
  30. <meta charset="UTF-8">
  31. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  32. <title>Admin Dashboard - <?php echo SITE_TITLE; ?></title>
  33. <link rel="stylesheet" href="../css/style.css">
  34. </head>
  35. <body>
  36. <div class="admin-layout">
  37. <header class="admin-header">
  38. <div class="header-content">
  39. <h1><?php echo SITE_TITLE; ?></h1>
  40. <nav class="admin-nav">
  41. <a href="index.php" class="nav-link active">Dashboard</a>
  42. <a href="publications.php" class="nav-link">Publications</a>
  43. <a href="categories.php" class="nav-link">Categories</a>
  44. <a href="logout.php" class="nav-link">Logout</a>
  45. </nav>
  46. <div class="user-info">
  47. Welcome, <?php echo htmlspecialchars($user['username']); ?>
  48. </div>
  49. </div>
  50. </header>
  51. <main class="admin-main">
  52. <?php if ($message): ?>
  53. <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
  54. <?php echo htmlspecialchars($message); ?>
  55. </div>
  56. <?php endif; ?>
  57. <section class="dashboard-stats">
  58. <h2>Overview</h2>
  59. <div class="stats-grid">
  60. <div class="stat-card">
  61. <h3>Total Publications</h3>
  62. <p class="stat-number"><?php echo $stats['total']; ?></p>
  63. </div>
  64. <div class="stat-card">
  65. <h3>Published</h3>
  66. <p class="stat-number"><?php echo $stats['published']; ?></p>
  67. </div>
  68. <div class="stat-card">
  69. <h3>Drafts</h3>
  70. <p class="stat-number"><?php echo $stats['draft']; ?></p>
  71. </div>
  72. <div class="stat-card">
  73. <h3>Archived</h3>
  74. <p class="stat-number"><?php echo $stats['archived']; ?></p>
  75. </div>
  76. </div>
  77. </section>
  78. <section class="recent-publications">
  79. <h2>Recent Publications</h2>
  80. <div class="table-container">
  81. <table class="admin-table">
  82. <thead>
  83. <tr>
  84. <th>Title</th>
  85. <th>Author</th>
  86. <th>Status</th>
  87. <th>Created</th>
  88. <th>Actions</th>
  89. </tr>
  90. </thead>
  91. <tbody>
  92. <?php foreach ($recentPublications as $pub): ?>
  93. <tr>
  94. <td>
  95. <a href="edit.php?id=<?php echo $pub['id']; ?>">
  96. <?php echo htmlspecialchars($pub['title']); ?>
  97. </a>
  98. </td>
  99. <td><?php echo htmlspecialchars($pub['author']); ?></td>
  100. <td>
  101. <span class="status-badge status-<?php echo $pub['status']; ?>">
  102. <?php echo ucfirst($pub['status']); ?>
  103. </span>
  104. </td>
  105. <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
  106. <td>
  107. <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm">Edit</a>
  108. <a href="index.php?action=delete&id=<?php echo $pub['id']; ?>"
  109. class="btn btn-sm btn-danger"
  110. onclick="return confirm('Are you sure you want to delete this publication?')">
  111. Delete
  112. </a>
  113. </td>
  114. </tr>
  115. <?php endforeach; ?>
  116. </tbody>
  117. </table>
  118. </div>
  119. <div class="actions">
  120. <a href="edit.php" class="btn btn-primary">Create New Publication</a>
  121. </div>
  122. </section>
  123. </main>
  124. </div>
  125. </body>
  126. </html>