|
|
@@ -24,18 +24,25 @@ if (session_status() === PHP_SESSION_NONE) {
|
|
|
session_start();
|
|
|
}
|
|
|
|
|
|
-$recordId = (int) ($_GET['rid'] ?? 0);
|
|
|
-$randId = trim( $_GET['rand'] ?? '');
|
|
|
-$clientId = (int) ($_GET['cid'] ?? 0);
|
|
|
+$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');
|
|
|
}
|
|
|
|
|
|
+if ($printMode) {
|
|
|
+ authenticatePrintPage($recordId, $randId);
|
|
|
+} else {
|
|
|
+ requireLogin();
|
|
|
+}
|
|
|
+
|
|
|
try {
|
|
|
$pdo = getDBConnection();
|
|
|
- $userId = getCurrentUserId();
|
|
|
+ $userId = $printMode ? null : getCurrentUserId();
|
|
|
|
|
|
$stmt = $pdo->prepare('SELECT * FROM plant_records WHERE id = ? AND rand = ?');
|
|
|
$stmt->execute([$recordId, $randId]);
|
|
|
@@ -61,10 +68,12 @@ try {
|
|
|
'recommended_details' => '',
|
|
|
'foliar_details' => '',
|
|
|
];
|
|
|
+ // In print/headless mode there is no session user; use the record owner's id instead.
|
|
|
+ $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, $userId]);
|
|
|
+ $stmtRpt->execute([$recordId, $reportUserId]);
|
|
|
$savedRow = $stmtRpt->fetchColumn();
|
|
|
if ($savedRow) {
|
|
|
$decoded = json_decode($savedRow, true);
|
|
|
@@ -238,7 +247,7 @@ function formatReportText(string $text): string
|
|
|
</div>
|
|
|
|
|
|
<!-- ── 2. AI Interpretation ───────────────────────────────────────── -->
|
|
|
- <div class="section-header">AI Soil Interpretation</div>
|
|
|
+ <div class="section-header">AI Plant Interpretation</div>
|
|
|
<div class="section-body report-section">
|
|
|
<?= formatReportText($savedComments['ai_interpretation'] ?? '') ?>
|
|
|
</div>
|