ソースを参照

Markdown Updates

Benjamin Harris 2 ヶ月 前
コミット
b0f1d69a5b

+ 19 - 2
client-assets/css/graphPrint.css

@@ -5,8 +5,25 @@
 */
 @media print {
     @page {
-        size: A4 portrait;
-        margin: 0.25cm;
+            size: A4 portrait;
+        }
+    @page :left {
+        margin-left: 0.5cm;
+    }
+    @page :right {
+        margin-right: 0.5cm;
+    }
+    @page :top {
+        margin-top: 0cm;
+    }
+    @page :bottom {
+        margin-bottom: 0cm;
+    }
+    body {
+        min-width: 992px !important;
+    }
+    .container {
+        min-width: 992px !important;
     }
 
     body {

+ 87 - 0
dashboard/crop-analysis/compost-test-data/compost-report.php

@@ -0,0 +1,87 @@
+<?php
+/**
+ * dashboard/crop-analysis/plant-test-data/plant-report.php
+ *
+ * Plant analysis report — editable sections with auto-save and Ollama AI interpretation.
+ */
+
+require_once __DIR__ . '/../../../config/database.php';
+require_once __DIR__ . '/../../../lib/auth.php';
+require_once __DIR__ . '/../../../lib/csrf.php';
+
+requireLogin();
+
+$recordId = (int)  ($_GET['rid']  ?? 0);
+$randId   = trim(  $_GET['rand']  ?? '');
+$clientId = (int)  ($_GET['cid']  ?? 0);
+
+if (!$recordId || $randId === '') {
+    http_response_code(400);
+    die('Invalid request parameters');
+}
+
+try {
+    $pdo    = getDBConnection();
+    $userId = getCurrentUserId();
+
+    $stmt = $pdo->prepare('SELECT * FROM plant_records WHERE id = ? AND rand = ?');
+    $stmt->execute([$recordId, $randId]);
+    $row = $stmt->fetch(PDO::FETCH_ASSOC);
+
+    if (!$row) {
+        http_response_code(404);
+        die('Plant record not found');
+    }
+
+    // Load spec ranges
+    $specs = [];
+    if (!empty($row['crop_type'])) {
+        $stmtSpec = $pdo->prepare('SELECT * FROM plant_specifications WHERE plant_type = ? LIMIT 1');
+        $stmtSpec->execute([$row['crop_type']]);
+        $specs = $stmtSpec->fetch(PDO::FETCH_ASSOC) ?: [];
+    }
+
+    // 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 plant-report.php: ' . $e->getMessage());
+    die('Database error occurred');
+}
+
+$h         = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8');
+$today     = date('jS F Y');
+$pageTitle = 'Compost Report' . (!empty($row['client_name']) ? ' — ' . $row['client_name'] : '');
+$siteName  = 'Crop Monitor';
+
+include __DIR__ . '/../../../layouts/header.php';
+?>
+<link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
+<style>
+    @media print {
+        .report-textarea {
+            border:none;
+        }
+    }
+    .report-textarea {
+        overflow: hidden;
+        resize: none;
+        overflow-y: auto;
+    }
+</style>

+ 23 - 22
dashboard/crop-analysis/plant-test-data/plant-report.php

@@ -8,6 +8,7 @@
 require_once __DIR__ . '/../../../config/database.php';
 require_once __DIR__ . '/../../../lib/auth.php';
 require_once __DIR__ . '/../../../lib/csrf.php';
+require_once __DIR__ . '/../../../vendor/autoload.php';
 
 requireLogin();
 
@@ -70,36 +71,32 @@ $today     = date('jS F Y');
 $pageTitle = 'Plant Report' . (!empty($row['client_name']) ? ' — ' . $row['client_name'] : '');
 $siteName  = 'Crop Monitor';
 
+// Parse and render markdown text from AI-generated report sections
+function formatReportText(string $text): string
+{
+    if (trim($text) === '') {
+        return '<p class="text-muted fst-italic">No content saved.</p>';
+    }
+    $parsedown = new Parsedown();
+    $parsedown->setSafeMode(true);
+    return $parsedown->text($text);
+}
+
 include __DIR__ . '/../../../layouts/header.php';
 ?>
 <link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
 <style>
     @media print {
-        @page {
-            size: A4 portrait;
-        }
-        @page :left {
-            margin-left: 0.5cm;
-        }
-        @page :right {
-            margin-right: 0.5cm;
-        }
-        @page :top {
-            margin-top: 0cm;
-        }
-        @page :bottom {
-            margin-bottom: 0cm;
-        }
-        body {
-            min-width: 992px !important;
-        }
-        .container {
-            min-width: 992px !important;
-        }
         .report-textarea {
-            border:none;
+            display: none;
+        }
+        .report-print-preview {
+            display: block !important;
         }
     }
+    .report-print-preview {
+        display: none;
+    }
     .report-textarea {
         overflow: hidden;
         resize: none;
@@ -170,6 +167,7 @@ include __DIR__ . '/../../../layouts/header.php';
                                       class="form-control report-textarea" rows="6"
                                       placeholder="Enter a general comment on this plant analysis..."
                             ><?= $h($savedComments['general_details']) ?></textarea>
+                            <div class="report-print-preview"><?= formatReportText($savedComments['general_details']) ?></div>
                         </div>
                     </div>
 
@@ -190,6 +188,7 @@ include __DIR__ . '/../../../layouts/header.php';
                                       class="form-control report-textarea" rows="10"
                                       placeholder="Click 'Interpret with AI' to generate an interpretation, or type manually..."
                             ><?= $h($savedComments['ai_interpretation']) ?></textarea>
+                            <div class="report-print-preview"><?= formatReportText($savedComments['ai_interpretation']) ?></div>
                         </div>
                     </div>
 
@@ -207,6 +206,7 @@ include __DIR__ . '/../../../layouts/header.php';
                                       class="form-control report-textarea" rows="6"
                                       placeholder="Enter recommended remedial program details..."
                             ><?= $h($savedComments['recommended_details']) ?></textarea>
+                            <div class="report-print-preview"><?= formatReportText($savedComments['recommended_details']) ?></div>
                         </div>
                     </div>
 
@@ -224,6 +224,7 @@ include __DIR__ . '/../../../layouts/header.php';
                                       class="form-control report-textarea" rows="6"
                                       placeholder="Enter foliar spray program details..."
                             ><?= $h($savedComments['foliar_details']) ?></textarea>
+                            <div class="report-print-preview"><?= formatReportText($savedComments['foliar_details']) ?></div>
                         </div>
                     </div>
 

+ 0 - 22
dashboard/crop-analysis/soil-test-data/soil-report-pdf.php

@@ -123,32 +123,10 @@ function formatReportText(string $text): string
     <link rel="stylesheet" href="/client-assets/css/graphPrint.css" media="print">
     <style>
         @media print {
-            @page {
-                size: A4 portrait;
-            }
-            @page :left {
-                margin-left: 0.5cm;
-            }
-            @page :right {
-                margin-right: 0.5cm;
-            }
-            @page :top {
-                margin-top: 0cm;
-            }
-            @page :bottom {
-                margin-bottom: 0cm;
-            }
-            body {
-                min-width: 992px !important;
-            }
-            .container {
-                min-width: 992px !important;
-            }
             .d-print-none  { display: none !important; }
             .page-break    { page-break-before: always; }
             body           { font-size: 11px; }
             .report-section p { font-size: 11px; }
-
         }
         .report-section p   { margin-bottom: 0.6rem; line-height: 1.6; }
         .report-section h1,

+ 23 - 22
dashboard/crop-analysis/soil-test-data/soil-report.php

@@ -9,6 +9,7 @@ require_once __DIR__ . '/../../../config/database.php';
 require_once __DIR__ . '/../../../lib/auth.php';
 require_once __DIR__ . '/../../../lib/csrf.php';
 require_once __DIR__ . '/../../../lib/soil_calculations.php';
+require_once __DIR__ . '/../../../vendor/autoload.php';
 
 requireLogin();
 
@@ -113,6 +114,17 @@ function calcDeficit(array $row, array $spec, string $col, string $minCol, strin
     return $deficit > 0 ? round($deficit, 2) : 0.0;
 }
 
+// Parse and render markdown text from AI-generated report sections
+function formatReportText(string $text): string
+{
+    if (trim($text) === '') {
+        return '<p class="text-muted fst-italic">No content saved.</p>';
+    }
+    $parsedown = new Parsedown();
+    $parsedown->setSafeMode(true);
+    return $parsedown->text($text);
+}
+
 include __DIR__ . '/../../../layouts/header.php';
 ?>
 <link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
@@ -120,31 +132,16 @@ include __DIR__ . '/../../../layouts/header.php';
     * { margin: 0; padding: 0; box-sizing: border-box; }
         body { background: #fff; }
     @media print {
-        @page {
-            size: A4 portrait;
-        }
-        @page :left {
-            margin-left: 0.5cm;
-        }
-        @page :right {
-            margin-right: 0.5cm;
-        }
-        @page :top {
-            margin-top: 0cm;
-        }
-        @page :bottom {
-            margin-bottom: 0cm;
-        }
-        body {
-            min-width: 992px !important;
-        }
-        .container {
-            min-width: 992px !important;
-        }
         .report-textarea {
-            border:none;
+            display: none;
+        }
+        .report-print-preview {
+            display: block !important;
         }
     }
+    .report-print-preview {
+        display: none;
+    }
     .element-required-module .card-group .col {
         padding: 0 10px;
     }
@@ -286,6 +283,7 @@ include __DIR__ . '/../../../layouts/header.php';
                 <textarea id="overview" name="overview" class="form-control report-textarea" rows="6"
                           placeholder="Enter an overview of the soil analysis results..."
                 ><?= htmlspecialchars($savedComments['overview'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
+                <div class="report-print-preview"><?= formatReportText($savedComments['overview'] ?? '') ?></div>
             </div>
         </div>
 
@@ -306,6 +304,7 @@ include __DIR__ . '/../../../layouts/header.php';
                           class="form-control report-textarea" rows="10"
                           placeholder="Click 'Interpret with AI' to generate an agronomic interpretation, or type manually..."
                 ><?= htmlspecialchars($savedComments['ai_interpretation'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
+                <div class="report-print-preview"><?= formatReportText($savedComments['ai_interpretation'] ?? '') ?></div>
             </div>
         </div>
 
@@ -326,6 +325,7 @@ include __DIR__ . '/../../../layouts/header.php';
                           class="form-control report-textarea" rows="6"
                           placeholder="Enter the foliar spray program details..."
                 ><?= htmlspecialchars($savedComments['foliar_details'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
+                <div class="report-print-preview"><?= formatReportText($savedComments['foliar_details'] ?? '') ?></div>
             </div>
         </div>
 
@@ -343,6 +343,7 @@ include __DIR__ . '/../../../layouts/header.php';
                           class="form-control report-textarea" rows="6"
                           placeholder="Enter the microbial / biological program details..."
                 ><?= htmlspecialchars($savedComments['microbe_program'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
+                <div class="report-print-preview"><?= formatReportText($savedComments['microbe_program'] ?? '') ?></div>
             </div>
         </div>
 

+ 87 - 0
dashboard/crop-analysis/water-test-data/water-report.php

@@ -0,0 +1,87 @@
+<?php
+/**
+ * dashboard/crop-analysis/plant-test-data/plant-report.php
+ *
+ * Plant analysis report — editable sections with auto-save and Ollama AI interpretation.
+ */
+
+require_once __DIR__ . '/../../../config/database.php';
+require_once __DIR__ . '/../../../lib/auth.php';
+require_once __DIR__ . '/../../../lib/csrf.php';
+
+requireLogin();
+
+$recordId = (int)  ($_GET['rid']  ?? 0);
+$randId   = trim(  $_GET['rand']  ?? '');
+$clientId = (int)  ($_GET['cid']  ?? 0);
+
+if (!$recordId || $randId === '') {
+    http_response_code(400);
+    die('Invalid request parameters');
+}
+
+try {
+    $pdo    = getDBConnection();
+    $userId = getCurrentUserId();
+
+    $stmt = $pdo->prepare('SELECT * FROM plant_records WHERE id = ? AND rand = ?');
+    $stmt->execute([$recordId, $randId]);
+    $row = $stmt->fetch(PDO::FETCH_ASSOC);
+
+    if (!$row) {
+        http_response_code(404);
+        die('Plant record not found');
+    }
+
+    // Load spec ranges
+    $specs = [];
+    if (!empty($row['crop_type'])) {
+        $stmtSpec = $pdo->prepare('SELECT * FROM plant_specifications WHERE plant_type = ? LIMIT 1');
+        $stmtSpec->execute([$row['crop_type']]);
+        $specs = $stmtSpec->fetch(PDO::FETCH_ASSOC) ?: [];
+    }
+
+    // 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 plant-report.php: ' . $e->getMessage());
+    die('Database error occurred');
+}
+
+$h         = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8');
+$today     = date('jS F Y');
+$pageTitle = 'Water Report' . (!empty($row['client_name']) ? ' — ' . $row['client_name'] : '');
+$siteName  = 'Crop Monitor';
+
+include __DIR__ . '/../../../layouts/header.php';
+?>
+<link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
+<style>
+    @media print {
+        .report-textarea {
+            border:none;
+        }
+    }
+    .report-textarea {
+        overflow: hidden;
+        resize: none;
+        overflow-y: auto;
+    }
+</style>