Webhooks/process_form.php hinzugefügt
This commit is contained in:
@@ -0,0 +1,216 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
$config = require_once __DIR__ . '/../config.php';
|
||||||
|
$api_key = $config['api_key_docuseal'];
|
||||||
|
$docuseal_url = rtrim($config['docuseal_url'], '/');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
http_response_code(405);
|
||||||
|
die("Fehler: Nur POST-Anfragen erlaubt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['website_hp'])) {
|
||||||
|
http_response_code(403);
|
||||||
|
die("Spam erkannt. Anfrage blockiert.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_SESSION['last_sub']) && (time() - $_SESSION['last_sub'] < 5)) {
|
||||||
|
http_response_code(429);
|
||||||
|
die("Du sendest Anfragen zu schnell. Bitte warte einen Moment.");
|
||||||
|
}
|
||||||
|
$_SESSION['last_sub'] = time();
|
||||||
|
|
||||||
|
$template_id = (int)($_POST['template_id'] ?? 0);
|
||||||
|
$submitters_data = [];
|
||||||
|
|
||||||
|
switch ($template_id) {
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
$email = filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL);
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) die("Fehler: Ungültige E-Mail.");
|
||||||
|
|
||||||
|
$stand_type = $_POST['stand_type'] ?? 'Händler';
|
||||||
|
$power_option = $_POST['power_option'] ?? 'kein';
|
||||||
|
|
||||||
|
$submitters_data = [[
|
||||||
|
"role" => "Aussteller",
|
||||||
|
"email" => $email,
|
||||||
|
"values" => [
|
||||||
|
"shop_name" => htmlspecialchars($_POST['shop_name'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"contact_name" => htmlspecialchars($_POST['contact_name'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"tax_id" => htmlspecialchars($_POST['tax_id'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"address" => htmlspecialchars($_POST['address'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"email" => $email,
|
||||||
|
"phone" => htmlspecialchars($_POST['phone'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"description" => htmlspecialchars($_POST['description'] ?? '', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"meters" => (int)($_POST['meters'] ?? 0),
|
||||||
|
"tables" => (int)($_POST['tables'] ?? 0),
|
||||||
|
"total_price" => htmlspecialchars($_POST['total_price'] ?? '0,00 €', ENT_QUOTES, 'UTF-8'),
|
||||||
|
"check_dealer" => ($stand_type === 'Händler') ? "X" : "",
|
||||||
|
"check_artist" => ($stand_type === 'Künstler') ? "X" : "",
|
||||||
|
"strom_klein" => ($power_option === 'klein') ? "X" : "",
|
||||||
|
"strom_groß" => ($power_option === 'gross') ? "X" : "",
|
||||||
|
"check_terms" => "X",
|
||||||
|
"check_privacy"=> "X"
|
||||||
|
]
|
||||||
|
]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
if (isset($_POST['discord_role']) && $_POST['discord_role'] == '1' && !empty($_POST['discord_name'])) {
|
||||||
|
$discord_data = [
|
||||||
|
'discord_name' => $_POST['discord_name'],
|
||||||
|
'discord_role' => true
|
||||||
|
];
|
||||||
|
$ch_disc = curl_init($config['discord_url']);
|
||||||
|
curl_setopt($ch_disc, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch_disc, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch_disc, CURLOPT_POSTFIELDS, json_encode($discord_data));
|
||||||
|
curl_setopt($ch_disc, CURLOPT_TIMEOUT, 10);
|
||||||
|
curl_setopt($ch_disc, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Authorization: ' . $config['discord_auth']
|
||||||
|
]);
|
||||||
|
|
||||||
|
$disc_response = curl_exec($ch_disc);
|
||||||
|
$disc_error = curl_error($ch_disc);
|
||||||
|
$disc_http_code = curl_getinfo($ch_disc, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
|
if ($disc_error) {
|
||||||
|
file_put_contents('bot_debug.log', "cURL Fehler: $disc_error" . PHP_EOL, FILE_APPEND);
|
||||||
|
} elseif ($disc_http_code !== 200) {
|
||||||
|
file_put_contents('bot_debug.log', "Bot Fehler HTTP-Code: $disc_http_code | Resp: $disc_response" . PHP_EOL, FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
$geburtsdatum_raw = $_POST['geburtstag'] ?? '';
|
||||||
|
$date_obj = DateTime::createFromFormat('d.m.Y', $geburtsdatum_raw);
|
||||||
|
$geburtsdatum_iso = $date_obj ? $date_obj->format('Y-m-d') : $geburtsdatum_raw;
|
||||||
|
|
||||||
|
$tage = $_POST['tage'] ?? [];
|
||||||
|
$bereiche = $_POST['bereiche'] ?? [];
|
||||||
|
$anrede = $_POST['anrede'] ?? '';
|
||||||
|
|
||||||
|
$submitters_data = [[
|
||||||
|
"role" => "Helfer",
|
||||||
|
"email" => $_POST['email'] ?? '',
|
||||||
|
"fields" => [
|
||||||
|
["name" => "herr", "value" => (strtolower($anrede) === 'herr') ? "true" : "false"],
|
||||||
|
["name" => "frau", "value" => (strtolower($anrede) === 'frau') ? "true" : "false"],
|
||||||
|
["name" => "divers", "value" => (strtolower($anrede) === 'divers') ? "true" : "false"],
|
||||||
|
["name" => "Vorname", "value" => $_POST['vorname'] ?? ''],
|
||||||
|
["name" => "Nachname", "value" => $_POST['nachname'] ?? ''],
|
||||||
|
["name" => "Geburtstag", "value" => $geburtsdatum_iso],
|
||||||
|
["name" => "T-Shirt", "value" => $_POST['tshirt'] ?? ''],
|
||||||
|
["name" => "Strasse", "value" => $_POST['strasse'] ?? ''],
|
||||||
|
["name" => "PLZ_Ort", "value" => $_POST['plz_ort'] ?? ''],
|
||||||
|
["name" => "Email", "value" => $_POST['email'] ?? ''],
|
||||||
|
["name" => "Handy", "value" => $_POST['handy'] ?? ''],
|
||||||
|
["name" => "Notfallkontakt", "value" => $_POST['notfall'] ?? ''],
|
||||||
|
["name" => "Tag_Fr", "value" => in_array("Fr", $tage) ? "true" : "false"],
|
||||||
|
["name" => "Tag_Sa", "value" => in_array("Sa", $tage) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Kasse", "value" => in_array("Kasse", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Security", "value" => in_array("Security", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Info", "value" => in_array("Info", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Catering", "value" => in_array("Catering", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Technik", "value" => in_array("Technik", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Bereich_Springer", "value" => in_array("Springer", $bereiche) ? "true" : "false"],
|
||||||
|
["name" => "Faehigkeiten", "value" => $_POST['skills'] ?? ''],
|
||||||
|
["name" => "Essen", "value" => $_POST['essen'] ?? ''],
|
||||||
|
["name" => "Allergie_Vorhanden", "value" => (!empty($_POST['allergien'])) ? "true" : "false"],
|
||||||
|
["name" => "Allergien_Text", "value" => $_POST['allergien'] ?? ''],
|
||||||
|
["name" => "Einwilligung_Checkbox", "value" => isset($_POST['einwilligung']) ? "true" : "false"],
|
||||||
|
["name" => "WhatsApp_Checkbox", "value" => isset($_POST['whatsapp']) ? "true" : "false"]
|
||||||
|
]
|
||||||
|
]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
$email = filter_var(trim($_POST['email'] ?? ''), FILTER_VALIDATE_EMAIL);
|
||||||
|
$act_name = trim($_POST['act_name'] ?? '');
|
||||||
|
$contact_name = trim($_POST['contact_name'] ?? '');
|
||||||
|
$terms_accepted = isset($_POST['terms']) ? true : false;
|
||||||
|
|
||||||
|
if (!$email || empty($act_name) || empty($contact_name)) die("Validierungsfehler: Pflichtfelder fehlen.");
|
||||||
|
if (!$terms_accepted) die("Validierungsfehler: Teilnahmebedingungen müssen akzeptiert werden.");
|
||||||
|
|
||||||
|
$has_equipment = trim($_POST['has_equipment'] ?? 'Nein');
|
||||||
|
$music_source = trim($_POST['music_source'] ?? '');
|
||||||
|
|
||||||
|
$submitters_data = [[
|
||||||
|
"email" => $email,
|
||||||
|
"name" => $contact_name,
|
||||||
|
"fields" => [
|
||||||
|
["name" => "act_name", "default_value" => $act_name],
|
||||||
|
["name" => "ansprechpartner", "default_value" => $contact_name],
|
||||||
|
["name" => "email", "default_value" => $email],
|
||||||
|
["name" => "anzahl_personen", "default_value" => (string)intval($_POST['person_count'] ?? 1)],
|
||||||
|
["name" => "dauer_minuten", "default_value" => (string)intval($_POST['duration'] ?? 0)],
|
||||||
|
["name" => "beschreibung", "default_value" => trim($_POST['description'] ?? '')],
|
||||||
|
["name" => "technik", "default_value" => trim($_POST['tech_needs'] ?? '')],
|
||||||
|
["name" => "ja_equipment_vorhanden", "default_value" => ($has_equipment === 'Ja')],
|
||||||
|
["name" => "nein_equipment_vorhanden", "default_value" => ($has_equipment === 'Nein')],
|
||||||
|
["name" => "equipment_beschreibung", "default_value" => trim($_POST['equipment_description'] ?? '')],
|
||||||
|
["name" => "Keine_Musik", "default_value" => ($music_source === 'Keine Musik')],
|
||||||
|
["name" => "wir_reichen_ein", "default_value" => ($music_source === 'Vorab eingereicht')],
|
||||||
|
["name" => "wir_bringen_mit", "default_value" => ($music_source === 'USB-Stick am Tag')],
|
||||||
|
["name" => "gesamtbetrag", "default_value" => trim($_POST['total_price'] ?? '')],
|
||||||
|
["name" => "teilnahmebedingungen", "default_value" => $terms_accepted]
|
||||||
|
]
|
||||||
|
]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
die("Fehler: Unbekannte Formular-ID (Template $template_id).");
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
"template_id" => $template_id,
|
||||||
|
"send_email" => false,
|
||||||
|
"submitters" => $submitters_data
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($docuseal_url . "/api/submissions/");
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'X-Auth-Token: ' . $api_key,
|
||||||
|
'Content-Type: application/json'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curl_error = curl_error($ch);
|
||||||
|
|
||||||
|
if ($http_code === 200 || $http_code === 201) {
|
||||||
|
$result = json_decode($response, true);
|
||||||
|
|
||||||
|
$slug = $result[0]['slug'] ?? $result['slug'] ?? null;
|
||||||
|
$signing_url = $result[0]['url'] ?? $result['url'] ?? null;
|
||||||
|
|
||||||
|
if (!$signing_url && $slug) {
|
||||||
|
$signing_url = $docuseal_url . "/s/" . $slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($signing_url) {
|
||||||
|
header("Location: " . $signing_url);
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
echo "<h2>Fehler: Konnte den Signatur-Link nicht generieren!</h2>";
|
||||||
|
echo "<b>Rohe API-Antwort:</b><br><pre>" . htmlspecialchars($response) . "</pre>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<h1>🚨 VERBINDUNG ZU DOCUSEAL FEHLGESCHLAGEN 🚨</h1>";
|
||||||
|
echo "<p><b>HTTP-Code:</b> " . htmlspecialchars($http_code) . "</p>";
|
||||||
|
if ($curl_error) echo "<p><b>cURL Fehler:</b> " . htmlspecialchars($curl_error) . "</p>";
|
||||||
|
echo "<p><b>API-Antwort:</b> <span style='color:red;'>" . htmlspecialchars($response) . "</span></p>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user