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


class DataMenuSucheByDatum extends DataMenuSucheKurse
{
  private $vondat;
  private $bisdat;

  public function __construct($pUrlparameter)
  {
    parent::__construct($pUrlparameter);

    $gesuchteVeranarten = SessionOperations::getVarValueSuche('kfs_veranartids', '##');
    if ($gesuchteVeranarten === '##') {
      
      SessionOperations::setVarValueSuche('kfs_veranartids', $this->settings->kalenderVeranart);
    }

    $this->vondat = SessionOperations::getVarValueSuche('kfs_beginn_dat1');
    $this->bisdat = SessionOperations::getVarValueSuche('kfs_beginn_dat2');

    $this->status1 = "<a class='statusadresse' href='" . CleanOperations::cleanStringForHtml(INDEXSCRIPT) . '?urlparameter=' . CleanOperations::cleanStringForHtml($this->urlparameter->getStreamWith(array('kathaupt'), array('27'))) . '&kfs_beginn_dat1=' . $this->vondat . '&kfs_beginn_dat2=' . $this->bisdat . "'>Kalender</a>\n";
  }

  public function setStatusMeldung()
  {
    $tmptext = '';
    if ($this->vondat != '' or $this->bisdat != '') {
      if ($this->vondat == $this->bisdat) {
        $tmptext .= 'am ' . $this->vondat;
      } else {
        if ($this->vondat != '') {
          $tmptext .= ' von "' . $this->addfdatetime->getValidDateString($this->vondat) . '"';
        }
        if ($this->bisdat != '') {
          $tmptext .= ' bis "' . $this->addfdatetime->getValidDateString($this->bisdat) . '"';
        }
      }
    }

    if ($tmptext != '') {
      $textobj = $this->dbwtexte->getTextById(TEXTE_VERANSTALTUNGENAM);
      $textobjwert = str_replace(
        '{%such_kriterien%}',
        $tmptext,
        trim($textobj->wert)
      );
      $tmptext = 'Veranstaltungen ' . $tmptext . ':';
      $tmptext = $textobjwert == '' ? $tmptext : $textobjwert;
    } else { 
      $textobj = $this->dbwtexte->getTextById(TEXTE_GEFUNDEN);
      $tmptext = 'Gefundene Veranstaltungen:';
      $tmptext = trim($textobj->wert) == '' ? $tmptext : trim($textobj->wert);
    }
    if (SessionOperations::getVarValueSuche('seitenwahlerror', '--') == 1) {
      $tmptext = 'Die Seitenangabe ist fehlerhaft. Bitte geben Sie eine Seitenzahl zwischen 1 und ' . (SessionOperations::getVarValueSuche('seitenanzahl')) . ' ein.';
      $textobj = $this->dbwtexte->getTextById(TEXTE_FALSCHESEITENANGABE);
      $tmptext = trim($textobj->wert) == '' ? $tmptext : trim($textobj->wert);
    }

    if (trim($tmptext) != '') {
      if ($this->status2 != '') {
        $this->status2 = $this->status2 . BR . CleanOperations::cleanStringContainingHtml($tmptext);
      } else {
        $this->status2 = CleanOperations::cleanStringContainingHtml($tmptext);
      }
    }
  }

  
  public function _getClickPath()
  {
    
    DataMenuMain::_getClickPath();
    
    if ($this->toolsettings->titleKursBereich != '') {
      $this->clickpfad = "<span class='clickadresse'>" . ' ' . CleanOperations::cleanStringForHtml(stripslashes($this->toolsettings->titleKursBereich)) . ' ' . "</span>\n";
      $this->clickpfad .= "<span class='trennzeichen'>" . ' ' . CleanOperations::cleanStringContainingHtml($this->toolsettings->trennzeichenKategorie) . ' ' . '</span>';
    }
    $this->clickpfad .= "<span class='clickadrbold'>" . CleanOperations::cleanStringForHtml($this->toolsettings->clickVeranstKalender) . "</span>\n";
    
    return $this->clickpfad;
  }

  
  public function getBlaettern()
  {
    $result = parent::getBlaettern();
    if ($result[4] != '') {
      $result[4] = $this->addDate($result[4]);
    }
    if ($result[5] != '') {
      $result[5] = $this->addDate($result[5]);
    }

    return $result;
  }

  private function addDate($link)
  {
    $result = $link;
    if ($this->vondat != '') {
      $result .= '&amp;kfs_beginn_dat1=' . CleanOperations::cleanStringForHtml($this->addfdatetime->getValidDateString($this->vondat));
    }
    if ($this->bisdat != '') {
      $result .= '&amp;kfs_beginn_dat2=' . CleanOperations::cleanStringForHtml($this->addfdatetime->getValidDateString($this->bisdat));
    }

    return $result;
  }
}