<?php
require_once 'lib/api.php';
require_once 'lib/tools.php';
// some sort of limit?!
session_start();

$ret = '';
$data = array("kunde" => array(), "uuid" => '');

$fields = array("kundennr", "firma", "vorname", "nachname", "adresse", "plz", "ort");
foreach ($fields as $key) {
    if (isset($_GET[$key])) {
        $data['kunde'][$key] = $_GET[$key];
    }
}
if (isset($_GET['telefon'])) {
    $data['kunde']['kontakt'] = array();
    $data['kunde']['kontakt'][] = array(
        "typ" => "telefon",
        "wert" => $_GET['telefon']);
}

$ret = api_call('kunde/aendern', $data);

if (!isset($ret['kunde'])) {
    return;
}
$ret['kunde']['html'] = adresse($ret['kunde'], 'kundendaten');

header('Content-Type: application/json');
echo json_encode($ret['kunde']);