'soil_records', 'plant' => 'plant_records', 'water' => 'water_records', 'animal' => 'animal_records', 'compost' => 'soil_records', // compost uses soil_records with analysis_type ]; try { $pdo = getDBConnection(); $table = $tableMap[$type]; $stmt = $pdo->prepare("SELECT * FROM {$table} WHERE id = ? AND rand = ?"); $stmt->execute([$recordId, $randId]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { http_response_code(404); die('Record not found'); } } catch (PDOException $e) { error_log('DB error in coverpage.php: ' . $e->getMessage()); die('Database error'); } $h = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8'); // ── Common fields (shared column names across all tables) ─────────────────── $clientName = $h($row['client_name'] ?? ''); $siteAddress = $h($row['site_address'] ?? ''); $statePost = $h($row['state_postcode'] ?? ''); $email = $h($row['email'] ?? ''); $labNo = $h($row['lab_no'] ?? ''); $batchNo = $h($row['batch_no'] ?? ''); $sampleId = $h($row['sample_id'] ?? ''); $siteId = $h($row['site_id'] ?? ''); $dateSampled = $h($row['date_sampled'] ?? ''); $analysisType = $h($row['analysis_type'] ?? ''); // Type-specific fields $subjectLine = ''; if ($type === 'soil' || $type === 'compost') { $subjectLine = $h($row['crop_type'] ?? $row['soil_type'] ?? ''); } elseif ($type === 'plant') { $subjectLine = $h($row['crop_type'] ?? ''); } elseif ($type === 'water') { $subjectLine = $h($row['water_source'] ?? $row['analysis_type'] ?? ''); } elseif ($type === 'animal') { $subjectLine = $h($row['animal'] ?? $row['analysis_type'] ?? ''); } // Report type label and accent colour $typeConfig = [ 'soil' => ['label' => 'Soil Analysis', 'accent' => '#4a7c4e', 'bg' => 'Vineyard-Soil.jpg'], 'plant' => ['label' => 'Plant Tissue Analysis', 'accent' => '#2e6b3e', 'bg' => 'grass.jpg'], 'water' => ['label' => 'Water Analysis', 'accent' => '#1a5f8a', 'bg' => 'irrigation-water.jpg'], 'animal' => ['label' => 'Animal Dietary Balance', 'accent' => '#7a5230', 'bg' => 'grass.jpg'], 'compost' => ['label' => 'Compost Analysis', 'accent' => '#5a4a1e', 'bg' => 'Vineyard-Soil.jpg'], ]; $cfg = $typeConfig[$type]; $label = $cfg['label']; $accent = $cfg['accent']; $bgImg = '/client-assets/images/' . $cfg['bg']; $today = date('jS F Y'); ?> <?= $label ?><?= $clientName !== '' ? ' — ' . $clientName : '' ?>