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


class TabKursDetailsDownloads4Mitarbeiter extends TabKursDetailsDownloads4Dozenten
{
  
  protected function _getDokumente2Show($pDistinctDokArys)
  {
    $doks2Show = array_merge($pDistinctDokArys['doksReleased'], $pDistinctDokArys['doksToRelease']);
    
    
    usort($doks2Show, array(__CLASS__, '_sortDokusByName'));

    return $doks2Show;
  }

  protected function _sortDokusByName($pDok1, $pDok2)
  {
    
    return strcmp($pDok1->bezeichnung, $pDok2->bezeichnung);
  }

  
  protected function getReleaseButton($pDokument)
  {
    $result = '';
    
    
    if (isset($this->links['releaseDoku']) && $this->links['releaseDoku'] != '') {
      
      

      $xsrf = new Xsrf();
      $xsrfKey = $xsrf->generateKey4Action('wt_dokument_release', $pDokument->id);


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

      $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) . '"});'
                       . '$("#releaseDoku_' . CleanOperations::cleanInt($pDokument->id) . '").data("releaseXsrf", "' . CleanOperations::cleanStringForJs($xsrfKey) . '" );'
                     . '});'
                   . '</script>'
                 . '</a>' . "\n";
    }

    return $result;
  }

  

  
  protected function getDeleteButton($pDokument)
  {
    $result = '';
    if (isset($this->links['deleteDoku']) && $this->links['deleteDoku'] != '') {
      
      
      

      $xsrf = new Xsrf();
      $xsrfKey = $xsrf->generateKey4Action('wt_dokument_delete', $pDokument->id);

      $result .= '<a href="' . CleanOperations::cleanStringForHtml($this->links['deleteDoku']) . '" class="kdetails_deleteDoku" id="deleteDoku_'
                    . CleanOperations::cleanStringForHtml($pDokument->id) . '" title="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' löschen">'
                    . '<img src="images/loeschen.gif" alt="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' löschen" />';

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

    return $result;
  }

  
  protected function getChangeButton($pDokument)
  {
    $result = '';
    if (isset($this->links['changeDoku']) && $this->links['changeDoku'] != '') {
      $xsrf = new Xsrf();
      $xsrfKey = $xsrf->generateKey4Action('wt_dokument_bearbeiten', $pDokument->id);

      $result .= '<a href="' . CleanOperations::cleanStringForHtml($this->links['changeDoku']) . '" class="kdetails_changeDoku" id="changeDoku_'
                    . $pDokument->id . '" title="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' bearbeiten">'
                    . '<img src="images/edit.gif" alt="Dokument ' . CleanOperations::cleanStringForHtml($pDokument->bezeichnung) . ' bearbeiten" />';
      
      
      $result .= '<script type="text/javascript">'
                     . '$(document).ready(function() {'
                       . '$("#changeDoku_' . CleanOperations::cleanInt($pDokument->id) . '").data("dokument", ' . JsonOperations::encode($pDokument) . ' );'
                       . '$("#changeDoku_' . CleanOperations::cleanInt($pDokument->id) . '").data("changeXsrf", "' . CleanOperations::cleanStringForJs($xsrfKey) . '" );'
                       . '});'
                   . '</script>'
                 . '</a>' . "\n";
    }

    return $result;
  }

  
  protected function getFreigabeInput()
  {
    $result = '<div class="freigabeZeile">' . "\n";
    $result .= HTMLOperations::createButtonSpan('Freigeben', 'Dokument freigeben', '', 'freigabe', 'images/okay.gif') . "\n";
    $result .= '<# if (freigabenoetig == "W" && freigabeam === "") {#><span class="freigabeAnzeige">Freigabe n&ouml;tig!</span><#} 
                   else {#><span class="freigabeAnzeige"></span> <#}#>' . "\n";
    $result .= '</div>' . "\n";

    
    

    
    $result .= '<p class="freigabevonam">'
                . '<label for="detail_freigabeam_dokumente">Freigabe am:</label>' . "\n"
                . '<input type="text" name="detail_freigabeam_dokumente" id="detail_freigabeam_dokumente" value="<#=freigabeam#>" '
                . 'class="hasDatePicker val_date" />' . "\n";
    
    $userKuerzel = SessionOperations::getCurrentWebToolsUserKennung();
    $result .= '<label class="label4select" for="detail_freigabevon_dokumente">von:</label>' . "\n"
            . '<span class="freigabevon">'
            . ' <# if (freigabeam !== "") {#>' . $userKuerzel . '<#} else {#>  <#}#>' . "\n"
            . '</span>' . "\n"
            . '<input type="hidden" name="detail_freigabevon_dokumente" id="detail_freigabevon_dokumente" value="<#=freigabevon#>" />' . "\n"
            . '</p>' . "\n";

    return $result;
  }

  

  
  protected function getFreigabeNoetigInput()
  {
    $zusatzAttribut = ' <# if (freigabenoetig == "W") {#>value="W"<#} else {#>value="F"<#}#>';
    $result = '<p class="freigabeMA">' . "\n";
    $result .= '<input type="hidden" name="detail_freigabenoetig_dokumente" id="detail_freigabenoetig_dokumente" '
            . $zusatzAttribut . '>' . '</p>' . "\n";

    return $result;
  }

  
  protected function _getZusatzInfo4FreigabeMessage()
  {
    return ' für den Dozenten bzw. Teilnehmer';
  }

  
  public function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $user = SessionOperations::getCurrentWebToolsUser();
    $userKuerzel = SessionOperations::getCurrentWebToolsUserKennung();

    $result .= JsOperations::getDeclarationString('KuferTools.UserBen', $user->ben);
    $result .= JsOperations::getDeclarationString('KuferTools.UserKuerzel', $userKuerzel);

    return $result;
  }
}