<?php

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


class DataMenuKursUebersicht extends DataMenuKurse 
{
  
  public $dbwKurse;

  
  public $vhs;
  
  public $settings;

  public function __construct($urlParam)
  {
    parent::__construct($urlParam);

    $this->settings = ToolSettingsAPI::getToolSettings(4);


    $this->dbwKurse = new DBWorkKurseINetAktivFilterUebersicht();

    $sortkursegesamtuebersichtkriterium = $this->settings->sortkursegesamtuebersichtkriterium;
    $this->dbwKurse->setOrderByValues($this->urlparameter, $this->sortierungWieFuerKurssuche($sortkursegesamtuebersichtkriterium), $this->settings->sortkursegesamtuebersichtrichtung);

    $this->exportadapter = new ExpKursuebersicht();


    $this->vhs = BASysSettingsAPI::getBASysSettings();
  }

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

  public function getdataarraybody($pKnrTeil = '')
  {
    
    $this->dbwKurse->fromobject->semester = $this->toolsettings->semlist;
    $this->dataarraybody = $this->dbwKurse->getKurseByKnrSpecial($pKnrTeil);
    if ($this->settings->kurseGesamtuebersichtAlleDatenLaden) {
      $knrs = ArrayOperations::mapAttribut($this->dataarraybody, 'id');
      $this->dataarraybody = WBKursStore::getKurseByIdArray($knrs);
    }
    $this->nrOfMainBodyElements = count($this->dataarraybody);
  }

  public function prepareMainmenu($pZeitBereich = 'noRestrict')
  {
    
    
    $this->getsight();
    $this->getdataarrayheader();

    if ($this->isBocholtVhs()) {
      
      $this->dataarraybody = array(new Kurs()); 
    } else {
      $this->getdataarraybody();
    }
    $this->getdataarrayfooter();
    $this->getdataarraynodata();
    $this->getdataarraynocolumn();
  }

  public function mainmenu()
  {
    $this->prepareMainmenu();
    if ($this->toolsettings->showClickpfad) {
      
      echo $this->getClickPath();
    }
    echo "<div class='hauptseite'>\n";
    $this->statusmenu();
    echo $this->getContentAnker();
    
    if ($this->isBocholtVhs()) {
      
      for ($i = 1; $i <= 3; $i++) {
        $this->getdataarraybody($i);
        
        if (count($this->dataarraybody) > 0) {
          $this->dataarrayheader = array_slice($this->dataarraybody, 0, 1);
          $this->showheader();
          $this->showbody();
          $this->showfooter();
        }
        
        else {
          $this->shownodata();
        }
      }
    } else {
      
      if (count($this->dataarraybody) > 0) {
        $this->showheader();
        $this->showbody();
        $this->showfooter();
      }
      
      else {
        $this->shownodata();
      }
    }
    echo '</div>';
  }

  private function isBocholtVhs()
  {
    return (StringOperations::substr($this->vhs->vhsbezeichnung, 0, 7) == 'Bocholt') && (StringOperations::strtoupper(StringOperations::substr($this->vhs->vhskurzbezeichnung, 0, 3)) == 'VHS');
  }
}