publications.php 12 KB

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