line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Data::ResultsHelper; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
32517
|
use vars qw($AUTOLOAD $VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
74
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5708
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '1.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
0
|
|
my $type = shift; |
12
|
0
|
0
|
|
|
|
|
my @PASSED_ARGS = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my @DEFAULT_ARGS = ( |
14
|
|
|
|
|
|
|
prefs => {}, |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
prefix => 'rh', |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
back_text => 'back', |
19
|
|
|
|
|
|
|
next_text => 'next', |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
set_cookie => 1, |
22
|
|
|
|
|
|
|
cookie_ttl => '1 hour', |
23
|
|
|
|
|
|
|
base_dir => "/tmp/results_helper", |
24
|
|
|
|
|
|
|
cookie_filename => time . "." . $$, |
25
|
|
|
|
|
|
|
cookie_brick_over => 0, |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#delimiter => '\|', |
28
|
|
|
|
|
|
|
#filter_columns_offset => 0, |
29
|
|
|
|
|
|
|
#sort_code => [], |
30
|
|
|
|
|
|
|
); |
31
|
0
|
|
|
|
|
|
my %ARGS = (@DEFAULT_ARGS, @PASSED_ARGS); |
32
|
0
|
0
|
|
|
|
|
unless($ARGS{cookie_name}) { |
33
|
0
|
0
|
0
|
|
|
|
if($0 && $0 =~ m@.+/(.+)$@) { |
34
|
0
|
|
|
|
|
|
$ARGS{cookie_name} = "rh_$1"; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
|
$ARGS{cookie_name} = "results_helper"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
my $self = bless \%ARGS, $type; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $prefs_defaults = { |
42
|
|
|
|
|
|
|
at_a_time => 25, |
43
|
|
|
|
|
|
|
start_number => 1, |
44
|
|
|
|
|
|
|
sort_column => 0, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
foreach my $key (qw(at_a_time start_number sort_column)) { |
48
|
0
|
0
|
|
|
|
|
if(exists $self->{prefs}{$key}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
next; |
50
|
|
|
|
|
|
|
} elsif(exists $self->form->{$key}) { |
51
|
0
|
|
|
|
|
|
$self->{prefs}{$key} = $self->form->{$key}; |
52
|
|
|
|
|
|
|
} elsif(exists $prefs_defaults->{$key}) { |
53
|
0
|
|
|
|
|
|
$self->{prefs}{$key} = $prefs_defaults->{$key}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub form { |
60
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
61
|
0
|
0
|
|
|
|
|
unless($self->{form}) { |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->{form} = {}; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
require CGI; |
66
|
0
|
|
|
|
|
|
my $q = CGI->new; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my %form = $q->Vars; |
69
|
0
|
|
|
|
|
|
foreach my $key (keys %form) { |
70
|
0
|
|
|
|
|
|
my $value = $form{$key}; |
71
|
0
|
0
|
|
|
|
|
if($value =~ /\0/) { |
72
|
0
|
|
|
|
|
|
$self->{form}{$key} = [split /\0/, $value]; |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
|
$self->{form}{$key} = $value; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
return $self->{form}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub generate_results_ref { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
unless($self->retrieve_results) { |
85
|
0
|
|
|
|
|
|
return {}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->_filter; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->cache_results; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
0
|
|
|
|
if ($self->{headers} && (ref($self->{headers}) eq 'ARRAY')) { |
93
|
0
|
|
|
|
|
|
unshift(@{$self->{results}},$self->{headers}); |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->{results_ref} = { |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->generate_toc_ref; |
100
|
0
|
|
|
|
|
|
$self->generate_show_cols_ref; |
101
|
0
|
|
|
|
|
|
$self->generate_header_ref; |
102
|
0
|
|
|
|
|
|
return $self->{results_ref}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub cache_results { |
106
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
107
|
0
|
0
|
|
|
|
|
if($self->set_cookie) { |
108
|
0
|
|
|
|
|
|
require File::CacheDir; |
109
|
0
|
|
|
|
|
|
my $cookie_name = $self->cookie_name; |
110
|
0
|
|
|
|
|
|
my $cache_dir = File::CacheDir->new({ |
111
|
|
|
|
|
|
|
filename => $self->cookie_filename, |
112
|
|
|
|
|
|
|
ttl => $self->cookie_ttl, |
113
|
|
|
|
|
|
|
base_dir => $self->base_dir, |
114
|
|
|
|
|
|
|
cookie_name => $cookie_name, |
115
|
|
|
|
|
|
|
cookie_brick_over => $self->cookie_brick_over, |
116
|
|
|
|
|
|
|
set_cookie => 1, |
117
|
|
|
|
|
|
|
}); |
118
|
0
|
0
|
|
|
|
|
$cache_dir->{content_typed} = $ENV{CONTENT_TYPED} if($ENV{CONTENT_TYPED}); |
119
|
0
|
|
|
|
|
|
my $filename = $cache_dir->cache_dir; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
$self->store($self->{results}, $filename) || $self->my_die("store to $filename failed"); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub store { |
126
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
127
|
0
|
|
|
|
|
|
require Storable; |
128
|
0
|
|
|
|
|
|
return Storable::store(@_); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub retrieve { |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
133
|
0
|
|
|
|
|
|
require Storable; |
134
|
0
|
|
|
|
|
|
return Storable::retrieve(@_); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub my_die { |
138
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
139
|
0
|
|
|
|
|
|
die "@_"; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub generate_show_cols_ref { |
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
145
|
0
|
|
|
|
|
|
for(my $i=0;$i<@{$self->{results}->[0]};$i++) { |
|
0
|
|
|
|
|
|
|
146
|
0
|
|
0
|
|
|
|
$ref->{"$self->{prefix}_show_cols"} ||= []; |
147
|
0
|
0
|
|
|
|
|
if($self->{results}[0][$i]) { |
148
|
0
|
|
|
|
|
|
push @{$ref->{"$self->{prefix}_show_cols"}}, $i; |
|
0
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub second_page { |
154
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
155
|
0
|
0
|
|
|
|
|
return ($self->get_pages > 1) ? 1 : 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub generate_toc_ref { |
159
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
0
|
|
|
|
return if(!$self->second_page && $self->smart_second_page_toc); |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
164
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_low"} = $self->low; |
165
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_high"} = $self->high; |
166
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_rows"} = $self->rows; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_page_text"} = []; |
169
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_page_href"} = []; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my $more_form_tack_on_string = $self->more_form_tack_on_string; |
172
|
0
|
|
|
|
|
|
my $script_name = $self->script_name; |
173
|
0
|
|
|
|
|
|
my $href = "$script_name?start_number=-start-$more_form_tack_on_string"; |
174
|
0
|
|
|
|
|
|
my $start; |
175
|
0
|
|
|
|
|
|
for(my $i=1;$i<=$self->get_pages($self->rows);$i++) { |
176
|
0
|
0
|
0
|
|
|
|
last if($self->toc_limit && $i > $self->toc_limit); |
177
|
0
|
|
|
|
|
|
$start = 1 + $self->{prefs}{at_a_time} * ($i - 1); |
178
|
0
|
|
|
|
|
|
my $tmp_href = $href; |
179
|
0
|
|
|
|
|
|
$tmp_href =~ s/-start-/$start/; |
180
|
0
|
|
|
|
|
|
push @{$ref->{$self->{prefix} . "_toc_page_text"}}, $i; |
|
0
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
push @{$ref->{$self->{prefix} . "_toc_page_href"}}, $tmp_href; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_back_text"} = $self->back_text; |
185
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_next_text"} = $self->next_text; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$self->link_current_page; |
188
|
0
|
|
|
|
|
|
$self->link_back_button($href); |
189
|
0
|
|
|
|
|
|
$self->link_next_button($href); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub link_current_page { |
193
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
194
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $temp_page = int($self->{prefs}{start_number}/$self->{prefs}{at_a_time}) + 1; |
197
|
0
|
|
|
|
|
|
my $temp_start_number = ($temp_page - 1) * $self->{prefs}{at_a_time} + 1; |
198
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_page_href"}[$temp_page - 1] = ''; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub link_back_button { |
202
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
203
|
0
|
|
|
|
|
|
my $href = shift; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
206
|
0
|
|
|
|
|
|
my $start = $self->{prefs}{start_number} - $self->{prefs}{at_a_time}; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
### if this is the first page, don't link the back button |
209
|
0
|
0
|
|
|
|
|
if($start < 1) { |
210
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_back_href"} = ''; |
211
|
|
|
|
|
|
|
} else { |
212
|
0
|
|
|
|
|
|
my $tmp_href = $href; |
213
|
0
|
|
|
|
|
|
$tmp_href =~ s/-start-/$start/; |
214
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_back_href"} = $tmp_href; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub link_next_button { |
219
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
220
|
0
|
|
|
|
|
|
my $href = shift; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
223
|
0
|
|
|
|
|
|
my $start = $self->{prefs}{start_number} + $self->{prefs}{at_a_time}; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
### if this is the last page, don't link the next button |
226
|
0
|
0
|
|
|
|
|
if($start > $self->rows) { |
227
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_next_href"} = ''; |
228
|
|
|
|
|
|
|
} else { |
229
|
0
|
|
|
|
|
|
my $tmp_href = $href; |
230
|
0
|
|
|
|
|
|
$tmp_href =~ s/-start-/$start/; |
231
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_toc_next_href"} = $tmp_href; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub script_name { |
236
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
237
|
0
|
0
|
|
|
|
|
unless($self->{script_name}) { |
238
|
0
|
|
0
|
|
|
|
$ENV{HTTP_HOST} ||= ""; |
239
|
0
|
|
0
|
|
|
|
$ENV{SCRIPT_NAME} ||= ""; |
240
|
0
|
|
0
|
|
|
|
$ENV{PATH_INFO} ||= ""; |
241
|
0
|
|
|
|
|
|
$self->{script_name} = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}$ENV{PATH_INFO}"; |
242
|
|
|
|
|
|
|
} |
243
|
0
|
|
|
|
|
|
return $self->{script_name}; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub generate_header_ref { |
247
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
248
|
0
|
|
0
|
|
|
|
my $headers = shift || $self->{results}[0]; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $ref = $self->{results_ref}; |
251
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_header_text"} = []; |
252
|
0
|
|
|
|
|
|
$ref->{$self->{prefix} . "_header_href"} = []; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
### set up the passed along query_string |
255
|
0
|
|
|
|
|
|
my $form_tack_on_string = $self->get_form_tack_on_string; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
### do the table header row |
258
|
0
|
0
|
|
|
|
|
unless ($self->{no_header}){ |
259
|
|
|
|
|
|
|
|
260
|
0
|
0
|
|
|
|
|
my $add_sort_column = ($self->{prefs}->{sort_column} =~ /^-?\d+(,[,\-\d]+)/) ? $1 : ""; |
261
|
0
|
|
|
|
|
|
foreach my $i (@{$ref->{"$self->{prefix}_show_cols"}}) { |
|
0
|
|
|
|
|
|
|
262
|
0
|
0
|
|
|
|
|
next unless length($self->{results}[0][$i]); |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
# doing the toggle for the links |
265
|
0
|
|
|
|
|
|
my $link = $self->script_name . "?"; |
266
|
0
|
0
|
|
|
|
|
if(!exists $self->{prefs}{sort_column}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
$link .= "sort_column=$i$add_sort_column$form_tack_on_string"; |
268
|
|
|
|
|
|
|
} elsif($self->{prefs}->{sort_column} =~ /^\-$i\b/) { |
269
|
0
|
|
|
|
|
|
$link .= "sort_column=$i$add_sort_column$form_tack_on_string"; |
270
|
|
|
|
|
|
|
} elsif($self->{prefs}->{sort_column} =~ /^\b$i\b/) { |
271
|
0
|
|
|
|
|
|
$link .= "sort_column=-$i$add_sort_column$form_tack_on_string"; |
272
|
|
|
|
|
|
|
} else { |
273
|
0
|
|
|
|
|
|
$link .= "sort_column=$i$add_sort_column$form_tack_on_string"; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
push @{$ref->{$self->{prefix} . "_header_text"}}, $self->{results}[0][$i]; |
|
0
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
push @{$ref->{$self->{prefix} . "_header_href"}}, $link; |
|
0
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub AUTOLOAD { |
285
|
0
|
|
|
0
|
|
|
my $self = shift; |
286
|
0
|
|
|
|
|
|
my $return; |
287
|
0
|
0
|
|
|
|
|
if($AUTOLOAD =~ /.+::(.+)/) { |
288
|
0
|
|
|
|
|
|
my $method = $1; |
289
|
0
|
0
|
|
|
|
|
$return = $self->{$method} if(exists $self->{$method}); |
290
|
|
|
|
|
|
|
} |
291
|
0
|
|
|
|
|
|
return $return; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub _filter { |
295
|
0
|
|
|
0
|
|
|
my $self = shift; |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
### want to change sort_code to an array ref |
298
|
0
|
0
|
|
|
|
|
if(ref $self->{sort_code} eq 'HASH') { |
299
|
0
|
|
|
|
|
|
my $tmp = []; |
300
|
0
|
|
|
|
|
|
foreach(sort keys %{$self->{sort_code}}) { |
|
0
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
$tmp->[$_] = $self->{sort_code}->{$_}; |
302
|
|
|
|
|
|
|
} |
303
|
0
|
|
|
|
|
|
$self->{sort_code} = $tmp; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
my $rows = $self->rows; |
307
|
0
|
0
|
0
|
|
|
|
if(( exists $self->{prefs}{sort_column}) && $self->{prefs}{sort_column} =~ /^[0-9,\-]+$/) { |
308
|
|
|
|
|
|
|
# the 1 signifies there is a header row |
309
|
0
|
|
|
|
|
|
require Sort::ArrayOfArrays; |
310
|
0
|
|
|
|
|
|
$self->{results} = Sort::ArrayOfArrays::sort_it($self->{results}, $self->{prefs}->{sort_column}, $self->{sort_code}, 1); |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub retrieve_results { |
315
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
316
|
|
|
|
|
|
|
|
317
|
0
|
0
|
0
|
|
|
|
return $self->{results} if defined($self->{results}) && ref($self->{results}) && $#{ $self->{results} } > -1; |
|
0
|
|
0
|
|
|
|
|
318
|
|
|
|
|
|
|
|
319
|
0
|
|
|
|
|
|
require CGI; |
320
|
0
|
|
|
|
|
|
my $cookie_name = $self->cookie_name; |
321
|
0
|
|
|
|
|
|
my $cookie_value = CGI::cookie($cookie_name); |
322
|
0
|
|
0
|
|
|
|
my $filename = $cookie_value || ""; |
323
|
0
|
0
|
|
|
|
|
$filename = $self->base_dir . $filename unless ($filename =~ /^$self->{base_dir}/); |
324
|
0
|
0
|
0
|
|
|
|
if( $filename && -f $filename ) { |
|
|
0
|
|
|
|
|
|
325
|
0
|
|
|
|
|
|
$self->{results} = $self->retrieve($filename); |
326
|
|
|
|
|
|
|
}elsif( $self->can('generate_results') ) { |
327
|
0
|
|
|
|
|
|
$self->generate_results; |
328
|
|
|
|
|
|
|
}else{ |
329
|
0
|
|
|
|
|
|
return ""; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
return $self->{results}; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub rows { |
336
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
### need to subtract 1 since the zeroth row is the header information |
339
|
0
|
|
|
|
|
|
return @{$self->{results}} - 1; |
|
0
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub get_pages { |
343
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
344
|
0
|
|
0
|
|
|
|
my $rows = shift || $self->rows; |
345
|
0
|
|
|
|
|
|
my $pages = int($rows / $self->{prefs}->{at_a_time}) + 1; |
346
|
0
|
0
|
|
|
|
|
$pages-- unless($rows % $self->{prefs}->{at_a_time}); |
347
|
0
|
|
|
|
|
|
return $pages; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub low { |
351
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
352
|
0
|
|
|
|
|
|
return $self->{prefs}{start_number}; |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub high { |
356
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
357
|
0
|
|
0
|
|
|
|
my $rows = shift || $self->rows; |
358
|
0
|
0
|
|
|
|
|
return ($self->{prefs}->{start_number} + $self->{prefs}->{at_a_time} - 1 > $rows) |
359
|
|
|
|
|
|
|
? $rows : $self->{prefs}->{start_number} + $self->{prefs}->{at_a_time} - 1; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
sub get_values { |
363
|
0
|
|
|
0
|
0
|
|
my $values=shift; |
364
|
0
|
0
|
|
|
|
|
return () unless defined $values; |
365
|
0
|
0
|
|
|
|
|
if (ref $values eq "ARRAY") { |
366
|
0
|
|
|
|
|
|
return @$values; |
367
|
|
|
|
|
|
|
} |
368
|
0
|
|
|
|
|
|
return ($values); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub get_form_tack_on_string { |
372
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
373
|
0
|
|
|
|
|
|
my $form_tack_on_string = ''; |
374
|
0
|
|
|
|
|
|
my %hash = (%{$self->form}, %{$self->{prefs}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
375
|
0
|
|
|
|
|
|
while(my ($key, $value) = each %hash) { |
376
|
0
|
0
|
0
|
|
|
|
next if(!$value || $key eq 'sort_column' || $key eq 'start_number'); |
|
|
|
0
|
|
|
|
|
377
|
0
|
|
|
|
|
|
foreach(get_values($value)) { |
378
|
0
|
|
|
|
|
|
$form_tack_on_string .= "&" . URLEncode($key) . "=" . URLEncode($_); |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
0
|
|
|
|
|
|
return $form_tack_on_string; |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub more_form_tack_on_string { |
385
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
386
|
0
|
|
0
|
|
|
|
my $more_form_tack_on_string = $self->get_form_tack_on_string || ""; |
387
|
0
|
|
|
|
|
|
foreach (qw(sort_column) ){ |
388
|
0
|
0
|
|
|
|
|
$more_form_tack_on_string .= "&$_=$self->{prefs}->{$_}" if(exists $self->{prefs}{$_}); |
389
|
|
|
|
|
|
|
} |
390
|
0
|
|
|
|
|
|
return $more_form_tack_on_string; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
sub URLEncode { |
394
|
0
|
|
|
0
|
0
|
|
my $arg = shift; |
395
|
0
|
0
|
|
|
|
|
my ($ref,$return) = ref($arg) ? ($arg,0) : (\$arg,1) ; |
396
|
|
|
|
|
|
|
|
397
|
0
|
0
|
|
|
|
|
if (defined $$ref) { |
398
|
0
|
|
|
|
|
|
$$ref =~ s/([^\w\.\-\ \@\/\:])/sprintf("%%%02X",ord($1))/eg; |
|
0
|
|
|
|
|
|
|
399
|
0
|
|
|
|
|
|
$$ref =~ y/\ /+/; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
0
|
0
|
|
|
|
|
return $return ? $$ref : ''; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
sub URLDecode { |
406
|
0
|
|
|
0
|
0
|
|
my $arg = shift; |
407
|
0
|
0
|
|
|
|
|
my ($ref,$return) = ref($arg) ? ($arg,0) : (\$arg,1) ; |
408
|
|
|
|
|
|
|
|
409
|
0
|
0
|
|
|
|
|
if (defined $$ref) { |
410
|
0
|
|
|
|
|
|
$$ref =~ y/+/ /; |
411
|
0
|
|
|
|
|
|
$$ref =~ s/%([a-f0-9]{2})/chr hex $1/eig; |
|
0
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
0
|
0
|
|
|
|
|
return $return ? $$ref : ''; |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
sub to_char { |
418
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
419
|
0
|
|
|
|
|
|
my ($time, $format, $localtime) = @_; |
420
|
0
|
0
|
0
|
|
|
|
return "" unless($time && length $time); |
421
|
0
|
|
|
|
|
|
my @array; |
422
|
0
|
0
|
|
|
|
|
if($localtime) { |
423
|
0
|
|
|
|
|
|
@array = localtime($time); |
424
|
|
|
|
|
|
|
} else { |
425
|
0
|
|
|
|
|
|
@array = gmtime($time); |
426
|
|
|
|
|
|
|
} |
427
|
0
|
|
|
|
|
|
my @mm = qw(01 02 03 04 05 06 07 08 09 10 11 12); |
428
|
0
|
|
|
|
|
|
my @mon = qw(jan feb mar apr may jun jul aug sep oct nov dec); |
429
|
0
|
|
|
|
|
|
my @Mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
430
|
0
|
|
|
|
|
|
my @month = qw(January February March April May June July August September October November December); |
431
|
0
|
|
|
|
|
|
my @wday = qw(SUN MON TUE WED THU FRI SAT); |
432
|
0
|
|
|
|
|
|
my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); |
433
|
0
|
|
|
|
|
|
my @short_weekday = qw(Sun Mon Tue Wed Thu Fri Sat); |
434
|
0
|
|
|
|
|
|
$format =~ s/\bd\b|\bday\b/$array[3]/ige; |
|
0
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
|
$format =~ s/dd/sprintf "%02u", $array[3]/ige; |
|
0
|
|
|
|
|
|
|
436
|
0
|
|
|
|
|
|
$format =~ s/mm/$mm[$array[4]]/ige; |
|
0
|
|
|
|
|
|
|
437
|
0
|
|
|
|
|
|
$format =~ s/\bmon\b/$mon[$array[4]]/ge; |
|
0
|
|
|
|
|
|
|
438
|
0
|
|
|
|
|
|
$format =~ s/\bMon\b/$Mon[$array[4]]/ge; |
|
0
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
|
$format =~ s/\bmonth\b/$month[$array[4]]/ige; |
|
0
|
|
|
|
|
|
|
440
|
0
|
|
|
|
|
|
$format =~ s/yyyy/$array[5]+1900/ige; |
|
0
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
|
$format =~ s/\byy\b/substr($array[5], 1, 2)/ige; |
|
0
|
|
|
|
|
|
|
442
|
0
|
|
|
|
|
|
$format =~ s/\bhour\b|\bhr\b|\bh\b|\bhh24\b/sprintf "%02u", $array[2]/ige; |
|
0
|
|
|
|
|
|
|
443
|
0
|
|
|
|
|
|
$format =~ s/\b12hour\b|\b12hr\b|\b12h\b/get_12hour($array[2])/ige; |
|
0
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
|
$format =~ s/\bhour\b|\bhr\b|\bh\b/$array[2]/ige; |
|
0
|
|
|
|
|
|
|
445
|
0
|
|
|
|
|
|
$format =~ s/\bminute\b|\bmin\b|\bm\b/sprintf "%02u", $array[1]/ige; |
|
0
|
|
|
|
|
|
|
446
|
0
|
|
|
|
|
|
$format =~ s/\bsecond\b|\bsec\b|\bs\b|\bss\b/sprintf "%02u", $array[0]/ige; |
|
0
|
|
|
|
|
|
|
447
|
0
|
|
|
|
|
|
$format =~ s/\bwdy\b/$weekday[$array[6]]/ige; |
|
0
|
|
|
|
|
|
|
448
|
0
|
|
|
|
|
|
$format =~ s/\bwd\b/$short_weekday[$array[6]]/ige; |
|
0
|
|
|
|
|
|
|
449
|
0
|
|
|
|
|
|
$format =~ s/\bdy\b/$wday[$array[6]]/ige; |
|
0
|
|
|
|
|
|
|
450
|
0
|
|
|
|
|
|
return $format; |
451
|
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
1; |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
__END__ |