| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/auth.php';
- require_once '../includes/publication.php';
- require_once '../includes/translation.php';
- // Include LDAP class if LDAP is enabled
- if (LDAP_ENABLED) {
- require_once '../includes/ldap.php';
- }
- $auth = new Auth();
- $auth->requireAuth();
- $publication = new Publication();
- $user = $auth->getUser();
- // Initialize translation system
- $translation = Translation::getInstance();
- // Handle actions
- $action = $_GET['action'] ?? '';
- $message = '';
- if ($action === 'delete' && isset($_GET['id'])) {
- $id = (int)$_GET['id'];
- try {
- $publication->delete($id);
- $message = t('admin_publication_deleted_success');
- } catch (Exception $e) {
- $message = t('admin_publication_deleted_error') . ' ' . $e->getMessage();
- }
- }
- // Get filter parameters
- $status = $_GET['status'] ?? 'all';
- $search = $_GET['search'] ?? '';
- $page = max(1, (int)($_GET['page'] ?? 1));
- $limit = 20;
- $offset = ($page - 1) * $limit;
- // Get publications
- if ($search) {
- $publications = $publication->search($search, $status === 'all' ? 'all' : $status);
- $totalPublications = count($publications);
- // Apply pagination
- $publications = array_slice($publications, $offset, $limit);
- } else {
- $publications = $publication->getAll($status === 'all' ? 'all' : $status, $limit, $offset);
- $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications" . ($status !== 'all' ? " WHERE status = '$status'" : ""))['count'];
- }
- $totalPages = ceil($totalPublications / $limit);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title><?php echo t('admin_nav_publications'); ?> - <?php echo SITE_TITLE; ?></title>
- <link rel="stylesheet" href="../css/style.css">
- </head>
- <body>
- <div class="admin-layout">
- <header class="admin-header">
- <div class="header-content">
- <h1><?php echo SITE_TITLE; ?></h1>
- <nav class="admin-nav">
- <a href="index.php" class="nav-link"><?php echo t('admin_nav_dashboard'); ?></a>
- <a href="publications.php" class="nav-link active"><?php echo t('admin_nav_publications'); ?></a>
- <a href="categories.php" class="nav-link"><?php echo t('admin_nav_categories'); ?></a>
- <?php if (LDAP_ENABLED): ?>
- <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
- <?php endif; ?>
- <a href="logout.php" class="nav-link"><?php echo t('admin_nav_logout'); ?></a>
- </nav>
- <div class="user-info">
- <?php echo t('admin_welcome'); ?>, <?php echo htmlspecialchars($user['username']); ?>
- </div>
- </div>
- </header>
- <main class="admin-main">
- <div class="page-header">
- <h2><?php echo t('admin_nav_publications'); ?></h2>
- <a href="edit.php" class="btn btn-primary"><?php echo t('admin_create_publication'); ?></a>
- </div>
-
- <?php if ($message): ?>
- <div class="alert alert-<?php echo strpos($message, 'Error') === false ? 'success' : 'error'; ?>">
- <?php echo htmlspecialchars($message); ?>
- </div>
- <?php endif; ?>
- <div class="filters">
- <form method="get" class="filter-form">
- <div class="filter-group">
- <label for="status"><?php echo t('admin_table_status'); ?>:</label>
- <select id="status" name="status" onchange="this.form.submit()">
- <option value="all" <?php echo $status === 'all' ? 'selected' : ''; ?>><?php echo t('admin_filter_all'); ?></option>
- <option value="published" <?php echo $status === 'published' ? 'selected' : ''; ?>><?php echo t('admin_published'); ?></option>
- <option value="draft" <?php echo $status === 'draft' ? 'selected' : ''; ?>><?php echo t('admin_drafts'); ?></option>
- <option value="archived" <?php echo $status === 'archived' ? 'selected' : ''; ?>><?php echo t('admin_archived'); ?></option>
- </select>
- </div>
-
- <div class="filter-group">
- <label for="search"><?php echo t('search'); ?>:</label>
- <input type="text" id="search" name="search" value="<?php echo htmlspecialchars($search); ?>" placeholder="<?php echo t('admin_search_publications'); ?>...">
- </div>
-
- <button type="submit" class="btn btn-sm"><?php echo t('admin_filter_button'); ?></button>
- <?php if ($search || $status !== 'all'): ?>
- <a href="publications.php" class="btn btn-sm btn-secondary"><?php echo t('admin_clear_button'); ?></a>
- <?php endif; ?>
- </form>
- </div>
- <div class="table-container">
- <table class="admin-table">
- <thead>
- <tr>
- <th><?php echo t('admin_table_title'); ?></th>
- <th><?php echo t('admin_table_author'); ?></th>
- <th><?php echo t('admin_table_status'); ?></th>
- <th><?php echo t('admin_table_created'); ?></th>
- <th><?php echo t('admin_table_updated'); ?></th>
- <th><?php echo t('admin_table_actions'); ?></th>
- </tr>
- </thead>
- <tbody>
- <?php if (empty($publications)): ?>
- <tr>
- <td colspan="6" class="text-center"><?php echo t('admin_no_publications_found'); ?></td>
- </tr>
- <?php else: ?>
- <?php foreach ($publications as $pub): ?>
- <tr>
- <td>
- <a href="edit.php?id=<?php echo $pub['id']; ?>">
- <?php echo htmlspecialchars($pub['title']); ?>
- </a>
- <?php if ($pub['summary']): ?>
- <div class="summary-preview">
- <?php echo htmlspecialchars(substr($pub['summary'], 0, 100)) . (strlen($pub['summary']) > 100 ? '...' : ''); ?>
- </div>
- <?php endif; ?>
- </td>
- <td><?php echo htmlspecialchars($pub['author']); ?></td>
- <td>
- <span class="status-badge status-<?php echo $pub['status']; ?>">
- <?php echo ucfirst($pub['status']); ?>
- </span>
- </td>
- <td><?php echo date('M j, Y', strtotime($pub['created_at'])); ?></td>
- <td><?php echo date('M j, Y', strtotime($pub['updated_at'])); ?></td>
- <td>
- <div class="action-buttons">
- <a href="public/publication.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm" target="_blank">View</a>
- <a href="edit.php?id=<?php echo $pub['id']; ?>" class="btn btn-sm">Edit</a>
- <?php if ($pub['status'] === 'draft'): ?>
- <a href="edit.php?id=<?php echo $pub['id']; ?>&action=publish" class="btn btn-sm btn-success">Publish</a>
- <?php endif; ?>
- <a href="publications.php?action=delete&id=<?php echo $pub['id']; ?>"
- class="btn btn-sm btn-danger"
- onclick="return confirm('Are you sure you want to delete this publication?')">
- Delete
- </a>
- </div>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php endif; ?>
- </tbody>
- </table>
- </div>
- <?php if ($totalPages > 1): ?>
- <div class="pagination">
- <?php if ($page > 1): ?>
- <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page - 1])); ?>" class="pagination-link">« Previous</a>
- <?php endif; ?>
- <?php for ($i = 1; $i <= $totalPages; $i++): ?>
- <?php if ($i == $page): ?>
- <span class="pagination-current"><?php echo $i; ?></span>
- <?php else: ?>
- <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>" class="pagination-link"><?php echo $i; ?></a>
- <?php endif; ?>
- <?php endfor; ?>
- <?php if ($page < $totalPages): ?>
- <a href="?<?php echo http_build_query(array_merge($_GET, ['page' => $page + 1])); ?>" class="pagination-link">Next »</a>
- <?php endif; ?>
- </div>
- <?php endif; ?>
- </main>
- </div>
- <style>
- .page-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 2rem;
- }
-
- .filters {
- background: white;
- padding: 1.5rem;
- border-radius: 0.5rem;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
- margin-bottom: 2rem;
- }
-
- .filter-form {
- display: flex;
- gap: 1rem;
- align-items: end;
- flex-wrap: wrap;
- }
-
- .filter-group {
- display: flex;
- flex-direction: column;
- gap: 0.5rem;
- }
-
- .filter-group label {
- font-weight: 500;
- font-size: 0.875rem;
- }
-
- .filter-group input,
- .filter-group select {
- min-width: 150px;
- }
-
- .summary-preview {
- font-size: 0.75rem;
- color: #6c757d;
- margin-top: 0.25rem;
- max-width: 300px;
- }
-
- .action-buttons {
- display: flex;
- gap: 0.5rem;
- flex-wrap: wrap;
- }
-
- .text-center {
- text-align: center;
- padding: 2rem;
- color: #6c757d;
- }
-
- @media (max-width: 768px) {
- .page-header {
- flex-direction: column;
- gap: 1rem;
- align-items: stretch;
- }
-
- .filter-form {
- flex-direction: column;
- align-items: stretch;
- }
-
- .action-buttons {
- flex-direction: column;
- }
- }
- </style>
- </body>
- </html>
|