<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include_once ($_SERVER['DOCUMENT_ROOT'] . '/_config/functions.php');
spl_autoload_register('my_autoload');
include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/chk.auth.php');


$headline                           = '<h2>Neuer Kunde</h2>';
$site                               = $_SERVER["HTTP_REFERER"];
$sitePrevious                       = $_SERVER["HTTP_REFERER"];

$client                             = new client();

if($_SERVER["REQUEST_METHOD"]       == "POST") {
  $passwordRules                    = $client->checkPasswdComplexity($_POST['password'], 1, 8);
  
  if ($passwordRules                === false) {
    $errMsg                         = 'Das Passwort entspricht nicht den vogegebenen Regeln!';
    echo '<meta http-equiv="refresh" content="0; URL=' . HOME_DIR_HTML . TEMPLATE_DIR . '/clients/error.php?err=' . urlencode($errMsg) . '">';
    exit();
  }
  
  $client->saveNewClientData($_POST);
  echo '<meta http-equiv="refresh" content="0; URL=' . $_POST['site'] . '">';

} else {
  $dropdownZugehoerigkeit           = $client->getDropdownZugehoerigkeit();
  include ($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/clients/create.php');
}

