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


class WBFreeKontaktFormularCheck extends WBAnmeldungCheck
{
  public function __construct()
  {
    parent::__construct();
    $this->exportAdapter = new ExpFreeKontaktFormular();
    $this->exportAdapter->initiate();
    $this->exportAdapter->export->initiate();
  }

  
  public function check($pPrefix = 'kontaktedit')
  {
    if ($this->exportAdapter == null) {
      return false;
    }
    $this->prepareVorlage();
    $pflichtFelder = $this->getPflichtFelder($pPrefix);

    
    foreach ($pflichtFelder as $key => $value) {
      if (!$this->_checkPflichtFeld($value)) {
        $this->pflichtfeldFehlerArray[$key] = $this->getFehlerMeldung($key);
      }
    }

    return count($this->pflichtfeldFehlerArray) == 0;
  }

  public function _checkPflichtfeld($pVarName, $pSessPraefix = 'w', $pSessSuffix = '', $pCheckKonto = true, $pCheckSepa = true)
  {
    if ($pVarName === 'captcha' || $pVarName === 'captcha_ohnebr') {
      $capi = \Kufer\Web\Classes\Captchas\CaptchaFactory::getCaptcha4KuferWEB();

      return $capi->isValid(null, true, 'kontaktedit');
    }

    
    $pVarName = StringOperations::substr($pVarName, 0, strrpos($pVarName, '_', -1));

    return SessionOperations::getFreeKontaktFormularValueFromSession($pVarName) !== '';
  }
}