<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


define('ISKUFERTOOLS', true);


include_once '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'constants.php';

CodingOperations::encodeEingaben();
CodingOperations::setObStartIfInternalAndExternalEncodingAreDiffrent();
CodingOperations::setEncodingResponseHeader();

SecurityOperations::PurgeInput();

if (!session_id()) {
  session_start();
}

SessionOperations::setVarValueWTIntern('user_id', -1);


if (RequestOperations::getVarValue('neuesLogin') == '1') {
  $name = PostOperations::getVarValue('name');
  $vorname = PostOperations::getVarValue('vorname');
  $telefonnummer = PostOperations::getVarValue('telefonnummer');

  $email = PostOperations::getVarValue('email');
  $bemerkung = PostOperations::getVarValue('bemerkung');
  $userGroup = PostOperations::getVarValue('userGroup');

  $plz = PostOperations::getVarValue('plz');
  $strasse = PostOperations::getVarValue('strasse');
  $ort = PostOperations::getVarValue('ort');

  $loginAnfFormular = new BuildLoginAnfFormular($name, $vorname, $telefonnummer, $email, $bemerkung, $userGroup, $plz, $strasse, $ort);

  if (PostOperations::getVarValue('loginAnforderungAbgesendet') == 'abgesendet') {
    if ($loginAnfFormular->validate()) {
      $loginAnfFormular->sendEMail();
    }
  }

  echo $loginAnfFormular->getSightComplete();
} else {
  $tool0settings = ToolSettingsAPI::getToolSettings(0);
  if ($tool0settings->captchaLoginFehlerhaft) {
    $dbwLoginVersuch = new DBWorkToolsLoginError(1, true);
    $mitCaptcha = $dbwLoginVersuch->useCaptcha4CurrentIp();
  } else {
    $mitCaptcha = false;
  }

  $login = new BuildLogin(
    SecurityOperations::checkWtLogout(),
    RequestOperations::getVarValue('sessionfail', false),
    RequestOperations::getVarValue('denied', false),
    RequestOperations::getVarValue('nouserpw', false),
    StringOperations::htmlentities(RequestOperations::getVarValue('deniedFor', '')),
    $mitCaptcha
  );

  echo $login->getSightComplete();
}

CodingOperations::encodeAnzeige();