address.php
3375a8a6
 <?php
40e4230b
 require_once "lib/api.php";
 require_once "lib/auftrag.php";
3375a8a6
 session_start();
 
3a6b9e82
 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']));
3375a8a6
     die();
 }
 
71db6706
 
 $content = '';
d4c1bfec
 $kunde = null;
 if (isset($_SESSION['name'])) {
     $kunde = suche_kunde($_SESSION['name'], $_SESSION['phone']);
 }
3375a8a6
 if ($kunde) {
3a6b9e82
     $fields = array("kundennr" => "kundennr", "firma" => "firma", "fname" => "vorname", "lname" => "nachname", "address" => "adresse", "zip" => "plz", "city" => "ort");
d4c1bfec
     foreach ($fields as $sesskey => $arrkey) {
40e4230b
         if (isset($_SESSION[$sesskey]) && $_SESSION[$sesskey] != '' && $_SESSION[$sesskey] != 'bekannt') {
             $kunde[$arrkey] = $_SESSION[$sesskey];
         }
3a6b9e82
         if (isset($kunde[$arrkey])) {
             $_SESSION[$sesskey] = $kunde[$arrkey];
         }
d4c1bfec
     }
     unset($_SESSION['name']);
3375a8a6
 }
 
 if (isset($_REQUEST['error'])) {
9b550393
     $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>
3375a8a6
     </div>';
 }
 
3a6b9e82
 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];
         }
     }
489c0171
     if (isset($_SESSION['name'])) {
         $kunde['nachname'] = ucwords($_SESSION['name']);
         if (strpos($_SESSION['name'], ' ') !== false) {
             $parts = explode(" ", ucwords($_SESSION['name']));
             $kunde['nachname'] = array_pop($parts);
             $kunde['vorname'] = implode(" ", $parts);
 
         }
     }
3a6b9e82
 }
3375a8a6
 $headline = 'Adresse eingeben';
489c0171
 if ($kunde['kundennr']) {
d4c1bfec
     $headline = 'Willkommen zurück!';
3375a8a6
     $content .= '
d4c1bfec
         <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>
3375a8a6
     ';
 } else { 
     $content .= '
d4c1bfec
         <p>Bitte geben Sie in diesem Schritt Ihre Adresse ein.</p>
3375a8a6
     ';
 }
d4c1bfec
 
3a6b9e82
 $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] = '';
d4c1bfec
     }
3a6b9e82
 
3375a8a6
 }
 
3a6b9e82
 
3375a8a6
 $content .= '
     <form class="form" action="save.php" method="post">
3a6b9e82
     <input type="hidden" name="form" value="address">';
 if (isset($kunde['firma']) && $kunde['firma'] != '') {
     $content .= '
3375a8a6
     <div class="form-group form-group-lg row">
3a6b9e82
         <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>
3375a8a6
     </div>
     <div class="form-group form-group-lg row">
3a6b9e82
         <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>
3375a8a6
     </div>
     <div class="form-group form-group-lg row">
3a6b9e82
         <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>
3375a8a6
     </div>
       <div class="form-group form-group-lg">
         <div><input class="btn btn-primary btn-lg" type="submit" value="Weiter &gt;"></div>
     </div>
     </form>
 
 ';
 
 
 include("template.php");