publications.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 filter parameters
  33. $status = $_GET['status'] ?? 'all';
  34. $search = $_GET['search'] ?? '';
  35. $page = max(1, (int)($_GET['page'] ?? 1));
  36. $limit = 20;
  37. $offset = ($page - 1) * $limit;
  38. // Get publications
  39. if ($search) {
  40. $publications = $publication->search($search, $status === 'all' ? 'all' : $status);
  41. $totalPublications = count($publications);
  42. // Apply pagination
  43. $publications = array_slice($publications, $offset, $limit);
  44. } else {
  45. $publications = $publication->getAll($status === 'all' ? 'all' : $status, $limit, $offset);
  46. $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications" . ($status !== 'all' ? " WHERE status = '$status'" : ""))['count'];
  47. }
  48. $totalPages = ceil($totalPublications / $limit);
  49. ?>
  50. <!DOCTYPE html>
  51. <html lang="en">
  52. <head>
  53. <meta charset="UTF-8">
  54. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  55. <title><?php echo t('admin_nav_publications'); ?> - <?php echo SITE_TITLE; ?></title>
  56. <link rel="stylesheet" href="../css/style.css">
  57. </head>
  58. <body>
  59. <div class="admin-layout">
  60. <header class="admin-header">
  61. <div class="header-content">
  62. <h1><a href="/index.php"><?php echo SITE_TITLE; ?></a></h1>
  63. <nav class="admin-nav">
  64. <a href="index.php" class="nav-link"><?php echo t('admin_nav_dashboard'); ?></a>
  65. <a href="publications.php" class="nav-link active"><?php echo t('admin_nav_publications'); ?></a>
  66. <a href="categories.php" class="nav-link"><?php echo t('admin_nav_categories'); ?></a>
  67. <a href="comments.php" class="nav-link"><?php echo t('admin_nav_comments'); ?></a>
  68. <a href="users.php" class="nav-link"><?php echo t('manage_users'); ?></a>
  69. <?php if (LDAP_ENABLED): ?>
  70. <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
  71. <?php endif; ?>
  72. <a href="logout.php" class="nav-link"><?php echo t('admin_nav_logout'); ?></a>
  73. </nav>
  74. <div class="user-info">
  75. <?php echo t('admin_welcome'); ?>, <?php echo htmlspecialchars($user['username']); ?>
  76. </div>
  77. </div>
  78. </header>
  79. <main class="admin-main">
  80. <div class="page-header">
  81. <h2><?php echo t('admin_nav_publications'); ?></h2>
  82. <a href="edit.php" class="btn btn-primary"><?php echo t('admin_create_publication'); ?></a>
  83. </div>
  84. <?php if ($message): ?>
  85. <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
  86. <?php echo htmlspecialchars($message); ?>
  87. </div>
  88. <?php endif; ?>
  89. <div class="filters">
  90. <form method="get" class="filter-form">
  91. <div class="filter-group">
  92. <label for="status"><?php echo t('admin_table_status'); ?>:</label>
  93. <select id="status" name="status" onchange="this.form.submit()">
  94. <option value="all" <?php echo $status === 'all' ? 'selected' : ''; ?>><?php echo t('admin_filter_all'); ?></option>
  95. <option value="published" <?php echo $status === 'published' ? 'selected' : ''; ?>><?php echo t('admin_published'); ?></option>
  96. <option value="draft" <?php echo $status === 'draft' ? 'selected' : ''; ?>><?php echo t('admin_drafts'); ?></option>
  97. <option value="archived" <?php echo $status === 'archived' ? 'selected' : ''; ?>><?php echo t('admin_archived'); ?></option>
  98. </select>
  99. </div>
  100. <div class="filter-group">
  101. <label for="search"><?php echo t('search'); ?>:</label>
  102. <input type="text" id="search" name="search" value="<?php echo htmlspecialchars($search); ?>" placeholder="<?php echo t('admin_search_publications'); ?>...">
  103. </div>
  104. <button type="submit" class="btn btn-sm"><?php echo t('admin_filter_button'); ?></button>
  105. <?php if ($search || $status !== 'all'): ?>
  106. <a href="publications.php" class="btn btn-sm btn-secondary"><?php echo t('admin_clear_button'); ?></a>
  107. <?php endif; ?>
  108. </form>
  109. </div>
  110. <div class="table-container">
  111. <table class="admin-table">
  112. <thead>
  113. <tr>
  114. <th><?php echo t('admin_table_title'); ?></th>
  115. <th><?php echo t('admin_table_author'); ?></th>
  116. <th><?php echo t('admin_table_status'); ?></th>
  117. <th><?php echo t('admin_table_created'); ?></th>
  118. <th><?php echo t('admin_table_updated'); ?></th>
  119. <th><?php echo t('admin_table_actions'); ?></th>
  120. </tr>
  121. </thead>
  122. <tbody>
  123. <?php if (empty($publications)): ?>
  124. <tr>
  125. <td colspan="6" class="text-center"><?php echo t('admin_no_publications_found'); ?></td>
  126. </tr>
  127. <?php else: ?>
  128. <?php foreach ($publications as $pub): ?>
  129. <tr>
  130. <td>
  131. <a href="edit.php?id=<?php echo $pub['id']; ?>">
  132. <?php echo htmlspecialchars($pub['title']); ?>
  133. </a>
  134. <?php if ($pub['summary']): ?>
  135. <div class="summary-preview">
  136. <?php echo htmlspecialchars(substr($pub['summary'], 0, 100)) . (strlen($pub['summary']) > 100 ? '...' : ''); ?>
  137. </div>
  138. <?php endif; ?>
  139. </td>
  140. <td><?php echo htmlspecialchars($pub['author']); ?></td>
  141. <td>
  142. <span class="status-badge status-<?php echo $pub['status']; ?>">
  143. <?php echo ucfirst($pub['status']); ?>
  144. </span>
  145. </td>
  146. <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
  147. <td><?php echo date('M j, Y', strtotime($pub['updated_at'])); ?></td>
  148. <td>
  149. <div class="action-buttons">
  150. <a href="/public/publication.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm" target="_blank">View</a>
  151. <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm">Edit</a>
  152. <?php if ($pub['status'] === 'draft'): ?>
  153. <a href="edit.php?id=<?php echo $pub['id']; ?>&action=publish" class="btn btn-sm btn-success">Publish</a>
  154. <?php endif; ?>
  155. <a href="publications.php?action=delete&id=<?php echo $pub['id']; ?>"
  156. class="btn btn-sm btn-danger"
  157. onclick="return confirm('Are you sure you want to delete this publication?')">
  158. Delete
  159. </a>
  160. </div>
  161. </td>
  162. </tr>
  163. <?php endforeach; ?>
  164. <?php endif; ?>
  165. </tbody>
  166. </table>
  167. </div>
  168. <?php if ($totalPages > 1): ?>
  169. <div class="pagination">
  170. <?php if ($page > 1): ?>
  171. <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page - 1])); ?>" class="pagination-link">« Previous</a>
  172. <?php endif; ?>
  173. <?php for ($i = 1; $i <= $totalPages; $i++): ?>
  174. <?php if ($i == $page): ?>
  175. <span class="pagination-current"><?php echo $i; ?></span>
  176. <?php else: ?>
  177. <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>" class="pagination-link"><?php echo $i; ?></a>
  178. <?php endif; ?>
  179. <?php endfor; ?>
  180. <?php if ($page < $totalPages): ?>
  181. <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page + 1])); ?>" class="pagination-link">Next »</a>
  182. <?php endif; ?>
  183. </div>
  184. <?php endif; ?>
  185. </main>
  186. </div>
  187. <style>
  188. .page-header {
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. margin-bottom: 2rem;
  193. }
  194. .filters {
  195. background: white;
  196. padding: 1.5rem;
  197. border-radius: 0.5rem;
  198. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  199. margin-bottom: 2rem;
  200. }
  201. .filter-form {
  202. display: flex;
  203. gap: 1rem;
  204. align-items: end;
  205. flex-wrap: wrap;
  206. }
  207. .filter-group {
  208. display: flex;
  209. flex-direction: column;
  210. gap: 0.5rem;
  211. }
  212. .filter-group label {
  213. font-weight: 500;
  214. font-size: 0.875rem;
  215. }
  216. .filter-group input,
  217. .filter-group select {
  218. min-width: 150px;
  219. }
  220. .summary-preview {
  221. font-size: 0.75rem;
  222. color: #6c757d;
  223. margin-top: 0.25rem;
  224. max-width: 300px;
  225. }
  226. .action-buttons {
  227. display: flex;
  228. gap: 0.5rem;
  229. flex-wrap: wrap;
  230. }
  231. .text-center {
  232. text-align: center;
  233. padding: 2rem;
  234. color: #6c757d;
  235. }
  236. @media (max-width: 768px) {
  237. .page-header {
  238. flex-direction: column;
  239. gap: 1rem;
  240. align-items: stretch;
  241. }
  242. .filter-form {
  243. flex-direction: column;
  244. align-items: stretch;
  245. }
  246. .action-buttons {
  247. flex-direction: column;
  248. }
  249. }
  250. </style>
  251. </body>
  252. </html>