<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Veranstalter\KursVorschlag\KoopUebersichtDialog;

class KoopUebersichtDialogUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new KoopUebersichtDialogResponse());
  }

  public static function getToolSectionId()
  {
    return 742;
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_KURSVORSCHLAG_VA;
  }

  private function getSuchFelder()
  {
    if (\DBWorkBASysSettings::isSalzburgBildungswerk()) {
      $veranstalter = \Kufer\Web\KuferTools\Veranstalter\Utils\VeranstalterUtils::getVeranstalterDozent();

      return  '<label for="tn_search_name" class="search_label">Name/Org.:</label> '
              . '<input id="tn_search_name" name="s_name" class="tn_search_name dataTableSearch form-control">'
              . '<br>'
              . '<label for="tn_search_gemeinde" class="search_label">Gemeinde:</label> '
              . '<input id="tn_search_gemeinde" name="s_gemeinde" class="tn_search_gemeinde dataTableSearch form-control" value="' . $veranstalter->gemeinde . '">'
              . '<label for="tn_search_bezirk" class="search_label">Bezirk:</label> '
              . '<input id="tn_search_bezirk" name="s_bezirk" class="tn_search_bezirk dataTableSearch form-control" value="' . $veranstalter->bezirk . '">';
    } else {
      return  '<label for="tn_search_name">Name:</label> '
              . '<input id="tn_search_name" name="s_name" class="tn_search_name dataTableSearch form-control"> '
              . '<label for="tn_search_vorname">Vorname:</label> '
              . '<input id="tn_search_vorname" name="s_vorname" class="tn_search_vorname dataTableSearch form-control"> '
              . '<label for="tn_search_nr">Nr:</label> '
              . '<input id="tn_search_nr" name="s_doznr" size="4" class="tn_search_nr dataTableSearch form-control">';
    }
  }

  
  private function getDozUebersichtDialog($pClass = 'tn_uebersicht_dialog')
  {
    $columns = $this->getColumns($this->toolSettings);
    $result = '<div class="' . \CleanOperations::cleanStringForHtml($pClass) . '">';
    $result
              .= '<div class="tn_search form-inline">'
              . $this->getSuchFelder()
              . '<span class="tn_search_start dataTableSearchButton"><button style="margin-right:5px; margin-left:10px;" type="button" class="btn btn-default collapse-button" title="suchen" >'
       . '<i class="fa fa-search" aria-hidden="true"></i>'
              . '</button></span>'
              . '<span class="tn_search_back dataTablePrevious"><button style="margin-right:5px;" type="button" class="btn btn-default collapse-button" title="vorherig" >'
       . '<i class="fa fa-arrow-left" aria-hidden="true"></i>'
              . '</button></span>'
              . '<span class="tn_search_vor dataTableNext"><button type="button" class="btn btn-default collapse-button" title="nächste" >'
       . '<i class="fa fa-arrow-right" aria-hidden="true"></i>'
              . '</button></span>'
              . '</div>';
    $result .= '<table class="dataTable_dozUebersicht display"><thead><tr>';
    $result .= '<th width="20px"></th>'; 
    foreach ($columns as $column) {
      $result .= '<th width="' . \CleanOperations::cleanInt($column->width) . '">' . \CleanOperations::cleanStringForHtml($column->title) . '</th>';
    }
    $columnsCount = count($columns);
    $result .= '</tr></thead><tbody><tr><td colspan="' . $columnsCount . '">Daten werden geladen</td></tr></tbody></table></div>';

    return $result;
  }

  private function getClassName()
  {
    return 'tn_uebersicht_dialog';
    
  }

  public function action()
  {
    $class = $this->getClassName();
    $dialog = $this->getDozUebersichtDialog($class);

    return $this->getResponse($dialog);
  }

  protected function getResponse($dialog)
  {
    $this->response->dialog = $dialog;

    return $this->response;
  }
}

class KoopUebersichtDialogRequest
{
  public $mehrfachAnm;
}

class KoopUebersichtDialogResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $dialog;
}