Thesaurus/ajax/newSubject.php
2026-02-23 16:11:35 +01:00

51 lines
1.7 KiB
PHP

<?php
/**
* newSubject.php - Erstellt einen neuen Schlagwort-Eintrag
*
* Nutzt die CRUD-Klasse aus libAuthorities.php
*/
header('Content-Type: application/json; charset=utf-8');
include "db_connection.php";
include "libAuthorities.php";
// Parameter aus JavaScript (SubjectScript.js → CreateNewEntry)
$term = isset($_POST['term']) ? trim($_POST['term']) : '';
$detailType = isset($_POST['detailtype']) ? trim($_POST['detailtype']) : '';
$classification = isset($_POST['classification']) ? trim($_POST['classification']) : '';
$scopenote = isset($_POST['scopenote']) ? trim($_POST['scopenote']) : '';
if (empty($term)) {
echo json_encode(['status' => 400, 'message' => 'Bitte Schlagwort eingeben!']);
exit();
}
try {
$crud = new CRUD();
// Normalisierten Descriptor-Text erzeugen (entspricht Anchor.Text in der DB)
$desc = $crud->prepare_desc($term);
$completetext = $term;
// Dubletten-Prüfung gegen Anchor.Text (normalisierte Form)
$existing = $crud->checkDuplicateByNormalizedText('Subject', $desc);
if ($existing > 0) {
echo json_encode(['status' => 409, 'message' => 'Ein Schlagwort mit diesem Begriff existiert bereits']);
exit();
}
// Neuen Eintrag erstellen
$result = $crud->insertNewTerm('Subject', $term, $desc, $detailType, $classification, $scopenote, $completetext);
echo json_encode([
'status' => 200,
'message' => 'Schlagwort erfolgreich erstellt',
'Anchor' => $result['IDAnchor'],
'Entry' => $result['IDEntry'],
'Linking' => $result['IDLinking']
]);
} catch (Exception $e) {
echo json_encode(['status' => 500, 'message' => $e->getMessage()]);
}
?>