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



class EmailXML extends Datamodul
{
  public $ewahl;
  public $typ; 
  public $name;
  public $vorname;
  public $zusatz;
  public $zusatz2;
  public $zusatz3;
  public $strasse;
  public $ort;
  public $geschlecht;
  public $beruf;
  public $gebdatum;
  public $gebjahr;
  public $altersklasse;
  public $kontonr;
  public $blz;
  public $bankbez;
  public $kontoinh;
  public $rechadr1;
  public $rechadr2;
  public $rechadr3;
  public $rechadr4;
  public $rechadr5;
  public $rechadr6;
  public $erm_grund;
  public $erm_proz;

  public $bemerkung;
  public $tnr;
  public $status;
  public $statusinfo;
  public $eingelesen;
  public $ausweisnr;
  public $mitgliednr;
  public $ausweisdat;
  public $bearbeiter;
  public $bearbdatum;
  public $arbamtnr;
  public $staatsang = '';
  public $arykommunikation = array();

  
  public $sessionid;
  
  public $sessiontime;
  
  public $geburtsort;
  
  public $nation = '';

  
  public $bundesland = '';
  public $krit1 = '';
  public $krit2 = '';
  public $krit3 = '';
  public $krit4 = '';
  public $krit5 = '';
  public $krit6 = '';
  public $krit7 = '';
  public $krit8 = '';
  public $krit9 = '';
  public $krit10 = '';
  public $krit11 = '';
  public $krit12 = '';
  public $krit13 = '';
  public $krit14 = '';
  public $krit15 = '';
  public $krit16 = '';
  public $newsl_erlaubt = '';
  public $newsl_bemerk = '';
  public $pers_nr = '';
  public $bic = '';
  public $iban = '';

  public $name_titel = '';

  public $last_erteilt;
  public $wblogin;
  public $keinebankverbindung;
  public $erziehungsbername;
  public $erziehungsbervorname;
  public $erziehungsbertnr;

  
  public $arykennzeichen = array();

  public $arykwerb = array();

  public $aryattachments = array();

  
  public $payonline;
  public $epay_tid;
  public $epay_tid_merchant;
  public $epay_type;
  public $epay_ordertime;
  public $epay_payerid;
  public $epay_institution;
  public $epay_feeamount;
  public $epay_amount;
  public $epay_blz;
  public $epay_bank;
  public $epay_bic;
  public $epay_iban;
  public $epay_kontoinhaber;
  public $epay_kontonr;
  public $epay_expiry;
  public $epay_cardholder;
  public $epay_processing_mode;
  
  public $epay_authorizationid;
  public $epay_order_id;
  public $epay_capture_id;

  
  public $epay_state;

  public $epay_payment_date;

  
  public $epay_pendingReason;

  
  public $sozarbeitgeber;
  public $sozposition;
  public $arbeit;
  public $ausbildung;

  public $abteilung;
  public $orgaeinh;

  
  public $mandatam;
  
  public $kommprio;
  public $anm_quelle;

  
  public $spendenbetrag;

  public $homeoffice;

  public $ustid;

  public $dse_unterschrieben_datum;
  public $dse_unterschrieben_bearbeiter;
  public $dse_unterschrieben_weg;
  public $dse_widerrufen_datum;
  public $dse_widerrufen_bearbeiter;
  public $dse_widerrufen_weg;

  public $weitergabekommunikationfg;

  public $zustimmung_hygiene;
  public $zustimmung_indiv;
  public $zustimmung_fuehrung;

  
  public $rech_tnr;
  public $rech_name;
  public $rech_vorname;
  public $rech_zusatz1;
  public $rech_zusatz2;
  public $rech_zusatz3;
  public $rech_strasse;
  public $rech_ort;
  public $rech_dauerhaft;
  public $rech_email;

  
  public function getVarName4Person($var)
  {
    switch ($var) {
      default: return $var;
      case 'gebdatum': return 'gebdat';
      case 'kontonr': return 'konto';
      case 'kontoinh': return 'kontoinhaber';
      case 'altersklasse': return 'alterskl';
      case 'anm_quelle': return 'anmquelle';

    }
  }

  public function addKommunikation($pEmailXMLKomm)
  {
    array_push($this->arykommunikation, $pEmailXMLKomm);
  }

  public function addKommunikationByParam($art, $bez, $wert)
  {
    $komm = new EmailXMLKomm();
    $komm->kommart = $art;
    $komm->kommbez = $bez;
    $komm->kommwert = $wert;
    $this->addKommunikation($komm);
  }

  public function addKennzeichenByParam($pKennz, $pText = '')
  {
    $kennz = new EmailXMLKennz();
    $kennz->setValue2Var('kennz', $pKennz);
    $kennz->setValue2Var('kennztext', $pText);
    $this->addKennzeichen($kennz);
  }

  public function addKennzeichen($pEmailXMLKennz)
  {
    if (!is_array($this->arykennzeichen)) {
      $this->arykennzeichen = array();
    }
    array_push($this->arykennzeichen, $pEmailXMLKennz);
  }

  public function addAttachment($pEmailXMLAttachment)
  {
    if (!is_array($this->aryattachments)) {
      $this->aryattachments = array();
    }
    array_push($this->aryattachments, $pEmailXMLAttachment);
  }

  public function addAttachmentByParam($pName, $pFilename, $pTyp, $pNachweis = 'F', $pBeschreibung = '')
  {
    $attach = new EmailXMLAttach();
    $attach->filename = $pName;
    $attach->typ = $pTyp;
    $attach->loadFromFile($pFilename);
    $attach->beschreibung = $pBeschreibung;
    $attach->nachweis = $pNachweis;
    $this->addAttachment($attach);
  }

  public function addKWerb($pEmailXMLKWerb)
  {
    if (!is_array($this->arykwerb)) {
      $this->arykwerb = array();
    }
    array_push($this->arykwerb, $pEmailXMLKWerb);
  }

  public function addKWerbByParam($pTyp, $pWert, $pBemerkung = '')
  {
    $item = new EmailXMLKWerb();
    $item->setValue2Var('kwerbungtyp', $pTyp);
    $item->setValue2Var('kwerbungwert', $pWert);
    $item->setValue2Var('kwerbungbemerkung', $pBemerkung);
    $this->addKWerb($item);
  }

  
  public function addEPayInfo(EPayInfo $pEPayInfo)
  {
    $this->epay_tid = $pEPayInfo->tid;
    $this->epay_tid_merchant = $pEPayInfo->tidMerchant;
    $this->epay_type = $pEPayInfo->type;
    $this->epay_ordertime = $pEPayInfo->ordertime;
    $this->epay_payerid = $pEPayInfo->payerid;
    $this->epay_institution = $pEPayInfo->institution;
    $this->epay_feeamount = $pEPayInfo->feeamount;
    $this->epay_amount = $pEPayInfo->amount;

    $this->epay_state = $pEPayInfo->paymentState;
    $this->epay_payment_date = $pEPayInfo->paymentDate;
    $this->epay_pendingReason = $pEPayInfo->pendingReason;

    $this->epay_order_id = $pEPayInfo->order_id;
    $this->epay_authorizationid = $pEPayInfo->authorizationid;
    $this->epay_capture_id = $pEPayInfo->capture_id;

    $this->epay_processing_mode = $pEPayInfo->processingMode;
  }

  public function getVarValue($name)
  {
    switch (StringOperations::strtolower($name)) {
      case 'email':
         for ($i = 0; $i < count($this->arykommunikation); $i++) {
           if (StringOperations::strtolower($this->arykommunikation[$i]->kommart) == 'e') {
             return $this->arykommunikation[$i];
           }
         }
         
       default: return Datamodul::getVarValue($name);
    }
  }

  public function getXMLNode($pNodeTag = 'STAMMDATEN')
  {
    $exceptions = array('arykommunikation', 'eingelesen', 'arykennzeichen', 'arykwerb', 'id', 'aryattachments');
    
    $rootNode = new XMLNode($pNodeTag);
    for ($i = 0; $i < $this->getVarCount(); $i++) {
      $varname = $this->getVarname($i);
      if (in_array($varname, $exceptions)) {
        continue;
      }
      $value = $this->getVarValue($varname);
      if (is_numeric($value) || $value != '') {
        $rootNode->addChild(new XMLNode(StringOperations::strtoupper($varname), $this->getVarValue($varname)));
      }
    }

    if (count($this->arykommunikation) > 0) {
      $kommunikation = new XMLNode('KOMMUNIKATION');
      foreach ($this->arykommunikation as $kommnode) {
        $kommunikation->addChild($kommnode->getXMLNode());
      }
      $rootNode->addChild($kommunikation);
    }

    if (count($this->arykennzeichen) > 0) {
      $kennzeichen = new XMLNode('KENNZEICHEN');
      foreach ($this->arykennzeichen as $kennznode) {
        $kennzeichen->addChild($kennznode->getXMLNode());
      }
      $rootNode->addChild($kennzeichen);
    }

    if (count($this->arykwerb) > 0) {
      $parent = new XMLNode('KEINEWERBUNG');
      foreach ($this->arykwerb as $node) {
        $parent->addChild($node->getXMLNode());
      }
      $rootNode->addChild($parent);
    }
    

    if (count($this->aryattachments) > 0) {
      $parent = new XMLNode('ATTACHMENTS');
      foreach ($this->aryattachments as $node) {
        $parent->addChild($node->getXMLNode());
      }
      $rootNode->addChild($parent);
    }

    return $rootNode;
  }

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'last_erteilt':
      case 'ausweisdat':
      case 'bearbdatum':
      case 'mandatam':
        return \DatamodulVarType::TYPE_DATE;
      case 'erm_proz':
      case 'erm_grund':
      case 'tnr':
      case 'status':
      case 'sessiontime':
      case 'erziehungsbertnr':
      case 'kommprio':
      case 'rech_tnr':
        return \DatamodulVarType::TYPE_INT;
      case 'epay_feeamount':
      case 'epay_amount':
      case 'spendenbetrag':
        return \DatamodulVarType::TYPE_FLOAT;
      case 'epay_ordertime':
      case 'dse_unterschrieben_datum':
      case 'dse_widerrufen_datum':
      case 'eingelesen':
      case 'payment_date':
        return \DatamodulVarType::TYPE_DATETIME;
      case 'homeoffice':
      
      
      
      
      
        return \DatamodulVarType::TYPE_BOOL_WF;
    }
  }
}