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

class DataMenuFreeKontaktFormularBestaetigung extends DataMenuMain
{
  public function __construct($pUrlparameter)
  {
    parent::__construct($pUrlparameter);
    $this->exportadapter = new ExpFreeKontaktFormular();
  }
  
  public function getsight($pSightId = 485) {
    parent::getsight($pSightId);
  }
  
  
  public function _getClickPath($pName = 'Kontaktformular-Bestätigung')
  {
    if (trim($this->toolsettings->darstellungKlickpfadKontaktFormularBestaetigung) !== '') {
      $pName = $this->toolsettings->darstellungKlickpfadKontaktFormularBestaetigung;
    }
    return CleanOperations::cleanStringForHtml($pName);
  }
  
  public function mainmenu()
  {
    $this->prepareMainmenu();
    if ($this->toolsettings->showClickpfad) {
      echo $this->getClickPath();
    }
    
    echo "<div class='hauptseite'>\n";
    $this->statusmenu();
    echo $this->getContentAnker();
    
    if (GetOperations::isDefined('absenden')) {
      $emailVersendet = false;
      if (!$this->_isBrowserReload()) {
        $emailVersendet = $this->_sendFormular();
        if ($emailVersendet) {
          $this->_setBrowserReloadSchutz();
          SessionOperations::resetFreeKontaktFormular();
          $this->shownocolumn();
        }
        else {
          $this->shownodata();
        }
      }
      else {
        $this->shownocolumn();
      }
    }
    else {
      $this->showheader();
      $this->showbody();
      $this->showfooter();
    }
    echo "</div>";
  }
  
  public function showheader()
  {
    DataMenu::showheader();
  }

  public function showfooter()
  {
    DataMenu::showfooter();
  }
  
  public function shownodata()
  {
    DataMenu::shownodata();
  }
  
  public function shownocolumn() {
    DataMenu::shownocolumn();
  }
  
  
  private function _isBrowserReload()
  {
    return SessionOperations::getVarValueIntern('freeKontaktFormularBereitsGesendet', true);
  }
  
  
  private function _setBrowserReloadSchutz()
  {
    SessionOperations::setVarValueIntern('freeKontaktFormularBereitsGesendet', true);
  }
  
  
  private function _getEmailContent()
  {
    $result = '';
    
    $dmbasis = new DataMenuBasis(new URLParameterBasis(false));
    $dmbasis->getSight(486);
    
    $dmbasis->exportadapter = new ExpFreeKontaktFormular();
    $dmbasis->dataarrayheader = array(new Datamodul());
    $dmbasis->dataarraybody = array(new Datamodul());
    $dmbasis->dataarrayfooter = array(new Datamodul());
    
    $result .= $dmbasis->getheader();
    $result .= $dmbasis->getbody();
    $result .= $dmbasis->getfooter();
    
    return $result;
  }
  
  
  private function _sendFormular()
  {
    $allgSettings = AllgSettingsAPI::getAllgSettings();
    $valid = ValidierungWB::getInstance();
    $email = $allgSettings->vhsemail;
    if (trim($this->toolsettings->kontaktFormularAltEmailAdresse) !== '') {
      if ($valid->isValidVar('email', $this->toolsettings->kontaktFormularAltEmailAdresse)) {
        $email = $this->toolsettings->kontaktFormularAltEmailAdresse;
      }
    }
    
    $subject = 'Kontaktformular';
    if (trim($this->toolsettings->kontaktFormularEmailBetreff) !== '') {
      $subject = $this->toolsettings->kontaktFormularEmailBetreff;
    }
    
    $smtp = new smtpMail();
    $smtp->SetVar2Value('to', $email);
    $smtp->SetVar2Value('subject', $subject);
    $smtp->SetVar2Value('body', $this->_getEmailContent());
    $smtp->SetVar2Value('contenttype', SMTP_CONTENTTYPE_HTML);
    
    return $smtp->sendMail();
  }
}
?>