85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* UpdateTerm.php - Aktualisiert einen bestehenden Normdaten-Eintrag
|
|
*
|
|
* Parameter (POST) - von JavaScript:
|
|
* - AnchorID: ID des Eintrags
|
|
* - authType: Typ (Subject, Person, etc.)
|
|
* - term: Neuer Anzeigetext
|
|
* - detailtype: Neuer Untertyp (optional)
|
|
* - classification: Neuer Klassifikationscode (optional)
|
|
* - scopenote: Neuer Kommentar (optional)
|
|
*/
|
|
|
|
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");
|
|
|
|
// Parameter aus JavaScript
|
|
$id = isset($_POST['AnchorID']) ? intval($_POST['AnchorID']) : 0;
|
|
if ($id === 0) {
|
|
$id = isset($_POST['ID']) ? intval($_POST['ID']) : 0;
|
|
}
|
|
$text = isset($_POST['term']) ? trim($_POST['term']) : '';
|
|
$detailType = isset($_POST['detailtype']) ? trim($_POST['detailtype']) : '';
|
|
$classification = isset($_POST['classification']) ? trim($_POST['classification']) : '';
|
|
$comment = isset($_POST['scopenote']) ? trim($_POST['scopenote']) : '';
|
|
|
|
if ($id === 0) {
|
|
echo json_encode(['success' => false, 'error' => 'ID muss angegeben werden']);
|
|
exit();
|
|
}
|
|
|
|
if (empty($text)) {
|
|
echo json_encode(['success' => false, 'error' => 'Text darf nicht leer sein']);
|
|
exit();
|
|
}
|
|
|
|
mysqli_begin_transaction($conn);
|
|
|
|
try {
|
|
// 1. Anchor aktualisieren (Text, DetailType, Classification)
|
|
$updateAnchorSql = "UPDATE Anchor SET
|
|
Text = '" . mysqli_real_escape_string($conn, $text) . "',
|
|
DetailType = '" . mysqli_real_escape_string($conn, $detailType) . "',
|
|
Classification = '" . mysqli_real_escape_string($conn, $classification) . "'
|
|
WHERE ID = $id";
|
|
|
|
if (!mysqli_query($conn, $updateAnchorSql)) {
|
|
throw new Exception('Fehler beim Aktualisieren des Anchor: ' . mysqli_error($conn));
|
|
}
|
|
|
|
// 2. Entry aktualisieren
|
|
$updateEntrySql = "UPDATE Entry SET
|
|
Text = '" . mysqli_real_escape_string($conn, $text) . "',
|
|
CompleteText = '" . mysqli_real_escape_string($conn, $text) . "',
|
|
Comment = '" . mysqli_real_escape_string($conn, $comment) . "'
|
|
WHERE ID = $id";
|
|
|
|
if (!mysqli_query($conn, $updateEntrySql)) {
|
|
throw new Exception('Fehler beim Aktualisieren des Entry: ' . mysqli_error($conn));
|
|
}
|
|
|
|
mysqli_commit($conn);
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'message' => 'Eintrag erfolgreich aktualisiert'
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
mysqli_rollback($conn);
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
?>
|