source: trunk/Packages/CoolWeb/Modules/PageList.pas

Last change on this file was 151, checked in by chronos, 9 months ago
File size: 3.0 KB
Line 
1unit PageList;
2
3interface
4
5uses
6 Classes, SysUtils, HtmlClasses;
7
8type
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
30implementation
31
32constructor TPageList.Create;
33begin
34 ItemPerPage := 40;
35 VisiblePageItems := 30;
36 QueryItems := TQueryString.Create;
37 QueryItems.SetStringServer;
38 HTMLId := '';
39end;
40
41destructor TPageList.Destroy;
42begin
43 FreeAndNil(QueryItems);
44 inherited;
45end;
46
47function TPageList.Hyperlink: string;
48begin
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;
56end;
57
58function TPageList.Process: string;
59begin
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> &nbsp; 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 + '>&lt;&lt;</a> ';
77 QueryItems.Data['Page'] := (Page - 1);
78 Output := Output + '<a ' + Hyperlink + '>&lt;</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 + '>&gt;</a> ';
98 QueryItems.Data.Values['Page'] := (PageCount - 1);
99 Output := Output + '<a ' + Hyperlink + '>&gt;&gt;</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;*)
105end;
106
107end.
108
Note: See TracBrowser for help on using the repository browser.