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


class Stundeplangrafik extends DruckGrafikKW
{
  public function getListID()
  {
    return 17;
  }

  

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

  

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

  

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

  

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

    return false;
  }

  

  
  public function _getTimeary()
  {
    $dbwstdplan = new DBWorkHLDozStdplanUhr();
    
    $stdplanuhr = $dbwstdplan->getAll();

    $stdcount = count($stdplanuhr);
    for ($i = 0;$i < $stdcount;$i++) {
      $this->timeary[$i]['von'] = $stdplanuhr[$i]->uhrvon;
      $this->timeary[$i]['bis'] = $stdplanuhr[$i]->uhrbis;
    }

    
    $this->timeary[$stdcount]['von'] = '24:01';
    $this->timeary[$stdcount]['bis'] = '24:01';
  }

  

  
  protected function _printDruckListe($pKurs = '')
  {

        

    
    
    

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


    $this->pdf->ln(-0.5 * $this->height);
    $this->pdf->CellAtX('10.5%', 'Mo., ' . $this->kwary['Mo'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('22.9%', 'Di., ' . $this->kwary['Di'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('35.3%', 'Mi., ' . $this->kwary['Mi'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('47.7%', 'Do., ' . $this->kwary['Do'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('60.1%', 'Fr., ' . $this->kwary['Fr'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('72.5%', 'Sa., ' . $this->kwary['Sa'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->CellAtX('84.9%', 'So., ' . $this->kwary['So'], 'B', 'C', '', '12.4%', 1, $this->height, 0);
    $this->pdf->ln($this->height);
    $this->pdf->SetFillColor(200, 200, 200);	

    $dbwDoz = new DBWorkDozenten();
    $dozent = $dbwDoz->getDozent($this->dozId);

    $this->pdf->CellAtX('3%', $dozent->name . ', ' . $dozent->vorname, 'B', '', '', '94.3%', 1, $this->height, 1);
    $this->pdf->ln($this->height);

    for ($itag = 0;$itag < 8;$itag++) {
      $this->_printKursCell($itag);
    }
  }

  

  
  public function _printKursCell($pTag)
  {
    
    $wotagary = array_keys($this->kwary);
    

    
    $izeit = 0;
    
    foreach ($this->timeary as $zeit) {
      
      if (strcmp($zeit['von'], '24:01') != 0 && strcmp($zeit['bis'], '24:01') != 0) {
        
        if ($pTag == 0) {
          $this->setFillColor4Border();	
          $this->pdf->CellAtX('3%', '', 'B', '', '', '7.5%', 1, 2 * $this->height, 1);
          $this->pdf->ln(3);
          $this->pdf->CellAtX('3%', $zeit['von'] . '-' . $zeit['bis'], 'B', '', '', '7.5%', 0, 2 * $this->height, 0);
          $this->pdf->ln(-3);
        }
        
        else {
          $this->setFillColor4Cell(); 
          

          
          $zeit_ende = isset($this->kursetage[0]->zeit_ende) ? $this->kursetage[0]->zeit_ende : '';
          $zeit_beginn = isset($this->kursetage[0]->zeit_beg) ? $this->kursetage[0]->zeit_beg : '';
          if (strcmp($zeit['von'], $zeit_ende) <= 0 && strcmp($zeit['bis'], $zeit_beginn) > 0
                            && strcmp($this->kursetage[0]->datum, $this->kwary[$wotagary[$pTag - 1]]) == 0) {

                        
            $this->pdf->CellAtX(12.4 * ($pTag - 1) + 10.5 . '%', '', 'B', '', '', '12.4%', 1, 2 * $this->height, 1);
            $this->pdf->CellAtX(12.4 * ($pTag - 1) + 10.5 . '%', $this->kursetage[0]->knr, 'B', '', 8, '12.4%', 0, $this->height, 0);
            $this->pdf->CellAtX(12.4 * ($pTag - 1) + 10.5 . '%', $this->kursetage[0]->zeit_beg . '-' . $this->kursetage[0]->zeit_ende, '', 'R', 8, '12.4%', 0, $this->height, 0);
            $this->pdf->ln($this->height);
            $this->pdf->CellAtX(12.4 * ($pTag - 1) + 10.5 . '%', $this->kursetage[0]->kurs->kurzbez, '', '', 8, '12.4%', 0, $this->height, 0);
            $this->pdf->ln(-$this->height);
            if (strcmp($this->timeary[$izeit]['bis'], $this->kursetage[0]->zeit_ende) >= 0) {
              array_shift($this->kursetage);
            }
            $zeit_ende = isset($this->kursetage[0]->zeit_ende) ? $this->kursetage[0]->zeit_ende : '';
            $zeit_beginn = isset($this->kursetage[0]->zeit_beg) ? $this->kursetage[0]->zeit_beg : '';
          }
          else {
            $this->pdf->CellAtX(12.4 * ($pTag - 1) + 10.5 . '%', '', 'B', '', '', '12.4%', 1, 2 * $this->height, 0);
          }

          
                    $this->setFillColor4Border();	
        }
                $izeit++;
        $this->pdf->ln(2 * $this->height);
      } 
    }  
    $this->pdf->ln(-2 * $this->height * ($izeit));
  }

  
}