index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // Start session for language preference
  3. if (session_status() === PHP_SESSION_NONE) {
  4. session_start();
  5. }
  6. require_once '../includes/config.php';
  7. require_once '../includes/database.php';
  8. require_once '../includes/auth.php';
  9. require_once '../includes/publication.php';
  10. require_once '../includes/translation.php';
  11. // Include LDAP class if LDAP is enabled
  12. if (LDAP_ENABLED) {
  13. require_once '../includes/ldap.php';
  14. }
  15. $auth = new Auth();
  16. $auth->requireAuth();
  17. $publication = new Publication();
  18. $user = $auth->getUser();
  19. // Translation system is auto-initialized when translation.php is included
  20. // Handle actions
  21. $action = $_GET['action'] ?? '';
  22. $message = '';
  23. if ($action === 'delete' && isset($_GET['id'])) {
  24. $id = (int)$_GET['id'];
  25. try {
  26. $publication->delete($id);
  27. $message = t('admin_publication_deleted_success');
  28. } catch (Exception $e) {
  29. $message = t('admin_publication_deleted_error') . ' ' . $e->getMessage();
  30. }
  31. }
  32. // Get statistics
  33. $stats = $publication->getStats();
  34. // Get recent publications
  35. $recentPublications = $publication->getAll('all', 10);
  36. ?>
  37. <!DOCTYPE html>
  38. <html lang="en">
  39. <head>
  40. <meta charset="UTF-8">
  41. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  42. <title><?php echo t('admin_dashboard_title'); ?> - <?php echo SITE_TITLE; ?></title>
  43. <link rel="stylesheet" href="../css/style.css">
  44. </head>
  45. <body>
  46. <div class="admin-layout">
  47. <header class="admin-header">
  48. <div class="header-content">
  49. <h1><a href="/index.php"><?php echo SITE_TITLE; ?></a></h1>
  50. <nav class="admin-nav">
  51. <a href="index.php" class="nav-link active"><?php echo t('admin_nav_dashboard'); ?></a>
  52. <a href="publications.php" class="nav-link"><?php echo t('admin_nav_publications'); ?></a>
  53. <a href="categories.php" class="nav-link"><?php echo t('admin_nav_categories'); ?></a>
  54. <a href="users.php" class="nav-link"><?php echo t('manage_users'); ?></a>
  55. <?php if (LDAP_ENABLED): ?>
  56. <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
  57. <?php endif; ?>
  58. <a href="logout.php" class="nav-link"><?php echo t('admin_nav_logout'); ?></a>
  59. </nav>
  60. <div class="user-info">
  61. <?php echo t('admin_welcome'); ?>, <?php echo htmlspecialchars($user['username']); ?>
  62. </div>
  63. </div>
  64. </header>
  65. <main class="admin-main">
  66. <?php if ($message): ?>
  67. <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
  68. <?php echo htmlspecialchars($message); ?>
  69. </div>
  70. <?php endif; ?>
  71. <section class="dashboard-stats">
  72. <h2><?php echo t('admin_overview'); ?></h2>
  73. <div class="stats-grid">
  74. <div class="stat-card">
  75. <h3><?php echo t('admin_total_publications'); ?></h3>
  76. <p class="stat-number"><?php echo $stats['total']; ?></p>
  77. </div>
  78. <div class="stat-card">
  79. <h3><?php echo t('admin_published'); ?></h3>
  80. <p class="stat-number"><?php echo $stats['published']; ?></p>
  81. </div>
  82. <div class="stat-card">
  83. <h3><?php echo t('admin_drafts'); ?></h3>
  84. <p class="stat-number"><?php echo $stats['draft']; ?></p>
  85. </div>
  86. <div class="stat-card">
  87. <h3><?php echo t('admin_archived'); ?></h3>
  88. <p class="stat-number"><?php echo $stats['archived']; ?></p>
  89. </div>
  90. </div>
  91. </section>
  92. <section class="recent-publications">
  93. <h2><?php echo t('admin_recent_publications'); ?></h2>
  94. <div class="table-container">
  95. <table class="admin-table">
  96. <thead>
  97. <tr>
  98. <th><?php echo t('admin_table_title'); ?></th>
  99. <th><?php echo t('admin_table_author'); ?></th>
  100. <th><?php echo t('admin_table_status'); ?></th>
  101. <th><?php echo t('admin_table_created'); ?></th>
  102. <th><?php echo t('admin_table_actions'); ?></th>
  103. </tr>
  104. </thead>
  105. <tbody>
  106. <?php foreach ($recentPublications as $pub): ?>
  107. <tr>
  108. <td>
  109. <a href="edit.php?id=<?php echo $pub['id']; ?>">
  110. <?php echo htmlspecialchars($pub['title']); ?>
  111. </a>
  112. </td>
  113. <td><?php echo htmlspecialchars($pub['author']); ?></td>
  114. <td>
  115. <span class="status-badge status-<?php echo $pub['status']; ?>">
  116. <?php echo ucfirst($pub['status']); ?>
  117. </span>
  118. </td>
  119. <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
  120. <td>
  121. <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm"><?php echo t('admin_action_edit'); ?></a>
  122. <a href="index.php?action=delete&id=<?php echo $pub['id']; ?>"
  123. class="btn btn-sm btn-danger"
  124. onclick="return confirm('<?php echo t('admin_confirm_delete'); ?>')">
  125. <?php echo t('admin_action_delete'); ?>
  126. </a>
  127. </td>
  128. </tr>
  129. <?php endforeach; ?>
  130. </tbody>
  131. </table>
  132. </div>
  133. <div class="actions">
  134. <a href="edit.php" class="btn btn-primary"><?php echo t('admin_create_publication'); ?></a>
  135. </div>
  136. </section>
  137. </main>
  138. </div>
  139. </body>
  140. </html>