| 4 |
- |
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/:standard escape/;
|
|
|
6 |
use scanFunctions;
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
my $pageTitle = "CC Coffees";
|
|
|
10 |
my $prefscookie = "CCCoffeesPrefs";
|
|
|
11 |
our $DBTABLE = 'v_coffees';
|
|
|
12 |
my %COLUMNS = (
|
|
|
13 |
roaster => [qw(Roaster 05 text)],
|
|
|
14 |
coffee => [qw(Coffee 10 text)],
|
|
|
15 |
region => [qw(Region 15 text)],
|
|
|
16 |
source => [qw(Source 20 select)],
|
|
|
17 |
url => [qw(URL 25 text)],
|
|
|
18 |
rating => [qw(Rating 30 number)],
|
|
|
19 |
location => [qw(Location 35 text)],
|
|
|
20 |
notes => [qw(Notes 40 text)]
|
|
|
21 |
);
|
|
|
22 |
our @defaultFields = (qw(roaster coffee region rating));
|
|
|
23 |
my $stylesheet = "style.css";
|
|
|
24 |
|
|
|
25 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
26 |
# It will recieve a hashref to the object lineitem
|
|
|
27 |
|
|
|
28 |
sub modify_roaster {
|
|
|
29 |
# Turn it into a link to the manage_roaster.pl page
|
|
|
30 |
my $lineItem = shift;
|
|
|
31 |
my $rster = escape ($lineItem->{'roaster'});
|
|
|
32 |
return a ({-href=>"/manage_roaster.pl?roaster=$rster"}, $lineItem->{'roaster'});
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
sub modify_url {
|
|
|
36 |
# Make the URL an actual link
|
|
|
37 |
my $lineItem = shift;
|
|
|
38 |
return a ({-href=>$lineItem->{'url'}, -target=>"_blank"}, $lineItem->{'url'});
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
# Ideally, nothing below this comment needs to change
|
|
|
45 |
#-------------------------------------------------------------------------------
|
|
|
46 |
|
|
|
47 |
our %NAME = map { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
|
|
|
48 |
our %colOrderHash = map { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
|
|
|
49 |
our %colFilterTypeHash = map { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
|
|
|
50 |
|
|
|
51 |
our @allFields = sort byfield keys %NAME;
|
|
|
52 |
our @displayFields = ();
|
|
|
53 |
our @hideFields = ();
|
|
|
54 |
my $QUERY_STRING;
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
our %FORM;
|
|
|
58 |
foreach (param())
|
|
|
59 |
{
|
|
|
60 |
$FORM{$_} = param($_); # Retrieve all of the FORM data submitted
|
|
|
61 |
|
|
|
62 |
if ((/^filter/) and ($FORM{$_} ne '')) # Build a set of filters to apply
|
|
|
63 |
{
|
|
|
64 |
my ($filter,$field) = split /-/, $_;
|
|
|
65 |
|
|
|
66 |
$FILTER->{$field} = $FORM{$_};
|
|
|
67 |
}
|
|
|
68 |
elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
69 |
{ push @displayFields, $_; }
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
if (exists $FORM{autoload}) # If the FORM was submitted (i.e. the page is being redisplayed),
|
|
|
74 |
{ # build the data for the cookie that remembers the page setup
|
|
|
75 |
my $disFields = join ":", @displayFields;
|
|
|
76 |
my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
|
|
|
77 |
|
|
|
78 |
$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{autoload};
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
if (!(exists $FORM{autoload})) # No FORM was submitted...
|
|
|
83 |
{
|
|
|
84 |
if (my $prefs = cookie($prefscookie)) # Check for cookies from previous visits.
|
|
|
85 |
{
|
|
|
86 |
my ($disF, $filts, $al) = split /&/,$prefs;
|
|
|
87 |
@displayFields = split /:/,$disF;
|
|
|
88 |
|
|
|
89 |
foreach $pair (split /:/, $filts)
|
|
|
90 |
{
|
|
|
91 |
my ($key, $value) = split /=/, $pair;
|
|
|
92 |
$FORM{"filter-$key"} = $value;
|
|
|
93 |
$FILTER->{$key} = $value;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
$FORM{autoload} = $al;
|
|
|
97 |
$QUERY_STRING = $prefs;
|
|
|
98 |
}
|
|
|
99 |
else # Otherwise suppply a default list of columns.
|
|
|
100 |
{ @displayFields = @defaultFields; }
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
# let's just make sure the columns are in the right order
|
|
|
104 |
@displayFields = sort byfield @displayFields;
|
|
|
105 |
|
|
|
106 |
# If the field isn't in the displayFields list, then add it to the hideFields list
|
|
|
107 |
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
|
|
|
108 |
|
|
|
109 |
# Process any filters provided in the form to pass to the database
|
|
|
110 |
my @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
|
|
|
111 |
|
|
|
112 |
# Given the fields to display and the where conditions,
|
|
|
113 |
# "getData" will return a reference to an array of
|
|
|
114 |
# hash references of the results.
|
|
|
115 |
my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE) };
|
|
|
116 |
my $x = scalar @ProductList; # How many results were returned?
|
|
|
117 |
|
|
|
118 |
# Set some cookie stuff...
|
|
|
119 |
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
|
|
|
120 |
my $queryCookie = cookie(-NAME=>$prefscookie,
|
|
|
121 |
-VALUE=>"$QUERY_STRING",
|
|
|
122 |
-PATH=>"$path",
|
|
|
123 |
-EXPIRES=>'+365d');
|
|
|
124 |
|
|
|
125 |
print header (-cookie=> [$queryCookie] );
|
|
|
126 |
|
|
|
127 |
# print "<!-- FORM \n\n"; # Debug code to dump the FORM to a html comment
|
|
|
128 |
# print "I'm catching updates!!!\n\n";
|
|
|
129 |
# foreach $key (sort (keys %FORM)) # Must be done after the header is written!
|
|
|
130 |
# { print "\t$key: $FORM{$key}\n"; }
|
|
|
131 |
# print "--> \n\n";
|
|
|
132 |
#
|
|
|
133 |
#
|
|
|
134 |
# print "<!-- ENV \n\n"; # Debug code to dump the ENV to a html comment
|
|
|
135 |
# foreach $key (sort (keys %ENV)) # Must be done after the header is written!
|
|
|
136 |
# { print "\t$key: $ENV{$key}\n"; }
|
|
|
137 |
# print "--> \n\n";
|
|
|
138 |
#
|
|
|
139 |
# print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
#------------------
|
|
|
143 |
|
|
|
144 |
our ($onClick, $onChange);
|
|
|
145 |
if ($FORM{autoload}) # Toggle the autoload fields within the table elements
|
|
|
146 |
{ $onClick = "onClick='submit();'";
|
|
|
147 |
$onChange = "onChange='submit();'"; }
|
|
|
148 |
else
|
|
|
149 |
{ $onClick = "";
|
|
|
150 |
$onChange = ""; }
|
|
|
151 |
|
|
|
152 |
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
|
|
|
153 |
print start_form (-action => url (), -method => "POST", -name => "Req");
|
|
|
154 |
|
|
|
155 |
print<<header;
|
|
|
156 |
<TABLE>
|
|
|
157 |
<TR>
|
|
|
158 |
<TD>
|
|
|
159 |
<TABLE>
|
|
|
160 |
<TR>
|
|
|
161 |
<TD width=610 class="accent" height=60>
|
|
|
162 |
header
|
|
|
163 |
print h1 (' ', $pageTitle);
|
|
|
164 |
print<<headercont;
|
|
|
165 |
</TD>
|
|
|
166 |
<TD><img SRC="/images/headerblank.gif" NOSAVE height=38 width=165></TD>
|
|
|
167 |
</TR>
|
|
|
168 |
</TABLE>
|
|
|
169 |
</TD>
|
|
|
170 |
<TR>
|
|
|
171 |
<TD> </TD>
|
|
|
172 |
</TR>
|
|
|
173 |
<TR>
|
|
|
174 |
<TD>
|
|
|
175 |
<TABLE>
|
|
|
176 |
<TR>
|
|
|
177 |
<TD rowspan=2 align=left width=610>
|
|
|
178 |
<TABLE>
|
|
|
179 |
headercont
|
|
|
180 |
|
|
|
181 |
# Print the Hidden fields' check boxes
|
|
|
182 |
|
|
|
183 |
my $tc = 1;
|
|
|
184 |
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields)
|
|
|
185 |
{
|
|
|
186 |
if ($tc == 1)
|
|
|
187 |
{print "\t\t\t\t\t\t<TR>\n\t\t\t\t\t\t\t<TD width=25% nowrap><FONT size=1><b><INPUT type=checkbox name=$field value=true $onClick class=accent>$NAME{$field}</TD>\n"; $tc++;}
|
|
|
188 |
elsif ($tc == 4)
|
|
|
189 |
{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT size=1><b><INPUT type=checkbox name=$field value=true $onClick class=accent>$NAME{$field}</TD>\n\t\t\t\t\t\t</TR>\n"; $tc=1;}
|
|
|
190 |
else
|
|
|
191 |
{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT size=1><b><INPUT type=checkbox name=$field value=true $onClick class=accent>$NAME{$field}</TD>\n"; $tc++;}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
if ($FORM{autoload})
|
|
|
195 |
{
|
|
|
196 |
$trueChecked = "checked";
|
|
|
197 |
$falseChecked = "";
|
|
|
198 |
}
|
|
|
199 |
else
|
|
|
200 |
{
|
|
|
201 |
$trueChecked = "";
|
|
|
202 |
$falseChecked = "checked";
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
print<<header3;
|
|
|
206 |
<TR>
|
|
|
207 |
<TD colspan=4 align=center><FONT size=1 color=saddlebrown><B>
|
|
|
208 |
Autoload: <INPUT type=radio name=autoload value=1 onClick='Req.submit();' $trueChecked class=accent>On <INPUT type=radio name=autoload value=0 onClick='Req.submit();' $falseChecked class=accent>Off
|
|
|
209 |
</TD>
|
|
|
210 |
</TR>
|
|
|
211 |
</TABLE>
|
|
|
212 |
</TD>
|
|
|
213 |
<TD nowrap>
|
|
|
214 |
<A HREF='' onClick="window.document.Req.submit(); return false;"><IMG SRC='/images/refresh.button.gif' border=0></A><br>
|
|
|
215 |
</TD>
|
|
|
216 |
</TR>
|
|
|
217 |
<TR>
|
|
|
218 |
<TD align=left><B><FONT size=1><br>
|
|
|
219 |
Display <A HREF='' onClick="window.document.Req.method = 'GET'; window.document.Req.submit(); return false;">Full URL</a> : <a href=/>[Go HOME]</a></TD>
|
|
|
220 |
</TR>
|
|
|
221 |
|
|
|
222 |
</TABLE>
|
|
|
223 |
</TD>
|
|
|
224 |
</TR>
|
|
|
225 |
<TR>
|
|
|
226 |
<TD> </TD>
|
|
|
227 |
</TR>
|
|
|
228 |
<TR>
|
|
|
229 |
<TD>
|
|
|
230 |
<TABLE cellspacing=2 cellpadding=4 width=100\%>
|
|
|
231 |
<TR>
|
|
|
232 |
header3
|
|
|
233 |
|
|
|
234 |
# Print the Column headings
|
|
|
235 |
foreach $f (@displayFields)
|
|
|
236 |
{ print "\t\t\t\t\t<TH><INPUT type=checkbox name=$f value=true checked $onClick class=accent>$NAME{$f}</TH>\n"; }
|
|
|
237 |
|
|
|
238 |
print "\t\t\t\t</TR>\n\t\t\t\t<TR>\n";
|
|
|
239 |
# and now the filter boxes
|
|
|
240 |
|
|
|
241 |
foreach $f (@displayFields)
|
|
|
242 |
{
|
|
|
243 |
print "\t\t\t\t\t<TD align=left bgcolor=#E6E6E6><FONT size=1>";
|
|
|
244 |
print filter ($f);
|
|
|
245 |
# print " ";
|
|
|
246 |
print "</TD>\n";
|
|
|
247 |
}
|
|
|
248 |
print "\t\t\t\t</TR>\n";
|
|
|
249 |
print end_form ();
|
|
|
250 |
|
|
|
251 |
my $cw = scalar @displayFields;
|
|
|
252 |
|
|
|
253 |
print<<header2;
|
|
|
254 |
</TR>
|
|
|
255 |
<TR>
|
|
|
256 |
<TD colspan=$cw></TD>
|
|
|
257 |
</TR>
|
|
|
258 |
header2
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
my $co = '#FFFFFF';
|
|
|
262 |
|
|
|
263 |
foreach $t (@ProductList) # Unt now we print the tickets!
|
|
|
264 |
{
|
|
|
265 |
print "\t\t\t\t<TR>\n";
|
|
|
266 |
foreach $f (@displayFields)
|
|
|
267 |
{
|
|
|
268 |
if (exists &{"modify_".$f}) {
|
|
|
269 |
$t->{$f} = &{"modify_".$f} ($t);
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
print "\t\t\t\t\t<TD align=left valign=top bgcolor='$co'><FONT size=1>".$t->{$f}." </TD>\n";
|
|
|
273 |
}
|
|
|
274 |
print "\t\t\t\t</TR>\n";
|
|
|
275 |
|
|
|
276 |
if ($co eq '#FFFFFF')
|
|
|
277 |
{ $co = '#F9F9F9'; }
|
|
|
278 |
else
|
|
|
279 |
{ $co = '#FFFFFF'; }
|
|
|
280 |
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
print<<tail;
|
|
|
284 |
</TABLE>
|
|
|
285 |
</TD>
|
|
|
286 |
</TR>
|
|
|
287 |
</TABLE>
|
|
|
288 |
<br><br>
|
|
|
289 |
<FONT size=2><B>$x Record(s) Displayed</font>
|
|
|
290 |
<BR><BR>
|
|
|
291 |
<FONT size=1><B>This page was displayed on $now<BR>
|
|
|
292 |
Please direct questions, problems, and concerns to <FONT color=saddlebrown>noone\@gmail.com</FONT>
|
|
|
293 |
|
|
|
294 |
<SCRIPT language="JavaScript">
|
|
|
295 |
<!--
|
|
|
296 |
|
|
|
297 |
var ticket_window, severity_window, user_window;
|
|
|
298 |
|
|
|
299 |
function NewWindow () {
|
|
|
300 |
if ((ticket_window == null) || (ticket_window.closed == true))
|
|
|
301 |
ticket_window = open(\"\",\"Details\",\"width=650,height=650,menubar,scrollbars,resizable\");
|
|
|
302 |
ticket_window.focus();
|
|
|
303 |
return true;
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
function SevWindow () {
|
|
|
307 |
if ((severity_window == null) || (severity_window.closed == true))
|
|
|
308 |
severity_window = open(\"\",\"SevDetails\",\"width=500,height=300,menubar\");
|
|
|
309 |
severity_window.focus();
|
|
|
310 |
return true;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
function UserWindow () {
|
|
|
314 |
if ((user_window == null) || (user_window.closed == true))
|
|
|
315 |
user_window = open(\"\",\"UserDetails\",\"width=310,height=115,menubar\");
|
|
|
316 |
user_window.focus();
|
|
|
317 |
return true;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
//-->
|
|
|
321 |
</SCRIPT>
|
|
|
322 |
|
|
|
323 |
tail
|
|
|
324 |
|
|
|
325 |
print end_html;
|