git.schokokeks.org
Repositories
Help
Report an Issue
bibweb.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
bfc6ce6
Branches
Tags
master
bibweb.git
lib
auftrag.php
API-Aufrufe über Guzzle um Feedback bekommen zu können
Bernd Wurst
commited
bfc6ce6
at 2023-08-11 10:48:24
auftrag.php
Blame
History
Raw
<?php require_once('api.php'); function suche_kunde($name, $number) { global $content; if (! $number) { return NULL; } $ret = api_call('GET', 'customerContacts/search/'.format_number_api($number)); if ($ret['status_code'] >= 400) { foreach ($ret['data']['validation_errors'] as $item) { $_SESSION['warning'][] = $item['message']; } return null; } $ret = $ret['data']; if (count($ret) > 0) { $name = strtolower($name); foreach ($ret as $item) { $cust = $item['customer']; if ($name == strtolower($cust['lastname']) || $name == strtolower($cust['firstname']) || $name == strtolower($cust['firstname'] .' '. $cust['lastname']) || $name == strtolower($cust['lastname'] .' '. $cust['firstname']) ) { return $cust; } } } return null; /* $kundenliste = json_decode(file_get_contents('../kunden.json'), TRUE); foreach ($kundenliste as $k) { foreach ($k['kontakt'] as $kon) { if ($kon['wert'] == $number) { return $k; } } } */ } function erstelle_kunde($daten) { $json = [ "firstname" => $daten['fname'] ?: null, "lastname" => $daten['lname'], "phone" => format_number_api($daten['phone']), "street" => $daten['address'] ?: null, "zip" => $daten['zip'] ?: null, "city" => $daten['city'] ?: null, "contacts" => []]; $filename = '../data/'.date('Y').'/neukunde-'.time().'.json'; @file_put_contents($filename, json_encode($json)); $ret = api_call('POST', 'customers', $json); if ($ret['status_code'] >= 400) { foreach ($ret['data']['validation_errors'] as $item) { $_SESSION['warnings'][] = $item['message']; } return null; } $ret = $ret['data']; if (isset($ret['id'])) { return $ret['id']; } else { return null; } } require_once('vendor/autoload.php'); function format_number_national($number) { $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); try { $phoneNumber = $phoneNumberUtil->parse($number, 'DE'); } catch (Exception $e) { return NULL; } if ($phoneNumberUtil->isValidNumber($phoneNumber)) { return $phoneNumberUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::NATIONAL); } return NULL; } function format_number($number) { $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); try { $phoneNumber = $phoneNumberUtil->parse($number, 'DE'); } catch (Exception $e) { return NULL; } if ($phoneNumberUtil->isValidNumber($phoneNumber)) { return $phoneNumberUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::INTERNATIONAL); } return NULL; }