setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $clients = $pdo->query("SELECT clientCode FROM clients ORDER BY clientCode")->fetchAll(PDO::FETCH_COLUMN) ?: []; $questionnaireIds = $pdo->query("SELECT id FROM questionnaires")->fetchAll(PDO::FETCH_COLUMN) ?: []; $qidSet = array_fill_keys($questionnaireIds, true); $completed = []; $stmt = $pdo->query("SELECT clientCode, questionnaireId, isDone FROM completed_questionnaires"); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $c = $row['clientCode'] ?? 'undefined'; $q = $row['questionnaireId'] ?? 'undefined'; $completed[$c][$q] = ((int)($row['isDone'] ?? 0)) ? true : false; } $answers = []; $stmt = $pdo->query("SELECT clientCode, questionId, answerValue FROM answers"); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $c = $row['clientCode'] ?? 'undefined'; $q = $row['questionId'] ?? 'undefined'; $answers[$c][$q] = (string)($row['answerValue'] ?? ''); } // ---- HTML ---- echo ''; echo ''; echo ''; // Row 1: checkbox + IDs (bleiben als technische Schlüssel im Kopf – Werte darunter sind übersetzt) echo ''; foreach ($order as $id) echo ''; echo ''; // Row 2: blank + English labels echo ''; foreach ($order as $id) { $lbl = $labels[$id] ?? ''; echo ''; } echo ''; foreach ($clients as $client) { echo ''; echo ''; foreach ($order as $id) { if ($id === 'client_code') { $val = $client; } elseif (isset($qidSet[$id]) && strpos($id, '-') === false) { $val = ($completed[$client][$id] ?? false) ? 'Done' : 'Not Done'; } else { $raw = $answers[$client][$id] ?? ''; $val = (strlen(trim($raw)) > 0) ? t_val($id, $raw, $vals) : 'None'; } echo ''; } echo ''; } echo '
'.htmlspecialchars($id).'
'.htmlspecialchars($lbl).'
'.htmlspecialchars($val).'
'; } catch (Throwable $e) { http_response_code(500); echo "Error: ".htmlspecialchars($e->getMessage()); } finally { @unlink($tmp); }