Bernd Wurst commited on 2026-09-30 11:07:04
Zeige 6 geänderte Dateien mit 111 Einfügungen und 25 Löschungen.
| ... | ... |
@@ -1,32 +1,28 @@ |
| 1 | 1 |
function email_click( event ) {
|
| 2 |
- email = $('#btn-email').text().split(' an ').pop()
|
|
| 2 |
+ // $(this) bezieht sich auf den konkret angeklickten Button (z.B. #btn-email_0) |
|
| 3 |
+ var email = $(this).text().split(' an ').pop().trim();
|
|
| 3 | 4 |
$('#notification').val('email:' + email);
|
| 4 | 5 |
$('form').submit();
|
| 5 | 6 |
event.preventDefault(); |
| 6 | 7 |
} |
| 7 | 8 |
|
| 8 |
- |
|
| 9 | 9 |
function whatsapp_click( event ) {
|
| 10 |
- number = $('#btn-whatsapp').text().split(' an ').pop()
|
|
| 10 |
+ var number = $(this).text().split(' an ').pop().trim();
|
|
| 11 | 11 |
$('#notification').val('whatsapp:' + number);
|
| 12 | 12 |
$('form').submit();
|
| 13 | 13 |
event.preventDefault(); |
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 |
- |
|
| 17 | 16 |
function sms_click( event ) {
|
| 18 |
- number = $('#btn-sms').text().split(' an ').pop()
|
|
| 17 |
+ var number = $(this).text().split(' an ').pop().trim();
|
|
| 19 | 18 |
$('#notification').val('sms:' + number);
|
| 20 | 19 |
$('form').submit();
|
| 21 | 20 |
event.preventDefault(); |
| 22 | 21 |
} |
| 23 | 22 |
|
| 24 |
- |
|
| 25 | 23 |
$(function () {
|
| 26 |
- |
|
| 27 |
- $('#btn-email').click(email_click);
|
|
| 28 |
- $('#btn-sms').click(sms_click);
|
|
| 29 |
- $('#btn-whatsapp').click(whatsapp_click);
|
|
| 30 |
- |
|
| 24 |
+ // Event Delegation mit Attribut-Selektor (findet btn-email, btn-email_0, btn-email_1 ...) |
|
| 25 |
+ $(document).on('click', '[id^="btn-email"]', email_click);
|
|
| 26 |
+ $(document).on('click', '[id^="btn-sms"]', sms_click);
|
|
| 27 |
+ $(document).on('click', '[id^="btn-whatsapp"]', whatsapp_click);
|
|
| 31 | 28 |
}); |
| 32 |
- |
| ... | ... |
@@ -209,7 +209,7 @@ input[type=submit] {
|
| 209 | 209 |
margin-bottom: 0.5em; |
| 210 | 210 |
} |
| 211 | 211 |
|
| 212 |
-#btn-sms {
|
|
| 212 |
+.btn-sms {
|
|
| 213 | 213 |
min-width: 280px; |
| 214 | 214 |
padding-top: 150px; |
| 215 | 215 |
background-image: url("images/sms.png");
|
| ... | ... |
@@ -217,7 +217,7 @@ input[type=submit] {
|
| 217 | 217 |
background-position: center 10px; |
| 218 | 218 |
} |
| 219 | 219 |
|
| 220 |
-#btn-whatsapp {
|
|
| 220 |
+.btn-whatsapp {
|
|
| 221 | 221 |
min-width: 280px; |
| 222 | 222 |
padding-top: 150px; |
| 223 | 223 |
background-image: url("images/whatsapp.png");
|
| ... | ... |
@@ -225,7 +225,7 @@ input[type=submit] {
|
| 225 | 225 |
background-position: center 10px; |
| 226 | 226 |
} |
| 227 | 227 |
|
| 228 |
-#btn-email {
|
|
| 228 |
+.btn-email {
|
|
| 229 | 229 |
min-width: 280px; |
| 230 | 230 |
padding-top: 150px; |
| 231 | 231 |
background-image: url("images/email.png");
|
| ... | ... |
@@ -51,6 +51,26 @@ function erstelle_kunde($daten) {
|
| 51 | 51 |
} |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
+function erstelle_kontakt($kunde, $kontakt) {
|
|
| 55 |
+ $json = [ |
|
| 56 |
+ "label" => $kontakt['label'], |
|
| 57 |
+ "phone" => $kontakt["phone"] ?? null, |
|
| 58 |
+ "email" => $kontakt["email"] ?? null, |
|
| 59 |
+ ]; |
|
| 60 |
+ $filename = '../data/'.date('Y').'/'.time().'-neukontakt.json';
|
|
| 61 |
+ @file_put_contents($filename, json_encode($json)); |
|
| 62 |
+ $ret = api_call('POST', 'anonymous/newcontact/'.$kunde, $json);
|
|
| 63 |
+ if ($ret['status_code'] >= 400) {
|
|
| 64 |
+ foreach ($ret['data']['validation_errors'] as $item) {
|
|
| 65 |
+ $_SESSION['warnings'][] = $item['key'].': '.$item['message']; |
|
| 66 |
+ } |
|
| 67 |
+ return null; |
|
| 68 |
+ } |
|
| 69 |
+ $ret = $ret['data']; |
|
| 70 |
+ return $ret; |
|
| 71 |
+ |
|
| 72 |
+} |
|
| 73 |
+ |
|
| 54 | 74 |
require_once(__DIR__.'/../vendor/autoload.php'); |
| 55 | 75 |
|
| 56 | 76 |
function format_number_national($number) {
|
| ... | ... |
@@ -0,0 +1,50 @@ |
| 1 |
+<?php |
|
| 2 |
+require_once "utils.php"; |
|
| 3 |
+session_start(); |
|
| 4 |
+ |
|
| 5 |
+if (!isset($_SESSION['kundennr'])) {
|
|
| 6 |
+ header('Location: kunde.php');
|
|
| 7 |
+ die(); |
|
| 8 |
+} |
|
| 9 |
+ |
|
| 10 |
+$headline = 'Neue Kontaktdaten eingeben'; |
|
| 11 |
+$content = ' |
|
| 12 |
+ <p>Bitte neue Telefonnummer und/order E-Mail-Adresse eingeben:</p> |
|
| 13 |
+ '; |
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+ $content .= ' |
|
| 17 |
+ <form class="form" action="save.php" method="post"> |
|
| 18 |
+ <input type="hidden" name="form" value="newcontact">'; |
|
| 19 |
+ $content .= ' |
|
| 20 |
+<div class="row g-2"> |
|
| 21 |
+ <div class="col-sm-12"> |
|
| 22 |
+ <div class="form-floating mb-2"> |
|
| 23 |
+ <input type="text" class="form-control" id="label" name="label" placeholder="Name" value="' . htmlspecialchars($_SESSION['name']) . '"> |
|
| 24 |
+ <label for="label">Name des Kontakts</label> |
|
| 25 |
+ </div> |
|
| 26 |
+ </div> |
|
| 27 |
+</div> |
|
| 28 |
+<div class="row g-2"> |
|
| 29 |
+ <div class="col-sm-12"> |
|
| 30 |
+ <div class="form-floating mb-2"> |
|
| 31 |
+ <input type="phone" class="form-control" id="phone" name="phone" placeholder="Telefonnummer" autocomplete="phone"> |
|
| 32 |
+ <label for="phone">Telefonnummer</label> |
|
| 33 |
+ </div> |
|
| 34 |
+ </div> |
|
| 35 |
+</div> |
|
| 36 |
+<div class="row g-2"> |
|
| 37 |
+ <div class="col-sm-12"> |
|
| 38 |
+ <div class="form-floating mb-2"> |
|
| 39 |
+ <input type="email" class="form-control" id="email" name="email" placeholder="E-Mail-Adresse" autocomplete="email"> |
|
| 40 |
+ <label for="email">E-Mail-Adresse</label> |
|
| 41 |
+ </div> |
|
| 42 |
+ <p>Sie erhalten eine E-Mail-Bestätigung an diese E-Mail-Adresse.</p> |
|
| 43 |
+ </div> |
|
| 44 |
+</div> |
|
| 45 |
+<div class="mb-2"> |
|
| 46 |
+ <div><input class="btn btn-primary btn-lg" type="submit" value="Weiter >"></div> |
|
| 47 |
+</div> |
|
| 48 |
+'; |
|
| 49 |
+ |
|
| 50 |
+include("template.php");
|
| ... | ... |
@@ -17,10 +17,10 @@ $content = '<p>Wie möchten Sie bevorzugt kontaktiert werden, wenn Ihr Auftrag e |
| 17 | 17 |
<div class="row mb-1 g-3">'; |
| 18 | 18 |
|
| 19 | 19 |
$num = 0; |
| 20 |
-$phonenumbers = array_filter($_SESSION['phonenumbers'], function($v) {
|
|
| 20 |
+$phonenumbers = array_unique(array_filter($_SESSION['phonenumbers'], function($v) {
|
|
| 21 | 21 |
return str_starts_with($v, '+491'); |
| 22 |
-}); |
|
| 23 |
-$emailaddrs = $_SESSION['emailaddrs']; |
|
| 22 |
+})); |
|
| 23 |
+$emailaddrs = array_unique($_SESSION['emailaddrs']); |
|
| 24 | 24 |
|
| 25 | 25 |
$num = count($phonenumbers) * 2 + count($emailaddrs); |
| 26 | 26 |
|
| ... | ... |
@@ -30,22 +30,26 @@ if ($num < 2) {
|
| 30 | 30 |
header('Location: obstart.php');
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
-foreach ($phonenumbers as $phone) {
|
|
| 33 |
+foreach ($phonenumbers as $index => $phone) {
|
|
| 34 | 34 |
$phone = format_number_national($phone); |
| 35 | 35 |
$content .= ' |
| 36 |
- <div class="col-sm-6"><a href="#" class="btn btn-lg btn-light w-100" id="btn-whatsapp">Whatsapp an<br> '.$phone.'</a></div>'; |
|
| 36 |
+ <div class="col-sm-6"><a href="#" class="btn btn-lg btn-light w-100 btn-whatsapp" id="btn-whatsapp_'.$index.'">Whatsapp an<br> '.$phone.'</a></div>'; |
|
| 37 | 37 |
$content .= ' |
| 38 |
- <div class="col-sm-6"><a href="#" class="btn btn-lg btn-light w-100" id="btn-sms">SMS an<br> '.$phone.'</a></div>'; |
|
| 38 |
+ <div class="col-sm-6"><a href="#" class="btn btn-lg btn-light w-100 btn-sms" id="btn-sms_'.$index.'">SMS an<br> '.$phone.'</a></div>'; |
|
| 39 | 39 |
} |
| 40 |
-foreach ($emailaddrs as $email) {
|
|
| 40 |
+foreach ($emailaddrs as $index => $email) {
|
|
| 41 | 41 |
if (!isset($_SESSION['email']) || !$_SESSION['email']) {
|
| 42 | 42 |
$_SESSION['email'] = $email; |
| 43 | 43 |
} |
| 44 | 44 |
$content .= ' |
| 45 | 45 |
</div> |
| 46 | 46 |
<div class="row"> |
| 47 |
- <div class="col-sm-12"><a href="#" class="btn btn-lg btn-light w-100" id="btn-email">E-Mail an<br> '.$email.'</a></div>'; |
|
| 47 |
+ <div class="col-sm-12"><a href="#" class="btn btn-lg btn-light w-100 btn-email" id="btn-email_'.$index.'">E-Mail an<br> '.$email.'</a></div>'; |
|
| 48 | 48 |
} |
| 49 |
+$content .= ' |
|
| 50 |
+ </div> |
|
| 51 |
+ <div class="row"> |
|
| 52 |
+ <div class="col-sm-12"><a href="newcontact.php" class="btn btn-lg btn-light w-100" id="btn-newcontact">Neue Kontaktdaten angeben</a></div>'; |
|
| 49 | 53 |
$content .= '<input type="hidden" name="notification" id="notification" value=""> |
| 50 | 54 |
</div>'; |
| 51 | 55 |
|
| ... | ... |
@@ -227,14 +227,30 @@ if (isset($_REQUEST['form'])) {
|
| 227 | 227 |
} |
| 228 | 228 |
} else {
|
| 229 | 229 |
if (isset($_SESSION['email']) && $_SESSION['email']) {
|
| 230 |
- // Not implemented |
|
| 231 |
- //update_kunde($_SESSION['kundennr'], ['email' => $_SESSION['email']]); |
|
| 230 |
+ erstelle_kontakt($_SESSION['kundennr'], [ |
|
| 231 |
+ "label" => trim(htmlspecialchars($_SESSION['name'])), |
|
| 232 |
+ "phone" => null, |
|
| 233 |
+ "email" => trim(htmlspecialchars($_REQUEST['email'])), |
|
| 234 |
+ ]); |
|
| 232 | 235 |
} |
| 233 | 236 |
} |
| 234 | 237 |
$_SESSION['address_done'] = true; |
| 235 | 238 |
$redirect = nextPage(); |
| 236 | 239 |
break; |
| 237 | 240 |
|
| 241 |
+ case 'newcontact': |
|
| 242 |
+ $kunde = erstelle_kontakt($_SESSION['kundennr'], [ |
|
| 243 |
+ "label" => trim(htmlspecialchars($_REQUEST['label'])) ?? $_SESSION['name'], |
|
| 244 |
+ "phone" => format_number_api(trim(htmlspecialchars($_REQUEST['phone']))), |
|
| 245 |
+ "email" => trim(htmlspecialchars($_REQUEST['email'])), |
|
| 246 |
+ ]); |
|
| 247 |
+ $_SESSION['email'] = $_REQUEST['email'] ?? $_SESSION['email']; |
|
| 248 |
+ $_SESSION['phone'] = $_REQUEST['phone'] ?? $_SESSION['phone']; |
|
| 249 |
+ $_SESSION['emailaddrs'] = $kunde['email']; |
|
| 250 |
+ $_SESSION['phonenumbers'] = $kunde['phone']; |
|
| 251 |
+ $redirect = "notification.php"; |
|
| 252 |
+ break; |
|
| 253 |
+ |
|
| 238 | 254 |
case 'notification': |
| 239 | 255 |
if (isset($_REQUEST['notification'])) {
|
| 240 | 256 |
list($schema, $content) = explode(':', $_REQUEST['notification']);
|
| 241 | 257 |