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

class TabSight extends NormalSight
{
  protected function getTBodyOpen()
  {
    return '<tbody>';
  }

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

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

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

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

  public function getTitle()
  {
    return '';
  }

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

    return $str;
  }

  public function isLikeNumber($pValue, $pColumn = null)
  {
    $result = parent::isLikeNumber($pValue);
    if (!$result) {
      if ($pColumn != null) {
        if ($pColumn->datamodul == 'zahlung' && in_array($pColumn->fieldname, array('betrag_p', 'betrag_m', 'zahlnummer'))) {
          $result = true;
        }
      }
    }

    return $result;
  }

  
  public function getTableCell($pValue, $pColumn, $pTextcolor = true)
  {
    $class = $pColumn->datamodul . '_' . $pColumn->fieldname;
    $result = '<td class="' . CleanOperations::cleanStringForHtml($class) . '" style="width:' . CleanOperations::cleanStringForHtml($pColumn->width) . 'px; text-align:' . ($this->isLikeNumber($pValue, $pColumn) ? 'right' : 'left') . '">';
    $result .= '<span style="font-size:' . CleanOperations::cleanStringForHtml($pColumn->fontsize) . 'px; text-align:' . ($this->isLikeNumber($pValue) ? 'right' : 'left');

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

    return $result;
  }

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

  public function getHeader()
  { 
    
    $str = '';
    if ($this->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->getTitle() != '') {
      $str .= '  <h2>' . $this->getTitle() . '</h2>';
    }
    $tmp = $this->checkErrors();
    if (trim($tmp) != '') {
      $str .= '  <br><span class="error">' . $tmp . '</span>';
    }

    return $str;
  }
}