<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */


class TNDruckliste extends DruckSheet
{
  protected $vonDate;
  protected $bisDate;
  protected $kursetage;
  protected $tnName;

  
  protected $tnr;

  protected $fontsize4Cell;
  
  
  protected $terminbereich;

  public function __construct($pSelnr, $pToolId)
  {
    $this->toolId = $pToolId;
    $this->setDrucksettings();
    
    $this->kurstage = new webtools\drucklisten\Kurstage();
    $this->kurstage->von = '';
    $this->kurstage->bis = '';

    $this->dtop = new DateTimeOperations();
    $this->mop = new MathOperations();
    $this->htmlop = new HTMLOperations();

    if (isset($this->settings->kurstage->von, $this->settings->kurstage->bis)
      && ($this->settings->kurstage->von != '') && ($this->settings->kurstage->bis != '')) {
      $this->kurstage->von = $this->settings->kurstage->von;
      $this->kurstage->bis = $this->settings->kurstage->bis;
    }
  }

  
  public function _prepare($pData = array(), $pTnr = -1, $pTerminbereich = '', $pVonDate = '', $pBisDate = '', $pKnr = '')
  {
    parent::_prepare($pKnr);

    $this->tnr = $pTnr;

    
    
    $this->kursetage = $pData;

    
    if (!empty($pVonDate)) {
      $this->vonDate = $pVonDate;
    }
    if (!empty($pBisDate)) {
      $this->bisDate = $pBisDate;
    }

    
    if (!empty($pData)) {
      
      
      if (empty($this->kurstage->von)) {
        $this->kurstage->von = $pData[0]->datum;
      }
      if (empty($this->kurstage->bis)) {
        $this->kurstage->bis = $pData[count($pData) - 1]->datum;
      }

      
      
      if (empty($pVonDate)) {
        $this->vonDate = $this->kurstage->von; 
      }
      if (empty($pBisDate)) {
        
        $this->bisDate = $this->kurstage->bis;
      }
    } 

    
    $this->terminbereich = $pTerminbereich;


    $dbwTN = new DBWorkTeilnehmer();
    $teilnehmer = $dbwTN->getTeilnehm($pTnr);
    $this->tnName = $teilnehmer->namevorname;
    

    $this->fontsize4Cell = '';
    if ($this->settings->druckbereich->hochformat == 1) {
      $this->fontsize4Cell = '8%';
    }
  }

  

  
  public function create($pData = array(), $pTnr = -1, $pTerminbereich = '', $pVonDate = '', $pBisDate = '', $pDozId = -1, $pPrintAllowed4User = false)
  {
    
    
    $this->pdf = $this->__initPDF();
    $this->_prepare($pData, $pTnr, $pTerminbereich, $pVonDate, $pBisDate);
    $this->pdf->AddPage();
    $this->_createContent();
    $this->footer();
    $this->pdf->Output('', $this->getOutputName());
  }

  
  public function fieldname()
  {
    return '<fieldset id="kurstage"><legend>im Zeitraum</legend>';
  }

  public function _createContent($pKurs = '')
  {
    $this->_printDruckListe();
  }

  
  public function setDrucksettings()
  {
    $this->settings = new \webtools\tnlisten\DruckTNSettings();
  }

  
  public function header($pKnr = '')
  {
    $this->_createHeader();
  }

  
  public function _createHeader($pKurs = '')
  {
    $logoFilePath = PDFLogo::getLogoFilePath();
    if (PDFLogo::printLogoImg($this->pdf, $logoFilePath)) {
      $this->pdf->ln(9);
    } else {
      $this->pdf->ln();
    }

    $allgsettings = AllgSettingsAPI::getAllgSettings();

    
    $this->pdf->ln();
    
    $this->pdf->CellAtX('3%', StringOperations::html_entity_decode($allgsettings->vhsname), 'B', '', 16);
    
    $this->pdf->CellAtX('80%', 'Datum: ' . $this->dtop->getDateNow());
    $this->pdf->ln(8);
    
    if (!($this->settings->title1)) {
      $this->setTitle1();
    }
    $this->pdf->CellAtX('3%', $this->settings->title1, 'B', '', 14, '77%');
    $this->pdf->CellAtX('80%', 'Seite:         ' . $this->pdf->PageNo());
    $maxwidth = $this->getWidth4Title();
    if ($this->pdf->GetStringWidth($this->settings->title1) > $maxwidth) {
      $this->pdf->ln(7);
    }
    
    
    

    $datepart = '';
    if (!empty($this->vonDate) && !empty($this->bisDate) && $this->terminbereich == 'bereich') {
      $this->pdf->ln(5);
      $datepart .= 'vom ' . $this->vonDate . ' bis ' . $this->bisDate;
      $this->pdf->CellAtX('3%', $datepart, 'B', '', 11, '93%');
      $this->pdf->ln(6);
    } else {
      $this->pdf->ln(6);
    }
    
    $this->printSubtitle();
    $this->pdf->ln(5);
  }

  

  
  public function _getEndbemerkung()
  {
    return '';
  }

  
  public function _getKurstage($changeHL)
  {
    return;
  }

  
  public function getZusatzspaltenEnabled($optionName)
  {
    return false;
  }
}