line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Paging::SQL;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#
|
4
|
|
|
|
|
|
|
# PARAMETER README
|
5
|
|
|
|
|
|
|
#
|
6
|
|
|
|
|
|
|
# $hash->{"HP_A"} : all page(s) amount
|
7
|
|
|
|
|
|
|
# $hash->{"HP_C"} : curret page number
|
8
|
|
|
|
|
|
|
# $hash->{"HP_P"} : other user parameter
|
9
|
|
|
|
|
|
|
# $hash->{"HP_U"} : user script uri
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
# Set GET to POST method
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
sub BEGIN {
|
16
|
|
|
|
|
|
|
# set version to ENV
|
17
|
1
|
|
|
1
|
|
1437
|
$HTML::Paging::SQL::revision = '$Id: SQL.pm,v 1.17 2002/01/18 12:37:57 wangaocheng Exp $';
|
18
|
1
|
|
|
|
|
10
|
($HTML::Paging::SQL::VERSION) = '$Revision: 1.17 $' =~ /(\d+\.\d+)/;
|
19
|
1
|
|
|
|
|
13
|
$ENV{"HTML_PAGING_SQL"} = $HTML::Paging::SQL::VERSION;
|
20
|
1
|
50
|
|
|
|
5275
|
if ($ENV{"REQUEST_METHOD"} eq "POST") {
|
21
|
0
|
|
|
|
|
|
sysread(STDIN, $HTML::Paging::SQL::buffer, $ENV{"CONTENT_LENGTH"});
|
22
|
0
|
|
|
|
|
|
$ENV{"REQUEST_METHOD"} = "GET";
|
23
|
0
|
|
|
|
|
|
$ENV{"QUERY_STRING"} = "$HTML::Paging::SQL::buffer";
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#
|
28
|
|
|
|
|
|
|
# Create a new object
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
sub new {
|
31
|
0
|
|
|
0
|
1
|
|
my $class = shift;
|
32
|
0
|
|
|
|
|
|
my $self = {};
|
33
|
|
|
|
|
|
|
# process user parameter
|
34
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq "HASH") {
|
35
|
0
|
|
|
|
|
|
$self = shift;
|
36
|
|
|
|
|
|
|
} else {
|
37
|
0
|
|
|
|
|
|
my %self = @_;
|
38
|
0
|
|
|
|
|
|
$self = \%self;
|
39
|
|
|
|
|
|
|
}
|
40
|
0
|
0
|
|
|
|
|
if ($self->{"all"} !~ m/^\d+$/) {
|
41
|
0
|
|
|
|
|
|
$self->{"all"} = 0; # process error here
|
42
|
|
|
|
|
|
|
}
|
43
|
0
|
0
|
|
|
|
|
if ($self->{"num"} !~ m/^\d+$/) {
|
44
|
0
|
|
|
|
|
|
$self->{"num"} = 10; # set per page default
|
45
|
|
|
|
|
|
|
}
|
46
|
0
|
|
|
|
|
|
return bless $self,$class;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#
|
50
|
|
|
|
|
|
|
# Format output with Number Mode
|
51
|
|
|
|
|
|
|
#
|
52
|
|
|
|
|
|
|
sub number {
|
53
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
54
|
0
|
|
|
|
|
|
my $hash = $self->_status();
|
55
|
0
|
|
|
|
|
|
my @result;
|
56
|
0
|
|
|
|
|
|
$result[1] = $self->{"num"} * ($hash->{"HP_C"}-1);
|
57
|
0
|
|
|
|
|
|
$result[2] = $self->{"num"};
|
58
|
0
|
0
|
|
|
|
|
if ($self->{"all"} < $self->{"num"}) {
|
59
|
0
|
|
|
|
|
|
return @result; # output null to caller
|
60
|
|
|
|
|
|
|
}
|
61
|
0
|
|
|
|
|
|
my $param = {};
|
62
|
|
|
|
|
|
|
# process user parameter
|
63
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq "HASH") {
|
64
|
0
|
|
|
|
|
|
$param = shift;
|
65
|
|
|
|
|
|
|
} else {
|
66
|
0
|
|
|
|
|
|
my %param = @_;
|
67
|
0
|
|
|
|
|
|
$param = \%param;
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
# set default back & forward icon
|
70
|
0
|
0
|
|
|
|
|
if (!$param->{"bicon"}) {
|
71
|
0
|
|
|
|
|
|
$param->{"bicon"} = "<<";
|
72
|
|
|
|
|
|
|
}
|
73
|
0
|
0
|
|
|
|
|
if (!$param->{"ficon"}) {
|
74
|
0
|
|
|
|
|
|
$param->{"ficon"} = ">>";
|
75
|
|
|
|
|
|
|
}
|
76
|
0
|
0
|
0
|
|
|
|
if ($param->{"sub"} !~ /^\d+$/ or $param->{"sub"} >= $hash->{"HP_A"}) {
|
77
|
0
|
|
|
|
|
|
$param->{"sub"} = 0;
|
78
|
|
|
|
|
|
|
}
|
79
|
0
|
|
|
|
|
|
my ($current,$total);
|
80
|
0
|
0
|
|
|
|
|
if ($param->{"sub"}) {
|
81
|
0
|
|
|
|
|
|
$current = $hash->{"HP_C"}/$param->{"sub"}; # start page number
|
82
|
|
|
|
|
|
|
# not current page end number
|
83
|
0
|
0
|
|
|
|
|
if ($current =~ /\d+\.\d+/) {
|
84
|
0
|
|
|
|
|
|
$current = int($current) * $param->{"sub"} + 1;
|
85
|
|
|
|
|
|
|
} else {
|
86
|
|
|
|
|
|
|
# I think this is page end number :)
|
87
|
0
|
|
|
|
|
|
$current = $hash->{"HP_C"} - $param->{"sub"} + 1;
|
88
|
|
|
|
|
|
|
}
|
89
|
0
|
|
|
|
|
|
$total = $current + $param->{"sub"} - 1;
|
90
|
|
|
|
|
|
|
} else {
|
91
|
0
|
|
|
|
|
|
$current = 1;
|
92
|
0
|
|
|
|
|
|
$total = $hash->{"HP_A"};
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
# return HTML code
|
95
|
0
|
|
|
|
|
|
undef $result[0];
|
96
|
0
|
|
|
|
|
|
$result[0] .= "\n";
|
97
|
0
|
0
|
0
|
|
|
|
if ($param->{"sub"} && $hash->{"HP_C"} > $param->{"sub"}) {
|
98
|
0
|
|
|
|
|
|
$result[0] .= qq|
99
|
0
|
0
|
|
|
|
|
$result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
|
100
|
0
|
|
|
|
|
|
$result[0] .= qq|HP_C=| . ($current-1) . qq|"|;
|
101
|
0
|
0
|
|
|
|
|
$result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
|
102
|
0
|
|
|
|
|
|
$result[0] .= qq|>|;
|
103
|
0
|
|
|
|
|
|
$result[0] .= qq|$param->{"bicon"}|;
|
104
|
0
|
|
|
|
|
|
$result[0] .= qq|\n|;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
# set number now
|
107
|
0
|
|
|
|
|
|
for (my $i=$current; $i<=$total ; $i++) {
|
108
|
0
|
0
|
|
|
|
|
if ($i > $hash->{"HP_A"}) {
|
109
|
0
|
|
|
|
|
|
last;
|
110
|
|
|
|
|
|
|
}
|
111
|
0
|
0
|
|
|
|
|
if ($i == $hash->{"HP_C"}) {
|
112
|
0
|
|
|
|
|
|
$result[0] .= qq|$i \n|;
|
113
|
|
|
|
|
|
|
} else {
|
114
|
0
|
|
|
|
|
|
$result[0] .= qq|
115
|
0
|
0
|
|
|
|
|
$result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
|
116
|
0
|
|
|
|
|
|
$result[0] .= qq|HP_C=$i"|;
|
117
|
0
|
0
|
|
|
|
|
$result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
|
118
|
0
|
|
|
|
|
|
$result[0] .= qq|>|;
|
119
|
0
|
|
|
|
|
|
$result[0] .= qq|$i|;
|
120
|
0
|
|
|
|
|
|
$result[0] .= qq|\n|;
|
121
|
|
|
|
|
|
|
}
|
122
|
0
|
0
|
|
|
|
|
if ($i == $hash->{"HP_A"}) {
|
123
|
0
|
|
|
|
|
|
last;
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
}
|
126
|
0
|
0
|
0
|
|
|
|
if ($param->{"sub"} && ($current+$param->{"sub"}-1) < $hash->{"HP_A"}) {
|
127
|
0
|
|
|
|
|
|
$result[0] .= qq|
128
|
0
|
0
|
|
|
|
|
$result[0] .= qq|$hash->{'HP_P'}&| if ($hash->{'HP_P'});
|
129
|
0
|
|
|
|
|
|
$result[0] .= qq|HP_C=| . ($total+1) . qq|"|;
|
130
|
0
|
0
|
|
|
|
|
$result[0] .= qq| target="$param->{'target'}"| if ($param->{"target"});
|
131
|
0
|
|
|
|
|
|
$result[0] .= qq|>|;
|
132
|
0
|
|
|
|
|
|
$result[0] .= qq|$param->{"ficon"}|;
|
133
|
0
|
|
|
|
|
|
$result[0] .= qq|\n|;
|
134
|
|
|
|
|
|
|
}
|
135
|
0
|
|
|
|
|
|
$result[0] .= "\n";
|
136
|
0
|
|
|
|
|
|
return @result;
|
137
|
|
|
|
|
|
|
}
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
#
|
140
|
|
|
|
|
|
|
# Get current status { private method }
|
141
|
|
|
|
|
|
|
#
|
142
|
|
|
|
|
|
|
sub _status {
|
143
|
0
|
|
|
0
|
|
|
my $self = shift;
|
144
|
0
|
|
|
|
|
|
my $hash = {};
|
145
|
0
|
|
|
|
|
|
my $form = {};
|
146
|
0
|
|
|
|
|
|
$hash->{"HP_A"} = $self->{"all"}/$self->{"num"};
|
147
|
0
|
0
|
|
|
|
|
if ($hash->{"HP_A"} =~ /\d+\.\d+/) {
|
148
|
0
|
|
|
|
|
|
$hash->{"HP_A"} = int($hash->{"HP_A"}) + 1;
|
149
|
|
|
|
|
|
|
}
|
150
|
0
|
|
|
|
|
|
my $uri = $ENV{"REQUEST_URI"};
|
151
|
0
|
|
|
|
|
|
my ($script,$string) = split(/\?/,$uri);
|
152
|
0
|
|
|
|
|
|
my @param;
|
153
|
|
|
|
|
|
|
# process GET method
|
154
|
0
|
0
|
|
|
|
|
if (!$HTML::Paging::SQL::buffer) {
|
155
|
0
|
|
|
|
|
|
@param = split('&',$string);
|
156
|
|
|
|
|
|
|
} else {
|
157
|
0
|
|
|
|
|
|
chomp($HTML::Paging::SQL::buffer);
|
158
|
0
|
|
|
|
|
|
@param = split('&',$HTML::Paging::SQL::buffer);
|
159
|
|
|
|
|
|
|
}
|
160
|
0
|
|
|
|
|
|
foreach (@param) {
|
161
|
0
|
|
|
|
|
|
$_ =~ s/\+/ /g;
|
162
|
0
|
|
|
|
|
|
my ($key, $val) = split(/=/,$_);
|
163
|
0
|
|
|
|
|
|
$key =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
|
|
0
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
|
|
0
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$form->{"$key"} = "$val";
|
166
|
|
|
|
|
|
|
}
|
167
|
0
|
|
|
|
|
|
$hash->{"HP_U"} = $script; #CALLER URI
|
168
|
0
|
|
0
|
|
|
|
$hash->{"HP_C"} = $form->{"HP_C"} || 1; #CURRENT PAGE
|
169
|
|
|
|
|
|
|
# process overflow
|
170
|
0
|
0
|
|
|
|
|
if ($hash->{"HP_C"} > $hash->{"HP_A"}) {
|
171
|
0
|
|
|
|
|
|
$hash->{"HP_C"} = $hash->{"HP_A"};
|
172
|
|
|
|
|
|
|
}
|
173
|
0
|
0
|
|
|
|
|
if ($hash->{"HP_C"} < 1) {
|
174
|
0
|
|
|
|
|
|
$hash->{"HP_C"} = 1;
|
175
|
|
|
|
|
|
|
}
|
176
|
0
|
|
|
|
|
|
undef @param;
|
177
|
0
|
|
|
|
|
|
foreach (keys %$form) {
|
178
|
0
|
0
|
0
|
|
|
|
next if ($_ eq "HP_C" or $_ eq "");
|
179
|
0
|
|
|
|
|
|
push(@param,$_."=".$form->{"$_"});
|
180
|
|
|
|
|
|
|
}
|
181
|
0
|
|
|
|
|
|
$hash->{"HP_P"} = join("&",@param); #OTHER PARAMETER
|
182
|
0
|
|
|
|
|
|
return $hash;
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1;
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__
|