| 7 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
4 |
|
|
|
5 |
use CGI qw/param cookie header start_html url/;
|
|
|
6 |
use HTML::Tiny;
|
|
|
7 |
use scanFunctions;
|
|
|
8 |
our $h = HTML::Tiny->new( mode => 'html' );
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
my $pageTitle = "CC Roasters";
|
|
|
12 |
my $prefscookie = "CCRoastersPrefs";
|
|
|
13 |
our $DBTABLE = 'roasters';
|
|
|
14 |
my %COLUMNS = (
|
|
|
15 |
roaster => [qw(Roaster 5 text static)],
|
|
|
16 |
url => [qw(URL 10 text default)],
|
|
|
17 |
location => [qw(Location 15 text default)],
|
|
|
18 |
note => [qw(Notes 20 text)]
|
|
|
19 |
);
|
|
|
20 |
my $stylesheet = "style.css";
|
|
|
21 |
my $homeURL = '/';
|
|
|
22 |
|
|
|
23 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
24 |
# It will recieve a hashref to the object lineitem
|
|
|
25 |
|
|
|
26 |
sub modify_roaster {
|
|
|
27 |
# Turn it into a link to the manage_roaster.pl page
|
|
|
28 |
my $lineItem = shift;
|
|
|
29 |
my $rster = $h->url_encode ($lineItem->{'roaster'});
|
|
|
30 |
return $h->a ({ href=>"/manage_roaster.pl?roaster=$rster" }, $lineItem->{'roaster'});
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
sub modify_url {
|
|
|
34 |
# Make the URL an actual link
|
|
|
35 |
my $lineItem = shift;
|
|
|
36 |
return $h->a ({ href=>$lineItem->{'url'}, -target=>"_blank" }, $lineItem->{'url'});
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
# Ideally, nothing below this comment needs to change
|
|
|
43 |
#-------------------------------------------------------------------------------
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
our %NAME = map { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
|
|
|
47 |
our %colOrderHash = map { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
|
|
|
48 |
our %colFilterTypeHash = map { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
|
|
|
49 |
our @staticFields = grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
|
|
|
50 |
our @defaultFields = grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
|
|
|
51 |
#our @defaultFields = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
|
|
|
52 |
|
|
|
53 |
our @allFields = sort byfield keys %NAME;
|
|
|
54 |
our @displayFields = ();
|
|
|
55 |
our @hideFields = ();
|
|
|
56 |
my $QUERY_STRING;
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
our %FORM;
|
|
|
60 |
foreach (param()) {
|
|
|
61 |
$FORM{$_} = param($_); # Retrieve all of the FORM data submitted
|
|
|
62 |
|
|
|
63 |
if ((/^filter/) and ($FORM{$_} ne '')) { # Build a set of filters to apply
|
|
|
64 |
my ($filter,$field) = split /-/, $_;
|
|
|
65 |
$FILTER->{$field} = $FORM{$_};
|
|
|
66 |
} elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
67 |
{ push @displayFields, $_; }
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
if (exists $FORM{autoload}) { # If the FORM was submitted (i.e. the page is being redisplayed),
|
|
|
72 |
# build the data for the cookie that remembers the page setup
|
|
|
73 |
my $disFields = join ":", @displayFields;
|
|
|
74 |
my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
|
|
|
75 |
|
|
|
76 |
$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{autoload};
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
if (!(exists $FORM{autoload})) { # No FORM was submitted...
|
|
|
81 |
if (my $prefs = cookie($prefscookie)) { # Check for cookies from previous visits.
|
|
|
82 |
my ($disF, $filts, $al) = split /&/,$prefs;
|
|
|
83 |
@displayFields = split /:/,$disF;
|
|
|
84 |
|
|
|
85 |
foreach $pair (split /:/, $filts) {
|
|
|
86 |
my ($key, $value) = split /=/, $pair;
|
|
|
87 |
$FORM{"filter-$key"} = $value;
|
|
|
88 |
$FILTER->{$key} = $value;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
$FORM{autoload} = $al;
|
|
|
92 |
$QUERY_STRING = $prefs;
|
|
|
93 |
} else { @displayFields = @defaultFields; } # Otherwise suppply a default list of columns.
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
# let's just make sure the columns are in the right order (and there aren't any missing)
|
|
|
97 |
@displayFields = sort byfield uniq @displayFields, @staticFields;
|
|
|
98 |
|
|
|
99 |
# If the field isn't in the displayFields list, then add it to the hideFields list
|
|
|
100 |
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
|
|
|
101 |
|
|
|
102 |
# Process any filters provided in the form to pass to the database
|
|
|
103 |
my @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
|
|
|
104 |
|
|
|
105 |
# Given the fields to display and the where conditions,
|
|
|
106 |
# "getData" will return a reference to an array of
|
|
|
107 |
# hash references of the results.
|
|
|
108 |
my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE) };
|
|
|
109 |
my $x = scalar @ProductList; # How many results were returned?
|
|
|
110 |
|
|
|
111 |
# Set some cookie stuff...
|
|
|
112 |
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
|
|
|
113 |
my $queryCookie = cookie(-NAME=>$prefscookie,
|
|
|
114 |
-VALUE=>"$QUERY_STRING",
|
|
|
115 |
-PATH=>"$path",
|
|
|
116 |
-EXPIRES=>'+365d');
|
|
|
117 |
|
|
|
118 |
print header (-cookie=> [ $queryCookie ] );
|
|
|
119 |
|
|
|
120 |
# print "<!-- FORM \n\n"; # Debug code to dump the FORM to a html comment
|
|
|
121 |
# print "I'm catching updates!!!\n\n";
|
|
|
122 |
# foreach $key (sort (keys %FORM)) # Must be done after the header is written!
|
|
|
123 |
# { print "\t$key: $FORM{$key}\n"; }
|
|
|
124 |
# print "--> \n\n";
|
|
|
125 |
#
|
|
|
126 |
#
|
|
|
127 |
# print "<!-- ENV \n\n"; # Debug code to dump the ENV to a html comment
|
|
|
128 |
# foreach $key (sort (keys %ENV)) # Must be done after the header is written!
|
|
|
129 |
# { print "\t$key: $ENV{$key}\n"; }
|
|
|
130 |
# print "--> \n\n";
|
|
|
131 |
#
|
|
|
132 |
# print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
#------------------
|
|
|
136 |
|
|
|
137 |
# Toggle the autoload fields within the table elements
|
|
|
138 |
our ($onClick, $onChange); # (also used in scanFunctions)
|
|
|
139 |
my ($radiobutton, $refreshbutton);
|
|
|
140 |
if ($FORM{autoload}) {
|
|
|
141 |
$onClick = "onClick='submit();'";
|
|
|
142 |
$onChange = "onChange='submit();'";
|
|
|
143 |
$radiobutton = $h->div ({ class=>'autoload' },
|
|
|
144 |
["Autoload Changes: ",
|
|
|
145 |
$h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
|
|
|
146 |
$h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
|
|
|
147 |
]);
|
|
|
148 |
} else {
|
|
|
149 |
$onClick = "";
|
|
|
150 |
$onChange = "";
|
|
|
151 |
$radiobutton = $h->div ({ class=>'autoload' },
|
|
|
152 |
["Autoload Changes: ",
|
|
|
153 |
$h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ",
|
|
|
154 |
$h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
|
|
|
155 |
]);
|
|
|
156 |
$refreshbutton = $h->input ({ type=>"button", value=>"Apply Changes", onClick=>"submit(); return false;" });
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
|
|
|
161 |
|
|
|
162 |
# Print the header
|
|
|
163 |
|
|
|
164 |
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
|
|
|
165 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
166 |
$h->h1 ($pageTitle),
|
|
|
167 |
$h->div ({ class=>"sp0" }, [
|
|
|
168 |
$h->div ({ class=>"spLeft" }, [
|
|
|
169 |
$radiobutton
|
|
|
170 |
]),
|
|
|
171 |
$h->div ({ class=>"spRight" }, [
|
|
|
172 |
$h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
|
|
|
173 |
$refreshbutton
|
|
|
174 |
]),
|
|
|
175 |
]),
|
|
|
176 |
]);
|
|
|
177 |
|
|
|
178 |
# Print the Hidden fields' check boxes (if there are any)
|
|
|
179 |
|
|
|
180 |
my $c = 1;
|
|
|
181 |
my @hiddencheckboxes;
|
|
|
182 |
my @hiddenrows;
|
|
|
183 |
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
|
|
|
184 |
if ($FORM{autoload}) {
|
|
|
185 |
push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters', nowrap=>[], onClick=>"Req.$field.click();" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation(); submit();" }), $NAME{$field} ]);
|
|
|
186 |
} else {
|
|
|
187 |
push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters', nowrap=>[], onClick=>"Req.$field.checked=!Req.$field.checked;" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation();" }), $NAME{$field} ]);
|
|
|
188 |
}
|
|
|
189 |
if (! $c % 4) {
|
|
|
190 |
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
|
|
|
191 |
@hiddencheckboxes = [];
|
|
|
192 |
$c++;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless ! $c % 4;
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
if (scalar @hideFields) {
|
|
|
199 |
my @topleft;
|
|
|
200 |
push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
|
|
|
201 |
push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
|
|
|
202 |
|
|
|
203 |
print $h->div ({ class=>"sp0" }, [
|
|
|
204 |
$h->div ({ class=>"spLeft" }, [ @topleft ]),
|
|
|
205 |
$h->div ({ class=>"spRight" }, [
|
|
|
206 |
])
|
|
|
207 |
]);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
# Print the main table...............................................
|
|
|
211 |
|
|
|
212 |
print $h->open ('div', { class=>'rTable' });
|
|
|
213 |
|
|
|
214 |
my @tmptitlerow;
|
|
|
215 |
foreach $f (@displayFields) { # Print the Column headings
|
|
|
216 |
if (inArray ($f, \@staticFields)) {
|
|
|
217 |
push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
|
|
|
218 |
} else {
|
|
|
219 |
if ($FORM{autoload}) {
|
|
|
220 |
push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.click();" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>'event.stopPropagation(); submit();' }), $NAME{$f} ]);
|
|
|
221 |
} else {
|
|
|
222 |
push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.checked=!Req.$f.checked;" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>"event.stopPropagation();" }), $NAME{$f} ]);
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
my @tmpfilters;
|
|
|
228 |
foreach $f (@displayFields) { # and now the filter boxes
|
|
|
229 |
push @tmpfilters, $h->div ({ class=>'rTableCell filters' }, filter ($f) )
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ @tmpfilters ], $h->div ({ class=>"rTableCell" }));
|
|
|
233 |
|
|
|
234 |
foreach $t (@ProductList) { # Unt now we print the things!
|
|
|
235 |
my @tmprow;
|
|
|
236 |
foreach $f (@displayFields)
|
|
|
237 |
{
|
|
|
238 |
# Look to see if there's a function named modify_<fieldname>() defined for this field
|
|
|
239 |
if (exists &{"modify_".$f}) {
|
|
|
240 |
$t->{$f} = &{"modify_".$f} ($t);
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
push @tmprow, $h->div ({ class=>'rTableCell' }, $t->{$f});
|
|
|
244 |
}
|
|
|
245 |
print $h->div ({ class=>'rTableRow shaded' }, [ @tmprow ]);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
print $h->close ('div');
|
|
|
249 |
|
|
|
250 |
# close things out................................................
|
|
|
251 |
|
|
|
252 |
print $h->br; # print $h->br;
|
|
|
253 |
print $h->div ({ class=>"sp0" }, [
|
|
|
254 |
$h->div ({ class=>"spLeft" }, [
|
|
|
255 |
$h->div ({ class=>"footer" }, [
|
|
|
256 |
"To bookmark, save, or send this exact view, use the ",
|
|
|
257 |
$h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
|
|
|
258 |
$h->br,
|
|
|
259 |
"This page was displayed on $now",
|
|
|
260 |
$h->br,
|
|
|
261 |
"Please direct questions, problems, and concerns to noone\@gmail.com"
|
|
|
262 |
])
|
|
|
263 |
]),
|
|
|
264 |
$h->div ({ class=>"spRight" }, [
|
|
|
265 |
$h->h5 ("$x Record". ($x == 1 ? "" : "s") ." Displayed")
|
|
|
266 |
]),
|
|
|
267 |
]);
|
|
|
268 |
|
|
|
269 |
#print $h->br; # print $h->br;
|
|
|
270 |
#print $h->h5 ("$x Record(s) Displayed");
|
|
|
271 |
#print $h->div ({ class=>"footer" }, [
|
|
|
272 |
# "To bookmark, save, or send this exact view, use the ",
|
|
|
273 |
# $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
|
|
|
274 |
# $h->br,
|
|
|
275 |
# "This page was displayed on $now",
|
|
|
276 |
# $h->br,
|
|
|
277 |
# "Please direct questions, problems, and concerns to noone\@gmail.com"
|
|
|
278 |
#]);
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
print $h->close('form');
|
|
|
282 |
print $h->close('html');
|