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

53 lines
1.6 KiB
PHP

<?php
/**
* newCorporate.php - Erstellt einen neuen Körperschaftseintrag
*
* 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
$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 Namen eingeben!']);
exit();
}
try {
$crud = new CRUD();
// Descriptor erstellen (für Anchor.Text)
$desc = $crud->prepare_desc($term);
$completetext = $term;
// Prüfen ob bereits existiert
$existing = $crud->readAuthorityNumbersOfRecords('Corporate', $term, 0, true);
if ($existing > 0) {
echo json_encode(['status' => 409, 'message' => 'Eine Körperschaft mit diesem Namen existiert bereits']);
exit();
}
// Neuen Eintrag erstellen
$result = $crud->insertNewTerm('Corporate', $term, $desc, $detailType, $classification, $scopenote, $completetext);
echo json_encode([
'status' => 200,
'message' => 'Körperschaft erfolgreich erstellt',
'Anchor' => $result['IDAnchor'],
'Entry' => $result['IDEntry'],
'Linking' => $result['IDLinking']
]);
} catch (Exception $e) {
echo json_encode(['status' => 500, 'message' => $e->getMessage()]);
}
?>