prepare('SELECT * FROM animal_records WHERE id = ? AND rand = ?'); $stmt->execute([$recordId, $randId]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { http_response_code(404); die('Animal record not found'); } // Load saved report comments $savedComments = [ 'general_details' => '', 'ai_interpretation' => '', 'recommended_details' => '', 'foliar_details' => '', ]; $stmtRpt = $pdo->prepare( 'SELECT comment FROM reports WHERE record_id = ? AND modx_user_id = ? ORDER BY id DESC LIMIT 1' ); $stmtRpt->execute([$recordId, $userId]); $savedRow = $stmtRpt->fetchColumn(); if ($savedRow) { $decoded = json_decode($savedRow, true); if (is_array($decoded)) { $savedComments = array_merge($savedComments, $decoded); } } } catch (PDOException $e) { error_log('DB error in animal-report.php: ' . $e->getMessage()); die('Database error occurred'); } $h = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8'); $today = date('jS F Y'); $pageTitle = 'Animal Dietary Report' . (!empty($row['client_name']) ? ' — ' . $row['client_name'] : ''); $siteName = 'Crop Monitor'; function formatReportText(string $text): string { if (trim($text) === '') { return '
No content saved.
'; } $parsedown = new Parsedown(); $parsedown->setSafeMode(true); return $parsedown->text($text); } include __DIR__ . '/../../../layouts/header.php'; ?>