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


class Wochenplangrafik extends DruckGrafikKW
{
  
  public $zeilenhoehe;


  public $tageshöhe;

  
  public function getListID()
  {
    return 18;
  }

  

  public function getListTyp()
  {
    return '16';
  }

  

  public function loadFactoryDefaults()
  {
    parent::loadFactoryDefaults();
    $this->setTitle1();
  }

  

  public function setTitle1()
  {
    $this->settings->title1 = 'Wochenplan';
  }

  

  public function getDruckbereichEnabled($optionName)
  {
    
    switch ($optionName) {
            case 'querformat':
            return true;
        }

    return false;
  }

  

  
  public function _prepare($pKnr = '')
  {
    parent::_prepare($pKnr);


    
    $this->spaltenbeginnary = array(3, 'Mo' => 10.5, 'Di' => 21.9, 'Mi' => 33.3, 'Do' => 44.7, 'Fr' => 56.1, 'Sa' => 67.5, 'So' => 78.9);
    $this->spaltenbreiteary = array(7.5, 'Mo' => 11.4, 'Di' => 11.4, 'Mi' => 11.4, 'Do' => 11.4, 'Fr' => 11.4, 'Sa' => 11.4, 'So' => 11.4);

    if (count($this->timeary) == 11) {
      $this->zeilenhoehe = 12;
      $this->tageshöhe = 2.33;
    } elseif (count($this->timeary) == 10) {
      $this->zeilenhoehe = 13;
      $this->tageshöhe = 2.66;
    } else {
      $this->zeilenhoehe = 14;
      $this->tageshöhe = 3;
    }
  }

  

  
  public function _getTimeary()
  {
    
    $this->timeary = $this->settings->zeitpunkte->zeitab;
    
    $this->timeary = array_unique($this->timeary);
    sort($this->timeary);				
    while (!empty($this->timeary) && empty($this->timeary[0])) {
      array_shift($this->timeary);
    }
    sort($this->timeary);				
    array_push($this->timeary, '24:01');
  }

  

  
  protected function _printDruckListe($pKurs = '')
  {

        
    $this->pdf->ln(-0.5 * $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', '', '', '', '', $this->spaltenbreiteary[0] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Mo'] . '%', 'Mo., ' . $this->kwary['Mo'], '', '', '', $this->spaltenbreiteary['Mo'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Di'] . '%', 'Di., ' . $this->kwary['Di'], '', '', '', $this->spaltenbreiteary['Di'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Mi'] . '%', 'Mi., ' . $this->kwary['Mi'], '', '', '', $this->spaltenbreiteary['Mi'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Do'] . '%', 'Do., ' . $this->kwary['Do'], '', '', '', $this->spaltenbreiteary['Do'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Fr'] . '%', 'Fr., ' . $this->kwary['Fr'], '', '', '', $this->spaltenbreiteary['Fr'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['Sa'] . '%', 'Sa., ' . $this->kwary['Sa'], '', '', '', $this->spaltenbreiteary['Sa'] . '%', 1, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary['So'] . '%', 'So., ' . $this->kwary['So'], '', '', '', $this->spaltenbreiteary['So'] . '%', 1, $this->height);
    $this->pdf->ln($this->height);



    
    
    


    
    $date = isset($this->kursetage[0]->datum) ? $this->kursetage[0]->datum : '';
    while ($this->dtop->isDateBefore($date, $this->kwary['Mo']) && $this->kursetage) {
      array_shift($this->kursetage);
      $date = isset($this->kursetage[0]->datum) ? $this->kursetage[0]->datum : '';
    }


    
    $this->_printTimes();
    foreach ($this->kwary as $wochentag => $datum) {
      $this->_printKursCell($wochentag);
    }
  }

  

  
  public function _printTimes()
  {

        
    foreach ($this->timeary as $zeit) {
      if (strcmp($zeit, '24:01') != 0) {
        
        $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', '', 'B', '', '', $this->spaltenbreiteary[0] . '%', 1, $this->zeilenhoehe);

        
        $this->pdf->ln(1);
        $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', $zeit, 'B', '', '', $this->spaltenbreiteary[0] . '%', 0, $this->height);
        $this->pdf->ln($this->zeilenhoehe - 1);
      }
    }

    $this->pdf->ln(-(count($this->timeary) - 1) * $this->zeilenhoehe);
  }

  

  
  public function _printKursCell($pWochentag)
  {


        
    $date = isset($this->kursetage[0]->datum) ? $this->kursetage[0]->datum : '';
    $zeit_beg = isset($this->kursetage[0]->zeit_beg) ? $this->kursetage[0]->zeit_beg : '';
    while (strcmp($zeit_beg, $this->timeary[0]) < 0 && strcmp($this->kwary[$pWochentag], $date) == 0) {
      array_shift($this->kursetage);
      $date = isset($this->kursetage[0]->datum) ? $this->kursetage[0]->datum : '';
      $zeit_beg = isset($this->kursetage[0]->zeit_beg) ? $this->kursetage[0]->zeit_beg : '';
    }


    
    foreach ($this->timeary as $intervallnr => $zeit) {
      if (strcmp($zeit, '24:01') != 0) {


                
        $this->pdf->CellAtX($this->spaltenbeginnary[$pWochentag] . '%', '', 'B', '', '', $this->spaltenbreiteary[$pWochentag] . '%', 1, $this->zeilenhoehe);


        
        $date = isset($this->kursetage[0]->datum) ? $this->kursetage[0]->datum : '';
        if (strcmp($this->kwary[$pWochentag], $date) == 0) {
          $count = 0;
          
          while (isset($this->kursetage[0]) && strcmp($zeit, $this->kursetage[0]->zeit_beg) <= 0 && strcmp($this->timeary[$intervallnr + 1], $this->kursetage[0]->zeit_beg) > 0 && strcmp($this->kwary[$pWochentag], $this->kursetage[0]->datum) == 0) {
            
            
            if ($count < 2) {
              $this->pdf->ln($count * 2 * $this->tageshöhe);
              $this->pdf->CellAtX($this->spaltenbeginnary[$pWochentag] . '%', $this->kursetage[0]->zeit_beg . '-' . $this->kursetage[0]->zeit_ende . ' ' . $this->kursetage[0]->knr, '', '', 8, $this->spaltenbreiteary[$pWochentag] . '%', 0, $this->height);
              $this->pdf->ln($this->tageshöhe);
              $this->pdf->CellAtX($this->spaltenbeginnary[$pWochentag] . '%', $this->kursetage[0]->kursort->bezeichnung, '', '', 8, $this->spaltenbreiteary[$pWochentag] . '%', 0, $this->height);
              $this->pdf->ln(-$this->tageshöhe + $count * -2 * $this->tageshöhe);
              $count++;
            }

            array_shift($this->kursetage);
          }
        }
      }
      $this->pdf->ln($this->zeilenhoehe);
    }
    $this->pdf->ln(-(count($this->timeary)) * $this->zeilenhoehe);
  }

  

  
  public function getKWblockanf()
  {
    return "<div class = 'kwblock'>";
  }

  
  public function getKWblockend()
  {
    return '</div>';
  }

  
  public function _getZeitpunkteab()
  {
    $zeitpktopt = array();
    $result = "<div class = 'Zeitpunkteab'>" . "<label id='l_Zeitpunkteab' for='Zeitpunkteab'>";
    for ($i = 1;$i <= 10;$i++) {
      $zeitpktopt[$i] = $this->_getSelOptionZeitpkt($this->settings->zeitpunkte->zeitab[$i]);
      $checked = ($this->settings->zeitpunkte->zeitckx[$i]) ? 'checked' : '';
      $indiv = "onclick = 'setZeitDisabledChange(" . $i . ")'";
      $result .= "<div class = 'Zeitab" . $i . "'>"
              
              . $this->htmlop->CreateInputTag('zeitckx' . $i, 'checkbox', 'zeitckx' . $i, '', '', $indiv, $checked, '', '') . 'Zeit ab: '
              . $this->htmlop->CreateSelectTag($zeitpktopt[$i], 'selectzeitab' . $i, '', 'selectzeitab' . $i, '', '', '', false)
              . '</div>';
    }
    $result .= BR_WT . '</label></div>';

    return $result;
  }

  

  
  
  public function isZeitpunkteUsed()
  {
    return true;
  }
}