git.schokokeks.org
Repositories
Help
Report an Issue
bibweb.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
4963b3d
Branches
Tags
master
bibweb.git
lib
auftrag.php
Auswahl, ob per E-Mail oder SMS benachrichtigt werden soll
Bernd Wurst
commited
4963b3d
at 2024-09-20 07:41:52
auftrag.php
Blame
History
Raw
<?php require_once('api.php'); function phonetisch_reduzieren($word) { $word=strtolower($word); $substitution=array( "ä"=>"ae", "ö"=>"oe", "ü"=>"ue", "ß"=>"ss", "ph"=>"f" ); foreach ($substitution as $letter=>$substitution) { $word=str_replace($letter,$substitution,$word); } return $word; } 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 ((isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['lastname'])) || (isset($cust['firstname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['firstname'])) || (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['firstname'] .' '. $cust['lastname'])) || (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($cust['lastname'] .' '. $cust['firstname'])) || (isset($cust['firstname']) && isset($cust['lastname']) && phonetisch_reduzieren($name) == phonetisch_reduzieren($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 kunde_erste_kontakte($customerno) { $ret = api_call('GET', 'customers/'.(int) $customerno); if ($ret['status_code'] >= 400) { // Fehler. Belästige den Kunden nicht damit return []; } $ret = $ret['data']; $kontakte = []; if (isset($ret['phone']) && str_starts_with($ret['phone'], '+491')) { $kontakte['mobil'] = $ret['phone']; } if (isset($ret['email']) && $ret['email']) { $kontakte['email'] = $ret['email']; } foreach ($ret['contacts'] as $c) { if (!isset($kontakte['mobil']) && isset($c['phone']) && str_starts_with($c['phone'], '+491')) { $kontakte['mobil'] = $c['phone']; } if (!isset($kontakte['email']) && isset($c['email']) && $c['email']) { $kontakte['email'] = $c['email']; } } return $kontakte; } function kunde_hat_email($customerno) { $ret = api_call('GET', 'customers/'.(int) $customerno); if ($ret['status_code'] >= 400) { // Fehler. Belästige den Kunden nicht damit return true; } $ret = $ret['data']; if (isset($ret['email']) && $ret['email']) { return true; } foreach ($ret['contacts'] as $c) { if (isset($c['email']) && $c['email']) { return true; } } return false; } function update_kunde($customerno, $daten) { $ret = api_call('GET', 'customers/'.(int) $customerno); if ($ret['status_code'] >= 400) { // Fehler. Erstelle Neukunde erstelle_kunde($daten); return; } $customer = $ret['data']; foreach ($daten as $field => $value) { if ($value) { $customer[$field] = $value; } } $filename = '../data/'.date('Y').'/'.time().'-kunde-'.$customerno.'.json'; @file_put_contents($filename, json_encode($customer)); $ret = api_call('PUT', 'customers/'.(int) $customerno, $customer); if ($ret['status_code'] >= 400) { foreach ($ret['data']['validation_errors'] as $item) { $_SESSION['warnings'][] = $item['key'].': '.$item['message']; } return null; } $ret = $ret['data']; if (isset($ret['id'])) { return $ret['id']; } else { return null; } } function erstelle_kunde($daten) { $json = [ "firstname" => $daten['fname'] ?: null, "lastname" => $daten['lname'], "phone" => format_number_api($daten['phone']), "email" => $daten['email'] ?: null, "street" => $daten['address'] ?: null, "zip" => $daten['zip'] ?: null, "city" => $daten['city'] ?: null, "contacts" => []]; $filename = '../data/'.date('Y').'/'.time().'-neukunde.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['key'].': '.$item['message']; } return null; } $ret = $ret['data']; if (isset($ret['id'])) { return $ret['id']; } else { return null; } } require_once(__DIR__.'/../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; }