From a0fa4dfd1a623ed661be79494f4977d190efb708 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Sat, 5 Sep 2026 17:29:44 +0200 Subject: [PATCH] Extend public upload with personal friendship codes --- customer-qr-upload.php | 156 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 143 insertions(+), 13 deletions(-) diff --git a/customer-qr-upload.php b/customer-qr-upload.php index 6c21722..415d987 100644 --- a/customer-qr-upload.php +++ b/customer-qr-upload.php @@ -15,6 +15,7 @@ if (!defined('BRATONIEN_TOOLS_PATH')) } require_once(BRATONIEN_TOOLS_PATH.'include/customer_qr_upload.inc.php'); +require_once(BRATONIEN_TOOLS_PATH.'include/friendship_code_upload.inc.php'); $settings = bratonien_tools_customer_qr_settings(); if (empty($settings['enabled'])) @@ -26,9 +27,11 @@ if (empty($settings['enabled'])) } bratonien_tools_customer_qr_ensure_storage(); +bratonien_tools_friendship_code_ensure_storage(); $year_limits = bratonien_tools_customer_qr_year_limits(); +$action = (string)($_GET['action'] ?? ''); -if ((string)($_GET['action'] ?? '') === 'check') +if ($action === 'check') { header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store, max-age=0'); @@ -57,10 +60,37 @@ if ((string)($_GET['action'] ?? '') === 'check') exit; } +if ($action === 'check_friendship') +{ + header('Content-Type: application/json; charset=utf-8'); + header('Cache-Control: no-store, max-age=0'); + + try + { + $name = bratonien_tools_friendship_code_name($_GET['name'] ?? ''); + $exists = bratonien_tools_friendship_code_exists_for_name($name); + echo json_encode(array( + 'ok' => true, + 'available' => !$exists, + 'name' => $name, + 'message' => $exists + ? 'Für diesen Namen ist bereits ein Freundschaftscode hinterlegt.' + : 'Für diesen Namen kann ein Freundschaftscode hinterlegt werden.', + ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + } + catch (Throwable $e) + { + http_response_code(400); + echo json_encode(array('ok' => false, 'message' => $e->getMessage()), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + } + exit; +} + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $results = array(); $year = bratonien_tools_customer_qr_default_year(); + $upload_type = (string)($_POST['upload_type'] ?? 'qr'); try { @@ -78,24 +108,40 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') check_pwg_token(); } - $year = bratonien_tools_customer_qr_year($_POST['upload_year'] ?? ''); - - if (empty($_FILES['qr_files'])) + if ($upload_type === 'friendship') { - throw new RuntimeException('Es wurden keine QR-Code-Dateien ausgewählt.'); + $name = bratonien_tools_friendship_code_name($_POST['friend_name'] ?? ''); + if (empty($_FILES['friend_file'])) + { + throw new RuntimeException('Es wurde keine Freundschaftscode-Datei ausgewählt.'); + } + + $results[] = bratonien_tools_friendship_code_process_upload($name, $_FILES['friend_file']); } + else + { + $upload_type = 'qr'; + $year = bratonien_tools_customer_qr_year($_POST['upload_year'] ?? ''); - $numbers = isset($_POST['qr_numbers']) && is_array($_POST['qr_numbers']) - ? array_values($_POST['qr_numbers']) - : array(); + if (empty($_FILES['qr_files'])) + { + throw new RuntimeException('Es wurden keine QR-Code-Dateien ausgewählt.'); + } - $results = bratonien_tools_customer_qr_process_uploads($year, $_FILES['qr_files'], $numbers); + $numbers = isset($_POST['qr_numbers']) && is_array($_POST['qr_numbers']) + ? array_values($_POST['qr_numbers']) + : array(); + + $results = bratonien_tools_customer_qr_process_uploads($year, $_FILES['qr_files'], $numbers); + } } catch (Throwable $e) { $results[] = array( 'status' => 'error', + 'kind' => $upload_type === 'friendship' ? 'friendship' : 'qr', 'file' => '', + 'name' => $upload_type === 'friendship' ? trim((string)($_POST['friend_name'] ?? '')) : '', 'year' => $year, 'number' => '', 'message' => $e->getMessage(), @@ -103,6 +149,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') } $_SESSION['bratonien_customer_qr_flash'] = array( + 'type' => $upload_type, 'year' => $year, 'results' => $results, ); @@ -169,18 +216,25 @@ header('Cache-Control: no-store, max-age=0');

QR-Code Upload

-

Lade einen oder mehrere QR-Codes hoch und ordne jedem Code eine eindeutige Nummer zu.

+

QR-Codes und persönliche Freundschaftscodes hochladen.

Ergebnis

- +
- +
-
Jahr · QR-Code #
+
Name:
+
Jahr · QR-Code #
@@ -189,6 +243,8 @@ header('Cache-Control: no-store, max-age=0');
+ +

QR-Code

@@ -215,6 +271,31 @@ header('Cache-Control: no-store, max-age=0'); Eine Nummer kann innerhalb eines Jahres nur einmal verwendet werden.
+ +
+ + +

Persönlicher Freundschaftscode

+ +
+ +
+ +
Bitte Namen eingeben.
+
+ + +
+ +
Ein Bild pro Person. PNG, JPG, WEBP oder GIF.
+
+
+ +
+ + Pro Name wird genau ein persönlicher Freundschaftscode gespeichert. +
+
\ No newline at end of file