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











class AnmeldevorgangAdapter
{
  
  public $anmeldevorgang;
  public $infosubject;
  public $infobody;

  
  public function __construct($pSofortEinbuchen = false)
  {
    $uebermittlungsArt = $this->getUebermittlungsart();
    $this->anmeldevorgang = $this->_getAnmeldeVorgang4Uebermittlungsart($uebermittlungsArt, $pSofortEinbuchen);

    $this->anmeldevorgang->webtool = true;
    $this->anmeldevorgang->infosubject = $this->infosubject;
    $this->anmeldevorgang->infobody = $this->infobody;
  }

  
  private function _getAnmeldeVorgang4Uebermittlungsart($pUebermittlungsArt, $pSofortEinbuchen = false)
  {
    switch ($pUebermittlungsArt) {
      default:
      case ANMELDUNG_MATOOL_MAIL:
        return new AnmeldevorgangEMailXML();
      case ANMELDUNG_MATOOL_DMZ:
        return new AnmeldevorgangDMZ($pSofortEinbuchen);
      case ANMELDUNG_MATOOL_FILE:
        return new AnmeldevorgangEMailXMLFile();
      case ANMELDUNG_MATOOL_ONLINE:
        return new AnmeldevorgangDirektbetrieb();
    }
  }

  public static function getUebermittlungsart()
  {
    $uebermittlungsArt = self::_getUebermittlungsartWieKuferWEB();

    $dmzBetrieb = SessionOperations::isDmzBetrieb();

    if (SessionOperations::isReplikat()) {
      if ($dmzBetrieb && ($uebermittlungsArt == ANMELDUNG_MATOOL_DMZ)) {
        return ANMELDUNG_MATOOL_DMZ;
      } else {
        if ($uebermittlungsArt == ANMELDUNG_MATOOL_FILE) {
          return ANMELDUNG_MATOOL_FILE;
        } else {
          return ANMELDUNG_MATOOL_MAIL;
        }
      }
    } else {
      return ANMELDUNG_MATOOL_ONLINE;
    }
  }

  private static function _getUebermittlungsartWieKuferWEB()
  {
    $settings = ToolSettingsAPI::getToolSettings(0);
    if ($settings->uebermittlungsartMitabeiterTools == ANMELDUNG_MATOOL_WIEKUFERWEB) {
      $uebermittlungsart = $settings->savemail2file;
      switch ($uebermittlungsart) {
        default:
        case ANMELDUNGPER_MAIL:
          return ANMELDUNG_MATOOL_MAIL;
        case ANMELDUNGPER_DMZ:
          return ANMELDUNG_MATOOL_DMZ;
        case ANMELDUNGPER_FILE:
          return ANMELDUNG_MATOOL_FILE;
      }
    } else {
      return $settings->uebermittlungsartMitabeiterTools;
    }
  }
}

class Anmeldevorgang
{
  
  
  
  public $keepwk = false;
  
  
  public $ssl = false;
  public $knr;
  public $titel;
  public $tnname;
  public $tnemail;
  public $tnr = -1;
  public $webtool;
  public $successful;
  public $infosubject;
  public $infobody;

  
  public $fileAttachments = array();

  
  public $sendInfoMail = true;
  
  public $bccAnmeldebestaetigungeMail = false;
  
  public $bccAnmeldebestaetigungeMailAdresse = '';
  
  public $sendAnmeldeInfoMail = false;
  
  public $anmeldeInfoSubject = 'Benachrichtigung bei Anmeldungseingang';
  
  public $anmeldeInfoAdresse = '';
  
  public $anmeldeInfoBody = '';

  
  public $encryptXML = false;

  public $infoMailSent = array('email' => 'empty', 'sent' => false);

  public function start()
  {
    if ($this->successful) {
      if ($this->sendInfoMail) { 

        $this->infoMailSent = $this->sendInfoMail();
      }

      
      if ($this->sendAnmeldeInfoMail) {
        $this->sendAnmeldeInfoMail();
      }

      
      
      
      
      
      
      if (!$this->keepwk) {
        $warenkorbk = new DBWorkWarenkorbKurse();
        $warenkorbk->clear();
      }
    }
  }

  
  public function sendInfoMail()
  {
    $sendInfoMailArray = $this->infoMailSent;

    if ($this->tnemail != '') {
      $validation = ValidierungBasis::getInstance();
      if ($validation->isValidVar('email', $this->tnemail) === true) {
        $sendInfoMailArray['email'] = 'valid';
        $email = new smtpMail();
        $email->SetVar2Value('to', $this->tnemail);

        if ($this->infobody == '') {
          $body = 'Sofern möglich, werden unsere Mitarbeiter Sie zu folgenden Veranstaltungen anmelden:<br />' . "\r\n";

          $kursary = $this->ExplodeKnr();
          $titelary = $this->ExplodeTitel();
          for ($i = 0; $i < count($kursary); $i++) {
            $body .= $kursary[$i] . ' ' . $titelary[$i] . "<br />\r\n";
          }
          $this->infobody = $body;
        }

        if ($this->infosubject == '') {
          $allgsettings = AllgSettingsAPI::getAllgSettings();
          $subject = $allgsettings->vhsname . ' - Bestätigung der Anmeldeanforderung für ' . $this->tnname;
          $this->infosubject = $subject;
        }

        $attachments = array();
        array_push($attachments, ...$this->fileAttachments);

        $email = new \Kufer\Mail\EMail\EMailHTML(\StringOperations::html_entity_decode($this->infosubject), $this->infobody, $attachments);
        $sender = \Kufer\Mail\Sender\EMailSenderFactory::create();
        $tnAddress = new \Kufer\Mail\Address\EMailAddress($this->tnname ?? '', $this->tnemail);
        $recipients = array($tnAddress);

        $sentMail = $sender->sendFromEinrichtung($email, $recipients, 'TeilnehmerIn')->hasSentAllMails();


        if ($this->bccAnmeldebestaetigungeMail) {
          if (!empty($this->bccAnmeldebestaetigungeMailAdresse)) {
            $bccMailAddress = new \Kufer\Mail\Address\EMailAddress('', $this->bccAnmeldebestaetigungeMailAdresse);
            $sentMail = $sender->sendFromEinrichtung($email, array($bccMailAddress), 'BCC')->hasSentAllMails() && $sentMail;
          } else {
            $sentMail = $sender->informEinrichtung($email)->hasSentAllMails() && $sentMail;
          }
        }

        if (($this->storeEMailToTeilnehmer ?? false) && $sentMail && $this->tnr !== -1) {
          
          $emailDocBuilder = \Kufer\KuferTools\Utils\Builder\EMailDokumentenverwaltungBuilder::fromIEMail($email);
          $emailDocBuilder
            ->addKontakt(\DBWorkTeilnehmer::getDefaultInstance()->getTeilnehm($this->tnr))
            ->setKurs($this->knr)
            ->setInfo('Anmeldebestätigung')
            ->setVersandtVomCurrentMitarbeiter()
            ->commit();
        }

        $sendInfoMailArray['sent'] = $sentMail;
      } else {
        $sendInfoMailArray['email'] = 'invalid';
      }
    }

    return $sendInfoMailArray;
  }

  public function sendAnmeldeInfoMail()
  {
    $email = new smtpMail();
    $email->SetVar2Value('to', $this->anmeldeInfoAdresse);
    $email->SetVar2Value('contenttype', SMTP_CONTENTTYPE_TEXT);
    $email->SetVar2Value('subject', $this->anmeldeInfoSubject);
    $email->SetVar2Value('body', $this->anmeldeInfoBody);

    $email->sendMail();
  }

  public function ExplodeKnr()
  {
    $this->knr = trim($this->knr, ' ;');

    return explode(';', $this->knr);
  }

  public function ExplodeTitel()
  {
    $this->titel = trim($this->titel, ' ;');

    return explode(';', $this->titel);
  }

  protected function getAnzahlWeitere()
  {
    if ((SessionOperations::getVarValueAnm(ANMELDEART) == 1) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 1)) {
      return SessionOperations::getVarValueWk('gAnzahl_Kinder', 0);
    } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 2) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 2)) {
      return SessionOperations::getVarValueWk('gAnzahl_Mitarbeiter', 0);
    } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 3) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 3)) {
      return SessionOperations::getVarValueWk('gAnzahl_Mehrfach', 0);
    } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 4) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 4)) {
      return SessionOperations::getVarValueWk('gAnzahl_Mehrfach', 0);
    }

    return 0;
  }
}

class AnmeldevorgangEMail extends Anmeldevorgang
{
  public $sendemail;
  public $email;
  public $body;

  public function __construct()
  {
    $this->sendemail = true;
  }

  public function setEMailbySession()
  {
  }

  public function start()
  {
    LoggerAnmeldung::logg('Anmeldung über KuferTools für Mitarbeiter. Übermittlung per XML.', 10);
    
    
    $this->setEMailbySession();

    $weitere = $this->getAnzahlWeitere();
    $status = SessionOperations::getVarValueIntern('w_belegungsstatus', 'A');
    LoggerAnmeldung::logg('Kurs: ' . $this->knr . '; Teilnehmer: ' . $this->tnname . '' . $this->tnemail . ' (' . $weitere . ' weitere); Status ' . $status, 10);

    $allgsettings = AllgSettingsAPI::getAllgSettings();
    
    
    if ($this->sendemail) {
      $this->email = new smtpMail();
      $this->email->SetVar2Value('to', $allgsettings->emailanm);
      $this->email->SetVar2Value('subject', 'automatisch generierte eMail - Anmeldung: ' . $this->body->name . ', ' . $this->body->vorname);
      $this->email->SetVar2Value('contenttype', SMTP_CONTENTTYPE_XML);

      $body = $this->body->Execute();

      if ($this->encryptXML) {
        $encodingResult = EncodingAPI::encodeComplete($body);
        if ($encodingResult !== false) {
          $body = $encodingResult;
        }
      }

      $this->email->SetVar2Value('body', $body);
      $this->successful = $this->email->sendMail();

      if ($this->successful) {
        LoggerAnmeldung::logg('Anmelde-XML per E-Mail gesendet.', 10);
      } else {
        LoggerAnmeldung::logg('Fehler beim Versenden der Anmelde-XML.', 10);
      }
    } else {
      $this->successful = true;
    }

    Anmeldevorgang::start();
    
    
    
  }
}

class AnmeldevorgangEMailXML extends AnmeldevorgangEMail
{
  public $result_w;

  public $belegTnr; 

  public function start()
  {
    
    
    
    
    if ($this->ssl == false && !isset($this->result_w)) {
      $warenkorb = new DBWorkWarenkorbKurse();
      $warenkorb->clear();
      $knrary = $this->ExplodeKnr();
      for ($i = 0; $i < count($knrary); $i++) {
        $warenkorb->addEntry($knrary[$i]);
      }
      $this->result_w = $warenkorb->getEntries();
    }
    if (SessionOperations::getVarValueAnm(ANMELDEART, '') != '') {
      if ((SessionOperations::getVarValueAnm(ANMELDEART) == 1) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 1)) {
        $this->body = new XMLMailAnmeldungElternKind();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 2) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 2)) {
        $this->body = new XMLMailAnmeldungFirma();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 3) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 3)) {
        $this->body = new XMLMailAnmeldungMehrfach();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 4) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 4)) {
        $this->body = new XMLMailAnmeldungMehrfach();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 5) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 5)) {
        $this->body = new XMLMailAnmeldungNormalHotel();
      } else {
        $this->body = new XMLMailAnmeldungNormal();
      }
    } else {
      $this->body = new XMLMailAnmeldungNormal();
    }

    AnmeldevorgangEMail::start();
    
    
    

    
    $settings = ToolSettingsAPI::getToolSettings(4);
    if (($settings->platzreservierung || $this->webtool) && $this->successful) {
      $packer = new AnmeldeObjPackerXML($this->result_w);
      $obj = $packer->getObjFromSession();

      $dbanmeldung = new DBWorkAnmeldungReservierung();
      for ($kurs = 0; $kurs < count($obj->emailxmlkurse); $kurs++) {
        
        $knr = $obj->emailxmlkurse[$kurs]->kursnummer;
        $belegung = new DBWorkBelegung();
        $belegobj = $belegung->getNewObject();
        if ($this->webtool) {
          if (is_numeric($this->tnr) && ($this->tnr > -1)) {
            $belegobj->tnr = $this->tnr;
          }
        } else {
          $belegobj->tnr = '0'; 
        }
        $belegobj->knr = $knr;
        $belegobj->anm_datum = $belegung->datetimeop->getDateNow();
        if ($this->webtool) {
          $belegobj->bemerkung = 'Platzreservierung für Buchung aus den ' . KUFERTOOLS;
          if (isset($obj->emailxmlkurse[$kurs]->anmeldeart)) {
            $belegobj->anmeldeart = $obj->emailxmlkurse[$kurs]->anmeldeart;
          }
        } else {
          if (is_numeric($this->tnr) && ($this->tnr > 0)) { 
            $belegobj->tnr = $this->tnr;
            $belegobj->bemerkung = 'Platzreservierung für Buchung aus den ' . KUFERTOOLS;
          } else {
            $belegobj->bemerkung = 'Platzreservierung für Buchung aus ' . KUFERWEB;
          }
        }
        $userid = SessionOperations::getUserID();
        $dbanmeldung->Anmeldung($belegobj, $userid);

        for ($j = 0; $j < count($obj->emailxmlkurse[$kurs]->aryweitere); $j++) { 
          
          
          if (!in_array(StringOperations::strtoupper($obj->emailxmlkurse[$kurs]->aryweitere[$j]->typ), array('K'))) {
            $dbanmeldung->Anmeldung($belegobj, $userid);
          }
        }

        LoggerAnmeldung::logg('Platzreservierung(en) in der Web-Datenbank geschrieben.', 10);
      }
    }
  }

  
  public function setEMailbySession()
  { 
    $packobj = new AnmeldeObjPackerXML($this->result_w);
    $obj = $packobj->getObjFromSession();
    $objsettings = ToolSettingsAPI::getToolSettings(0);
    if ($objsettings->encrypt) {
      $obj->emailxml->kontonr = MathOperations::aufbereitung($obj->emailxml->kontonr);
      $obj->emailxml->bankbez = $obj->emailxml->bankbez . ':';
      foreach ($obj->emailxmlkurse as $key => $emailXmlKurs) {
        $obj->emailxmlkurse[$key]->abw_kontonr = MathOperations::aufbereitung($obj->emailxmlkurse[$key]->abw_kontonr);
        $obj->emailxmlkurse[$key]->abw_bankbez = $obj->emailxmlkurse[$key]->abw_bankbez . ':';
      }
    }

    $this->body->name = $obj->emailxml->name;
    $this->body->vorname = $obj->emailxml->vorname;

    $tmpmail = $obj->emailxml->getVarValue('email');
    
    if (isset($tmpmail->kommwert)) {
      $this->tnemail = $tmpmail->kommwert;
    }
    $this->tnname = trim($obj->emailxml->vorname . ' ' . $obj->emailxml->name);

    $this->body->emailxml = $obj->emailxml;
    $this->body->emailxmlkurse = $obj->emailxmlkurse;

    if ($this->webtool && is_numeric($this->tnr) && ($this->tnr > -1)) {
      $dbwrepsettings = new DBWorkWebReplikatSettings();
      $repsett = $dbwrepsettings->getHighestTNNr();
      if ($this->tnr <= $repsett->value) {
        $this->body->emailxml->tnr = $this->tnr;
      }
    }

    $this->knr = '';
    for ($i = 0; $i < count($obj->emailxmlkurse); $i++) {
      $this->knr .= $obj->emailxmlkurse[$i]->kursnummer . ';';
    }
    
    $this->knr = StringOperations::substr($this->knr, 0, StringOperations::strlen($this->knr) - 1);
  }
}

class AnmeldevorgangEMailXMLFile extends AnmeldevorgangEMailXML
{
  public function __construct()
  {
    parent::__construct();
    $this->sendemail = false;
  }

  public function start()
  {
    AnmeldevorgangEMailXML::start();
    
    
    

    $warenkorb = new DBWorkWarenkorbKurse();
    $warenkorb->clear();
    $knrary = $this->ExplodeKnr();
    for ($i = 0; $i < count($knrary); $i++) {
      $warenkorb->addEntry($knrary[$i]);
    }
    

    $settings = ToolSettingsAPI::getToolSettings(0);
    $tmpfile = new SimpleFileWork();

    if (SessionOperations::getVarValueAnm(ANMELDEART, '') != '') {
      if ((SessionOperations::getVarValueAnm(ANMELDEART) == 1) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 1)) {
        $this->body = new XMLMailAnmeldungElternKind();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 2) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 2)) {
        $this->body = new XMLMailAnmeldungFirma();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 3) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 3)) {
        $this->body = new XMLMailAnmeldungMehrfach();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 4) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 4)) {
        $this->body = new XMLMailAnmeldungMehrfach();
      } elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 5) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 5)) {
        $this->body = new XMLMailAnmeldungNormalHotel();
      } else {
        $this->body = new XMLMailAnmeldungNormal();
      }
    } else {
      $this->body = new XMLMailAnmeldungNormal();
    }

    $tmpfile->clear();
    $tmpfile->access = 'a';

    $this->setEMailbySession();

    $body = $this->body->Execute();

    if ($this->encryptXML) {
      $encodingResult = EncodingAPI::encodeComplete($body);
      if ($encodingResult !== false) {
        $body = $encodingResult;
      }
    }

    $tmpfile->content = $body;

    $datetimeop = new DateTimeOperations();
    
    
    if (StringOperations::substr($settings->emailfilepath, -1) != '/') {
      $settings->emailfilepath .= '/';
    }

    do {
      $tmpfilefilename = $settings->emailfilepath . 'webbasys' . $datetimeop->getTimestampNow() . '.xml';
    } while (file_exists($tmpfilefilename));

    $tmpfile->filename = $tmpfilefilename;
    $tmpfile->openFile();
    $tmpfile->setContent();
    $tmpfile->closeFile();

    
    

    $this->successful = file_exists($tmpfilefilename);

    if ($this->successful) {
      LoggerAnmeldung::logg('XML-Datei erstellt unter ' . $tmpfilefilename, 10);
    } else {
      LoggerAnmeldung::logg('Fehler beim Erstellen der XML-Datei', 10);
    }
  }
}

class AnmeldevorgangDMZ extends Anmeldevorgang
{
  public $sofortEinbuchen;

  public function __construct($pSofortEinbuchen = false)
  {
    $this->sofortEinbuchen = $pSofortEinbuchen;
  }

  public function start()
  {
    LoggerAnmeldung::logg('Anmeldung über KuferTools für Mitarbeiter. Übermittlung über DMZ direkte Einbuchung.', 10);

    $dbwteilnehm = new DBWorkTeilnehmer();
    $teilnehmer = $dbwteilnehm->getTeilnehm($this->tnr);

    $this->tnname = $teilnehmer->getVarValue('name') . ' ' . $teilnehmer->getVarValue('vorname');
    $this->tnemail = $teilnehmer->getVarValueEx('email', 'kommunikation');

    $knr = $this->ExplodeKnr();
    $weitere = $this->getAnzahlWeitere();
    $status = SessionOperations::getVarValueIntern('w_belegungsstatus', 'A');
    LoggerAnmeldung::logg('Kurs: ' . $knr[0] . '; Teilnehmer: ' . $this->tnname . '' . $this->tnemail . ' (' . $weitere . ' weitere); Status ' . $status, 10);

    if ((!SessionOperations::isKuferTools() && SessionOperations::isSofortEinbuchen()) || (SessionOperations::isKuferTools() && SessionOperations::isSofortEinbuchen() && $this->sofortEinbuchen)) {
      
      $api = new AnmeldungDirektDmzApiSofortEinbuchen();
    } else {
      $api = new AnmeldungDirektDmzApi();
    }
    $this->successful = $api->doAnmeldung($this->tnr, false, $this->ExplodeKnr(), SessionOperations::getVarValueIntern('w_belegungsstatus', 'A'));

    if ($this->successful) {
      LoggerAnmeldung::logg('Anmeldung über DMZ erfolgreich durchgeführt.', 10);
    } else {
      LoggerAnmeldung::logg('Fehler beim Anmelden über DMZ.', 10);
    }

    parent::start();
  }
}

class AnmeldevorgangDirektbetrieb extends Anmeldevorgang
{
  public function start()
  {
    LoggerAnmeldung::logg('Anmeldung über KuferTools für Mitarbeiter. Übermittlung über Direktbetrieb.', 10);

    $dbwteilnehm = new DBWorkTeilnehmer();
    $teilnehmer = $dbwteilnehm->getTeilnehm($this->tnr);

    $this->tnname = $teilnehmer->getVarValue('name') . ' ' . $teilnehmer->getVarValue('vorname');
    $this->tnemail = $teilnehmer->getVarValueEx('email', 'kommunikation');

    $knr = $this->ExplodeKnr();
    $weitere = $this->getAnzahlWeitere();
    $status = SessionOperations::getVarValueIntern('w_belegungsstatus', 'A');
    LoggerAnmeldung::logg('Kurs: ' . $knr[0] . '; Teilnehmer: ' . $this->tnname . '' . $this->tnemail . ' (' . $weitere . ' weitere); Status ' . $status, 10);


    $api = new AnmeldungDirektbetriebApi();
    $this->successful = $api->doAnmeldung($this->tnr, $this->ExplodeKnr(), SessionOperations::getVarValueIntern('w_belegungsstatus', 'A'));

    if ($this->successful) {
      LoggerAnmeldung::logg('Anmeldung im Direktbetrieb erfolgreich durchgeführt.', 10);
    } else {
      LoggerAnmeldung::logg('Fehler beim Anmelden über Direktbetrieb.', 10);
    }

    parent::start();
  }
}




class AnmeldeObjPackerXML
{
  public $result_w;

  
  public function __construct($presult_w)
  {
    $this->result_w = $presult_w;
  }

  public function AddElternKindAnmeldung($obj)
  {
    for ($i = 0;$i < count($this->result_w);$i++) {
      $obj->emailxmlkurse[$i] = new EmailXMLKurse();
      $obj->emailxmlkurse[$i]->kursnummer = $this->result_w[$i]->id;
      
      $dbworkkurse = new DBWorkKurse();
      $kurs = $dbworkkurse->getKurs($obj->emailxmlkurse[$i]->kursnummer);
      $obj->emailxmlkurse[$i]->status = $kurs->emailstatus;
      
      $obj->emailxmlkurse[$i]->anzahl = SessionOperations::getVarValueWk('gAnzahl_Kinder');
      $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->kurs->gebuehr;
      
      $obj->emailxmlkurse[$i]->beleghistorie1 = SessionOperations::getVarValueIntern('w_beleghistorie1');
      $obj->emailxmlkurse[$i]->beleghistorie2 = SessionOperations::getVarValueIntern('w_beleghistorie2');
      $obj->emailxmlkurse[$i]->beleghistorie3 = SessionOperations::getVarValueIntern('w_beleghistorie3');
      $obj->emailxmlkurse[$i]->beleghistorie4 = SessionOperations::getVarValueIntern('w_beleghistorie4');
      $obj->emailxmlkurse[$i]->beleghistorie5 = SessionOperations::getVarValueIntern('w_beleghistorie5');
      $obj->emailxmlkurse[$i]->beleghistorie6 = SessionOperations::getVarValueIntern('w_beleghistorie6');
      $obj->emailxmlkurse[$i]->beleghistorie7 = SessionOperations::getVarValueIntern('w_beleghistorie7');
      $obj->emailxmlkurse[$i]->beleghistorie8 = SessionOperations::getVarValueIntern('w_beleghistorie8');
      $obj->emailxmlkurse[$i]->beleghistorie9 = SessionOperations::getVarValueIntern('w_beleghistorie9');
      $obj->emailxmlkurse[$i]->beleghistorie10 = SessionOperations::getVarValueIntern('w_beleghistorie10');
      $obj->emailxmlkurse[$i]->beleghistorie11 = SessionOperations::getVarValueIntern('w_beleghistorie11');
      $obj->emailxmlkurse[$i]->beleghistorie12 = SessionOperations::getVarValueIntern('w_beleghistorie12');
      $obj->emailxmlkurse[$i]->beleghistorie13 = SessionOperations::getVarValueIntern('w_beleghistorie13');
      $obj->emailxmlkurse[$i]->beleghistorie14 = SessionOperations::getVarValueIntern('w_beleghistorie14');
      $obj->emailxmlkurse[$i]->beleghistorie15 = SessionOperations::getVarValueIntern('w_beleghistorie15');
      $obj->emailxmlkurse[$i]->beleghistorie16 = SessionOperations::getVarValueIntern('w_beleghistorie16');

      $obj->emailxmlkurse[$i]->anmeldeart = SessionOperations::getVarValueIntern('w_anmeldeart');
      for ($j = 1; $j <= SessionOperations::getVarValueWk('gAnzahl_Kinder'); $j++) {
        
        $xml = new EmailXML();
        $addfop = new DateTimeOperations();
        $xml->eingelesen = $addfop->getDateTimeNow();
        $xml->typ = 'W';
        for ($c = 0; $c < $xml->getVarCount(); $c++) {
          $varname = $xml->getVarName4Person($xml->getVarName($c));
          if (SessionOperations::isDefinedIntern('w_' . $varname . '_k' . $j)) {
            $xml->setValue2Var($xml->getVarName($c), trim(SessionOperations::getVarValueIntern('w_' . $varname . '_k' . $j)));
          }
        }
        
        if (SessionOperations::isDefinedIntern('w_info_k' . $j)) {
          $xml->bemerkung = SessionOperations::getVarValueIntern('w_info_k' . $j);
        }

        $weitereanm = new EmailXMLWeitere();
        $weitereanm->emailxml = $xml;
        $weitereanm->typ = 'K';
        $obj->emailxmlkurse[$i]->addWeitere($weitereanm);
        $obj->emailxmlkurse[$i]->anzahl = count($obj->emailxmlkurse[$i]->aryweitere) + 1;
      }
    }
  }

  public function AddMehrfachAnmeldung($obj)
  {
    for ($i = 0;$i < count($this->result_w);$i++) {
      $obj->emailxmlkurse[$i] = new EmailXMLKurse();
      $obj->emailxmlkurse[$i]->kursnummer = $this->result_w[$i]->id;
      
      $dbworkkurse = new DBWorkKurse();
      $kurs = $dbworkkurse->getKurs($obj->emailxmlkurse[$i]->kursnummer);
      $obj->emailxmlkurse[$i]->status = $kurs->emailstatus;
      
      $obj->emailxmlkurse[$i]->anzahl = SessionOperations::getVarValueWk('gAnzahl_Mehrfach');
      if (isset($this->ssl) && $this->ssl) {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->gebuehr;
      } else {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->kurs->gebuehr;
      }

      
      $obj->emailxmlkurse[$i]->beleghistorie1 = SessionOperations::getVarValueIntern('w_beleghistorie1');
      $obj->emailxmlkurse[$i]->beleghistorie2 = SessionOperations::getVarValueIntern('w_beleghistorie2');
      $obj->emailxmlkurse[$i]->beleghistorie3 = SessionOperations::getVarValueIntern('w_beleghistorie3');
      $obj->emailxmlkurse[$i]->beleghistorie4 = SessionOperations::getVarValueIntern('w_beleghistorie4');
      $obj->emailxmlkurse[$i]->beleghistorie5 = SessionOperations::getVarValueIntern('w_beleghistorie5');
      $obj->emailxmlkurse[$i]->beleghistorie6 = SessionOperations::getVarValueIntern('w_beleghistorie6');
      $obj->emailxmlkurse[$i]->beleghistorie7 = SessionOperations::getVarValueIntern('w_beleghistorie7');
      $obj->emailxmlkurse[$i]->beleghistorie8 = SessionOperations::getVarValueIntern('w_beleghistorie8');
      $obj->emailxmlkurse[$i]->beleghistorie9 = SessionOperations::getVarValueIntern('w_beleghistorie9');
      $obj->emailxmlkurse[$i]->beleghistorie10 = SessionOperations::getVarValueIntern('w_beleghistorie10');
      $obj->emailxmlkurse[$i]->beleghistorie11 = SessionOperations::getVarValueIntern('w_beleghistorie11');
      $obj->emailxmlkurse[$i]->beleghistorie12 = SessionOperations::getVarValueIntern('w_beleghistorie12');
      $obj->emailxmlkurse[$i]->beleghistorie13 = SessionOperations::getVarValueIntern('w_beleghistorie13');
      $obj->emailxmlkurse[$i]->beleghistorie14 = SessionOperations::getVarValueIntern('w_beleghistorie14');
      $obj->emailxmlkurse[$i]->beleghistorie15 = SessionOperations::getVarValueIntern('w_beleghistorie15');
      $obj->emailxmlkurse[$i]->beleghistorie16 = SessionOperations::getVarValueIntern('w_beleghistorie16');

      $obj->emailxmlkurse[$i]->anmeldeart = SessionOperations::getVarValueIntern('w_anmeldeart');
      $persanz = SessionOperations::getVarValueWk('gAnzahl_Mehrfach');
      for ($j = 1; $j <= $persanz; $j++) {
        
        $xml = new EmailXML();
        $addfop = new DateTimeOperations();
        $xml->eingelesen = $addfop->getDateTimeNow();
        $xml->typ = 'W';
        for ($c = 0; $c < $xml->getVarCount(); $c++) {
          $varname = $xml->getVarName4Person($xml->getVarName($c));
          if (SessionOperations::isDefinedIntern('w_' . $varname . '_me' . $j)) {
            $xml->setValue2Var($xml->getVarName($c), trim(SessionOperations::getVarValueIntern('w_' . $varname . '_me' . $j)));
          }
        }
        $xml->vorname = trim(SessionOperations::getVarValueIntern('w_titel_me' . $j, '') . ' ' . SessionOperations::getVarValueIntern('w_vorname_me' . $j));
        if ($xml->gebdatum != '' && SessionOperations::isDefinedIntern('w_gebjahr_me' . $j)) {
          $xml->gebdatum = '01.01.' . SessionOperations::getVarValueIntern('w_gebjahr_me' . $j);
        }
        if ($xml->erm_grund != '') {
          $dbwerm = new DBWorkErmaessigung();
          $erm = $dbwerm->getErmaessigungbyNr($xml->erm_grund);
          if (count($erm) > 0) {
            $xml->erm_proz = $erm[0]->prozente;
          }
        }
        
        if (SessionOperations::isDefinedIntern('w_tel_me' . $j) and trim(SessionOperations::getVarValueIntern('w_tel_me' . $j) != '')) {
          $xml->addKommunikationByParam('T', 'Telefon', trim(SessionOperations::getVarValueIntern('w_tel_me' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_tel2_me' . $j) and trim(SessionOperations::getVarValueIntern('w_tel2_me' . $j)) != '') {
          $xml->addKommunikationByParam('T', 'Dienstlich', trim(SessionOperations::getVarValueIntern('w_tel2_me' . $j)));
        }

        if (SessionOperations::isDefinedIntern('w_mobil_me' . $j) and trim(SessionOperations::getVarValueIntern('w_mobil_me' . $j)) != '') {
          $xml->addKommunikationByParam('M', 'Mobil', trim(SessionOperations::getVarValueIntern('w_mobil_me' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_fax_me' . $j) and trim(SessionOperations::getVarValueIntern('w_fax_me' . $j)) != '') {
          $xml->addKommunikationByParam('F', 'Fax', trim(SessionOperations::getVarValueIntern('w_fax_me' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_email_me' . $j) and trim(SessionOperations::getVarValueIntern('w_email_me' . $j)) != '') {
          $xml->addKommunikationByParam('E', 'E-Mail', trim(SessionOperations::getVarValueIntern('w_email_me' . $j)));
        }

        $weitereanm = new EmailXMLWeitere();
        $weitereanm->emailxml = $xml;
        $weitereanm->typ = 'M';
        $obj->emailxmlkurse[$i]->addWeitere($weitereanm);
        $obj->emailxmlkurse[$i]->anzahl = count($obj->emailxmlkurse[$i]->aryweitere) + 1;
      }
    }
  }

  public function AddFirmenAnmeldung($obj)
  {
    for ($i = 0;$i < count($this->result_w);$i++) {
      $obj->emailxmlkurse[$i] = new EmailXMLKurse();
      $obj->emailxmlkurse[$i]->kursnummer = $this->result_w[$i]->id;
      
      $dbworkkurse = new DBWorkKurse();
      $kurs = $dbworkkurse->getKurs($obj->emailxmlkurse[$i]->kursnummer);
      $obj->emailxmlkurse[$i]->status = $kurs->emailstatus;
      
      $obj->emailxmlkurse[$i]->anzahl = SessionOperations::getVarValueWk('gAnzahl_Mitarbeiter');
      
      if (isset($this->ssl) && $this->ssl) {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->gebuehr;
      } else {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->kurs->gebuehr;
      }
      
      $obj->emailxmlkurse[$i]->beleghistorie1 = SessionOperations::getVarValueIntern('w_beleghistorie1');
      $obj->emailxmlkurse[$i]->beleghistorie2 = SessionOperations::getVarValueIntern('w_beleghistorie2');
      $obj->emailxmlkurse[$i]->beleghistorie3 = SessionOperations::getVarValueIntern('w_beleghistorie3');
      $obj->emailxmlkurse[$i]->beleghistorie4 = SessionOperations::getVarValueIntern('w_beleghistorie4');
      $obj->emailxmlkurse[$i]->beleghistorie5 = SessionOperations::getVarValueIntern('w_beleghistorie5');
      $obj->emailxmlkurse[$i]->beleghistorie6 = SessionOperations::getVarValueIntern('w_beleghistorie6');
      $obj->emailxmlkurse[$i]->beleghistorie7 = SessionOperations::getVarValueIntern('w_beleghistorie7');
      $obj->emailxmlkurse[$i]->beleghistorie8 = SessionOperations::getVarValueIntern('w_beleghistorie8');
      $obj->emailxmlkurse[$i]->beleghistorie9 = SessionOperations::getVarValueIntern('w_beleghistorie9');
      $obj->emailxmlkurse[$i]->beleghistorie10 = SessionOperations::getVarValueIntern('w_beleghistorie10');
      $obj->emailxmlkurse[$i]->beleghistorie11 = SessionOperations::getVarValueIntern('w_beleghistorie11');
      $obj->emailxmlkurse[$i]->beleghistorie12 = SessionOperations::getVarValueIntern('w_beleghistorie12');
      $obj->emailxmlkurse[$i]->beleghistorie13 = SessionOperations::getVarValueIntern('w_beleghistorie13');
      $obj->emailxmlkurse[$i]->beleghistorie14 = SessionOperations::getVarValueIntern('w_beleghistorie14');
      $obj->emailxmlkurse[$i]->beleghistorie15 = SessionOperations::getVarValueIntern('w_beleghistorie15');
      $obj->emailxmlkurse[$i]->beleghistorie16 = SessionOperations::getVarValueIntern('w_beleghistorie16');

      $obj->emailxmlkurse[$i]->anmeldeart = SessionOperations::getVarValueIntern('w_anmeldeart');
      for ($j = 1; $j <= SessionOperations::getVarValueWk('gAnzahl_Mitarbeiter'); $j++) {
        
        $xml = new EmailXML();
        $addfop = new DateTimeOperations();
        $xml->eingelesen = $addfop->getDateTimeNow();
        $xml->typ = 'W';
        for ($c = 0; $c < $xml->getVarCount(); $c++) {
          $varname = $xml->getVarName4Person($xml->getVarName($c));
          if (SessionOperations::isDefinedIntern('w_' . $varname . '_ma' . $j)) {
            $xml->setValue2Var($xml->getVarName($c), trim(SessionOperations::getVarValueIntern('w_' . $varname . '_ma' . $j)));
          }
        }

        $xml->vorname = trim(SessionOperations::getVarValueIntern('w_titel_ma' . $j, '') . ' ' . SessionOperations::getVarValueIntern('w_vorname_ma' . $j));
        
        
        
        
        

        if ($xml->gebdatum == '' && SessionOperations::isDefinedIntern('w_gebjahr_ma' . $j)) {
          $xml->gebdatum = '01.01.' . SessionOperations::getVarValueIntern('w_gebjahr_ma' . $j);
        }
        

        if (SessionOperations::isDefinedIntern('w_tel_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_tel_ma' . $j) != '')) {
          $xml->addKommunikationByParam('T', 'Telefon', trim(SessionOperations::getVarValueIntern('w_tel_ma' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_tel2_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_tel2_ma' . $j)) != '') {
          $xml->addKommunikationByParam('T', 'Dienstlich', trim(SessionOperations::getVarValueIntern('w_tel2_ma' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_mobil_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_mobil_ma' . $j)) != '') {
          $xml->addKommunikationByParam('M', 'Mobil', trim(SessionOperations::getVarValueIntern('w_mobil_ma' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_fax_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_fax_ma' . $j)) != '') {
          $xml->addKommunikationByParam('F', 'Fax', trim(SessionOperations::getVarValueIntern('w_fax_ma' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_email_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_email_ma' . $j)) != '') {
          $xml->addKommunikationByParam('E', 'E-Mail', trim(SessionOperations::getVarValueIntern('w_email_ma' . $j)));
        }
        if (SessionOperations::isDefinedIntern('w_kennz_ma' . $j) and trim(SessionOperations::getVarValueIntern('w_kennz_ma' . $j)) != '') {
          $xml->addKennzeichenByParam(trim(SessionOperations::getVarValueIntern('w_kennz_ma' . $j)));
        }
        $weitereanm = new EmailXMLWeitere();
        $weitereanm->emailxml = $xml;
        $weitereanm->typ = 'F';
        $obj->emailxmlkurse[$i]->addWeitere($weitereanm);
        $obj->emailxmlkurse[$i]->anzahl = count($obj->emailxmlkurse[$i]->aryweitere) + 1;
      }
    }
  }

  public function AddPaareAnmeldung($obj)
  {
    for ($i = 0;$i < count($this->result_w);$i++) {
      $obj->emailxmlkurse[$i] = new EmailXMLKurse();
      $obj->emailxmlkurse[$i]->kursnummer = $this->result_w[$i]->id;
      
      $dbworkkurse = new DBWorkKurse();
      $kurs = $dbworkkurse->getKurs($obj->emailxmlkurse[$i]->kursnummer);
      $obj->emailxmlkurse[$i]->status = $kurs->emailstatus;
      

      $obj->emailxmlkurse[$i]->anzahl = 1;



      $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->kurs->gebuehr;

      
      $obj->emailxmlkurse[$i]->beleghistorie1 = SessionOperations::getVarValueIntern('w_beleghistorie1');
      $obj->emailxmlkurse[$i]->beleghistorie2 = SessionOperations::getVarValueIntern('w_beleghistorie2');
      $obj->emailxmlkurse[$i]->beleghistorie3 = SessionOperations::getVarValueIntern('w_beleghistorie3');
      $obj->emailxmlkurse[$i]->beleghistorie4 = SessionOperations::getVarValueIntern('w_beleghistorie4');
      $obj->emailxmlkurse[$i]->beleghistorie5 = SessionOperations::getVarValueIntern('w_beleghistorie5');
      $obj->emailxmlkurse[$i]->beleghistorie6 = SessionOperations::getVarValueIntern('w_beleghistorie6');
      $obj->emailxmlkurse[$i]->beleghistorie7 = SessionOperations::getVarValueIntern('w_beleghistorie7');
      $obj->emailxmlkurse[$i]->beleghistorie8 = SessionOperations::getVarValueIntern('w_beleghistorie8');
      $obj->emailxmlkurse[$i]->beleghistorie9 = SessionOperations::getVarValueIntern('w_beleghistorie9');
      $obj->emailxmlkurse[$i]->beleghistorie10 = SessionOperations::getVarValueIntern('w_beleghistorie10');
      $obj->emailxmlkurse[$i]->beleghistorie11 = SessionOperations::getVarValueIntern('w_beleghistorie11');
      $obj->emailxmlkurse[$i]->beleghistorie12 = SessionOperations::getVarValueIntern('w_beleghistorie12');
      $obj->emailxmlkurse[$i]->beleghistorie13 = SessionOperations::getVarValueIntern('w_beleghistorie13');
      $obj->emailxmlkurse[$i]->beleghistorie14 = SessionOperations::getVarValueIntern('w_beleghistorie14');
      $obj->emailxmlkurse[$i]->beleghistorie15 = SessionOperations::getVarValueIntern('w_beleghistorie15');
      $obj->emailxmlkurse[$i]->beleghistorie16 = SessionOperations::getVarValueIntern('w_beleghistorie16');

      $obj->emailxmlkurse[$i]->anmeldeart = SessionOperations::getVarValueIntern('w_anmeldeart');

      
      $xml = new EmailXML();
      $addfop = new DateTimeOperations();
      $xml->eingelesen = $addfop->getDateTimeNow();
      $xml->typ = 'W';
      for ($c = 0; $c < $xml->getVarCount(); $c++) {
        $varname = $xml->getVarName4Person($xml->getVarName($c));
        if (SessionOperations::isDefinedIntern('w_' . $varname . '_pa')) {
          $xml->setValue2Var($xml->getVarName($c), trim(SessionOperations::getVarValueIntern('w_' . $varname . '_pa')));
        }
      }
      $titel = '';
      if (SessionOperations::isDefinedIntern('w_titel_pa')) {
        $titel = SessionOperations::getVarValueIntern('w_titel_pa');
      }
      $xml->vorname = trim($titel . ' ' . SessionOperations::getVarValueIntern('w_vorname_pa'));
      if ($xml->gebdatum == '' && SessionOperations::isDefinedIntern('w_geburtsdatum_pa')) { 
        $xml->gebdatum = SessionOperations::getVarValueIntern('w_geburtsdatum_pa');
      }

      if ($xml->gebdatum == '' && SessionOperations::isDefinedIntern('w_gebjahr_pa')) {
        $xml->gebdatum = '01.01.' . SessionOperations::getVarValueIntern('w_gebjahr_pa');
      }
      if ($xml->erm_grund != '') {
        $dbwerm = new DBWorkErmaessigung();
        $erm = $dbwerm->getErmaessigungbyNr($xml->erm_grund);
        if (count($erm) > 0) {
          $xml->erm_proz = $erm[0]->prozente;
        }
      }

      
      
      if (SessionOperations::isDefinedIntern('w_tel_pa') and trim(SessionOperations::getVarValueIntern('w_tel_pa') != '')) {
        $xml->addKommunikationByParam('T', 'Telefon', trim(SessionOperations::getVarValueIntern('w_tel_pa')));
      }
      if (SessionOperations::isDefinedIntern('w_tel2_pa') and trim(SessionOperations::getVarValueIntern('w_tel2_pa')) != '') {
        $xml->addKommunikationByParam('T', 'Dienstlich', trim(SessionOperations::getVarValueIntern('w_tel2_pa')));
      }
      if (SessionOperations::isDefinedIntern('w_mobil_pa') and trim(SessionOperations::getVarValueIntern('w_mobil_pa')) != '') {
        $xml->addKommunikationByParam('M', 'Mobil', trim(SessionOperations::getVarValueIntern('w_mobil_pa')));
      }
      if (SessionOperations::isDefinedIntern('w_fax_pa') and trim(SessionOperations::getVarValueIntern('w_fax_pa')) != '') {
        $xml->addKommunikationByParam('F', 'Fax', trim(SessionOperations::getVarValueIntern('w_fax_pa')));
      }
      if (SessionOperations::isDefinedIntern('w_email_pa') and trim(SessionOperations::getVarValueIntern('w_email_pa')) != '') {
        $xml->addKommunikationByParam('E', 'E-Mail', trim(SessionOperations::getVarValueIntern('w_email_pa')));
      }

      $weitere = new EmailXMLWeitere();
      $weitere->emailxml = $xml;
      $weitere->typ = 'M';
      $obj->emailxmlkurse[$i]->addWeitere($weitere);
      $obj->emailxmlkurse[$i]->anzahl = 2;
    }
  }

  public function AddNormalAnmeldung($obj)
  {
    for ($i = 0;$i < count($this->result_w);$i++) {
      $obj->emailxmlkurse[$i] = new EmailXMLKurse();
      $obj->emailxmlkurse[$i]->kursnummer = $this->result_w[$i]->id;
      
      $dbworkkurse = new DBWorkKurse();
      $kurs = $dbworkkurse->getKurs($obj->emailxmlkurse[$i]->kursnummer);
      $obj->emailxmlkurse[$i]->status = $kurs->emailstatus;
      

      $obj->emailxmlkurse[$i]->anzahl = 1;
      
      
      if (isset($this->ssl) && $this->ssl) {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->gebuehr;
      } else {
        $obj->emailxmlkurse[$i]->kursgebuehr = $this->result_w[$i]->kurs->gebuehr;
      }

      
      $obj->emailxmlkurse[$i]->beleghistorie1 = SessionOperations::getVarValueIntern('w_beleghistorie1');
      $obj->emailxmlkurse[$i]->beleghistorie2 = SessionOperations::getVarValueIntern('w_beleghistorie2');
      $obj->emailxmlkurse[$i]->beleghistorie3 = SessionOperations::getVarValueIntern('w_beleghistorie3');
      $obj->emailxmlkurse[$i]->beleghistorie4 = SessionOperations::getVarValueIntern('w_beleghistorie4');
      $obj->emailxmlkurse[$i]->beleghistorie5 = SessionOperations::getVarValueIntern('w_beleghistorie5');
      $obj->emailxmlkurse[$i]->beleghistorie6 = SessionOperations::getVarValueIntern('w_beleghistorie6');
      $obj->emailxmlkurse[$i]->beleghistorie7 = SessionOperations::getVarValueIntern('w_beleghistorie7');
      $obj->emailxmlkurse[$i]->beleghistorie8 = SessionOperations::getVarValueIntern('w_beleghistorie8');
      $obj->emailxmlkurse[$i]->beleghistorie9 = SessionOperations::getVarValueIntern('w_beleghistorie9');
      $obj->emailxmlkurse[$i]->beleghistorie10 = SessionOperations::getVarValueIntern('w_beleghistorie10');
      $obj->emailxmlkurse[$i]->beleghistorie11 = SessionOperations::getVarValueIntern('w_beleghistorie11');
      $obj->emailxmlkurse[$i]->beleghistorie12 = SessionOperations::getVarValueIntern('w_beleghistorie12');
      $obj->emailxmlkurse[$i]->beleghistorie13 = SessionOperations::getVarValueIntern('w_beleghistorie13');
      $obj->emailxmlkurse[$i]->beleghistorie14 = SessionOperations::getVarValueIntern('w_beleghistorie14');
      $obj->emailxmlkurse[$i]->beleghistorie15 = SessionOperations::getVarValueIntern('w_beleghistorie15');
      $obj->emailxmlkurse[$i]->beleghistorie16 = SessionOperations::getVarValueIntern('w_beleghistorie16');

      $obj->emailxmlkurse[$i]->zahlart = SessionOperations::getVarValueIntern('w_zahlart');

      if (SessionOperations::getVarValueIntern('w_abw_kontoverwenden') && SessionOperations::getVarValueIntern('w_abw_kontoverwenden')) {
        $obj->emailxmlkurse[$i]->abw_kursgeb = $obj->emailxmlkurse[$i]->kursgebuehr;
        $obj->emailxmlkurse[$i]->kursgebuehr = '0';
      }

      $obj->emailxmlkurse[$i]->abw_kontonr = SessionOperations::getVarValueIntern('w_abw_kontonr');
      $obj->emailxmlkurse[$i]->abw_blz = SessionOperations::getVarValueIntern('w_abw_blz');
      $obj->emailxmlkurse[$i]->abw_bankbez = SessionOperations::getVarValueIntern('w_abw_bankbez');
      $obj->emailxmlkurse[$i]->abw_kontoinh = SessionOperations::getVarValueIntern('w_abw_kontoinh');
      $obj->emailxmlkurse[$i]->abw_bic = SessionOperations::getVarValueIntern('w_abw_bic');
      $obj->emailxmlkurse[$i]->abw_iban = SessionOperations::getVarValueIntern('w_abw_iban');

      $obj->emailxmlkurse[$i]->anmeldeart = SessionOperations::getVarValueIntern('w_anmeldeart');
    }
  }

  
  public function AddNormalHotelAnmeldung($obj)
  {
    $this->AddNormalAnmeldung($obj); 
    

    
    $obj->emailxmlkurse[0]->hotelAnm = new EmailXMLHotel();

    
    $hd = new AnmeldedatenHotel();
    
    for ($varnum = 0; $varnum < $hd->getVarCount(); $varnum++) {
      
      $varname = $hd->getVarName($varnum);
      
      
      if (SessionOperations::isDefinedIntern('wh_' . $varname)) {
        $hd->setValue2Var($varname, SessionOperations::getVarValueIntern('wh_' . $varname));
      }
    }
    
    $obj->emailxmlkurse[0]->hotelAnm->CopyFromAnmeldedatenHotel($hd);
  }

  
  public function getObjFromSession()
  {
    $addfop = new DateTimeOperations();

    $obj = new EmailXMLContainer();
    $obj->emailxml = new EmailXML();
    $obj->emailxml->eingelesen = $addfop->getDateTimeNow();

    $obj->emailxml->sessionid = SessionOperations::getSessionID();
    $obj->emailxml->sessiontime = SessionOperations::getSessionTime();

    
    for ($c = 0; $c < $obj->emailxml->getVarCount(); $c++) {
      $varname = $obj->emailxml->getVarName4Person($obj->emailxml->getVarName($c));
      if (SessionOperations::isDefinedIntern('w_' . $varname)) {
        $obj->emailxml->setValue2Var($obj->emailxml->getVarName($c), SessionOperations::getVarValueIntern('w_' . $varname));
      }
    }

    
    
    if (SessionOperations::isDefinedIntern('w_ansprechpartner')) {
      $obj->emailxml->setValue2Var('rechadr2', SessionOperations::getVarValueIntern('w_' . 'ansprechpartner'));
    }

    
    
    if (SessionOperations::isDefinedIntern('w_anrede') && SessionOperations::getVarValueIntern('w_anrede') != '') { 
      $obj->emailxml->setValue2Var('anrede', SessionOperations::getVarValueIntern('w_anrede'));
    }
    if (SessionOperations::isDefinedIntern('w_geschlecht') && SessionOperations::getVarValueIntern('w_geschlecht') != '') {
      $obj->emailxml->setValue2Var('geschlecht', SessionOperations::getVarValueIntern('w_geschlecht'));
    }
    if (SessionOperations::isDefinedIntern('w_titel') && SessionOperations::isDefinedIntern('w_vorname')) {
      $obj->emailxml->vorname = ltrim(SessionOperations::getVarValueIntern('w_titel') . ' ') . SessionOperations::getVarValueIntern('w_vorname');
    }
    if ($obj->emailxml->gebdatum == '' && $obj->emailxml->gebjahr != '' && SessionOperations::isDefinedIntern('w_gebjahr')) {
      $obj->emailxml->gebdatum = '01.01.' . SessionOperations::getVarValueIntern('w_gebjahr');
    }
    if ($obj->emailxml->erm_grund != '') {
      $dbwerm = new DBWorkErmaessigung();
      $erm = $dbwerm->getErmaessigungbyNr($obj->emailxml->erm_grund);
      if (count($erm) > 0) {
        $obj->emailxml->erm_proz = $erm[0]->prozente;
      }
    }

    
    
    if (SessionOperations::isDefinedIntern('w_tel') and trim(SessionOperations::getVarValueIntern('w_tel') != '')) {
      $obj->emailxml->addKommunikationByParam('T', 'Telefon', trim(SessionOperations::getVarValueIntern('w_tel')));
    }
    if (SessionOperations::isDefinedIntern('w_tel1') and trim(SessionOperations::getVarValueIntern('w_tel1')) != '') {
      $obj->emailxml->addKommunikationByParam('T', 'Telefon', trim(SessionOperations::getVarValueIntern('w_tel1')));
    }
    if (SessionOperations::isDefinedIntern('w_tel2') and trim(SessionOperations::getVarValueIntern('w_tel2')) != '') {
      $obj->emailxml->addKommunikationByParam('T', 'Dienstlich', trim(SessionOperations::getVarValueIntern('w_tel')));
    }
    if (SessionOperations::isDefinedIntern('w_mobil') and trim(SessionOperations::getVarValueIntern('w_mobil')) != '') {
      $obj->emailxml->addKommunikationByParam('M', 'Mobil', trim(SessionOperations::getVarValueIntern('w_mobil')));
    }
    if (SessionOperations::isDefinedIntern('w_fax') and trim(SessionOperations::getVarValueIntern('w_fax')) != '') {
      $obj->emailxml->addKommunikationByParam('F', 'Fax', trim(SessionOperations::getVarValueIntern('w_fax_pa')));
    }
    if (SessionOperations::isDefinedIntern('w_email') and trim(SessionOperations::getVarValueIntern('w_email')) != '') {
      $obj->emailxml->addKommunikationByParam('E', 'E-Mail', trim(SessionOperations::getVarValueIntern('w_email')));
    }


    if (SessionOperations::getVarValueAnm(ANMELDEART, '') != '') {
      if ((SessionOperations::getVarValueAnm(ANMELDEART) == 1) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 1)) {
        $this->AddElternKindAnmeldung($obj);
      } 
      elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 2) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 2)) {
        $this->AddFirmenAnmeldung($obj);
      } 
      elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 3) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 3)) {
        $this->AddPaareAnmeldung($obj);
      } 
      elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 4) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 4)) {
        $this->AddMehrfachAnmeldung($obj);
      } 
      elseif ((SessionOperations::getVarValueAnm(ANMELDEART) == 5) || (isset($_REQUEST[ANMELDEART]) && $_REQUEST[ANMELDEART] == 5)) {
        $this->AddNormalHotelAnmeldung($obj);
      } 
      else {
        $this->AddNormalAnmeldung($obj);
      } 
    } else {
      $this->AddNormalAnmeldung($obj);
    } 

    return $obj;
  }
}


class InteressenbekundungsFactory
{
  
  public function getInstance()
  {
    $settings = ToolSettingsAPI::getToolSettings(0);

    $connectionInfo = DBConnectionInfo::getInstance();
    if ($connectionInfo->db_replikat) {

      if ($settings->savemail2file == ANMELDUNGPER_FILE) {
        return new InteressenbekundungXMLFile();
      }
      if ($settings->savemail2file == ANMELDUNGPER_ONLINE && $connectionInfo->db_hybrid) {
        return new InteressenbekundungDirekt();
      }
      if ($settings->savemail2file == ANMELDUNGPER_DMZ) {
        return new InteressenbekundungDMZ();
      } else {
        return new InteressenbekundungXMLEmail();
      }
    } else {
      return new InteressenbekundungDirekt();
    }
  }
}

class Interessenbekundung
{
  
  public function getXMLString($xo)
  {
    $xml = new XMLMailAnmeldungNormal();
    $xml->emailxml = $xo->emailxml;
    $xml->emailxmlkurse = $xo->emailxmlkurse;

    return $xml->Execute();
  }

  
  public function saveBekundung($pEmailXMLContainer)
  {
    return false;
  }
}


class InteressenbekundungXMLEmail extends Interessenbekundung
{
  
  public function setEmailSettings($e, $exc)
  {
    $allgsettings = AllgSettingsAPI::getAllgSettings();
    $e->SetVar2Value('to', $allgsettings->emailanm);
    $e->SetVar2Value('subject', 'automatisch generierte eMail - Anmeldung: ' . $exc->emailxml->name . ', ' . $exc->emailxml->vorname);
  }

  
  public function saveBekundung($pEmailXMLContainer)
  {
    
    $smtpMail = new smtpMail();
    $this->setEmailSettings($smtpMail, $pEmailXMLContainer);
    $smtpMail->body = $this->getXMLString($pEmailXMLContainer);
    $smtpMail->SetVar2Value('contenttype', SMTP_CONTENTTYPE_XML);

    
    return $smtpMail->sendMail();
  }
}



class InteressenbekundungXMLFile extends Interessenbekundung
{
  
  public function getRandomFilename()
  {
    $datetimeop = new DateTimeOperations();
    $settings = ToolSettingsAPI::getToolSettings(0);
    if (StringOperations::substr($settings->emailfilepath, -1) != '/') {
      $settings->emailfilepath .= '/';
    }

    do {
      $filename = $settings->emailfilepath . 'webbasys' . $datetimeop->getTimestampNow() . '.xml';
    } while (file_exists($filename));

    return $filename;
  }

  
  public function saveBekundung($pEmailXMLContainer)
  {
    $fileWork = new SimpleFileWork();
    $fileWork->clear();
    $fileWork->access = 'a';
    $fileWork->content = $this->getXMLString($pEmailXMLContainer);

    $fn = $this->getRandomFilename();
    $fileWork->filename = $fn;
    $fileWork->openFile();
    $fileWork->setContent();
    $fileWork->closeFile();
    $result = file_exists($fn);
    if (!$result) {
      Logger::logg("Konnte Interessenbekundung nicht als $fn speichern. Bitte Pfad 'Pfad der E-Mail-Datei' im Webadmin überprüfen!", 555);
    }

    return $result;
  }
}


class InteressenbekundungDirekt extends Interessenbekundung
{
  public function saveBekundung($pEmailXMLContainer)
  {
    $reservierung = new DBWorkAnmeldungReservierungEmailXML(2);
    $reservierung->emailxml = $pEmailXMLContainer->emailxml;
    $reservierung->emailxmlkurse = $pEmailXMLContainer->emailxmlkurse;
    $userid = SessionOperations::getUserID();

    return $reservierung->Anmeldung($userid, 'I');
  }
}


class InteressenbekundungDMZ extends Interessenbekundung
{
  
  public function saveBekundung($pEmailXMLContainer)
  {
    $node = $pEmailXMLContainer->emailxml->getXMLNode();
    $node2 = new XMLNode('Kurse');
    foreach ($pEmailXMLContainer->emailxmlkurse as $kurs) {
      $node2->addChild($kurs->getXMLNode());
    }
    $node->addChild($node2);

    $return = true;
    try {
      $abgleichAPI = new AbgleichAPI();
      $nutzlast = new Nutzlast($node);
      $abgleichAPI->sendeNachricht(AbgleichAPI::ABGLEICH_INTERESSENBEKUNDUNG, $nutzlast);
    } catch (Exception $e) {
      Logger::logg('Interessenbekundung - Folgende Exception ist aufgetreten: ' . $e->getMessage() . ' [' . $e->getTraceAsString() . ']', 200);
      $return = false;
    }

    return $return;
  }
}