112 lines
3.3 KiB
PHP
112 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* getAuthorityDataRaw.php - Liefert Daten für Autocomplete-Suche ODER einzelnen Eintrag per ID
|
|
*
|
|
* Parameter:
|
|
* - id: ID eines einzelnen Eintrags (für ModifyTerm)
|
|
* - search: Suchbegriff für Autocomplete (min. 2 Zeichen)
|
|
* - authType: Typ (Subject, Person, Corporate, Publisher, Classification)
|
|
* - limit: Max. Anzahl Ergebnisse (Standard: 10)
|
|
*/
|
|
|
|
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(['rows' => []]);
|
|
exit();
|
|
}
|
|
|
|
mysqli_set_charset($conn, "utf8");
|
|
|
|
// Prüfen ob ID-Abfrage (für ModifyTerm)
|
|
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
|
|
|
if ($id > 0) {
|
|
// Einzelnen Eintrag per ID laden
|
|
$sql = "SELECT a.ID, a.Type, a.DetailType, a.Classification,
|
|
e.Text, e.CompleteText, e.Comment as Scopenote
|
|
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) {
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
// Descriptor erstellen
|
|
$descriptor = strtolower($row['Text'] ?? '');
|
|
$descriptor = str_replace(' ', '_', $descriptor);
|
|
|
|
echo json_encode([
|
|
'rows' => [[
|
|
'ID' => $row['ID'],
|
|
'Type' => $row['Type'],
|
|
'DetailType' => $row['DetailType'] ?? '',
|
|
'Classification' => $row['Classification'] ?? '',
|
|
'Text' => $row['Text'] ?? '',
|
|
'CompleteText' => $row['CompleteText'] ?? '',
|
|
'Scopenote' => $row['Scopenote'] ?? '',
|
|
'Descriptor' => $descriptor
|
|
]]
|
|
], JSON_UNESCAPED_UNICODE);
|
|
} else {
|
|
echo json_encode(['rows' => []]);
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
exit();
|
|
}
|
|
|
|
// Sonst: Autocomplete-Suche
|
|
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
|
|
$authType = isset($_GET['authType']) ? trim($_GET['authType']) : '';
|
|
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
|
|
|
|
if (strlen($search) < 2) {
|
|
echo json_encode([]);
|
|
exit();
|
|
}
|
|
|
|
// Erlaubte Typen
|
|
$allowedTypes = ['Subject', 'Person', 'Corporate', 'Publisher', 'Classification'];
|
|
|
|
// SQL aufbauen
|
|
$searchEscaped = mysqli_real_escape_string($conn, $search);
|
|
|
|
$sql = "SELECT a.ID, a.Type, a.DetailType, e.Text, e.CompleteText
|
|
FROM Anchor a
|
|
LEFT JOIN Entry e ON a.ID = e.ID
|
|
WHERE (e.Text LIKE '%{$searchEscaped}%' OR e.CompleteText LIKE '%{$searchEscaped}%')";
|
|
|
|
// Typ-Filter falls angegeben
|
|
if (!empty($authType) && in_array($authType, $allowedTypes)) {
|
|
$sql .= " AND a.Type = '" . mysqli_real_escape_string($conn, $authType) . "'";
|
|
}
|
|
|
|
$sql .= " ORDER BY e.Text ASC LIMIT $limit";
|
|
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|
$data = [];
|
|
if ($result) {
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$data[] = [
|
|
'id' => $row['ID'],
|
|
'value' => $row['Text'],
|
|
'text' => $row['Text'],
|
|
'type' => $row['Type'],
|
|
'detailType' => $row['DetailType'] ?? '',
|
|
'completeText' => $row['CompleteText'] ?? ''
|
|
];
|
|
}
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
?>
|