<?php

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


class WBAnmeldungCheckKursInfo extends WBAnmeldungCheck
{
  public function __construct()
  {
    parent::__construct();
    $this->datamodul = SessionOperations::getBuchenKursInfoFromSession();
    $this->exportAdapter = new ExpTeilnehmer();
    $this->exportAdapter->initiate();
    $this->exportAdapter->export->initiate();
    $this->exportAdapter->export->exportresults = array($this->datamodul);
    $this->exportAdapter->export->selectResultset(0);
    $this->sessionSuffix = 'b';
  }

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

    

    
    
    
    $checkKonto = false;
    $checkSepa = false;
    
    foreach ($pflichtFelder as $pflichtFeld => $meldung) {
      if ($pflichtFeld === 'abw_kontonr' || $pflichtFeld === 'abw_blz') {
        $checkKonto = true;
      }
      if ($pflichtFeld === 'abw_iban' || $pflichtFeld === 'abw_bic') {
        $checkSepa = true;
      }
    }
    
    if ($checkKonto && $checkSepa) {
      $checkKonto = SessionOperations::getWKBankart(true) !== 'SEPA';
      $checkSepa = !$checkKonto;
    }

    $dontCheckPflichtfeld = array();

    
    $abw_kontoverwenden = SessionOperations::getVarValueWk('w_abw_kontoverwenden_b', 'X');
    if ($abw_kontoverwenden !== 'X') {
      if (!$abw_kontoverwenden) {
        foreach ($pflichtFelder as $key => $value) {
          if (preg_match('/abw_/', $key)) {
            array_push($dontCheckPflichtfeld, $key);
          }
        }
      }
    }

    
    foreach ($pflichtFelder as $key => $value) {

      if (in_array($key, $dontCheckPflichtfeld)) {
        continue;
      }

      if (!$this->_checkPflichtFeld($value, 'w', $this->sessionSuffix, $checkKonto, $checkSepa)) {
        $this->pflichtfeldFehlerArray[$key] = $this->getFehlerMeldung($key);
        continue;
      }
    }
    
    if ($this->datamodul != null) {
      $this->_checkValidierung('w', 'b', true);
    }
    if (count($this->pflichtfeldFehlerArray) > 0 || count($this->formatFehlerArray) > 0) {
      return false;
    }

    return true;
  }
}