[]]); exit(); } mysqli_set_charset($conn, "utf8"); // Beide Parameter-Namen unterstützen (JS sendet 'id') $id = isset($_GET['id']) ? intval($_GET['id']) : 0; if ($id === 0) { $id = isset($_GET['ID']) ? intval($_GET['ID']) : 0; } if ($id === 0) { echo json_encode(['rows' => []]); exit(); } // Hauptdaten laden $sql = "SELECT a.ID, a.Type, a.DetailType, a.Classification, a.Text as AnchorText, e.Text, e.CompleteText, e.Comment, e.DateCreated, e.DateModified FROM Anchor a LEFT JOIN Entry e ON a.ID = e.ID WHERE a.ID = $id"; $result = mysqli_query($conn, $sql); if (!$result || mysqli_num_rows($result) === 0) { echo json_encode(['rows' => []]); mysqli_close($conn); exit(); } $data = mysqli_fetch_assoc($result); // Relationen laden im Format das JS erwartet $relSql = "SELECT l.ID as LinkingID, l.IDAnchor, l.IDEntry, l.Relationtype, e.Text as EntryText, a.Type as EntryType FROM Linking l LEFT JOIN Entry e ON l.IDEntry = e.ID LEFT JOIN Anchor a ON l.IDEntry = a.ID WHERE l.IDAnchor = $id ORDER BY l.Relationtype, e.Text"; $relResult = mysqli_query($conn, $relSql); $relations = []; if ($relResult) { while ($relRow = mysqli_fetch_assoc($relResult)) { $relations[] = [ 'Relationtype' => $relRow['Relationtype'], 'TextRelation' => $relRow['EntryText'] ?? '', 'IDRelation' => $relRow['IDEntry'] ]; } } // Synonyme laden (nur für Subject) $synonymsText = ''; if ($data['Type'] === 'Subject' && !empty($data['Text'])) { $desc = strtolower($data['Text']); $desc = str_replace(' ', '_', $desc); $synSql = "SELECT IDLinking FROM Synonyms WHERE Descriptor = '" . mysqli_real_escape_string($conn, $desc) . "' LIMIT 1"; $synResult = mysqli_query($conn, $synSql); if ($synResult && mysqli_num_rows($synResult) > 0) { $synRow = mysqli_fetch_assoc($synResult); $idLinking = $synRow['IDLinking']; $synAllSql = "SELECT Text FROM Synonyms WHERE IDLinking = $idLinking AND Descriptor != '" . mysqli_real_escape_string($conn, $desc) . "' ORDER BY Text"; $synAllResult = mysqli_query($conn, $synAllSql); $synTexts = []; if ($synAllResult) { while ($syn = mysqli_fetch_assoc($synAllResult)) { $synTexts[] = $syn['Text']; } } $synonymsText = implode(', ', $synTexts); } } // Descriptor erstellen $descriptor = strtolower($data['Text'] ?? ''); $descriptor = str_replace(' ', '_', $descriptor); mysqli_close($conn); // Rückgabe im Format das JavaScript erwartet echo json_encode([ 'rows' => [[ 'ID' => $data['ID'], 'Type' => $data['Type'], 'Detailtype' => $data['DetailType'] ?? '', 'Classification' => $data['Classification'] ?? '', 'Text' => $data['Text'] ?? '', 'CompleteText' => $data['CompleteText'] ?? '', 'Scopenote' => $data['Comment'] ?? '', 'Descriptor' => $descriptor, 'Synonyms' => $synonymsText, 'Relations' => $relations, 'DateCreated' => $data['DateCreated'] ?? '', 'DateModified' => $data['DateModified'] ?? '' ]] ], JSON_UNESCAPED_UNICODE); ?>