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


class DataMenuLoginSepaMandat extends DataMenuMainTopLeft
{
  public function __construct($pUrlparameter)
  {
    parent::__construct($pUrlparameter);
    $this->exportadapter = new ExpStammBv();
  }

  public function getsight($sightid = 586)
  {
    parent::getsight($sightid);
  }

  public function _getClickPath($pName = 'Teilnehmer-Login - SEPA-Lastschriftmandat')
  {
    $this->_setStdClickPath($pName, 'clickKundenLoginSepaMandat');

    return $this->clickpfad;
  }

  public function mainmenu()
  {
    $this->prepareMainmenu();
    if ($this->toolsettings->showClickpfad) {
      echo $this->getClickPath();
    }
    echo '<div class="hauptseite_ohnestatus">' . "\n" . $this->getContentAnker();

    if (!$this->isStammhoererLoggedIn()) {
      $this->showNichtEingeloggt();
    } else {
      if (count($this->dataarraybody) > 0) {
        $this->showheader();
        $this->showbody();
        $this->showfooter();
      } else {
        $this->shownodata();
      }
    }

    echo '</div>';
  }

  
  public function getheader($pSgtVars = array())
  {
    
    $tmpexpadapter = $this->exportadapter;
    $this->exportadapter = new ExpTeilnehmer();

    $retour = parent::getheader($pSgtVars);

    
    $this->exportadapter = $tmpexpadapter;

    return $retour;
  }

  public function getdataarrayheader()
  {
    $this->dataarrayheader = SessionOperations::getTeilnehmerFromSession();
  }

  public function getdataarraybody()
  {
    $alleStammBvs = $this->getStammBv4Tn();
    $this->dataarraybody = array();
    foreach ($alleStammBvs as $stammbv) {
      if ($stammbv->id == $this->urlparameter->bv) {
        $this->dataarraybody[] = $stammbv;
      }
    }
  }

  private function isStammhoererLoggedIn()
  {
    $wblogin = $this->getWbLogin();

    return $wblogin !== null && trim($wblogin->login) !== '';
  }

  private function showNichtEingeloggt()
  {
    echo $this->getSightPart($this->sight->id, WB_SIGHT_PART_NOCOLUMN, array(new StammBv()));
  }

  private function getWbLogin()
  {
    static $wblogin = null;
    if (is_null($wblogin)) {
      $login = SessionOperations::getVarValueWk('w_login');
      $dbwWbLogin = new DBWorkWBLogins(1, true);
      $wblogin = $dbwWbLogin->getByLogin($login);
    }

    return $wblogin;
  }

  private function getStammBv4Tn($pRefreshCache = false)
  {
    $stammbv = null;
    if (is_null($stammbv) || $pRefreshCache) {
      $wbLogin = $this->getWbLogin();
      $stammbv = StammBvAPIHauptId::getStammBvByTnr($wbLogin->tnr);
      if ($stammbv === false) {
        $stammbv = array();
      }
    }

    return $stammbv;
  }
}