index.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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="comments.php" class="nav-link"><?php echo t('admin_nav_comments'); ?></a>
  55. <a href="users.php" class="nav-link"><?php echo t('manage_users'); ?></a>
  56. <a href="wordpress_import.php" class="nav-link"><?php echo t('wordpress_import'); ?></a>
  57. <?php if (LDAP_ENABLED): ?>
  58. <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
  59. <?php endif; ?>
  60. <a href="logout.php" class="nav-link"><?php echo t('admin_nav_logout'); ?></a>
  61. </nav>
  62. <div class="user-info">
  63. <?php echo t('admin_welcome'); ?>, <?php echo htmlspecialchars($user['username']); ?>
  64. </div>
  65. </div>
  66. </header>
  67. <main class="admin-main">
  68. <?php if ($message): ?>
  69. <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
  70. <?php echo htmlspecialchars($message); ?>
  71. </div>
  72. <?php endif; ?>
  73. <section class="dashboard-stats">
  74. <h2><?php echo t('admin_overview'); ?></h2>
  75. <div class="stats-grid">
  76. <div class="stat-card">
  77. <h3><?php echo t('admin_total_publications'); ?></h3>
  78. <p class="stat-number"><?php echo $stats['total']; ?></p>
  79. </div>
  80. <div class="stat-card">
  81. <h3><?php echo t('admin_published'); ?></h3>
  82. <p class="stat-number"><?php echo $stats['published']; ?></p>
  83. </div>
  84. <div class="stat-card">
  85. <h3><?php echo t('admin_drafts'); ?></h3>
  86. <p class="stat-number"><?php echo $stats['draft']; ?></p>
  87. </div>
  88. <div class="stat-card">
  89. <h3><?php echo t('admin_archived'); ?></h3>
  90. <p class="stat-number"><?php echo $stats['archived']; ?></p>
  91. </div>
  92. </div>
  93. </section>
  94. <section class="recent-publications">
  95. <h2><?php echo t('admin_recent_publications'); ?></h2>
  96. <div class="table-container">
  97. <table class="admin-table">
  98. <thead>
  99. <tr>
  100. <th><?php echo t('admin_table_title'); ?></th>
  101. <th><?php echo t('admin_table_author'); ?></th>
  102. <th><?php echo t('admin_table_status'); ?></th>
  103. <th><?php echo t('admin_table_created'); ?></th>
  104. <th><?php echo t('admin_table_actions'); ?></th>
  105. </tr>
  106. </thead>
  107. <tbody>
  108. <?php foreach ($recentPublications as $pub): ?>
  109. <tr>
  110. <td>
  111. <a href="edit.php?id=<?php echo $pub['id']; ?>">
  112. <?php echo htmlspecialchars($pub['title']); ?>
  113. </a>
  114. </td>
  115. <td><?php echo htmlspecialchars($pub['author']); ?></td>
  116. <td>
  117. <span class="status-badge status-<?php echo $pub['status']; ?>">
  118. <?php echo ucfirst($pub['status']); ?>
  119. </span>
  120. </td>
  121. <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
  122. <td>
  123. <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm"><?php echo t('admin_action_edit'); ?></a>
  124. <a href="index.php?action=delete&id=<?php echo $pub['id']; ?>"
  125. class="btn btn-sm btn-danger"
  126. onclick="return confirm('<?php echo t('admin_confirm_delete'); ?>')">
  127. <?php echo t('admin_action_delete'); ?>
  128. </a>
  129. </td>
  130. </tr>
  131. <?php endforeach; ?>
  132. </tbody>
  133. </table>
  134. </div>
  135. <div class="actions">
  136. <a href="edit.php" class="btn btn-primary"><?php echo t('admin_create_publication'); ?></a>
  137. </div>
  138. </section>
  139. </main>
  140. </div>
  141. </body>
  142. </html>