Fix market card save validation
This commit is contained in:
1 parent
6a12a43114
commit
28784ed6ac
1 file changed
+22
-12
@@ -33,12 +33,13 @@ if ($requestMethod === 'POST') {
|
|||||||
echo json_encode(['ok' => false, 'error' => 'Ungültige Anfrage']);
|
echo json_encode(['ok' => false, 'error' => 'Ungültige Anfrage']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$scope = (string) ($payload['scope'] ?? '');
|
try {
|
||||||
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
$scope = (string) ($payload['scope'] ?? '');
|
||||||
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
||||||
if ($scope === 'day') {
|
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
||||||
market_management_update_day($pdo, $id, $fields);
|
if ($scope === 'day') {
|
||||||
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
|
market_management_update_day($pdo, $id, $fields);
|
||||||
|
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
|
||||||
$marketFields = [];
|
$marketFields = [];
|
||||||
foreach (['market_name', 'category_id', 'website_url'] as $marketField) {
|
foreach (['market_name', 'category_id', 'website_url'] as $marketField) {
|
||||||
if (array_key_exists($marketField, $fields)) {
|
if (array_key_exists($marketField, $fields)) {
|
||||||
@@ -61,13 +62,17 @@ if ($requestMethod === 'POST') {
|
|||||||
market_management_update_market($pdo, (int) ($existingOccurrence['market_definition_id'] ?? 0), $marketFields);
|
market_management_update_market($pdo, (int) ($existingOccurrence['market_definition_id'] ?? 0), $marketFields);
|
||||||
}
|
}
|
||||||
if ($contactFields !== []) {
|
if ($contactFields !== []) {
|
||||||
$contactId = (int) ($fields['contact_person_id'] ?? $existingOccurrence['contact_person_id'] ?? 0);
|
$submittedContactId = trim((string) ($fields['contact_person_id'] ?? ''));
|
||||||
|
$contactId = (int) ($submittedContactId !== '' ? $submittedContactId : ($existingOccurrence['contact_person_id'] ?? 0));
|
||||||
update_contact_details($pdo, $contactId, $contactFields);
|
update_contact_details($pdo, $contactId, $contactFields);
|
||||||
}
|
}
|
||||||
$organizerFields = [];
|
$organizerFields = [];
|
||||||
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
||||||
if (array_key_exists($organizerField, $fields)) {
|
if (array_key_exists($organizerField, $fields)) {
|
||||||
$organizerFields[$organizerField] = $fields[$organizerField];
|
$value = trim((string) $fields[$organizerField]);
|
||||||
|
if ($value !== '') {
|
||||||
|
$organizerFields[$organizerField] = $value;
|
||||||
|
}
|
||||||
unset($fields[$organizerField]);
|
unset($fields[$organizerField]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,11 +87,16 @@ if ($requestMethod === 'POST') {
|
|||||||
if ($fields !== []) {
|
if ($fields !== []) {
|
||||||
market_management_update_occurrence($pdo, $id, $fields);
|
market_management_update_occurrence($pdo, $id, $fields);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException('Ungültiger Bearbeitungsbereich.');
|
throw new InvalidArgumentException('Ungültiger Bearbeitungsbereich.');
|
||||||
|
}
|
||||||
|
echo json_encode(['ok' => true]);
|
||||||
|
exit;
|
||||||
|
} catch (Throwable $error) {
|
||||||
|
http_response_code(422);
|
||||||
|
echo json_encode(['ok' => false, 'error' => $error->getMessage()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
echo json_encode(['ok' => true]);
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$occurrenceId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
$occurrenceId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
||||||
|
|||||||
Reference in new issue
Block a user