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

 


class PageFaMeineKurseUebersicht extends PageTnMeineKurseUebersicht
{
  private $_dbwBelegung;
  private $_dbwKurse;

  public function __construct($pPageTitle, $pPageId, $pTool, $pData, $pContentHeader, $pDbwBelegung, $countAllObjects, $objectsPerPage)
  {
    parent::__construct($pPageTitle, $pPageId, $pTool, $pData, $pContentHeader, $countAllObjects, $objectsPerPage);

    $this->_dbwBelegung = $pDbwBelegung;

    
    

    $this->_dbwKurse = new DBWorkKurseWT(1, true);

    
    
    
    $this->_dbwKurse->fromobject = $this->_dbwBelegung->fromobject->kurs;
    $this->_dbwKurse->toobject = $this->_dbwBelegung->toobject->kurs;
  }

  
  public function getContent()
  {
    $result = '';
    if (isset($this->links['filter'])) {
      
      $searchAPI = new KurssuchAPIwSearchWithoutKurszeitraum();
      
      $tool_action = $searchAPI->getKursSearchLink() . '&markerAction=loescheMarkierungen';
      $result .= $searchAPI->getSearchDiv($tool_action);
      $result .= $this->_getFilterMaKurseDiv();
    }
    
    
    
    $result .= '<form method="post" name="TNKurseForm" action="#">' . "\n";
    $result .= '<div id="main_content">' . "\n";

    if (!(count($this->_data) == 0 && $this->allgSettings->buttonleite_position == BUTTONBAR_BOTH)
       && ($this->allgSettings->buttonleite_position == BUTTONBAR_TOP || $this->allgSettings->buttonleite_position == BUTTONBAR_BOTH)) {
      $result .= $this->_getMainButtons();
    }


    $counter = 0;
    $dbwteilnehm = new DBWorkTeilnehmer(1, true);

    $showMitarbeiter = (isset($this->links['showmitarbeiter']) && $this->links['showmitarbeiter']);

    if (count($this->_data) > 0) {
      
      foreach ($this->_data as $belegung) {
        $belegung4html = new CleanDatamodulForHtml($belegung);
        $builder = new SightBuilderUebersicht($this->tool->getToolId(), $this->id, $belegung, true);
        $evenClass = ($counter % 2 == 0) ? ' farbe_sicht_erstezeile' : '';

        if ($belegung->getVarValue('anzahl_ma_firma') > 0 || $belegung->getVarValue('anzahl_ma_firma_platzreserv') > 0) {
          $plaetzeClass = ' mitma';
        }
        else {
          $plaetzeClass = ' ohnema';
        }
        $result .= '<div class="content_zeile' . $evenClass . $plaetzeClass . '">' . "\n";
        $result .= '<div class="steuerelemente">' . "\n";
        if ((isset($this->links['terminplan']) && $this->links['terminplan'])
           || (isset($this->links['termineics']) && $this->links['termineics'])) {
          $result .= '<input type="checkbox" id="b' . $belegung4html->id . '_' . $belegung4html->knr . '" name="' . $belegung4html->id . '" value="' . $belegung4html->id . '" class="belegungcheckbox markable">' . BR_WT;
        }
        if ((isset($this->links['details']) && $this->links['details'] != '')) {
          $sprachSettings = SettingsFactory::getSettings('SprachSettingsObject');
          $class = (DBWorkBASysSettings::isBlak()) ? 'class="kursdetails_lupe_blak"' : '';
          $result .= '<a href="' . $this->links['details'] . '&belid=' . $belegung4html->id . CleanOperations::cleanStringForHtml($this->_searchkurs) . '" class="details_link"><img src="images/details.gif" ' . $class . ' alt="Zu den Details" title="Zu den ' . CleanOperations::cleanStringForHtml($sprachSettings->Kurs['Singular']['Nominativ']) . 'details"></a>' . BR_WT . "\n";
        }
        if ($showMitarbeiter) {
          $result .= '<img src="images/anmclose.gif" class="firmenmitarbeiter_img">';
        }
        $result .= '</div>' . "\n";
        $result .= $builder->buildSight();

        
        
        if ($showMitarbeiter) {
          $result .= $this->_getFirmenMitarbeiterDiv($belegung, $dbwteilnehm);
        }
        $result .= '</div>' . "\n"; 
        $counter++;
      }
    } else { 
      if ($this->_searchkurs == '') {
        $result .= $this->getNoDataMessageDefault(3);
        if ($this->toolSettings->tnstatus !== '' || $this->toolSettings->tnstatus !== '-APSTZ') {
          Logger::logg('Firmentools / Kursübersicht: keine Kurse zur Anzeige vorhanden, '
                  . 'Einschränkung auf Status entspricht nicht dem Standard!', 15);
        }
      } else {
        $result .= $this->getNoDataMessageDefault(2);
      }
    }
    $result .= '</div>' . "\n"; 
    if ($this->allgSettings->buttonleite_position != BUTTONBAR_TOP) {
      $result .= $this->_getMainButtons();
    }
    $result .= '</form>' . "\n";

    return $result;
  }

  
  private function _getFirmenMitarbeiterDiv($pBelegung, $pDbwteilnehm)
  {
    $tnStatus = $this->toolSettings->tnstatus;
    if ($this->toolSettings->tnstatus == '') {
      $tnStatus = '-ATP';
    }
    $tnStatus = str_replace('-', ' ', $tnStatus);
    $tnStatus = StringOperations::convertArray2InList(\StringOperations::str_split($tnStatus));
    if (StringOperations::strpos($tnStatus, 'A') !== false) {
      $tnStatus .= ", ' ', ''";
    }

    
    $tnrObjAry = $pDbwteilnehm->getTeilnehmerByFirmaKurs($pBelegung->tnr, $pBelegung->knr, false, $tnStatus);

    if (count($tnrObjAry) == 0) {
      return '';
    }
    $result = '';

    
    $result .= '<div class="firmenmitarbeiter_div">';
    $result .= '<span class="text_main_menu bold">angemeldete Mitarbeiter:</span>' . BR_WT;

    $showWeitereKurse = (isset($this->links['showmitarbeiterkurse']) && $this->links['showmitarbeiterkurse']);
    foreach ($tnrObjAry as $tnrObj) {
      $result .= '<div class="maname">';

      if ($showWeitereKurse) {
        $result .= $this->_getTnListeZuKursDetail($tnrObj, $pBelegung);
      } else {
        $result .= $this->_getTnListeZuKursKompakt($tnrObj, $pBelegung);
      }
      $result .= '</div>'; 
    }
    $result .= '</div>'; 

    return $result;
  }

  private function _getTnListeZuKursKompakt($tnrObj, $pBelegung, $classMA = 'keine_kurse')
  {
    return '<span class="ma_list ' . CleanOperations::cleanStringForHtml($classMA) . '">' . CleanOperations::cleanStringForHtml($tnrObj->namevorname) . $this->getWeitereTnKursInfo($pBelegung->knr, $tnrObj->id) . '</span>';
  }

  private function _getTnListeZuKursDetail($tnrObj, $pBelegung)
  {
    $classMA = 'keine_kurse';
    $result = '';
    $kursAry = $this->_dbwKurse->getKurseByTeilnehmerFirma($tnrObj->id, $pBelegung->tnr);
    if (count($kursAry) > 1 || (count($kursAry) == 1 && $kursAry[0]->id != $pBelegung->knr)) {
      $result .= '<img src="images/anmclose.gif" class="tnkursefirma">';
      $classMA = '';
    }
    $result .= $this->_getTnListeZuKursKompakt($tnrObj, $pBelegung, $classMA);
    $result .= '<div class="kurse_div">';
    $showBisDato = true;
    foreach ($kursAry as $kurs) {
      if ($pBelegung->knr != $kurs->id) {
        
        
        if ($showBisDato) {
          $bisDato = '<span class="bold weiterema">bis dato auch noch belegt: </span>';
          $showBisDato = false;
          $classKU = 'erster_kurs';
        } else {
          $classKU = 'nobisdato';
          $bisDato = '';
        }
        
        $result .= $bisDato . '<span class="tool_21_mitarbeiterkurs ' . $classKU . '">' . CleanOperations::cleanStringForHtml($kurs->id) . ' ' . CleanOperations::cleanStringForHtml($kurs->kurzbez) . '</span>' . BR_WT;
      }
    }
    $result .= '</div>'; 

    return $result;
  }

  
  private function _getFilterMaKurseDiv()
  {
    $result = '<div id="filter_makurse">';
    
    
    
    
    
    $result .= '<input type="text" style="width: 0; height: 0; border: 0; position: absolute;">';
    $result .= '<h5>Zeitraum der angezeigten Seminare Ihrer Mitarbeiter:</h5>';
    $result .= '<div id="weitere_seminare_von_bis" class="text_main_menu">von <input id="makurse_beginn" class="hasDatePicker" size="10"
                maxlength="10" name="search_kursbeginnzeitraum_von" 
                value="' . SessionOperations::getVarValueWTIntern('ssearch_kursbeginnzeitraum_von_tool' . $this->tool->getToolId()) . '"> bis 
                <input id="makurse_ende" class="hasDatePicker" size="10"
                maxlength="10" name="search_kursbeginnzeitraum_bis" 
                value="' . SessionOperations::getVarValueWTIntern('ssearch_kursbeginnzeitraum_bis_tool' . $this->tool->getToolId()) . '"></div>';

    $result .= '<h5>Weitere Details zum Kursfilter:</h5>';
    $result .= '</div>'; 

    return $result;
  }

  
  protected function getWeitereTnKursInfo($pKnr, $pTnr)
  {
    return '';
  }

  
  public function getSpecialJS()
  {
    $fileAry = parent::getSpecialJS();
    
    $fileAry[] = 'js/FATool/kursuebersicht.js';

    return $fileAry;
  }

  public function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $result .= " registerNamespace('KuferTools');\n";

    
    
    $result .= JsOperations::getDeclarationBoolean('KuferTools.isBLAK', DBWorkBASysSettings::isBlak());

    
    $result .= $this->getSelektorKursFelderToDetails();

    return $result;
  }

  
  public function getSpecialCSS()
  {
    $cssAry = parent::getSpecialCss();
    $cssAry[] = './css/fatoolKursuebersicht.css';

    return $cssAry;
  }
}