| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- /**
- * Plant analysis results display page.
- * Loads a single plant_records row by rid + rand params.
- */
- require_once __DIR__ . '/../../../config/database.php';
- require_once __DIR__ . '/../../../lib/auth.php';
- if (session_status() === PHP_SESSION_NONE) {
- session_start();
- }
- requireLogin();
- $pdo = getDBConnection();
- $userId = getCurrentUserId();
- $recordId = (int) ($_GET['rid'] ?? 0);
- $randId = (float) ($_GET['rand'] ?? 0);
- $row = null;
- $specs = [];
- if ($recordId > 0) {
- $stmt = $pdo->prepare('SELECT * FROM plant_records WHERE id = ? AND rand = ? LIMIT 1');
- $stmt->execute([$recordId, $randId]);
- $row = $stmt->fetch();
- }
- if ($row) {
- $crop = $row['crop'] ?? '';
- $stmt = $pdo->prepare('SELECT * FROM plant_specifications WHERE crop = ? LIMIT 1');
- $stmt->execute([$crop]);
- $specs = $stmt->fetch() ?: [];
- }
- $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
- function statusBar(float $found, float $min, float $max): string {
- if ($max <= 0) return '<td colspan="3" class="text-muted text-center small">N/A</td>';
- $pct = ($max > $min) ? min(100, max(0, ($found - $min) / ($max - $min) * 100)) : 0;
- if ($found < $min) {
- $bar = '<td class="text-center"><div class="progress"><div class="progress-bar bg-danger" style="width:100%"></div></div></td>';
- $bar .= '<td></td><td></td>';
- } elseif ($found > $max) {
- $bar = '<td></td><td></td>';
- $bar .= '<td class="text-center"><div class="progress"><div class="progress-bar bg-warning" style="width:100%"></div></div></td>';
- } else {
- $bar = '<td></td>';
- $bar .= '<td class="text-center"><div class="progress"><div class="progress-bar bg-success" style="width:' . round($pct) . '%"></div></div></td>';
- $bar .= '<td></td>';
- }
- return $bar;
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Plant Analysis | Crop Monitor</title>
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" crossorigin="anonymous" rel="stylesheet">
- <link href="/client-assets/css/dashboard.css" rel="stylesheet">
- <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.3/html2pdf.bundle.min.js" crossorigin="anonymous"></script>
- <style>
- @media print {
- @page { size: A4 portrait; margin: 0.5cm; }
- .d-print-none { display: none !important; }
- }
- .progress { border-radius: 0 !important; }
- table.chart { width: 100%; border-collapse: collapse; }
- table.chart th, table.chart td { padding: 3px 6px; font-size: 0.85rem; }
- .chart-header th { background: #343a40; color: white; }
- .chart-header-sub th { background: #6c757d; color: white; }
- .lightgreen { background: #d4edda !important; color: #155724 !important; }
- .lightred { background: #f8d7da !important; color: #721c24 !important; }
- .lightpurple { background: #e2d9f3 !important; color: #432874 !important; }
- .stripe-1 { background: #f8f9fa; }
- .border-left { border-left: 1px solid #dee2e6; }
- .border-right { border-right: 1px solid #dee2e6; }
- .border-bottom { border-bottom: 1px solid #dee2e6; }
- .border-top { border-top: 1px solid #dee2e6; }
- </style>
- </head>
- <body>
- <div class="container" id="content">
- <?php if (!$row): ?>
- <div class="alert alert-danger mt-4">Record not found or access denied.</div>
- <?php else: ?>
- <div class="row mb-3">
- <div class="col-md-3">
- <img class="img-fluid" src="/client-assets/images/crop-monitor.png" alt="Crop Monitor">
- </div>
- </div>
- <div class="d-print-none mb-3">
- <button class="btn btn-success btn-sm downloadPDF">
- <i class="fas fa-download me-1"></i>Download PDF
- </button>
- </div>
- <div class="row">
- <div class="col-md-12 text-center fw-bold h4">ANALYSIS RESULTS</div>
- </div>
- <hr class="p-1 m-1">
- <table class="chart">
- <tbody>
- <tr class="chart-header">
- <th colspan="3" class="text-center border-left border-right border-top">ELEMENT</th>
- <th colspan="3" class="text-center border-right border-top">STATUS</th>
- </tr>
- <tr class="chart-header-sub">
- <th class="text-center border-bottom border-left">Elements</th>
- <th class="text-center border-bottom">Desired</th>
- <th class="text-center border-bottom">Found</th>
- <th class="text-center stripe-1">Deficient</th>
- <th class="text-center stripe-1">Ideal</th>
- <th class="text-center border-right stripe-1">High</th>
- </tr>
- <tr>
- <td class="border-left" colspan="6"></td>
- </tr>
- <tr class="chart-header-sub">
- <th colspan="3" class="border-left text-center lightgreen">MAJOR ELEMENTS</th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left border-right stripe-1"></th>
- </tr>
- <?php
- $majorElements = [
- ['n', 'Nitrogen', '%'],
- ['p', 'Phosphorus', '%'],
- ['k', 'Potassium', '%'],
- ['mg', 'Magnesium', '%'],
- ['ca', 'Calcium', '%'],
- ['na', 'Sodium', '%'],
- ];
- foreach ($majorElements as [$el, $nutrient, $unit]):
- $found = (float) ($row[$el] ?? 0);
- $min = (float) ($specs['min_' . $el] ?? 0);
- $max = (float) ($specs['max_' . $el] ?? 0);
- $desired = ($min > 0 || $max > 0) ? number_format($min, 2) . '–' . number_format($max, 2) : '—';
- ?>
- <tr>
- <td class="border-left"><?= $h($nutrient) ?> (<?= $h($unit) ?>)</td>
- <td><?= $h($desired) ?></td>
- <td><?= $found > 0 ? number_format($found, 3) : '—' ?></td>
- <?= statusBar($found, $min, $max) ?>
- </tr>
- <?php endforeach; ?>
- <tr><td colspan="6" class="border-left"></td></tr>
- <tr class="chart-header-sub">
- <th colspan="3" class="border-left text-center lightred">TRACE ELEMENTS</th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left border-right stripe-1"></th>
- </tr>
- <tr><td colspan="6" class="border-left"></td></tr>
- <?php
- $traceElements = [
- ['fe', 'Iron', 'ppm'],
- ['mn', 'Manganese', 'ppm'],
- ['zn', 'Zinc', 'ppm'],
- ['cu', 'Copper', 'ppm'],
- ['b', 'Boron', 'ppm'],
- ];
- foreach ($traceElements as [$el, $nutrient, $unit]):
- $found = (float) ($row[$el] ?? 0);
- $min = (float) ($specs['min_' . $el] ?? 0);
- $max = (float) ($specs['max_' . $el] ?? 0);
- $desired = ($min > 0 || $max > 0) ? number_format($min, 1) . '–' . number_format($max, 1) : '—';
- ?>
- <tr>
- <td class="border-left"><?= $h($nutrient) ?> (<?= $h($unit) ?>)</td>
- <td><?= $h($desired) ?></td>
- <td><?= $found > 0 ? number_format($found, 2) : '—' ?></td>
- <?= statusBar($found, $min, $max) ?>
- </tr>
- <?php endforeach; ?>
- <tr><td colspan="6" class="border-left"></td></tr>
- <tr class="chart-header-sub">
- <th colspan="3" class="border-left text-center lightpurple">MACRO ELEMENTS</th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left stripe-1"></th>
- <th class="text-center border-left border-right stripe-1"></th>
- </tr>
- <?php
- $macroElements = [
- ['m', 'Molybdenum', 'ppm'],
- ['co', 'Cobalt', 'ppm'],
- ['se', 'Selenium', 'ppm'],
- ['cl', 'Chloride', 'ppm'],
- ['c', 'Carbon', 'ppm'],
- ];
- foreach ($macroElements as [$el, $nutrient, $unit]):
- $found = (float) ($row[$el] ?? 0);
- $min = (float) ($specs['min_' . $el] ?? 0);
- $max = (float) ($specs['max_' . $el] ?? 0);
- $desired = ($min > 0 || $max > 0) ? number_format($min, 2) . '–' . number_format($max, 2) : '—';
- ?>
- <tr>
- <td class="border-left"><?= $h($nutrient) ?> (<?= $h($unit) ?>)</td>
- <td><?= $h($desired) ?></td>
- <td><?= $found > 0 ? number_format($found, 3) : '—' ?></td>
- <?= statusBar($found, $min, $max) ?>
- </tr>
- <?php endforeach; ?>
- <tr>
- <td class="border-bottom border-left"></td>
- <td class="border-bottom"></td>
- <td class="border-bottom"></td>
- <td class="border-bottom"></td>
- <td class="border-bottom"></td>
- <td class="border-bottom border-right"></td>
- </tr>
- </tbody>
- </table>
- <div class="mt-4 small text-muted">
- <p><i class="fa fa-leaf" style="color:green"></i> It is always an advantage to assess tissue analysis results along with a corresponding soil analysis for more accurate diagnosis of plant nutrient status.</p>
- <p><i class="fa fa-leaf" style="color:green"></i> Trace element levels — manganese, copper and zinc — can all be affected by fungicide spray residues, giving misleading results.</p>
- <p><i class="fa fa-leaf" style="color:green"></i> Talk to your qualified consultant to make a plan for correction or maintenance of the found nutrient levels.</p>
- <p style="font-style:italic;font-size:9px;">Desired ranges indexed from: CSIRO Plant Analysis Handbook 2nd Ed. Hill Laboratories consultants guide. PIRSA Soil and Plant Analysis.</p>
- <p style="font-style:italic;font-size:9px;">Any recommendations provided by Cropmonitor are advice only. We are not paid consultants and are not covered to accept responsibility for any of our suggestions.</p>
- </div>
- <?php endif; ?>
- </div>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
- <script>
- document.querySelector('.downloadPDF') && document.querySelector('.downloadPDF').addEventListener('click', function () {
- var opt = {
- margin: 3,
- filename: 'plant-analysis.pdf',
- image: { type: 'jpeg', quality: 1.0 },
- html2canvas: { scale: 2, letterRendering: true, windowWidth: 1024 },
- jsPDF: { orientation: 'portrait', unit: 'mm', format: 'a4' }
- };
- html2pdf().from(document.getElementById('content')).set(opt).save();
- });
- </script>
- </body>
- </html>
|