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

class DataMenuFreeKontaktFormular extends DataMenuMain
{
  
  private $_pflichtfeldFehlerArray = array();
  
  public function __construct($pUrlparameter)
  {
    parent::__construct($pUrlparameter);
    $this->exportadapter = new ExpFreeKontaktFormular();
  }
  
  public function getsight($pSightId = 484) {
    parent::getsight($pSightId);
  }
  
  
  public function _getClickPath($pName = 'Kontaktformular')
  {
    if (trim($this->toolsettings->darstellungKlickpfadKontaktFormular) !== '') {
      $pName = $this->toolsettings->darstellungKlickpfadKontaktFormular;
    }
    return $pName;
  }
  
  
  public function mainmenu()
  {
    $this->prepareMainmenu();
    if ($this->toolsettings->showClickpfad) {
      echo $this->getClickPath();
    }
    
    $warnungPflichtfelder = '';
    
    if($_SERVER['REQUEST_METHOD'] == 'POST' && !GetOperations::isDefined('zurueck')) {
      $this->_resetBrowserReloadSchutz();
      SessionOperations::getFreeKontaktFormularFromRequest2Session();
      if($this->_checkEingaben()) {
        return RequestOperations::toKathaupt(269);
      }
      else {
        $warnungPflichtfelder = $this->_getWarnungPflichtfelder();
        $this->exportadapter->setFehler($this->_pflichtfeldFehlerArray, array());
      }
    }
    
    echo "<div class='hauptseite'>\n";
    $this->statusmenu();
    echo $warnungPflichtfelder;
    echo $this->getContentAnker();
    $this->showheader();
    $this->showbody();
    $this->showfooter();
    echo "</div>";
  }
  
  public function showheader()
  {
    DataMenu::showheader();
  }

  public function showfooter()
  {
    DataMenu::showfooter();
  }
  
  
  private function _checkEingaben()
  {
    $checkKontaktForm = new WBFreeKontaktFormularCheck();
    
    $sightPartAry = array('header', 'body', 'footer');
    $check = true;
    
    foreach($sightPartAry as $sightPart) {
      $checkKontaktForm->vorlage = $this->sight->$sightPart;
      $check &= $checkKontaktForm->check('kontaktedit');
    }
    
    $this->_pflichtfeldFehlerArray = $checkKontaktForm->pflichtfeldFehlerArray;
    
    return $check;
  }
  
  
  private function _getWarnungPflichtfelder()
  {
    $result = '<ul class="warnungpflichtfelder">';
    foreach($this->_pflichtfeldFehlerArray as $key => $value) {
      $result .= '<li class="warnungpflichtfelder ' . CleanOperations::cleanStringForHtml($key) . '">' . CleanOperations::cleanStringForHtml($value) . '</li>';
    }
    $result .= '</ul>';
    
    return $result;
  }
  
  
  private function _resetBrowserReloadSchutz()
  {
    SessionOperations::setVarValueIntern('freeKontaktFormularBereitsGesendet', false);
  }
}
?>