index.php 6.4 KB

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