2026-10-23 13:14:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Core\Auth;
|
|
|
|
|
use App\Models\MembershipApplication;
|
|
|
|
|
use App\Models\Page;
|
|
|
|
|
|
|
|
|
|
class HomeController
|
|
|
|
|
{
|
|
|
|
|
public function pageHome(): void
|
|
|
|
|
{
|
|
|
|
|
$page = Page::byName('home');
|
|
|
|
|
$content = $page->content ?? '';
|
|
|
|
|
|
|
|
|
|
// Führende/abschließende Anführungszeichen entfernen (wie im Original)
|
|
|
|
|
$content = rtrim(ltrim($content, '"'), '"');
|
|
|
|
|
|
|
|
|
|
view('home', ['content' => $content]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function pageActivities(): void
|
|
|
|
|
{
|
|
|
|
|
$page = Page::byName('activities');
|
|
|
|
|
|
|
|
|
|
view('activities', ['content' => $page->content ?? '']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function becomeMember(): void
|
|
|
|
|
{
|
|
|
|
|
view('become_member');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function meetings(): void
|
|
|
|
|
{
|
|
|
|
|
view('meetings');
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 18:11:45 +01:00
|
|
|
public function guide(): void
|
|
|
|
|
{
|
|
|
|
|
view('guide');
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-23 13:14:31 +02:00
|
|
|
public function mitgliedsantrag(): void
|
|
|
|
|
{
|
|
|
|
|
view('mitgliedsantrag');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeMitgliedsantrag(): void
|
|
|
|
|
{
|
|
|
|
|
validate([
|
|
|
|
|
'nachname' => 'required',
|
|
|
|
|
'vorname' => 'required',
|
|
|
|
|
'strasse' => 'required',
|
|
|
|
|
'plz_ort' => 'required',
|
|
|
|
|
'geburtsdatum' => 'required',
|
|
|
|
|
'aufnahme_ab' => 'required',
|
|
|
|
|
'kontoinhaber' => 'required',
|
|
|
|
|
'iban' => 'required',
|
2026-11-08 19:16:53 +01:00
|
|
|
'email' => 'required|email',
|
2026-10-23 13:14:31 +02:00
|
|
|
]);
|
|
|
|
|
|
2026-11-08 18:57:37 +01:00
|
|
|
$signature1 = $this->decodeSignature((string) input('unterschrift_1'));
|
|
|
|
|
$signature2 = $this->decodeSignature((string) input('unterschrift_2'));
|
|
|
|
|
|
|
|
|
|
if ($signature1 === null) {
|
|
|
|
|
$_SESSION['_errors']['unterschrift_1'][] = 'Bitte unterschreiben Sie den Antrag.';
|
|
|
|
|
$_SESSION['_old'] = $this->oldApplicationInput();
|
|
|
|
|
back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($signature2 === null) {
|
|
|
|
|
$_SESSION['_errors']['unterschrift_2'][] = 'Bitte unterschreiben Sie das SEPA-Lastschriftmandat.';
|
|
|
|
|
$_SESSION['_old'] = $this->oldApplicationInput();
|
|
|
|
|
back();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-23 13:14:31 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
|
|
$nachname = (string) input('nachname');
|
|
|
|
|
$vorname = (string) input('vorname');
|
|
|
|
|
$strasse = (string) input('strasse');
|
|
|
|
|
$plzOrt = (string) input('plz_ort');
|
|
|
|
|
$telefon = (string) input('telefon');
|
|
|
|
|
$email = (string) input('email');
|
|
|
|
|
$geburtsdatum = (string) input('geburtsdatum');
|
|
|
|
|
$motorrad = (string) input('motorrad');
|
|
|
|
|
$aufnahmeAb = (string) input('aufnahme_ab');
|
|
|
|
|
$ortDatum1 = (string) input('ort_datum_1');
|
|
|
|
|
$mandatsref = (string) input('mandatsreferenz');
|
|
|
|
|
$glaeubigerId = (string) input('glaeubiger_id');
|
|
|
|
|
$kontoinhaber = (string) input('kontoinhaber');
|
|
|
|
|
$kreditinstitut = (string) input('kreditinstitut');
|
|
|
|
|
$bic = (string) input('bic');
|
|
|
|
|
$iban = (string) input('iban');
|
|
|
|
|
$ortDatum2 = (string) input('ort_datum_2');
|
2026-11-08 18:57:37 +01:00
|
|
|
|
|
|
|
|
$token = bin2hex(random_bytes(12));
|
|
|
|
|
$file1 = $this->saveSignatureFile($signature1, $token, 1);
|
|
|
|
|
$file2 = $this->saveSignatureFile($signature2, $token, 2);
|
|
|
|
|
|
|
|
|
|
if ($file1 === null || $file2 === null) {
|
|
|
|
|
$this->deleteSignatureFiles(array_filter([$file1, $file2]));
|
|
|
|
|
app_log('error', 'Mitgliedsantrag: Unterschrift konnte nicht gespeichert werden');
|
|
|
|
|
flash_set('error', 'Die Unterschrift konnte nicht gespeichert werden. Bitte den Administrator informieren.');
|
|
|
|
|
$_SESSION['_old'] = $this->oldApplicationInput();
|
|
|
|
|
redirect('/mitgliedsantrag');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$application = MembershipApplication::create([
|
|
|
|
|
'user_id' => $user?->id,
|
|
|
|
|
'nachname' => $nachname,
|
|
|
|
|
'vorname' => $vorname,
|
|
|
|
|
'strasse' => $strasse,
|
|
|
|
|
'plz_ort' => $plzOrt,
|
|
|
|
|
'telefon' => $telefon,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'geburtsdatum' => $geburtsdatum,
|
|
|
|
|
'motorrad' => $motorrad,
|
|
|
|
|
'aufnahme_ab' => $aufnahmeAb,
|
|
|
|
|
'ort_datum_1' => $ortDatum1,
|
|
|
|
|
'unterschrift_1' => $file1,
|
|
|
|
|
'mandatsreferenz' => $mandatsref,
|
|
|
|
|
'glaeubiger_id' => $glaeubigerId,
|
|
|
|
|
'kontoinhaber' => $kontoinhaber,
|
|
|
|
|
'kreditinstitut' => $kreditinstitut,
|
|
|
|
|
'bic' => $bic,
|
|
|
|
|
'iban' => $iban,
|
|
|
|
|
'ort_datum_2' => $ortDatum2,
|
|
|
|
|
'unterschrift_2' => $file2,
|
|
|
|
|
'created_at' => now(),
|
|
|
|
|
'updated_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
$this->deleteSignatureFiles([$file1, $file2]);
|
|
|
|
|
app_log('error', 'Mitgliedsantrag konnte nicht gespeichert werden', [
|
|
|
|
|
'exception' => $e::class,
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
flash_set('error', 'Der Antrag konnte nicht gespeichert werden. Bitte den Administrator informieren.');
|
|
|
|
|
$_SESSION['_old'] = $this->oldApplicationInput();
|
|
|
|
|
redirect('/mitgliedsantrag');
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 19:16:53 +01:00
|
|
|
$baseUrl = app_base_url();
|
2026-11-08 18:57:37 +01:00
|
|
|
$adminUrl = $baseUrl . '/admin/antraege/' . $application->id;
|
2026-10-23 13:14:31 +02:00
|
|
|
|
|
|
|
|
$body = "Neuer Mitgliedsantrag über die Website\n"
|
|
|
|
|
. "========================================\n\n"
|
|
|
|
|
. "Persönliche Angaben\n"
|
|
|
|
|
. " Nachname: " . $nachname . "\n"
|
|
|
|
|
. " Vorname: " . $vorname . "\n"
|
|
|
|
|
. " Straße, Nr.: " . $strasse . "\n"
|
|
|
|
|
. " PLZ, Ort: " . $plzOrt . "\n"
|
|
|
|
|
. " Telefon: " . $telefon . "\n"
|
|
|
|
|
. " E-Mail: " . $email . "\n"
|
|
|
|
|
. " Geburtsdatum: " . $geburtsdatum . "\n"
|
|
|
|
|
. " Motorrad: " . $motorrad . "\n"
|
|
|
|
|
. " Aufnahme ab: " . $aufnahmeAb . "\n"
|
|
|
|
|
. " Ort / Datum: " . $ortDatum1 . "\n"
|
2026-11-08 18:57:37 +01:00
|
|
|
. " Unterschrift: digital erfasst\n\n"
|
2026-10-23 13:14:31 +02:00
|
|
|
. "SEPA-Lastschriftmandat\n"
|
|
|
|
|
. " Mandatsreferenz: " . $mandatsref . "\n"
|
|
|
|
|
. " Gläubiger-ID: " . $glaeubigerId . "\n"
|
|
|
|
|
. " Kontoinhaber: " . $kontoinhaber . "\n"
|
|
|
|
|
. " Kreditinstitut: " . $kreditinstitut . "\n"
|
|
|
|
|
. " BIC: " . $bic . "\n"
|
|
|
|
|
. " IBAN: " . $iban . "\n"
|
|
|
|
|
. " Ort / Datum: " . $ortDatum2 . "\n"
|
2026-11-08 18:57:37 +01:00
|
|
|
. " Unterschrift: digital erfasst\n\n"
|
|
|
|
|
. "Antrag im Admin-Bereich ansehen:\n"
|
|
|
|
|
. " " . $adminUrl . "\n";
|
2026-10-23 13:14:31 +02:00
|
|
|
|
2026-11-08 19:29:45 +01:00
|
|
|
if (!send_mail(
|
2026-10-23 13:14:31 +02:00
|
|
|
(string) config('app.membership_notify_email'),
|
|
|
|
|
'Neuer Mitgliedsantrag: ' . $vorname . ' ' . $nachname,
|
|
|
|
|
$body,
|
|
|
|
|
$email
|
2026-11-08 19:29:45 +01:00
|
|
|
)) {
|
|
|
|
|
app_log('warning', 'Admin-Benachrichtigung über neuen Mitgliedsantrag fehlgeschlagen', [
|
|
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'email' => (string) config('app.membership_notify_email'),
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
app_log('info', 'Admin-Benachrichtigung über neuen Mitgliedsantrag gesendet', [
|
|
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'email' => (string) config('app.membership_notify_email'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2026-10-23 13:14:31 +02:00
|
|
|
|
2026-11-08 19:16:53 +01:00
|
|
|
$applicantBody = "Hallo " . trim($vorname . ' ' . $nachname) . ",\n\n"
|
|
|
|
|
. "vielen Dank für deinen Mitgliedsantrag. Wir haben deinen Antrag am "
|
|
|
|
|
. date('d.m.Y H:i') . " erhalten.\n\n"
|
|
|
|
|
. "Antragsnummer: " . $application->id . "\n"
|
|
|
|
|
. "E-Mail: " . $email . "\n\n"
|
|
|
|
|
. "Wir prüfen deinen Antrag und melden uns bei dir, sobald er bearbeitet wurde.\n\n"
|
|
|
|
|
. "Viele Grüße\n"
|
|
|
|
|
. "Motorrad-IG\n"
|
|
|
|
|
. $baseUrl . "\n";
|
|
|
|
|
|
2026-11-08 19:29:45 +01:00
|
|
|
if (!send_mail($email, 'Dein Mitgliedsantrag bei der Motorrad-IG', $applicantBody, (string) config('mail.reply_to'))) {
|
2026-11-08 19:16:53 +01:00
|
|
|
app_log('warning', 'Bestätigungs-E-Mail an Antragsteller fehlgeschlagen', [
|
|
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
app_log('info', 'Bestätigungs-E-Mail an Antragsteller gesendet', [
|
|
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 18:57:37 +01:00
|
|
|
app_log('info', 'Mitgliedsantrag gespeichert', [
|
|
|
|
|
'application_id' => $application->id,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-10-23 13:14:31 +02:00
|
|
|
$_SESSION['_flash']['status'] = 'Vielen Dank! Dein Mitgliedsantrag wurde gespeichert.';
|
|
|
|
|
|
|
|
|
|
redirect('/mitgliedsantrag');
|
|
|
|
|
}
|
2026-11-08 18:57:37 +01:00
|
|
|
|
|
|
|
|
/** Dekodiert eine Signatur aus dem Canvas (PNG-Data-URL). */
|
|
|
|
|
private function decodeSignature(string $dataUrl): ?string
|
|
|
|
|
{
|
|
|
|
|
if (!preg_match('#^data:image/png;base64,([A-Za-z0-9+/=\s]+)$#', $dataUrl, $matches)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$binary = base64_decode(preg_replace('/\s+/', '', $matches[1]), true);
|
|
|
|
|
|
|
|
|
|
if ($binary === false || strlen($binary) < 100 || strlen($binary) > 2_000_000) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$image = @imagecreatefromstring($binary);
|
|
|
|
|
|
|
|
|
|
if (!$image instanceof \GdImage) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$width = imagesx($image);
|
|
|
|
|
$height = imagesy($image);
|
|
|
|
|
|
|
|
|
|
if ($width < 20 || $height < 10 || $width > 3000 || $height > 1500) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $binary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function saveSignatureFile(string $binary, string $token, int $index): ?string
|
|
|
|
|
{
|
|
|
|
|
$dir = storage_path('img_storage/mitgliedsantrag');
|
|
|
|
|
|
|
|
|
|
if (!is_dir($dir) && !@mkdir($dir, 0775, true) && !is_dir($dir)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_writable($dir)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$filename = $token . '_' . $index . '.png';
|
|
|
|
|
|
|
|
|
|
if (@file_put_contents($dir . '/' . $filename, $binary) === false) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function deleteSignatureFiles(array $files): void
|
|
|
|
|
{
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
|
if (is_string($file) && $file !== '') {
|
|
|
|
|
@unlink(storage_path('img_storage/mitgliedsantrag/' . $file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function oldApplicationInput(): array
|
|
|
|
|
{
|
|
|
|
|
$old = $_POST;
|
|
|
|
|
unset($old['_token'], $old['unterschrift_1'], $old['unterschrift_2']);
|
|
|
|
|
|
|
|
|
|
return $old;
|
|
|
|
|
}
|
2026-10-23 13:14:31 +02:00
|
|
|
}
|