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