requireAuth(); $publication = new Publication(); $user = $auth->getUser(); // Handle actions $action = $_GET['action'] ?? ''; $message = ''; if ($action === 'delete' && isset($_GET['id'])) { $id = (int)$_GET['id']; try { $publication->delete($id); $message = 'Publication deleted successfully'; } catch (Exception $e) { $message = 'Error deleting publication: ' . $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); ?>