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


class TabKursDetailsDownloads4Dozenten extends TabKursDetailsDownloads
{
  
  protected $_freigabeDokuByMA;
  
  protected $_uploadResult;
  
  protected $_uploadMessage;

  
  public function __construct($pTabName, $pData, $pToolId, $pSightId, $pFreigabeDokuByMA, $pUploadResult, $pUploadMessage)
  {
    parent::__construct($pTabName, $pData, $pToolId, $pSightId);
    $this->_freigabeDokuByMA = $pFreigabeDokuByMA;
    $this->_uploadResult = $pUploadResult;
    $this->_uploadMessage = $pUploadMessage;
  }

  public function getSpecialJS()
  {
    $result = parent::getSpecialJS();
    
    $result[] = 'js/kursdokumente.js';

    return $result;
  }

  public function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    
    $result .= JsOperations::getDeclarationJson('KuferTools.KursDetails.Dokumente.List', array());
    
    
    $result .= JsOperations::getDeclarationBoolean('KuferTools.KursDetails.SearchKurs', GetOperations::getVarValue('searchkurs', false));

    $tool0Settings = ToolSettingsAPI::getToolSettings(0);
    if ($tool0Settings->dokuUploadAllowByExclude) {
      
      $fileExtStr = $tool0Settings->uploadBlacklist4Ext;
      $allowByExclude = true;
    } else {
      
      $fileExtStr = $tool0Settings->uploadWhitelist4Ext;
      $allowByExclude = false;
    }

    $result .= JsOperations::getDeclarationBoolean('KuferTools.KursDetails.Dokumente.AllowUploadByExclude', $allowByExclude);
    $result .= JsOperations::getDeclarationString('KuferTools.KursDetails.Dokumente.FileExtStr', $fileExtStr);
    $statusMessageStr4FileExt = DokuUploadUserAPI::getStatusMessagePart4FileExt($tool0Settings);
    $result .= JsOperations::getDeclarationString('KuferTools.KursDetails.Dokumente.FileExtMessagePart', $statusMessageStr4FileExt);

    if (isset($this->links['upload']) && $this->links['upload'] != '') {
      $xsrf = new Xsrf();
      $xsrfKey = $xsrf->generateKey4Action('wt_upload');
      $result .= JsOperations::getDeclarationString('KuferTools.KursDetails.Dokumente.UploadXsrf', $xsrfKey);
    }

    return $result . "\n";
  }

  
  protected function getReleaseButton($pDokument)
  {
    $result = '';

    $doznr = SessionOperations::getCurrentWebToolsUser()->dnr;

    if (isset($this->links['releaseDoku']) && $this->links['releaseDoku'] != '') {

      
      
      
      if ($pDokument->uploaddoz > 0 && $doznr == $pDokument->uploaddoz) {
        $result .= '<a href="' . CleanOperations::cleanStringForHtml($this->links['releaseDoku']) . '" class="kdetails_releaseDoku dozent" id="releaseDoku_'
                      . $pDokument->id . '" title="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' weiteren Kursen zuordnen">' . "\n"
                      . '<img src="images/entbuchen.gif" alt="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' weiteren Kursen zuordnen" />' . "\n";

        $result .= '<script type="text/javascript">'
                       . '$(document).ready(function() {'
                         . '$("#releaseDoku_' . CleanOperations::cleanInt($pDokument->id) . '").data("dokument", {id: ' . CleanOperations::cleanInt($pDokument->id) . ', bezeichnung: "' . CleanOperations::cleanStringForJs($pDokument->bezeichnung) . '"});'
                       . '});'
                     . '</script>' . "\n"
                   . '</a>' . "\n";
      }
    }

    return $result;
  }

  
  protected function getUploadButton()
  {
    $result = '';
    $result .= '<div id="kdetails_downloadsControlDiv" class="tab_controlDiv">' . "\n";
    
    if (isset($this->links['upload']) && $this->links['upload'] != '') {
      $result .= '<a href="' . CleanOperations::cleanStringForHtml($this->links['upload']) . '" id="kdetails_downloadLinkUpload" title="Dokumente hochladen">' . "\n"
                    . '<img src="layout/button_upload.gif" id="kdetails_downloadImgUpload" alt="Dokumente hochladen"></a>' . "\n";
    }
    $result .= '</div>' . "\n";

    return $result;
  }

  
  protected function getHinweis()
  {
    $message = '';
    if (!empty($this->_freigabeMessage)) {
      
      $message = '<div class="uploadmess">' . $this->_freigabeMessage . '</div>' . "\n";
    }

    return $message;
  }

  
  protected function getDokumenteList()
  {
    $result = '';
    $result .= '<!-- Sub-Template für eine Zeile der Dokumente -->';

    $result .= '<script class="templateDokumenteRow" type="text/html">'
    
        . '<tr><td><#= reihenfolge #></td><td><#= original #></td><td><#= stand #></td>' . "\n"
        . '<td class="downloadTN"><# switch(downloadTN) { case \'1\': #>Alle TN<#;break; 
                                                        case \'2\': #>TN mit Login<#;break;
                                                        case \'3\': #>TN im Kurs<#;break; } #> ' . "\n" 
        . '</td>' . "\n"

        . '</tr>' . "\n";
    $result .= '</script>' . "\n";
    

    $result .= "\n\n" . '<!-- Template für den Dokumente - Detail Bildschirm-->'
      . '<script class="templateDetailsDokumente" type="text/html">'
      . '<div id="detailsDokumente" class="editDokumente">'

      
      . '<label for="detail_bezeichnung_dokumente">Bezeichnung:</label>' . "\n"
      . '<input type="text" name="detail_bezeichnung_dokumente" id="detail_bezeichnung_dokumente" value="<#=bezeichnung#>" />' . BR_WT

      
      . '<label for="detail_original_dokumente">Datei:</label>' . "\n"

      . '<# if(fileInfo == "") {#>'

      . '<input type="file" name="detail_original_dokumente" id="detail_original_dokumente" value="<#=original#>" />'
      . '<# } else { #><div class="detail_origdoku"><em><#=original#>:</em> 
                     <span>eine Änderung ist nicht möglich</span></div>' . "\n"
      
      
      . '<input style="display:none;" type="file" name="detail_original_dokumente" id="detail_original_dokumente" 
        value="<#=original#>" /> <# }#>'
      . BR_WT

      
      . '<label for="detail_stand_dokumente">Stand:</label>' . "\n"
      . '<input type="text" name="detail_stand_dokumente" id="detail_stand_dokumente" value="<#=stand#>" class="hasDatePicker val_date" readonly="readonly" />' . BR_WT
      
      . '<label for="detail_bemerkung_dokumente">Bemerkung:</label>' . "\n"
      . '<textarea rows="3" cols="44" name="detail_bemerkung_dokumente" id="detail_bemerkung_dokumente"><#=bemerkung#></textarea>' . BR_WT
      
      . '<label for="detail_kosten_dokumente">Kosten:</label>' . "\n"
      . '<input type="text" name="detail_kosten_dokumente" id="detail_kosten_dokumente" class="val_float" value="<#=kosten#>" />&nbsp;EUR' . BR_WT
      
      . '<label for="detail_kostenbemerkung_dokumente">Kostenbemerkung:</label>' . "\n"
      . '<textarea rows="3" cols="44" name="detail_kostenbemerkung_dokumente" id="detail_kostenbemerkung_dokumente"><#=kostenbemerkung#></textarea>' . BR_WT;


    $result .= $this->getFreigabeNoetigInput();
    $result .= $this->getFreigabeInput();
    $result .= $this->getDownloadFuer();
    $result .= '</div></script>';

    return $result;
  }

  

  private function getDownloadFuer()
  {
    if (isset($this->links['downloadFuer']) && is_array($this->links['downloadFuer'])) {
      $downloadFuer = $this->links['downloadFuer'];
    } else {
      $downloadFuer = array();
    }

    $zeigeDefault = false;
    $nurEiner = false;
    if (!is_array($downloadFuer) || count($downloadFuer) === 0) {
      $zeigeDefault = true;
    } elseif (count($downloadFuer) === 1) {
      $nurEiner = true;
    }

    $auswahl = '';
    if ($zeigeDefault || in_array(ToolKurseDozentSettings::DOWNLOAD_ALLE_TN, $downloadFuer)) {
      if ($nurEiner) {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail displayNone" value="1" checked="checked">';
      } else {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail" value="1" <# if (downloadTN == "1") {#>checked<#}#>>';
      }
      $auswahl .= $input . '<span class="downloadTN">Alle Teilnehmer</span>' . "\n";
    }
    if ($zeigeDefault || in_array(ToolKurseDozentSettings::DOWNLOAD_TN_MIT_LOGIN, $downloadFuer)) {
      if ($nurEiner) {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail displayNone" value="2" checked="checked">';
      } else {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail" value="2" <# if (downloadTN == "2") {#>checked<#}#>>';
      }
      $auswahl .= $input
        . '<span class="downloadTN">Teilnehmer mit Login</span>' . "\n";
    }
    if ($zeigeDefault || in_array(ToolKurseDozentSettings::DOWNLOAD_TN_IM_KURS, $downloadFuer)) {
      if ($nurEiner) {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail displayNone" value="3" checked="checked">';
      } else {
        $input = '<input type="radio" name="detail_downloadTN_dokumente" class="dokudownload_detail" value="3" <# if (downloadTN == "3") {#>checked<#}#>>';
      }
      $auswahl .= $input
        . '<span class="downloadTN">Teilnehmer im Kurs</span>' . "\n";
    }

    return '<p class="downloadtext"> Download der Dokumente ist möglich für:</p>' . "\n"
      . '<div>'
        . $auswahl
      . '</div>' . "\n";
  }

  
  protected function getFreigabeInput()
  {
    return;
  }

  
  protected function getFreigabeNoetigInput()
  {
    $result = '';
    $inputtype = 'hidden';
    $zusatzAttribut = 'value="W"';
    $labeltext4DokuFreigabe = 'Das Dokument wird erst nach Freigabe durch einen Mitarbeiter angezeigt';
    $labelshift = '';
    if (!$this->_freigabeDokuByMA) {
      $zusatzAttribut = ' <# if (freigabenoetig == "W") {#>checked<#} #>';
      $inputtype = 'checkbox';
      $labeltext4DokuFreigabe = 'Freigabe durch einen Mitarbeiter ist nötig';
      $labelshift = 'shiftleft';
    }
    $result .= '<p class="freigabeMA">' . "\n"
      . '<input type="' . $inputtype . '" name="detail_freigabenoetig_dokumente" id="detail_freigabenoetig_dokumente" ' . $zusatzAttribut . '>' . "\n"
      . '<label class="label4select ' . $labelshift . '" for="detail_freigabenoetig_dokumente">' . $labeltext4DokuFreigabe . '</label>' . '</p>' . "\n";

    return $result;
  }
}