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


class TabHelper
{
  protected $_sight;
  protected $_sightId4Kursdetails = 377;

  public function __construct($pSight)
  {
    $this->_sight = $pSight;
  }

  public function getHeader()
  { 
    

    $str = '';
    if ($this->_sight->printmodus) {
      $allgsettings = AllgSettingsAPI::getAllgSettings();
      $str
        .= '   <h1>' . CleanOperations::cleanStringForHtml($allgsettings->vhsname) . '</h1>'
        . '   <span class="print_stand">Stand: ' . date('d.m.Y') . '</span><br>'
        . '  <span class="einrichtung_strasse">' . CleanOperations::cleanStringForHtml($allgsettings->vhsstrasse) . '</span><br>' . "\n"
        . '  <span class="einrichtung_telefon">' . CleanOperations::cleanStringForHtml($allgsettings->vhstelefon) . '</span><br>' . "\n";
    }
    if ($this->_sight->getTitle() != '') {
      $str .= '  <h2>' . $this->_sight->getTitle() . '</h2>';
    }
    $tmp = $this->_sight->checkErrors();
    if (trim($tmp) != '') {
      $str .= '  <br><span class="error">' . $tmp . '</span>';
    }

    return $str;
  }

  
  public function getFooter()
  {
    return '';
  }

  public function getTableHeaderCol($colindex)
  {
    $str = '';
    $class = $this->_sight->columnsary[$colindex]->datamodul . '_' . $this->_sight->columnsary[$colindex]->fieldname;
    $title = $this->_sight->columnsary[$colindex]->title;
    $str .= '  <th class="' . CleanOperations::cleanStringForHtml($class) . '" style="width: ' . CleanOperations::cleanStringForHtml($this->_sight->columnsary[$colindex]->width) . 'px; font-size: '
          . CleanOperations::cleanStringForHtml($this->_sight->columnsary[$colindex]->fontsize) . 'px';
    if ($this->_sight->columnsary[$colindex]->bold == 1) {
      $str .= '; font-weight: bold';
    }
    $str .= ';">';
    $str .= $title;
    $str .= '</th>';

    return $str;
  }

  
  public function getTableHeaderCheckCells()
  {
    $checkstr = '';
    
    if ($this->_sight->getMarkAllowed()) {
      $checkstr .= "<th class='doNotSort' width='15px'></th>\n";
    }

    return $checkstr;
  }

  
  public function getTableRowSelection($pRowindex)
  {
    $str = '';
    
    $id = $this->_sight->dataary[$pRowindex]->getVarValue('id');
    
    
    $encodeCharset = new EncodeCharset4RequestAndResponse();
    $id = $encodeCharset->decode($id);
    $id = urlencode($id);

    
    $knrAry = explode(':', SessionOperations::getVarValueWTIntern('totalkursdatastr_' . \ToolsAPI::TOOL_DOZENTENINFO_MA));

    
    if ($this->_sight->getMarkAllowed()) {
      $disabled = '';
      $class = 'markable';
      if (!in_array($id, $knrAry)) {
        $disabled = HTMLOperations::getEmptyAttribute('disabled');
        $class = 'displayNone';
      }
      $str .= '<td class="doNotSort" width="15px">' . "\n"
                . '<input type="checkbox" class="' . $class . '" name="' . CleanOperations::cleanStringForHtml($id) . '"  value="' . CleanOperations::cleanStringForHtml($id) . '" ' . $disabled . '>'
              . '</td>' . "\n";
    }

    return $str;
  }

  
  public function getTableCell($pValue, $pColumn, $pTextcolor = true)
  {
    $class = $pColumn->datamodul . '_' . $pColumn->fieldname;
    if ($pColumn->fieldname == 'emailgrafik' || $pColumn->fieldname == 'smsgrafik') {
      $textalign = 'center';
    } else {
      $textalign = $this->_sight->isLikeNumber($pValue) ? 'right' : 'left';
    }

    $result = '<td class="' . CleanOperations::cleanStringForHtml($class) . '" style="width:' . CleanOperations::cleanStringForHtml($pColumn->width) . 'px; text-align:' . $textalign;
    
    
    $result .= ';"><span style="font-size:' . CleanOperations::cleanStringForHtml($pColumn->fontsize) . 'px';

    if ($this->_sight->textcolor !== true) {
      $result .= '; color:' . CleanOperations::cleanStringForHtml($pTextcolor);
    }
    if ($pColumn->bold == 1) {
      $result .= '; font-weight: bold';
    }
    $result .= ';">';

    
    
    if ($class == 'kurstag_ausfall' && strip_tags($pValue) != 'A') {
      $result .= '&nbsp;';
    }
    
    
    elseif (in_array($class, CleanOperations::getFieldsWithoutCleaning())) {
      $result .= $pValue;
    } else {
      $result .= CleanOperations::cleanStringContainingHtml($pValue);
    }
    $result .= '</span></td>';

    return $result;
  }

  
  public function getTable()
  {
    if ($this->_sight->checkErrors() == '') {
      return $this->_sight->getParentTable();
    } else {
      return '';
    }
  }

  public function getTrOpen($pColor)
  {
    return '<tr>';
  }

  public function getTBodyOpen()
  {
    return '<tbody>';
  }

  public function getTBodyClose()
  {
    return '</tbody>';
  }

  public function getTHeadOpen()
  {
    return '<thead>';
  }

  public function getTHeadClose()
  {
    return '</thead>';
  }
}