commentModel = new CommentModel($conn); } public function getCommentsByTicketId($ticketId) { return $this->commentModel->getCommentsByTicketId($ticketId); } public function addComment($ticketId) { // Check if this is an AJAX request if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Get JSON data $data = json_decode(file_get_contents('php://input'), true); // Validate input if (empty($data['comment_text'])) { header('Content-Type: application/json'); echo json_encode([ 'success' => false, 'error' => 'Comment text cannot be empty' ]); return; } // Add comment $result = $this->commentModel->addComment($ticketId, $data); // Return JSON response header('Content-Type: application/json'); echo json_encode($result); } else { // For direct access, redirect to ticket view header("Location: /tinkertickets/ticket/$ticketId"); exit; } } }