&rand= * Headless Chrome: ?rid=&rand=&ptoken= */ require_once __DIR__ . '/../../../config/database.php'; require_once __DIR__ . '/../../../lib/auth.php'; require_once __DIR__ . '/../../../lib/print_auth.php'; require_once __DIR__ . '/../../../vendor/autoload.php'; if (session_status() === PHP_SESSION_NONE) { session_start(); } $recordId = (int) ($_GET['rid'] ?? 0); $randId = trim( $_GET['rand'] ?? ''); $clientId = (int) ($_GET['cid'] ?? 0); $printMode = isset($_GET['ptoken']) || isset($_GET['print']); if (!$recordId || $randId === '') { http_response_code(400); die('Invalid request parameters'); } $chromeAccess = authenticatePrintPage($recordId, $randId); try { $pdo = getDBConnection(); $userId = $chromeAccess ? null : getCurrentUserId(); $stmt = $pdo->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' => '', ]; $reportUserId = $userId ?? (int)($row['modx_user_id'] ?? 0); $stmtRpt = $pdo->prepare( 'SELECT comment FROM reports WHERE record_id = ? AND modx_user_id = ? ORDER BY id DESC LIMIT 1' ); $stmtRpt->execute([$recordId, $reportUserId]); $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-pdf.php: ' . $e->getMessage()); die('Database error occurred'); } $h = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8'); $today = date('jS F Y'); function formatReportText(string $text): string { if (trim($text) === '') { return '

No content saved.

'; } $parsedown = new Parsedown(); $parsedown->setSafeMode(true); return $parsedown->text($text); } ?> Animal Dietary Balance Report | Crop Monitor
Record not found or access denied.
Crop Monitor
Animal Dietary Balance Report
CLIENT: SAMPLE ID:
SITE ID: DATE SAMPLED:
ANALYSIS TYPE: LAB NUMBER:

General Comment
AI Dietary Interpretation
Recommended Supplementation Program
Ongoing Management Program

Any recommendations provided by Crop Monitor are advice only. We are not paid consultants and accept no responsibility for any of our suggestions.