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



 class WBAuthentifizierung extends DataMenuBasis
{
   
  var $infoanf = true;
  
  var $mode = 0; 
  
  
  var $pflichtfeldFehlerArray;
  
  
  var $formatFehlerArray;
  
  function __construct($pUrlparam)
  {
    parent::__construct($pUrlparam);
    if (!isset($this->dataarrayheader)) $this->dataarrayheader = Array(new Datamodul());
    if (!isset($this->dataarraybody))   $this->dataarraybody   = Array(new Datamodul());
    if (!isset($this->dataarrayfooter)) $this->dataarrayfooter = Array(new Datamodul());
    if (!isset($this->dataarraynodata))   $this->dataarraynodata   = Array(new Datamodul());
    if (!isset($this->dataarraynocolumn)) $this->dataarraynocolumn = Array(new Datamodul());
  }
  
  
  function checkData()
  { 
    SessionOperations::getTeilnehmerFromRequest2Session();
    
    switch ($this->mode) {
      case AUTH_INTERESSENBEKUNDUNG:
        $this->getSight(175);
        break;
      case AUTH_HANGARDETAILS:
        $this->getSight(174);
        break;
      case AUTH_KURSDETAILS:
        $this->getSight(176);
        break;
      case AUTH_KURSTAGE:
        $this->getSight(177);
        break;
    }
    
    $check = new WBAnmeldungCheckHauptTN();
    $check->vorlage = $this->sight->body;
    if (!$check->check()) {
      $this->pflichtfeldFehlerArray = $check->pflichtfeldFehlerArray;
      $this->formatFehlerArray = $check->formatFehlerArray;
    }
    return !(count($this->pflichtfeldFehlerArray)>0 || count($this->formatFehlerArray)>0);
  }
  
  function content()
  {
    if (count($this->pflichtfeldFehlerArray) > 0 || count($this->formatFehlerArray) > 0) {
      $dbwkurs = new DBWorkKurse();
      $this->dataarrayheader = array($dbwkurs->getKurs($this->urlparameter->knr));
      $this->dataarraybody = SessionOperations::getTeilnehmerFromSession();
      
      switch ($this->mode) {
        case AUTH_INTERESSENBEKUNDUNG:
          $this->warnungpflichtfelder(175, new ExpTeilnehmer());
          break;
        case AUTH_HANGARDETAILS:
          $this->warnungpflichtfelder(174, new ExpTeilnehmer());
          break;
        case AUTH_KURSDETAILS:
          $this->warnungpflichtfelder(176, new ExpTeilnehmer());
          break;
        case AUTH_KURSTAGE:
          $this->warnungpflichtfelder(177, new ExpTeilnehmer());
          break;
      }
    }
  }
  
  
  function getKursObjects($pKnr)
  {
    
    $wk = new DBWorkWarenkorb();
    
    $wk->clear();
    $knrAry = explode(';', $pKnr);
    for ($i = 0; $i < count($knrAry); $i++)
        $wk->addEntry($knrAry[$i]);
    return $wk->getEntries();
  }
  
   
  function setMode($pMode) {
    $this->mode = $pMode; 
  }   

  
  function sendInteressenbekundung($pKnr)
  {
    if (!$this->isMailAbsendbar())
      return false;
    
    
    $tn = SessionOperations::getTeilnehmerFromSession();
    
    $xmltn = Bucher::getEmailXMLFromTeilnehmer($tn[0]);
    
    
    
    $xmlkurs = new EmailXMLKurse();
    $xmlkurs->kursnummer = $pKnr;
    $xmlkurs->kursgebuehr = '0,00';
    $xmlkurs->status = 'I';
    $xmlkurs->anzahl = 1;
    
    if ( SessionOperations::getVarValueAnm('authart','none') !== 'none')
      $xmlkurs->beleghistorie1 = SessionOperations::getVarValueAnm('authart');
    if (SessionOperations::getVarValueWk('w_beleghistorie2','none') !== 'none')
      $xmlkurs->beleghistorie2 = SessionOperations::getVarValueWk('w_beleghistorie2');
    if (SessionOperations::getVarValueWk('w_beleghistorie3','none') !== 'none')
      $xmlkurs->beleghistorie3 = SessionOperations::getVarValueWk('w_beleghistorie3');
    if (SessionOperations::getVarValueWk('w_beleghistorie4','none') !== 'none')
      $xmlkurs->beleghistorie4 = SessionOperations::getVarValueWk('w_beleghistorie4');
    if (SessionOperations::getVarValueWk('w_beleghistorie5','none') !== 'none')
      $xmlkurs->beleghistorie5 = SessionOperations::getVarValueWk('w_beleghistorie5');
    if (SessionOperations::getVarValueWk('w_beleghistorie6','none') !== 'none')
      $xmlkurs->beleghistorie6 = SessionOperations::getVarValueWk('w_beleghistorie6');
    if (SessionOperations::getVarValueWk('w_beleghistorie7','none') !== 'none')
      $xmlkurs->beleghistorie7 = SessionOperations::getVarValueWk('w_beleghistorie7');
    if (SessionOperations::getVarValueWk('w_beleghistorie8','none') !== 'none')
      $xmlkurs->beleghistorie8 = SessionOperations::getVarValueWk('w_beleghistorie8');
    if (SessionOperations::getVarValueWk('w_beleghistorie9','none') !== 'none')
      $xmlkurs->beleghistorie9 = SessionOperations::getVarValueWk('w_beleghistorie9');
    if (SessionOperations::getVarValueWk('w_beleghistorie10','none') !== 'none')
      $xmlkurs->beleghistorie10 = SessionOperations::getVarValueWk('w_beleghistorie10');
    if (SessionOperations::getVarValueWk('w_beleghistorie11','none') !== 'none')
      $xmlkurs->beleghistorie11 = SessionOperations::getVarValueWk('w_beleghistorie11');
    if (SessionOperations::getVarValueWk('w_beleghistorie12','none') !== 'none')
      $xmlkurs->beleghistorie12 = SessionOperations::getVarValueWk('w_beleghistorie12');
    if (SessionOperations::getVarValueWk('w_beleghistorie13','none') !== 'none')
      $xmlkurs->beleghistorie13 = SessionOperations::getVarValueWk('w_beleghistorie13');
    if (SessionOperations::getVarValueWk('w_beleghistorie14','none') !== 'none')
      $xmlkurs->beleghistorie14 = SessionOperations::getVarValueWk('w_beleghistorie14');
    if (SessionOperations::getVarValueWk('w_beleghistorie15','none') !== 'none')
      $xmlkurs->beleghistorie15 = SessionOperations::getVarValueWk('w_beleghistorie15');
    if (SessionOperations::getVarValueWk('w_beleghistorie16','none') !== 'none')
      $xmlkurs->beleghistorie16 = SessionOperations::getVarValueWk('w_beleghistorie16');
    
    $xmlContainer = new EmailXMLContainer();
    $xmlContainer->emailxml = $xmltn;
    $xmlContainer->emailxmlkurse = array($xmlkurs);
    
    
    
    $factory = new InteressenbekundungsFactory();
    $work = $factory->getInstance();
    
    
    return $work->saveBekundung($xmlContainer); 
    
  }
  
  
  
  function warnungpflichtfelder($sightid, $expadapter)
  {
    $this->getsight($sightid);
    $this->exportadapter = $expadapter;
    $this->exportadapter->export->initiate();
    $this->exportadapter->setFehler($this->pflichtfeldFehlerArray, $this->formatFehlerArray);
    $this->showheader();
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET') {   
      echo '<span class="noget">Benutzen Sie zur Navigation bitte nur die dafür vorgesehenen Schaltflächen!</span>';
    }
    else
      $this->shownodata();
    $this->sight->body = str_replace('{%sbtn_wizzardweiter%}', 
            '{%sbtn_wizzardnichtweiter%}', $this->sight->body);

    echo '<ul class="warnungpflichtfelder">';
    foreach ($this->pflichtfeldFehlerArray as $varname=>$meldung)
      if ($meldung <> '') 
        echo '<li class="warnungpflichtfelder">'.CleanOperations::cleanStringContainingHtml($meldung).'</li>';

    
    echo $this->warnungValidierung($this->exportadapter->varlist);    
        
    echo '</ul>';

    $this->showbody();
    $this->showfooter();
  }
  
  
  function warnungValidierung($pArr)
  {
    $ret = '';
    if (count($this->formatFehlerArray) == 0)
      return $ret;
    foreach ($this->formatFehlerArray as $key=>$value) {
      $ret .= '  <li class="warnungvalidierung">'.CleanOperations::cleanStringContainingHtml($value)."</li>\n";
    }
    return $ret; 
  }
  
  
  public function isMailAbsendbar() {
    if ( (SessionOperations::getVarValueWk('w_name') == '') &&
         (SessionOperations::getVarValueWk('w_vorname') == '') &&
         (SessionOperations::getVarValueWk('w_zusatz') == '') &&
         (SessionOperations::getVarValueWk('w_namezusatz') == '')) {
        return false;
      }
    return true;
  }
}
?>