git.schokokeks.org
Repositories
Help
Report an Issue
bibweb.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
3a6b9e8
Branches
Tags
master
bibweb.git
address.php
Erste Version, die über die API speichert
Bernd Wurst
commited
3a6b9e8
at 2020-06-06 20:24:13
address.php
Blame
History
Raw
<?php session_start(); if (!isset($_SESSION['phone']) || (!isset($_SESSION['name']) && !isset($_SESSION['firma']) && !isset($_SESSION['lname']))) { header('Location: index.php?error&num='.urlencode($_SESSION['phone']).'&name='.urlencode($_SESSION['name'])); die(); } function suche_kunde($name, $number) { global $content; if (! $number) { return NULL; } $data = array("name" => $name, "telefon" => $number); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mosterei-wurst.de/api/v1/kunde/pruefen", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_HTTPHEADER => array("Content-Type: application/json"), CURLOPT_CUSTOMREQUEST => "POST")); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($curl); $err = curl_error($curl); $ret = @json_decode($response, true); if (!$ret || $ret["status"] == 'error' || !$ret["kundennr"]) { if (isset($ret["errno"]) && $ret["errno"] == "429") { $content .= '<div class="card text-white bg-danger mb-3"> <div class="card-header">Fehler</div> <div class="card-body">Die Suche anhand der Telefonnummer wurde verweigert, weil zu viele Zugriffe auf diese Funktion vorgenommen wurden. Bitte geben Sie Ihre Daten neu ein oder versuchen Sie es in wenigen Minuten noch einmal.</div> </div>'; } return null; } return $ret; /* $kundenliste = json_decode(file_get_contents('../kunden.json'), TRUE); foreach ($kundenliste as $k) { foreach ($k['kontakt'] as $kon) { if ($kon['wert'] == $number) { return $k; } } } */ } $content = ''; $kunde = null; if (isset($_SESSION['name'])) { $kunde = suche_kunde($_SESSION['name'], $_SESSION['phone']); } if ($kunde) { $fields = array("kundennr" => "kundennr", "firma" => "firma", "fname" => "vorname", "lname" => "nachname", "address" => "adresse", "zip" => "plz", "city" => "ort"); foreach ($fields as $sesskey => $arrkey) { if (isset($kunde[$arrkey])) { $_SESSION[$sesskey] = $kunde[$arrkey]; } } unset($_SESSION['name']); } if (isset($_REQUEST['error'])) { $content .= '<div class="card text-white bg-danger mb-3"> <div class="card-header">Fehler</div> <div class="card-body">Bitte geben Sie Ihren Namen an.</div> </div>'; } if (!$kunde) { $kunde = array('kundennr' => '', 'firma' => '', 'nachname' => '', 'vorname' => '', 'adresse' => '', 'plz' => '', 'ort' => ''); $fields = array("kundennr" => "kundennr", "firma" => "firma", "fname" => "vorname", "lname" => "nachname", "address" => "adresse", "zip" => "plz", "city" => "ort"); foreach ($fields as $sesskey => $arrkey) { if (isset($_SESSION[$sesskey])) { $kunde[$arrkey] = $_SESSION[$sesskey]; } } } $headline = 'Adresse eingeben'; if ($kunde) { $headline = 'Willkommen zurück!'; $content .= ' <p>Schön, wir kennen uns ja schon! Wenn sich an Ihrer Adresse seit Ihrem letztem Besuch etwas geändert hat, ändern Sie es bitte hier. Ansonsten können Sie die Felder so lassen. Aus Datenschutzgründen werden die gespeicherten Daten hier nicht angezeigt.</p> '; } else { $content .= ' <p>Bitte geben Sie in diesem Schritt Ihre Adresse ein.</p> '; } $fields = array("vorname" => "Vorname", "nachname" => "Nachname", "firma" => "Firmenname", "adresse" => "Adresse", "plz" => "PLZ", "ort" => "Ort"); $placeholders = $fields; $contents = $kunde; foreach ($fields as $field => $label) { if (isset($kunde[$field]) && $kunde[$field] == 'bekannt') { $placeholders[$field] = $label.' wie beim letzten Besuch'; $contents[$field] = ''; } elseif (!isset($contents[$field])) { $contents[$field] = ''; } } $content .= ' <form class="form" action="save.php" method="post"> <input type="hidden" name="form" value="address">'; if (isset($kunde['firma']) && $kunde['firma'] != '') { $content .= ' <div class="form-group form-group-lg row"> <div class="col-sm-12"><input class="form-control" id="address" name="address" type="text" placeholder="'.$placeholders['firma'].'" autocomplete="street-address" value="'.$contents['firma'].'"></div> </div>'; } $content .= ' <div class="form-group form-group-lg row"> <div class="col-sm-6"><input class="form-control" id="fname" name="fname" type="text" placeholder="'.$placeholders['vorname'].'" autocomplete="given-name" value="'.$contents['vorname'].'"></div> <div class="col-sm-6"><input class="form-control" id="lname" name="lname" type="text" placeholder="'.$placeholders['nachname'].'" autocomplete="family-name" value="'.$contents['nachname'].'"></div> </div> <div class="form-group form-group-lg row"> <div class="col-sm-12"><input class="form-control" id="address" name="address" type="text" placeholder="'.$placeholders['adresse'].'" autocomplete="street-address" value="'.$contents['adresse'].'"></div> </div> <div class="form-group form-group-lg row"> <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> <div class="col-sm-8"><input class="form-control" id="city" name="city" type="text" placeholder="'.$placeholders['ort'].'" autocomplete="locality" value="'.$contents['ort'].'"></div> </div> <div class="form-group form-group-lg"> <div><input class="btn btn-primary btn-lg" type="submit" value="Weiter >"></div> </div> </form> '; include("template.php");