Auswahl, ob per E-Mail oder SMS benachrichtigt werden soll
Bernd Wurst

Bernd Wurst commited on 2024-09-20 07:41:52
Zeige 7 geänderte Dateien mit 134 Einfügungen und 1 Löschungen.

... ...
@@ -0,0 +1,21 @@
1
+function email_click( event ) {
2
+        $('#notification').val('email');
3
+         $('form').submit();
4
+         event.preventDefault();
5
+}
6
+
7
+
8
+function sms_click( event ) {
9
+        $('#notification').val('sms');
10
+         $('form').submit();
11
+         event.preventDefault();
12
+}
13
+
14
+
15
+$(function () {
16
+    
17
+   $('#btn-email').click(email_click);
18
+    $('#btn-sms').click(sms_click);
19
+
20
+});
21
+
... ...
@@ -105,6 +105,22 @@ input[type=submit] {
105 105
     margin-bottom: 0.5em;
106 106
 }
107 107
 
108
+#btn-sms {
109
+    min-width: 280px; 
110
+    padding-top: 170px;
111
+    background-image: url("images/sms.png");
112
+    background-repeat: no-repeat;
113
+    background-position: center 10px;
114
+}
115
+
116
+#btn-email {
117
+    min-width: 280px; 
118
+    padding-top: 170px;
119
+    background-image: url("images/email.png");
120
+    background-repeat: no-repeat;
121
+    background-position: center 10px;
122
+}
123
+
108 124
 #btn-gitterbox {
109 125
     min-width: 280px;
110 126
     padding-top: 170px;
... ...
@@ -61,6 +61,32 @@ function suche_kunde($name, $number) {
61 61
         */
62 62
 }
63 63
 
64
+function kunde_erste_kontakte($customerno) {
65
+    $ret = api_call('GET', 'customers/'.(int) $customerno);
66
+    if ($ret['status_code'] >= 400) {
67
+        // Fehler. Belästige den Kunden nicht damit
68
+        return [];
69
+    }
70
+    $ret = $ret['data'];
71
+    $kontakte = [];
72
+    if (isset($ret['phone']) && str_starts_with($ret['phone'], '+491')) {
73
+        $kontakte['mobil'] = $ret['phone'];
74
+    }
75
+    if (isset($ret['email']) && $ret['email']) {
76
+        $kontakte['email'] = $ret['email'];
77
+    }
78
+    foreach ($ret['contacts'] as $c) {
79
+        if (!isset($kontakte['mobil']) && isset($c['phone']) && str_starts_with($c['phone'], '+491')) {
80
+            $kontakte['mobil'] = $c['phone'];
81
+        }
82
+        if (!isset($kontakte['email']) && isset($c['email']) && $c['email']) {
83
+            $kontakte['email'] = $c['email'];
84
+        }
85
+    }
86
+    return $kontakte;
87
+}
88
+
89
+
64 90
 function kunde_hat_email($customerno) {
65 91
     $ret = api_call('GET', 'customers/'.(int) $customerno);
66 92
     if ($ret['status_code'] >= 400) {
... ...
@@ -141,7 +167,7 @@ function erstelle_kunde($daten) {
141 167
     }
142 168
 }
143 169
 
144
-require_once('vendor/autoload.php');
170
+require_once(__DIR__.'/../vendor/autoload.php');
145 171
 
146 172
 function format_number_national($number) {
147 173
     $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
... ...
@@ -0,0 +1,54 @@
1
+<?php
2
+require_once "lib/api.php";
3
+require_once "lib/auftrag.php";
4
+session_start();
5
+
6
+if (!isset($_SESSION['phone']) || (!isset($_SESSION['name']) && !isset($_SESSION['firma']) && !isset($_SESSION['lname']))) {
7
+    header('Location: index.php?error&num='.urlencode($_SESSION['phone']).'&name='.urlencode($_SESSION['name']));
8
+    die();
9
+}
10
+
11
+// Hier ist der Kunde erstellt und mit Kundennummer bekannt.
12
+
13
+$headline = 'Benachrichtigung wählen';
14
+$content = '<p>Wie möchten Sie bevorzugt kontaktiert werden, wenn Ihr Auftrag erledigt ist?</p>
15
+        <form class="form" action="save.php" method="post">
16
+        <input type="hidden" name="form" value="notification">
17
+    <div class="form-group form-group-lg row">';
18
+
19
+$num = 0;
20
+$kontakte = kunde_erste_kontakte($_SESSION['kundennr']);
21
+
22
+if (isset($kontakte['email'])) {
23
+    $num++;
24
+    $email = $kontakte['email'];
25
+    if ($_SESSION['email'] != $kontakte['email']) {
26
+        // Adresse wurde nicht grade eingegeben, verschleiere Adresse
27
+        list($local, $domain) = explode('@', $kontakte['email']);
28
+        $local = substr_replace($local, '...', 2);
29
+        $email = $local . '@' . $domain;
30
+    }
31
+    $content .= '
32
+        <div class="col-sm-6"><a href="#" class="btn btn-block btn-lg btn-light" id="btn-email">E-Mail<br>an '.$email.'</a></div>';
33
+}
34
+if (isset($kontakte['mobil'])) {
35
+    $num++;
36
+    $phone = format_number_national($_SESSION['phone']);
37
+    if (!str_starts_with($phone, '01')) {
38
+        $phone = substr_replace(format_number_national($kontakte['mobil']), ' ...', 4, 5);
39
+    }
40
+    $content .= '
41
+        <div class="col-sm-6"><a href="#" class="btn btn-block btn-lg btn-light" id="btn-sms">SMS<br>an '.$phone.'</a></div>';
42
+}
43
+$content .= '<input type="hidden" name="notification" id="notification" value="">
44
+    </div>';
45
+ 
46
+if ($num < 2) {
47
+    // Nichts zum aussuchen!
48
+    header('Location: gitterbox.php');
49
+}
50
+
51
+
52
+$content .= '</form>';
53
+
54
+include("template.php");
... ...
@@ -129,6 +129,21 @@ if (isset($_REQUEST['form'])) {
129 129
                 }
130 130
             }
131 131
 
132
+            $redirect = 'notification.php';
133
+            break;
134
+
135
+        case 'notification':
136
+            if (isset($_REQUEST['notification'])) {
137
+                if ($_REQUEST['notification'] == 'sms') {
138
+                    $_SESSION['notificationPreference'] = 'sms';
139
+                } elseif ($_REQUEST['notification'] == 'whatsapp') {
140
+                    $_SESSION['notificationPreference'] = 'whatsapp';
141
+                } elseif ($_REQUEST['notification'] == 'email') {
142
+                    $_SESSION['notificationPreference'] = 'email';
143
+                } else {
144
+                    $_SESSION['notificationPreference'] = '';
145
+                }
146
+            }
132 147
             if ($_SESSION['mode'] == 'local') {
133 148
                 $_SESSION['angeliefert'] = true;
134 149
                 $redirect = 'gitterbox.php';
... ...
@@ -243,6 +259,7 @@ if (isset($_SESSION['neue'])) {
243 259
         $auftrag['notificationName'] = $_SESSION['name'];
244 260
         $auftrag['notificationPhone'] = $_SESSION['phone'];
245 261
         $auftrag['notificationEmail'] = isset($_SESSION['email']) ? $_SESSION['email'] : null;
262
+        $auftrag['notificationPreference'] = $_SESSION['notificationPreference'];
246 263
     }
247 264
     // fruitType
248 265
     $ret = api_call('GET', 'fruitTypes');
249 266