83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* getSynonyms.php - Lädt Synonyme für einen Begriff
|
|
*
|
|
* Parameter:
|
|
* - text: Der Begriff, für den Synonyme gesucht werden
|
|
*/
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
include "db_connection.php";
|
|
|
|
$conn = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
|
|
if (mysqli_connect_errno()) {
|
|
echo json_encode(['success' => false, 'error' => 'Datenbankverbindung fehlgeschlagen']);
|
|
exit();
|
|
}
|
|
|
|
mysqli_set_charset($conn, "utf8");
|
|
|
|
$text = isset($_GET['text']) ? trim($_GET['text']) : '';
|
|
|
|
if (empty($text)) {
|
|
echo json_encode(['success' => true, 'synonyms' => [], 'html' => '']);
|
|
exit();
|
|
}
|
|
|
|
// Descriptor erstellen (Kleinbuchstaben, Leerzeichen durch Unterstrich)
|
|
function prepare_desc($text) {
|
|
$desc = strtolower($text);
|
|
$desc = str_replace(' ', '_', $desc);
|
|
return $desc;
|
|
}
|
|
|
|
$desc = prepare_desc($text);
|
|
|
|
// Erst IDLinking für den Begriff finden
|
|
$sql = "SELECT IDLinking FROM Synonyms WHERE Descriptor = '" . mysqli_real_escape_string($conn, $desc) . "' LIMIT 1";
|
|
$res = mysqli_query($conn, $sql);
|
|
|
|
$synonyms = [];
|
|
$html = '';
|
|
|
|
if ($res && mysqli_num_rows($res) > 0) {
|
|
$row = mysqli_fetch_assoc($res);
|
|
$idLinking = $row['IDLinking'];
|
|
|
|
// Alle Synonyme mit dieser IDLinking laden (außer dem Begriff selbst)
|
|
$sql2 = "SELECT ID, Text, Descriptor FROM Synonyms WHERE IDLinking = $idLinking AND Descriptor != '" . mysqli_real_escape_string($conn, $desc) . "' ORDER BY Text";
|
|
$res2 = mysqli_query($conn, $sql2);
|
|
|
|
if ($res2) {
|
|
while ($syn = mysqli_fetch_assoc($res2)) {
|
|
$synonyms[] = [
|
|
'id' => $syn['ID'],
|
|
'text' => $syn['Text'],
|
|
'descriptor' => $syn['Descriptor']
|
|
];
|
|
|
|
// HTML für Anzeige generieren
|
|
$html .= '<tr>';
|
|
$html .= '<td><span class="badge" style="background-color: #e91e63;">SYN</span></td>';
|
|
$html .= '<td>' . htmlspecialchars($syn['Text']) . '</td>';
|
|
$html .= '<td class="text-end">';
|
|
$html .= '<button class="btn btn-sm btn-outline-danger" onclick="DeleteSynonym(\'' . addslashes($text) . '\', \'' . addslashes($syn['Text']) . '\')" title="Synonym entfernen">';
|
|
$html .= '<i class="fas fa-trash"></i>';
|
|
$html .= '</button>';
|
|
$html .= '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'synonyms' => $synonyms,
|
|
'html' => $html,
|
|
'count' => count($synonyms)
|
|
]);
|
|
|
|
mysqli_close($conn);
|
|
?>
|