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


class KursDozentSight4Tab extends KursDozentenSight
{
  
  protected $_tabHelper;
  
  protected $markAllowed;
  
  protected $_adr4DozDetailLink;

  public function __construct($pAdr4DozDetailLink)
  {
    parent::__construct('');
    $this->_tabHelper = new TabHelper($this);
    $this->_adr4DozDetailLink = $pAdr4DozDetailLink;
  }

  
  public function setMarkAllowed($pMarkAllowed)
  {
    $this->markAllowed = $pMarkAllowed;
  }

  public function getTitle()
  {
    return '';
  }

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

  

  
  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 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();
  }

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

    return $checkstr4th;
  }

  
  public function getTableRowSelection($pRowindex)
  {
    $str = '';
    $eMailChecked = '';
    if ((PostOperations::getVarValue('row' . $pRowindex)) == $this->dataary[$pRowindex]->getVarValue('id')) {
      $eMailChecked = "checked='checked'";
    }

    
    
    if ($this->markAllowed) {
      $dozhonid = $this->dataary[$pRowindex]->getVarValue('id');
      $dozid = CleanOperations::cleanInt($this->dataary[$pRowindex]->dozent->getVarValue('id'));

      $str .= '<td class="doNotSort" width="15px"><input id="dozent_' . $dozid . '" class="markable" type="checkbox" ' . $eMailChecked
                . ' name="row' . CleanOperations::cleanStringForHtml($pRowindex) . '" value="' . $dozhonid . '"></td>' . "\n";
      if (isset($this->emailallowed) && $this->emailallowed) {
        $str .= '<script type="text/javascript">$("#dozent_' . $dozid . '").data("email", "'
                   . CleanOperations::cleanStringForJs($this->dataary[$pRowindex]->dozent->getVarValueEx('email', 'kommunikation')) . '");</script>';
      }
    }

    return $str;
  }

  
  public function getTableRowContent($rowindex, $colindex)
  {
    static $dbwtools = null;
    if (is_null($dbwtools)) {
      $dbwtools = new DBWorkTools();
    }
    if (SessionOperations::getCurrentWebToolsUser()->ben >= 0) {
      $toToolId = $this->_adr4DozDetailLink[0]; 
      $toSectionId = $this->_adr4DozDetailLink[1]; 
      
      if ($dbwtools->isToolAllowed(\Kufer\Web\Classes\Identifier\Identifier::fromId($this->userid), $toToolId)) {
        $fieldname = $this->columnsary[$colindex]->fieldname;
        $datamodul = $this->columnsary[$colindex]->datamodul;
        if ($datamodul == 'dozent') {
          switch ($fieldname) {
            case 'namevorname':
            case 'name':
            case 'name_vorname_ohne_komma':
            case 'vorname_name_ohne_komma':
            case 'titel_name_vorname':
            case 'titel_vorname_name':
            $dnr = $this->dataary[$rowindex]->getVarValue('dnr');
            $value = $this->dataary[$rowindex]->getVarValueEx($fieldname, $datamodul);

            $DozDetailsLink = 'usertools.php?tool_id=' . CleanOperations::cleanInt($toToolId) . '&amp;toolsection_id=' . CleanOperations::cleanInt($toSectionId) . '&amp;dnr=' . CleanOperations::cleanInt($dnr) . '&amp;fromOtherTool=1';

            return Menu::getUserLink(CleanOperations::cleanStringContainingHtml($value), $DozDetailsLink, 2, false);
          }
        }
      }
    }

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