publications.php 11 KB

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