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

class KurseRaum4SightTab extends KurseRaumSight
{
  
  protected $_tabHelper;
  protected $linkKursdetails;

  
  private $_kursIdAry4User;
  
  
  private $_setLink2OtherTool;
  
  private $_tab4Dozent;

  public function __construct($pKursIdAry4User, $pNoInternetCare = false, $pLinkKursdetails = '', $pSetLink2OtherTool = false, $pTabsAry = array())
  {
    parent::__construct();
    $this->_tabHelper = new TabHelper($this);
    $this->linkKursdetails = $pLinkKursdetails;
    $this->_kursIdAry4User = $pKursIdAry4User;
    $this->_setLink2OtherTool = $pSetLink2OtherTool;
    
    $tabsAry = $pTabsAry;
    
    $this->_tab4Dozent = '';
    if (array_key_exists('Dozenten', $tabsAry)) {
      $this->_tab4Dozent = '#' . $tabsAry['Dozenten'];
    }
  }

  public function getTitle()
  {
    return '';
  }

  public function getColumns($justallowedcolumns = true)
  {
    parent::getColumns($justallowedcolumns);
  }

  public function getLink2Kursdetails()
  {
    return $this->linkKursdetails;
  }

  public function getHeader()
  {
    return $this->_tabHelper->getHeader();
  }

  public function getFooter()
  {
    return $this->_tabHelper->getFooter();
  }

  public function getCount()
  {
    return count($this->dataary);
  }

  public function getTableHeaderCol($colindex)
  {
    return $this->_tabHelper->getTableHeaderCol($colindex);
  }

  
  public function getTableHeaderCheckCells()
  {
    if ($this->linkKursdetails != '') {
      return "<th class='doNotSort' width='15px'></th>\n";
    }

    return '';
  }

  
  public function getTableRow($rowindex = -1)
  {
    $str = '';
    if (isset($this->colorevent)) {
      $this->textcolor = $this->colorevent->getTextColor($this->dataary[$rowindex]);
    }
    

    $str .= $this->getTableRowSelection($rowindex);
    for ($i = 0;$i < count($this->columnsary);$i++) {
      $value = $this->getTableRowContent($rowindex, $i);
      $str .= $this->getTableCell($value, $this->columnsary[$i], $this->textcolor);
    }

    return $str;
  }

  
  public function getTableRowSelection($pRowindex, $pColor = '')
  {
    $str = '';
    $sprachsettings = new SprachSettingsObject();
    if ($this->linkKursdetails != '') {
      $kursId = $this->dataary[$pRowindex]->getVarValue('id');
      $str .= '<td class="doNotSort" width="15px">';
      

      if (!$this->_setLink2OtherTool || in_array($kursId, $this->_kursIdAry4User)) {
        $str .= '<a href="' . CleanOperations::cleanStringForHtml($this->linkKursdetails) . '&nr=' . CleanOperations::cleanStringForHtml($kursId) . '" value="' . CleanOperations::cleanStringForHtml($kursId) . '" title="' . CleanOperations::cleanStringForHtml($sprachsettings->KursZusammengesetzt['Singular']['Nominativ']) . 'details">' . "\n";
        $str .= '<img src="images/details.gif"></a></td>' . "\n";
      } else {
        $str .= '&nbsp;</td>' . "\n";
      }
    }

    return $str;
  }

  
  public function getTableRowContent($rowindex, $colindex)
  {
    
    
    
    

    if ($this->linkKursdetails != '') {
      $fieldname = $this->columnsary[$colindex]->fieldname;
      $datamodul = $this->columnsary[$colindex]->datamodul;
      if ($fieldname == 'id' && $datamodul == 'kurs') {
        $knr = $this->dataary[$rowindex]->getVarValue('id');
        $value = $this->dataary[$rowindex]->getVarValueEx($fieldname, $datamodul);
        $retour = '<a href="' . CleanOperations::cleanStringForHtml($this->linkKursdetails) . '&nr=' . CleanOperations::cleanStringForHtml($knr) . '">' . CleanOperations::cleanStringContainingHtml($value) . '</a>';
        
        if (!$this->_setLink2OtherTool || in_array($knr, $this->_kursIdAry4User)) {
          return $retour;
        }
      } elseif ($fieldname == 'dozenten_kommasepariert' && $datamodul == 'kurs') {
        $knr = CleanOperations::cleanStringForHtml($this->dataary[$rowindex]->getVarValue('id'));
        $value = $this->dataary[$rowindex]->getVarValueEx($fieldname, $datamodul);
        
        $retour = '<a href="' . CleanOperations::cleanStringForHtml($this->linkKursdetails) . '&nr=' . $knr . CleanOperations::cleanStringForHtml($this->_tab4Dozent) . '">' . CleanOperations::cleanStringContainingHtml($value) . '</a>';

        
        if (!$this->_setLink2OtherTool || in_array($knr, $this->_kursIdAry4User)) {
          return $retour;
        }
      } 
    } 

    return parent::getTableRowContent($rowindex, $colindex);
  }

  
  public function getTableCell($pValue, $pColumn, $pTextcolor = true)
  {
    return $this->_tabHelper->getTableCell($pValue, $pColumn, $pTextcolor);
  }

  protected function getTrOpen($pColor)
  {
    return $this->_tabHelper->getTrOpen($pColor);
  }

  protected function getTBodyOpen()
  {
    return $this->_tabHelper->getTBodyOpen();
  }

  protected function getTBodyClose()
  {
    return $this->_tabHelper->getTBodyClose();
  }

  protected function getTHeadOpen()
  {
    return $this->_tabHelper->getTHeadOpen();
  }

  protected function getTHeadClose()
  {
    return $this->_tabHelper->getTHeadClose();
  }

  
  public function getTable()
  {
    return $this->_tabHelper->getTable();
  }

  public function getParentTable()
  {
    return parent::getTable();
  }
}