| 1 | unit UPageList;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, UHtmlClasses;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | TPageList = class
|
|---|
| 12 | TotalCount: Integer;
|
|---|
| 13 | Page: Integer;
|
|---|
| 14 | PageCount: Integer;
|
|---|
| 15 | Output: string;
|
|---|
| 16 | SQLLimit: string;
|
|---|
| 17 | ItemPerPage: Integer;
|
|---|
| 18 | VisiblePageItems: Integer;
|
|---|
| 19 | HTMLId: string;
|
|---|
| 20 | QueryItems: TQueryString;
|
|---|
| 21 | Around: Integer;
|
|---|
| 22 | constructor Create;
|
|---|
| 23 | function Hyperlink: string;
|
|---|
| 24 | function Process: string;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | implementation
|
|---|
| 29 |
|
|---|
| 30 | constructor TPageList.Create;
|
|---|
| 31 | begin
|
|---|
| 32 | ItemPerPage := 40;
|
|---|
| 33 | VisiblePageItems := 30;
|
|---|
| 34 | QueryItems := TQueryString.Create;
|
|---|
| 35 | QueryItems.SetStringServer;
|
|---|
| 36 | HTMLId := '';
|
|---|
| 37 | end;
|
|---|
| 38 |
|
|---|
| 39 | function TPageList.Hyperlink: string;
|
|---|
| 40 | begin
|
|---|
| 41 | // Create hyperlink
|
|---|
| 42 | if HTMLId = '' then Hyperlink := 'href="?' + QueryItems.GetString + '"'
|
|---|
| 43 | else begin
|
|---|
| 44 | QueryItems.Data.Values['Panel'] := '1';
|
|---|
| 45 | Hyperlink := 'href="" onclick="ReloadElement(''' + HTMLId + ''', ''?' + QueryItems.GetString + ''');return false;"';
|
|---|
| 46 | end;
|
|---|
| 47 | Result := Hyperlink;
|
|---|
| 48 | end;
|
|---|
| 49 |
|
|---|
| 50 | function TPageList.Process: string;
|
|---|
| 51 | begin
|
|---|
| 52 | (* Around := Round(VisiblePageItems / 2);
|
|---|
| 53 | Output := '';
|
|---|
| 54 | PageCount := Trunc(TotalCount / ItemPerPage) + 1;
|
|---|
| 55 |
|
|---|
| 56 | if not array_key_exists('Page', $_SESSION)) $_SESSION['Page'] := 0;
|
|---|
| 57 | if(array_key_exists('Page', $_GET)) $_SESSION['Page'] := $_GET['Page'] * 1;
|
|---|
| 58 | if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
|
|---|
| 59 | if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] := PageCount - 1;
|
|---|
| 60 | Page := $_SESSION['Page'];
|
|---|
| 61 |
|
|---|
| 62 | Output := Output + 'Počet položek: <strong>' + IntToStr(TotalCount) + '</strong> Stránky: ';
|
|---|
| 63 |
|
|---|
| 64 | Output := '';
|
|---|
| 65 | if PageCount > 1 then begin
|
|---|
| 66 | if Page > 0 then begin
|
|---|
| 67 | QueryItems.Data['Page'] := 0;
|
|---|
| 68 | Output := Output + '<a ' + Hyperlink + '><<</a> ';
|
|---|
| 69 | QueryItems.Data['Page'] := (Page - 1);
|
|---|
| 70 | Output := Output + '<a ' + Hyperlink + '><</a> ';
|
|---|
| 71 | end;
|
|---|
| 72 | PagesMax := PageCount - 1;
|
|---|
| 73 | PagesMin := 0;
|
|---|
| 74 | if PagesMax > (Page + Around) then PagesMax := Page + Around;
|
|---|
| 75 | if PagesMin < (Page - Around) then begin
|
|---|
| 76 | Output := Output + ' ... ';
|
|---|
| 77 | PagesMin := Page - Around;
|
|---|
| 78 | end;
|
|---|
| 79 | for I := PagesMin to PagesMax - 1 do begin
|
|---|
| 80 | if I = Page then Output := Output + '<strong>' + IntToStr(I + 1) '</strong> ';
|
|---|
| 81 | else begin
|
|---|
| 82 | QueryItems.Data['Page'] := I;
|
|---|
| 83 | Output := Output + '<a ' + Hyperlink + '>' + IntToStr(I + 1) + '</a> ';
|
|---|
| 84 | end;
|
|---|
| 85 | end;
|
|---|
| 86 | if PagesMax < (PageCount - 1) then Output := Output + ' ... ';
|
|---|
| 87 | if Page < (PageCount - 1) then begin
|
|---|
| 88 | QueryItems.Data.Values['Page'] := (Page + 1);
|
|---|
| 89 | Output := Output + '<a ' + Hyperlink + '>></a> ';
|
|---|
| 90 | QueryItems.Data.Values['Page'] := (PageCount - 1);
|
|---|
| 91 | Output := Output + '<a ' + Hyperlink + '>>></a>';
|
|---|
| 92 | end;
|
|---|
| 93 | end;
|
|---|
| 94 | if Output <> '' Output := '<div style="text-align: center">' + Output + '</div>';
|
|---|
| 95 | SQLLimit := ' LIMIT ' + IntToStr(Page * ItemPerPage) + ', ' + IntToStr(ItemPerPage);
|
|---|
| 96 | end;*)
|
|---|
| 97 | end;
|
|---|
| 98 |
|
|---|
| 99 | end.
|
|---|
| 100 |
|
|---|