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


class SeitenblaetternAPI
{
  
  public $anzahlproSeite = 0;
  
  public $countBefore;
  
  public $countBehind;
  
  public $countAll;

  
  public $html;

  
  public function __construct($anzahlproSeite, $countbefore, $countbehind, $countall)
  {
    $this->anzahlproSeite = $anzahlproSeite;
    $this->countBefore = $countbefore;
    $this->countBehind = $countbehind;
    $this->countAll = $countall;
    $this->html = new HTMLOperations();
  }

  
  public function getBlaetternArray()
  {
    
    
    
    
    

    $retAry = array('', '', '', '', '', '');
    if ($this->countBefore > 0 || $this->countBehind > 0 || $this->countAll > 0) {
      $retAry[0] = floor($this->countBefore / $this->anzahlproSeite + 1);
      $retAry[1] = ceil($this->countAll / $this->anzahlproSeite);
      $retAry[2] = $this->countBefore + 1;
      if ($this->countBehind > 0) {
        $retAry[3] = $this->countBefore + $this->anzahlproSeite;
      } else {
        $retAry[3] = $this->countAll;
      }
    }

    return $retAry;
  }

  
  public function getBlaetternText($blaetternAry)
  {
    $retString = '';
    if ($this->countBefore > 0 || $this->countBehind > 0) {
      $retString .= "<span class='blaetterntasten'>";
    }
    
    $layoutDir = \Kufer\Web\Classes\KwResourceLocator::getInstance()->locateLayoutDirRelative();

    if ($this->countBefore > 0) {
      $retString .= "\n";
      $retString .= " <a class='blaetterntasten' href='" . CleanOperations::cleanStringForHtml($blaetternAry[4]) . "' accesskey='-'>\n";
      $retString .= $this->html->CreateImageTag(
        $layoutDir . 'button_rueckwaerts.gif',
        'Rückwärts, Schnelltaste -',
        '',
        'blaettern',
        'title="Vorherige Seite"'
      ) . "\n</a>";
    }
    if ($this->countBehind > 0) {
      $retString .= "\n";
      $retString .= " <a class='blaetterntasten' href='" . CleanOperations::cleanStringForHtml($blaetternAry[5]) . "' accesskey='+'>\n";
      $retString .= $this->html->CreateImageTag(
        $layoutDir . 'button_vorwaerts.gif',
        'Vorwärts, Schnelltaste +',
        '',
        'blaettern',
        'title="Nächste Seite"'
      ) . "\n</a>";
    }
    if ($this->countBefore > 0 || $this->countBehind > 0) {
      $retString .= "\n</span>";
    }
    if ($this->countBefore > 0 || $this->countBehind > 0) {
      $retString .= "<span class='anzahl'>Seite ";
      $retString .= CleanOperations::cleanInt($blaetternAry[0]);
      $retString .= ' von ';
      $retString .= CleanOperations::cleanInt($blaetternAry[1]);
      $retString .= '</span>';
    }

    return $retString;
  }
}