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

namespace Kufer\KuferTools\Firma\BayerischerApothekertag\KursUebersicht;

class KursUebersichtPresenter extends \Kufer\KuferTools\Basis\Uebersicht\UebersichtMitWssPresenter
{
  protected function getBlaetternAction()
  {
    return 'kursuebersicht';
  }

  protected function getJsFilesSrcAryWeitere()
  {
    $js = parent::getJsFilesSrcAryWeitere();
    $js[] = $this->getJsFileFromSys('kursuebersicht.js');
    $js[] = $this->getJsFileFromSys('anmelden.js');

    return $js;
  }

  protected function getDatamodulFuerUeberschriftszeile()
  {
    return new \Kurs();
  }

  protected function getPanelTitleLink($kurs)
  {
    return 'index.php?tool_id=46&action=kursdetails&knr=' . urlencode($kurs->id);
  }

  protected function getPanelTitle($kurs)
  {
    return $kurs->id . ' - ' . $kurs->getVarValue('kurzbez_titel');
  }

  protected function getPanelTitleHinweis()
  {
    return 'Zu den ' . $this->useCaseResponse->sprachSettings->Kurs['Singular']['Nominativ'] . 'details';
  }

  protected function getPanelCheckBoxValue($kurs)
  {
    return $kurs->id;
  }

  protected function getPanelBootStrapColor($kurs)
  {
    if ($kurs->ausfall) {
      return 'danger';
    } else {
      return parent::getPanelBootStrapColor($kurs);
    }
  }

  protected function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();

    $this->toolSettings = \ToolSettingsAPI::getToolSettings(14); 
    $teilnehm = $this->useCaseResponse->teilnehmer;
    $tnrIban = $teilnehm->iban;
    if (!\SessionOperations::isReplikat()) {
      $tnrIban = \SecurityOperations::anonymizeString($tnrIban);
    }
    $result .= 'registerNamespace("KuferTools.UserInfo"); ';
    $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.CurrentUserIban', \StringOperations::htmlentities($tnrIban, ENT_QUOTES));
    $result .= 'KuferTools.UserInfo.UseSepa=true;';

    $result .= \JsOperations::getDeclarationBoolean('KuferTools.UserInfo.HasSepaMandat', $this->useCaseResponse->hasSepaMandat);
    if (isset($this->links['emptyMandatorys'])) {
      $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.EmptyMandatorys', 'new Array( "' . implode('", "', $this->links['emptyMandatorys']) . '" );');
    }
    $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.NewsletterErlaubt', $teilnehm->newsl_erlaubt);
    
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.NewsletterAnmeldung_erlaubt', $this->toolSettings->newsletterAnmeldung_erlaubt);
    $result .= \JsOperations::getDeclarationJsonBase64('KuferTools.ErlaubteZahlarten', $this->toolSettings->getErlaubteZahlArten());

    $result .= \JsOperations::getDeclarationInt('KuferTools.ToolSectionId', 94);

    
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextOhneMandat', \StringOperations::convertLinebreaks2HTML($this->toolSettings->sepaTextOhneMandat));
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextMitMandat', \StringOperations::convertLinebreaks2HTML($this->toolSettings->sepaTextMitMandat));
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextDruckLink', $this->toolSettings->sepaTextDruckLink);

    
    $result .= \JsOperations::getDeclarationString('KuferTools.AnmZusatzText', \StringOperations::convertLinebreaks2HTML($this->toolSettings->anm_zusatzText));
    $result .= \JsOperations::getDeclarationString('KuferTools.AnmZusatzAufforderung', \StringOperations::convertLinebreaks2HTML($this->toolSettings->anm_zusatzAufforderung));
    $result .= \JsOperations::getDeclarationString('KuferTools.KursData', $this->getJSONKursData($teilnehm));

    return $result;
  }

  private function getJSONKursData($teilnehmer)
  {
    
    

    $tnrKonto = $teilnehmer->konto;
    $tnrIban = $teilnehmer->iban;
    if (!\SessionOperations::isReplikat()) {
      $tnrKonto = \SecurityOperations::anonymizeString($tnrKonto);
      $tnrIban = \SecurityOperations::anonymizeString($tnrIban);
    }
    $tnrGutHaben = '';
    
    if (\DBWorkBASysSettings::isBlak() && \MathOperations::stringToFloat($teilnehmer->guthaben) > 0) {
      $tnrGutHaben = $teilnehmer->guthaben;
    }

    $guthaben = $tnrGutHaben;

    $kursdata = (object)array(
        'Knr' => '',
        'Titel' => '',
        'Zeitraum' => '',
        'Ort' => '',
        'Gebuehr' => '0',
        'GebuehrenErgaenzText' => '',
        'Aussenstelle' => '',
        'Konto' => \StringOperations::htmlentities($tnrKonto, ENT_QUOTES),
        'Iban' => \StringOperations::htmlentities($tnrIban, ENT_QUOTES),
        'Guthaben' => \StringOperations::htmlentities($guthaben . (($guthaben != '') ? ' ' . CURRENCY : ''), ENT_QUOTES)
      );

    return \JsonOperations::encodeBase64($kursdata);
  }
}