Răsfoiți Sursa

Updated Plant Analysis

Benjamin Harris 2 luni în urmă
părinte
comite
ad7450ee9b

+ 0 - 8
dashboard/crop-analysis/plant-test-data/plant-analysis.php

@@ -128,14 +128,6 @@ if (!$printMode) {
     .border-top    { border-top: 1px solid #dee2e6; }
 </style>
 
-<div id="layoutSidenav">
-    <div id="layoutSidenav_nav">
-    </div>
-    <div id="layoutSidenav_content">
-        <main>
-            <div class="container-fluid px-4">
-
-
 <div class="container" id="content">
 
     <?php if (!$row): ?>

+ 15 - 6
dashboard/crop-analysis/plant-test-data/plant-report-pdf.php

@@ -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>

+ 3 - 1
dashboard/crop-analysis/plant-test-data/plant-report.php

@@ -224,7 +224,7 @@ include __DIR__ . '/../../../layouts/header.php';
                                 <button type="button" class="btn btn-outline-primary btn-sm ai-generate-btn"
                                         data-section="foliar" data-target="#foliar_details">
                                     <i class="fas fa-robot me-1"></i>Generate with AI
-                                </button>`
+                                </button>
                             </div>
                         </div>
                         <div class="card-body">
@@ -397,3 +397,5 @@ include __DIR__ . '/../../../layouts/header.php';
 
 })();
 </script>
+
+<?php include __DIR__ . '/../../../layouts/footer.php'; ?>