3a6b9e82117083b183fa058562e12f1f0ffa748b
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

1) <?php
2) session_start();
3) 
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

4) if (! isset($_SESSION['handle']) || !$_SESSION['handle']) {
5)     $random = base64_encode(md5(microtime()));
6)     $_SESSION['handle'] = substr(str_replace(array('+', '=', '/'), '', $random), 0, 5);
Bernd Wurst Änderungen Stand 2019

Bernd Wurst authored 4 years ago

7)     $_SESSION['date'] = date('Y-m-d H:i:s.v');
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

8)     $_SESSION['complete'] = false;
9) }
10) 
Bernd Wurst Änderungen Stand 2019

Bernd Wurst authored 4 years ago

11) 
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

12) $redirect = NULL;
13) if (isset($_REQUEST['form'])) {
14)     switch ($_REQUEST['form']) {
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

15)         case 'start':
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

16)             $number = '';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

17)             if (isset($_REQUEST['phone']) && trim($_REQUEST['phone']) != '') {
Bernd Wurst Ergänze lokale Vorwahl bei...

Bernd Wurst authored 6 years ago

18)                 $number = trim($_REQUEST['phone']);
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

19)             }
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

20)             $name = '';
21)             if (isset($_REQUEST['name']) && trim($_REQUEST['name']) != '') {
22)                 $name = trim($_REQUEST['name']);
23)             }
24) 
25)             if (! $number || !$name) {
26)                 $redirect = 'index.php?error&num='.urlencode($number).'&name='.urlencode($name);
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

27)                 break;
28)             }
Bernd Wurst Änderungen Stand 2019

Bernd Wurst authored 4 years ago

29) 
30)             if (substr($number, 0, 1) != 0 && substr($number, 0, 3) != '+49') {
Bernd Wurst Ergänze lokale Vorwahl bei...

Bernd Wurst authored 6 years ago

31)                 $number = '07192'.$number;
32)             }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

33) 
34)             require_once('vendor/autoload.php');
35) 
36)             function format_number($number) {
37)                 $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
38)                 try {
39)                     $phoneNumber = $phoneNumberUtil->parse($number, 'DE');
40)                 } catch (Exception $e) {
41)                     return NULL;
42)                 }
43)                 if ($phoneNumberUtil->isValidNumber($phoneNumber)) {
44)                     return $phoneNumberUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::NATIONAL);
45)                 }
46)                 return NULL;
47)             }
48)             $number = format_number($number);
49) 
Bernd Wurst bestehende Kunden über die...

Bernd Wurst authored 4 years ago

50)             $_SESSION['name'] = htmlspecialchars($name);
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

51)             $_SESSION['phone'] = htmlspecialchars($number);
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

52)             if (isset($_REQUEST['save']) && $_REQUEST['save'] == 'yes' && $_SESSION['mode'] != 'local') {
Bernd Wurst bestehende Kunden über die...

Bernd Wurst authored 4 years ago

53)                 setcookie('NAME', $name, time() + 24*3600*500, "");
Bernd Wurst Cookie löschbar, Datenschut...

Bernd Wurst authored 6 years ago

54)                 setcookie('NUMBER', $number, time() + 24*3600*500, "");
55)             }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

56) 
Bernd Wurst Dateinamen geändert

Bernd Wurst authored 6 years ago

57)             $redirect = 'address.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

58)             break;
59) 
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

60)         case 'address':
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

61)             $fields = array("firma", "fname", "lname", "address", "zip", "city");
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

62)             foreach ($fields as $f) {
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

63)                 if (isset($_REQUEST[$f]) && trim($_REQUEST[$f]) != '') {
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

64)                     $_SESSION[$f] = trim(htmlspecialchars($_REQUEST[$f]));
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

65)                 } else {
66)                     if (! isset($_SESSION[$f])) {
67)                         $_SESSION[$f] = '';
68)                     }
69)                 }
70)             }
Bernd Wurst Fehlermeldungen auf BS4 por...

Bernd Wurst authored 6 years ago

71)             if ($_SESSION['lname'] == '') {
72)                 $redirect = 'address.php?error';
73)                 break;
74)             }
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

75)             if ($_SESSION['mode'] == 'local') {
76)                 $_SESSION['angeliefert'] = true;
77)                 $redirect = 'gitterbox.php';
78)             } elseif (isset($_SESSION['angeliefert'])) {
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

79)                 if ($_SESSION['angeliefert']) {
80)                     $redirect = 'gitterbox.php';
81)                 } else {
82)                     $redirect = 'gitterbox_spaeter.php';
83)                 }
84)             } else {
85)                 $redirect = 'anlieferung.php';
86)             }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

87)             break;
88) 
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

89)         case 'anlieferung':
90)             if (isset($_REQUEST['schonda'])) {
91)                 $_SESSION['angeliefert'] = true;
92)                 $redirect = 'gitterbox.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

93)             }
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

94)             if (isset($_REQUEST['kommtnoch'])) {
95)                 $_SESSION['angeliefert'] = false;
96)                 $redirect = 'gitterbox_spaeter.php';
97)             }
98)             break;
99)         case 'gitterbox':
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

100)             if (isset($_REQUEST['lieferart'])) {
101)                 if ($_REQUEST['lieferart'] == 'gitterbox') {
102)                     $_SESSION['lieferart'] = 'gitterbox';
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

103)                     $_SESSION['gbcount'] = htmlspecialchars($_REQUEST['gbcount']);
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

104)                 }
105)                 if ($_REQUEST['lieferart'] == 'anhaenger') {
106)                     $_SESSION['lieferart'] = 'anhaenger';
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

107)                     $_SESSION['kennz'] = htmlspecialchars($_REQUEST['kennz']);
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

108)                     if ($_SESSION['angeliefert'] === false && ! $_SESSION['kennz']) {
109)                         $redirect = 'gitterbox_spaeter.php?error';
110)                         break;
111)                     }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

112)                 }
113)             }
Bernd Wurst Dateinamen geändert

Bernd Wurst authored 6 years ago

114)             $redirect = 'gebrauchte.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

115)             break;
116) 
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

117)          case 'gebrauchte':
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

118)             if (isset($_REQUEST['kartonsja'])) {
119)                 $_SESSION['kartons'] = true;
120)             } 
121)             if (isset($_REQUEST['kartonsnein'])) {
122)                 $_SESSION['kartons'] = false;
123)             }
124) 
Bernd Wurst Dateinamen geändert

Bernd Wurst authored 6 years ago

125)             $redirect = 'auftrag.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

126)             break;
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

127)          case 'auftrag':
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

128)             if (isset($_REQUEST['5er'])) {
129)                 $_SESSION['neue'] = '5er';
130)             }
131)             if (isset($_REQUEST['10er'])) {
132)                 $_SESSION['neue'] = '10er';
133)             }
134)             if (isset($_REQUEST['submit']) && isset($_REQUEST['sonstiges']) && $_REQUEST['sonstiges'] != '') {
135)                 $_SESSION['neue'] = 'sonstiges';
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

136)                 $_SESSION['sonstiges'] = htmlspecialchars($_REQUEST['sonstiges']);
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

137)             }
138) 
139) 
Bernd Wurst Dateinamen geändert

Bernd Wurst authored 6 years ago

140)             $redirect = 'frischsaft.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

141)             break;
142) 
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

143)          case 'frischsaft':
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

144)             if (isset($_REQUEST['frischsaftnein'])) {
145)                 $_SESSION['frischsaft'] = 0;
146)             } elseif (isset($_REQUEST['frischsaft'])) {
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

147)                 $_SESSION['frischsaft'] = htmlspecialchars($_REQUEST['frischsaft']);
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

148)             }
149) 
Bernd Wurst Dateinamen geändert

Bernd Wurst authored 6 years ago

150)             $redirect = 'summary.php';
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

151)             break;
Bernd Wurst Spätere Anlieferung eingebaut

Bernd Wurst authored 6 years ago

152)         case 'summary':
Bernd Wurst anmerkungen ermöglicht

Bernd Wurst authored 6 years ago

153)             if (isset($_REQUEST['anmerkungen'])) {
154)                 $_SESSION['anmerkungen'] = htmlspecialchars($_REQUEST['anmerkungen']);
155)             }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

156) 
157)             $_SESSION['complete'] = true;
158)             $redirect = 'finish.php?handle='.$_SESSION['handle'];
159)             break;
160) 
161)     }
162) }
163) 
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

164) $data = array("handle" => $_SESSION['handle']);
165) 
166) $curl = curl_init();
167) 
168) curl_setopt_array($curl, array(
169)   CURLOPT_URL => "https://api.mosterei-wurst.de/api/v1/auftrag/lesen",
170)   CURLOPT_RETURNTRANSFER => true,
171)   CURLOPT_ENCODING => "",
172)   CURLOPT_MAXREDIRS => 10,
173)   CURLOPT_TIMEOUT => 30,
174)   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
175)   CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
176)   CURLOPT_CUSTOMREQUEST => "POST"));
177) 
178) curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
179) 
180) $response = curl_exec($curl);
181) $err = curl_error($curl);
182) 
183) $ret = @json_decode($response, true);
184) 
185) if (!isset($ret['auftrag'])) {
186)     echo 'Es gibt ein Problem beim Speichern der Auftragsdaten. Bitte wenden Sie sich persönlich an uns oder verwenden Sie einen Papierauftrag.';
187)     die();
188) }
189) 
190) 
191) $auftrag = $ret['auftrag'];
192) 
193) 
194) if (isset($_SESSION['kundennr'])) {
195)     $auftrag['kundennr'] = $_SESSION['kundennr'];
196) }
197) $addrfields = array("kundennr" => "kundennr", "firma" => "firma", "fname" => "vorname", "lname" => "nachname", "address" => "adresse", "zip" => "plz", "city" => "ort", "phone" => "telefon");
198) foreach ($addrfields as $sesskey => $apikey) {
199)     if (isset($_SESSION[$sesskey]) && $_SESSION[$sesskey] != 'bekannt') {
200)         $auftrag['kundendaten'][$apikey] = $_SESSION[$sesskey];
201)     }
202) }
203) 
204) if (count($auftrag['bestellung']) > 1) {
205)     echo 'Diese Bestellung wurde auf anderem Wege an uns übermittelt und kann mit dieser Oberfläche leider nicht verändert werden';
206)     die();
207) }
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

208) 
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

209) if (isset($_SESSION['lieferart']) && $_SESSION['lieferart'] == 'gitterbox' && isset($_SESSION['gbcount']) && $_SESSION['gbcount'] > 0) {
210)     if ($_SESSION['gbcount'] < count($auftrag['bestellung'][0]["gitterbox"])) {
211)         $auftrag['bestellung'][0]["gitterbox"] = array();
212)     }
213)     while (count($auftrag['bestellung'][0]["gitterbox"]) < $_SESSION['gbcount']) {
214)         $auftrag['bestellung'][0]["gitterbox"][] = array("id" => null);
215)     }
216) } else {
217)     $auftrag['bestellung'][0]["gitterbox"] = array();
Bernd Wurst Initial commit

Bernd Wurst authored 6 years ago

218) }
219) 
Bernd Wurst Erste Version, die über die...

Bernd Wurst authored 4 years ago

220) if (isset($_SESSION['lieferart']) && $_SESSION['lieferart'] == 'anhaenger') {
221)     $auftrag['bestellung'][0]['anhaenger'] = array(array("kennz" => null));
222)     if (isset($_SESSION['kennz']) && $_SESSION['kennz'] != '') {
223)         $auftrag['bestellung'][0]['anhaenger'][0]["kennz"] = $_SESSION['kennz'];
224)     }
225) }
226) 
227) if (isset($_SESSION['kartons']) && $_SESSION['kartons']) {
228)     $auftrag['bestellung'][0]['gebrauchte'] = true;
229) } else {
230)     $auftrag['bestellung'][0]['gebrauchte'] = false;
231) }
232) 
233) $auftrag['bestellung'][0]['neue'] = array();
234) if (isset($_SESSION['neue']) && $_SESSION['neue'] == 'sonstiges') {
235)     $auftrag['bestellung'][0]['neue']["sonstiges"] = $_SESSION["sonstiges"];
236) } elseif (isset($_SESSION['neue']) && $_SESSION['neue'] == '10er') {
237)     $auftrag['bestellung'][0]['neue']["10er"] = "100%";
238) } else {
239)     $auftrag['bestellung'][0]['neue']["5er"] = "100%";
240) }
241) 
242) if (isset($_SESSION['frischsaft']) && $_SESSION['frischsaft'] > 0) {
243)     $auftrag['bestellung'][0]['frischsaft'] = $_SESSION['frischsaft'];
244) } else {
245)     $auftrag['bestellung'][0]['frischsaft'] = null;
246) }
247) 
248) 
249) if (isset($_SESSION['anmerkungen']) && $_SESSION['anmerkungen'] != '') {
250)     $auftrag['bestellung'][0]['anmerkungen'] = $_SESSION['anmerkungen'];
251) }
252) 
253) if (isset($_SESSION['complete']) && $_SESSION['complete'] == true) {
254)     $auftrag['status'] = 'bestellt';
255) }
256) 
257) curl_setopt($curl, CURLOPT_URL, "https://api.mosterei-wurst.de/api/v1/auftrag/anlieferung");
258) curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($auftrag));
259) 
260) $response = curl_exec($curl);
261) $err = curl_error($curl);
262) 
263) $ret = @json_decode($response, true);
264) 
265) if ($ret['status'] == 'error') {
266)     echo 'Es gibt ein Problem beim Speichern des Auftrags. Bitte verwenden Sie diesmal einen Papier-Auftrag.';
267)     die();
268) }
269) 
270)