Name = 'Common'; $this->Version = '1.2'; $this->ReleaseDate = strtotime('2020-03-29'); $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/'; } } class Paging { public int $TotalCount; public int $ItemPerPage; public int $Around; public string $SQLLimit; public int $Page; function __construct() { global $System; $this->ItemPerPage = $System->Config['Web']['ItemsPerPage']; $this->Around = $System->Config['Web']['VisiblePagingItems']; } function Show(): string { $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); $Result = ''; if (array_key_exists('all', $QueryItems)) { $PageCount = 1; $ItemPerPage = $this->TotalCount; } else { $ItemPerPage = $this->ItemPerPage; $Around = round($this->Around / 2); $PageCount = floor($this->TotalCount / $ItemPerPage) + 1; } if (!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0; if (array_key_exists('page', $_GET) and is_numeric($_GET['page'])) $_SESSION['Page'] = $_GET['page'] * 1; if ($_SESSION['Page'] < 0) $_SESSION['Page'] = 0; if ($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1; $CurrentPage = $_SESSION['Page']; $Result .= 'Počet položek: '.$this->TotalCount.'   Stránky: '; $Result = ''; if ($PageCount > 1) { if ($CurrentPage > 0) { $QueryItems['page'] = 0; $Result.= '<< '; $QueryItems['page'] = ($CurrentPage - 1); $Result.= '< '; } $PagesMax = $PageCount - 1; $PagesMin = 0; if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around; if ($PagesMin < ($CurrentPage - $Around)) { $Result.= ' ... '; $PagesMin = $CurrentPage - $Around; } for ($i = $PagesMin; $i <= $PagesMax; $i++) { if ($i == $CurrentPage) $Result.= ''.($i + 1).' '; else { $QueryItems['page'] = $i; $Result .= ''.($i + 1).' '; } } if ($PagesMax < ($PageCount - 1)) $Result .= ' ... '; if ($CurrentPage < ($PageCount - 1)) { $QueryItems['page'] = ($CurrentPage + 1); $Result.= '> '; $QueryItems['page'] = ($PageCount - 1); $Result.= '>>'; } } $QueryItems['all'] = '1'; if ($PageCount > 1) $Result.= ' Vše'; $Result = '
'.$Result.'
'; $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage; $this->Page = $CurrentPage; return $Result; } }