ACC SHELL
<?php
/**
* Třída pro vygenerování pageru
*
* @author Filip Štencl
* @since 25.7.2013
*
*/
class pager {
public $now = 0;
private $limit = 20;
private $get = null;
public function __construct() { $this->get = $_GET; if (isset($_GET['offset']) && intval($_GET['offset']) > 0) { $this->now = intval($_GET['offset']); } else {$this->now = 0;} }
public function getLimit() { return $this->limit; }
public function getNow() { return $this->now; }
public function setLimit($limit) { $this->limit = $limit; }
public function getPaging ($offset, $pocet, $parameters = null) {
if($pocet <= $this->limit) { return true; }
if ( $offset > 0 ) { $parameters['offset'] = ($offset-$this->limit); $tfoot .= "<a href=\"".$this->makePageURL($parameters)."\" class=\"right\">«</a>"; }
for ( $i = 0; $i*$this->limit < $pocet; $i++ ) {
if ( $i*$this->limit == $offset ) { $tfoot .= "<span>".($i+1)."</span>"; }
else { $parameters['offset'] = ($i*$this->limit); $tfoot .= "<a href=\"".$this->makePageURL($parameters)."\">".($i+1)."</a>"; }
}
if ( $offset < $pocet-$this->limit ) {
$parameters['offset'] = ($offset+$this->limit);
$tfoot .= "<a href=\"".$this->makePageURL($parameters)."\" class=\"left\">»</a>";
}
return $tfoot;
}
public function getPaging_admin ($sql,$offset,$tableId = NULL) {
$pocet = dibi::query($sql)->count();
$tfoot = "<div class=\"strankovani_info\">";
if ($pocet == 0){ $tfoot .= "Nebyl nalezen žádný záznam";}
else {
if ($offset == 0) { $pom_pocet = $this->limit; }
else { $pom_pocet = $pocet;}
if ($pom_pocet > $pocet) { $pom_pocet = $pocet; }
$tfoot .= "Zobrazeno <strong>".($offset + 1) ."-".(($offset + $this->limit) < $pocet && $offset > 0 ? ($offset + $this->limit):$pom_pocet)."</strong> z celkem <strong>$pocet</strong>";
if ($tableId != NULL) { $tfoot .= " | <a href=\"#nastaveni_".$tableId."\" class=\"tooltip\" rel=\"modal\" title=\"změnit nastavení této tabulky\">Nastavení</a>"; }
}
$tfoot .= "</div>";
$tfoot .= "<div class=\"strankovani\">";
if (($offset + $this->limit) < $pocet || $offset > 0) {
for ( $i = 0; $i*$this->limit < $pocet; $i++ ) {
if ( $i*$this->limit == $offset ) { $tfoot .= "<span>".($i+1)."</span>"; }
else {
$parameters['offset'] = ($i*$this->limit);
$tfoot .= "<a href=\"".$this->makePageURL($parameters)."\" class=\"number tooltip\" title=\"Přejít na ".($i+1).". stranu \">".($i+1)."</a>";
}
}
}
$tfoot .= "</div>";
$tfoot .= "<div class=\"clear\"></div>";
return $tfoot;
}
public function getInfo ($sql,$tableId = NULL) {
$pocet = dibi::query($sql)->count();
$tfoot = "<div class=\"strankovani_info\">";
if ($pocet == 0){ $tfoot .= "Nebyl nalezen žádný záznam";}
else {
$tfoot .= "Zobrazeno <strong>$pocet</strong> z celkem <strong>$pocet</strong>";
if ($tableId != NULL) { $tfoot .= " | <a href=\"#nastaveni_".$tableId."\" class=\"tooltip\" rel=\"modal\" title=\"změnit nastavení této tabulky\">Nastavení</a>"; }
}
$tfoot .= "</div>";
$tfoot .= "<div class=\"clear\"></div>";
return $tfoot;
}
private function makePageURL($parameters) {
foreach($parameters as $key => $value) { $this->get[$key] = $value; }
$string = "?".http_build_query($this->get, "", "&");
return $string;
}
}
ACC SHELL 2018