addNote((int)$instanceId, $message, (int)$userId); if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-Type: application/json'); echo json_encode(['message' => 'Note added successfully.']); } else { header('Location: ' . $_SERVER['HTTP_REFERER']); } exit;