Bernd Wurst commited on 2023-09-22 09:56:08
Zeige 4 geänderte Dateien mit 75 Einfügungen und 2 Löschungen.
... | ... |
@@ -33,13 +33,20 @@ if (isset($_REQUEST['error'])) { |
33 | 33 |
|
34 | 34 |
|
35 | 35 |
$headline = 'Adresse eingeben'; |
36 |
-if (isset($_SESSION['kundennr']) and $_SESSION['kundennr']) { |
|
36 |
+if (isset($_SESSION['kundennr']) && $_SESSION['kundennr']) { |
|
37 | 37 |
$headline = 'Willkommen zurück!'; |
38 | 38 |
$content .= ' |
39 | 39 |
<p>Schön, wir kennen uns ja schon! Aus Datenschutzgründen wird Ihre Adresse hier nicht angezeigt. Sofern Sie Änderungen an Ihren Kundendaten wünschen, sprechen Sie uns bitte vor Ort darauf an.</p>'; |
40 | 40 |
$content .= ' |
41 | 41 |
<form class="form" action="save.php" method="post"> |
42 | 42 |
<input type="hidden" name="form" value="address">'; |
43 |
+ if (!kunde_hat_email($_SESSION['kundennr'])) { |
|
44 |
+ $content .= '<p><strong>Eine kleine Bitte:</strong> Wir kennen bisher noch keine E-Mail-Adresse von Ihnen. Wenn Sie uns eine E-Mail-Adresse angeben, können wir Sie auch per E-Mail über die Fertigstellung Ihres Auftrags benachrichtigen.</p> |
|
45 |
+ <div class="form-group form-group-lg row"> |
|
46 |
+ <div class="col-sm-12"><input class="form-control" id="email" name="email" type="text" placeholder="E-Mail-Adresse" autocomplete="email"></div> |
|
47 |
+ </div>'; |
|
48 |
+ } |
|
49 |
+ |
|
43 | 50 |
$content .= '<input name="fname" type="hidden" value="'.(isset($_SESSION['fname']) ? $_SESSION['fname'] : '').'"> |
44 | 51 |
<input name="lname" type="hidden" value="'.$_SESSION['lname'].'"> |
45 | 52 |
<div class="form-group form-group-lg"> |
... | ... |
@@ -59,6 +66,7 @@ if (isset($_SESSION['kundennr']) and $_SESSION['kundennr']) { |
59 | 66 |
$fields = array("vorname" => "Vorname", |
60 | 67 |
"nachname" => "Nachname", |
61 | 68 |
"firma" => "Firmenname", |
69 |
+ "email" => "E-Mail", |
|
62 | 70 |
"adresse" => "Adresse", |
63 | 71 |
"plz" => "PLZ", |
64 | 72 |
"ort" => "Ort"); |
... | ... |
@@ -94,6 +102,9 @@ if (isset($_SESSION['kundennr']) and $_SESSION['kundennr']) { |
94 | 102 |
<div class="form-group form-group-lg row"> |
95 | 103 |
<div class="col-sm-4"><input class="form-control" id="zip" name="zip" type="text" placeholder="'.$placeholders['plz'].'" autocomplete="postal-code" value="'.$contents['plz'].'"></div> |
96 | 104 |
<div class="col-sm-8"><input class="form-control" id="city" name="city" type="text" placeholder="'.$placeholders['ort'].'" autocomplete="locality" value="'.$contents['ort'].'"></div> |
105 |
+ </div> |
|
106 |
+ <div class="form-group form-group-lg row"> |
|
107 |
+ <div class="col-sm-12"><input class="form-control" id="email" name="email" type="text" placeholder="'.$placeholders['email'].'" autocomplete="email" value="'.$contents['email'].'"></div> |
|
97 | 108 |
</div> |
98 | 109 |
<div class="form-group form-group-lg"> |
99 | 110 |
<div><input class="btn btn-primary btn-lg" type="submit" value="Weiter >"></div> |
... | ... |
@@ -96,6 +96,10 @@ function api_call($method, $url, $content = []) |
96 | 96 |
$request = new Request(strtoupper($method), $url, $headers, $body); |
97 | 97 |
$res = $client->send($request, ['timeout' => 5]); |
98 | 98 |
|
99 |
+ //$filename = '../data/'.date('Y').'/debug-'.microtime(true).'.json'; |
|
100 |
+ //@file_put_contents($filename, strtoupper($method).' '.$url."\n".$body."\n".$res->getBody()); |
|
101 |
+ |
|
102 |
+ |
|
99 | 103 |
if ($res->getStatusCode() >= 500) { |
100 | 104 |
print('Es gibt gerade ein technisches Problem.'); |
101 | 105 |
die(); |
... | ... |
@@ -41,11 +41,65 @@ function suche_kunde($name, $number) { |
41 | 41 |
*/ |
42 | 42 |
} |
43 | 43 |
|
44 |
+function kunde_hat_email($customerno) { |
|
45 |
+ $ret = api_call('GET', 'customers/'.(int) $customerno); |
|
46 |
+ if ($ret['status_code'] >= 400) { |
|
47 |
+ // Fehler. Belästige den Kunden nicht damit |
|
48 |
+ return true; |
|
49 |
+ } |
|
50 |
+ $ret = $ret['data']; |
|
51 |
+ if (isset($ret['email']) && $ret['email']) { |
|
52 |
+ return true; |
|
53 |
+ } |
|
54 |
+ foreach ($ret['contacts'] as $c) { |
|
55 |
+ if (isset($c['email']) && $c['email']) { |
|
56 |
+ return true; |
|
57 |
+ } |
|
58 |
+ } |
|
59 |
+ return false; |
|
60 |
+} |
|
61 |
+ |
|
62 |
+ |
|
63 |
+ |
|
64 |
+function update_kunde($customerno, $daten) { |
|
65 |
+ $ret = api_call('GET', 'customers/'.(int) $customerno); |
|
66 |
+ if ($ret['status_code'] >= 400) { |
|
67 |
+ // Fehler. Erstelle Neukunde |
|
68 |
+ erstelle_kunde($daten); |
|
69 |
+ return; |
|
70 |
+ } |
|
71 |
+ $customer = $ret['data']; |
|
72 |
+ |
|
73 |
+ foreach ($daten as $field => $value) { |
|
74 |
+ if ($value) { |
|
75 |
+ $customer[$field] = $value; |
|
76 |
+ } |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ $filename = '../data/'.date('Y').'/kunde-'.$customerno.'-'.time().'.json'; |
|
80 |
+ @file_put_contents($filename, json_encode($customer)); |
|
81 |
+ $ret = api_call('PUT', 'customers/'.(int) $customerno, $customer); |
|
82 |
+ if ($ret['status_code'] >= 400) { |
|
83 |
+ foreach ($ret['data']['validation_errors'] as $item) { |
|
84 |
+ $_SESSION['warnings'][] = $item['key'].': '.$item['message']; |
|
85 |
+ } |
|
86 |
+ return null; |
|
87 |
+ } |
|
88 |
+ $ret = $ret['data']; |
|
89 |
+ if (isset($ret['id'])) { |
|
90 |
+ return $ret['id']; |
|
91 |
+ } else { |
|
92 |
+ return null; |
|
93 |
+ } |
|
94 |
+} |
|
95 |
+ |
|
96 |
+ |
|
44 | 97 |
function erstelle_kunde($daten) { |
45 | 98 |
$json = [ |
46 | 99 |
"firstname" => $daten['fname'] ?: null, |
47 | 100 |
"lastname" => $daten['lname'], |
48 | 101 |
"phone" => format_number_api($daten['phone']), |
102 |
+ "email" => $daten['email'] ?: null, |
|
49 | 103 |
"street" => $daten['address'] ?: null, |
50 | 104 |
"zip" => $daten['zip'] ?: null, |
51 | 105 |
"city" => $daten['city'] ?: null, |
... | ... |
@@ -85,7 +85,7 @@ if (isset($_REQUEST['form'])) { |
85 | 85 |
break; |
86 | 86 |
|
87 | 87 |
case 'address': |
88 |
- $fields = array("firma", "fname", "lname", "address", "zip", "city"); |
|
88 |
+ $fields = array("firma", "fname", "lname", "address", "zip", "city", "email"); |
|
89 | 89 |
foreach ($fields as $f) { |
90 | 90 |
if (isset($_REQUEST[$f]) && trim($_REQUEST[$f]) != '') { |
91 | 91 |
$_SESSION[$f] = trim(htmlspecialchars($_REQUEST[$f])); |
... | ... |
@@ -104,6 +104,10 @@ if (isset($_REQUEST['form'])) { |
104 | 104 |
if (!$_SESSION['kundennr']) { |
105 | 105 |
showError(); |
106 | 106 |
} |
107 |
+ } else { |
|
108 |
+ if (isset($_SESSION['email']) && $_SESSION['email']) { |
|
109 |
+ update_kunde($_SESSION['kundennr'], ['email' => $_SESSION['email']]); |
|
110 |
+ } |
|
107 | 111 |
} |
108 | 112 |
|
109 | 113 |
if ($_SESSION['mode'] == 'local') { |
110 | 114 |