index.php 5.7 KB

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