52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* newPerson.php - Erstellt einen neuen Personeneintrag
|
|
*
|
|
* 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();
|
|
|
|
// 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)
|
|
// Verhindert Fehlalarme durch abweichende Groß-/Kleinschreibung oder Sonderzeichen
|
|
$existing = $crud->checkDuplicateByNormalizedText('Person', $desc);
|
|
if ($existing > 0) {
|
|
echo json_encode(['status' => 409, 'message' => 'Eine Person mit diesem Namen existiert bereits']);
|
|
exit();
|
|
}
|
|
|
|
// Neuen Eintrag erstellen
|
|
$result = $crud->insertNewTerm('Person', $term, $desc, $detailType, $classification, $scopenote, $completetext);
|
|
|
|
echo json_encode([
|
|
'status' => 200,
|
|
'message' => 'Person erfolgreich erstellt',
|
|
'Anchor' => $result['IDAnchor'],
|
|
'Entry' => $result['IDEntry'],
|
|
'Linking' => $result['IDLinking']
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 500, 'message' => $e->getMessage()]);
|
|
}
|
|
?>
|