publications.php 12 KB

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