requireAuth(); $comment = new Comment(); $user = $auth->getUser(); // Handle actions $action = $_GET['action'] ?? ''; $message = ''; if ($action === 'approve' && isset($_GET['id'])) { $id = (int)$_GET['id']; if ($comment->updateStatus($id, 'approved')) { $message = t('admin_comment_approved_success'); } else { $message = t('admin_comment_approve_error'); } header('Location: comments.php?message=' . urlencode($message)); exit; } if ($action === 'reject' && isset($_GET['id'])) { $id = (int)$_GET['id']; if ($comment->updateStatus($id, 'rejected')) { $message = t('admin_comment_rejected_success'); } else { $message = t('admin_comment_reject_error'); } header('Location: comments.php?message=' . urlencode($message)); exit; } if ($action === 'delete' && isset($_GET['id'])) { $id = (int)$_GET['id']; if ($comment->delete($id)) { $message = t('admin_comment_deleted_success'); } else { $message = t('admin_comment_delete_error'); } header('Location: comments.php?message=' . urlencode($message)); exit; } if ($action === 'reply' && isset($_POST['comment_id']) && isset($_POST['reply_content'])) { $commentId = (int)$_POST['comment_id']; $replyContent = trim($_POST['reply_content']); // Get original comment to get publication ID $originalComment = $comment->getById($commentId); if ($originalComment && !empty($replyContent)) { $replyData = [ 'publication_id' => $originalComment['publication_id'], 'parent_id' => $commentId, 'name' => $user['username'], 'content' => $replyContent, 'replied_by' => $user['id'] ]; if ($comment->createAdminReply($replyData)) { $message = t('admin_reply_added_success'); } else { $message = t('admin_reply_add_error'); } } else { $message = t('admin_reply_invalid_data'); } header('Location: comments.php?message=' . urlencode($message)); exit; } // Get pagination parameters $page = max(1, (int)($_GET['page'] ?? 1)); $limit = 20; $offset = ($page - 1) * $limit; // Get status filter $status = $_GET['status'] ?? ''; // Get comments $comments = $comment->getAll($status ?: null, $limit, $offset); $totalComments = $comment->getCountByStatus($status ?: null); $totalPages = ceil($totalComments / $limit); // Handle message from redirect if (isset($_GET['message'])) { $message = htmlspecialchars($_GET['message']); } ?> <?php echo t('manage_comments'); ?> - <?php echo SITE_TITLE; ?>

()

:
1): ?>