Blame | Last modification | View Log | RSS feed
#!/usr/bin/perl#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }use CGI qw/:standard escape/;use scanFunctions;my $pageTitle = "CC Coffees";my $prefscookie = "CCCoffeesPrefs";our $DBTABLE = 'v_coffees';my %COLUMNS = (roaster => [qw(Roaster 05 text)],coffee => [qw(Coffee 10 text)],region => [qw(Region 15 text)],source => [qw(Source 20 select)],url => [qw(URL 25 text)],rating => [qw(Rating 30 number)],location => [qw(Location 35 text)],notes => [qw(Notes 40 text)]);our @defaultFields = (qw(roaster coffee region rating));my $stylesheet = "style.css";# If we need to modify line item values, create a subroutine named "modify_$columnname"# It will recieve a hashref to the object lineitemsub modify_roaster {# Turn it into a link to the manage_roaster.pl pagemy $lineItem = shift;my $rster = escape ($lineItem->{'roaster'});return a ({-href=>"/manage_roaster.pl?roaster=$rster"}, $lineItem->{'roaster'});}sub modify_url {# Make the URL an actual linkmy $lineItem = shift;return a ({-href=>$lineItem->{'url'}, -target=>"_blank"}, $lineItem->{'url'});}# Ideally, nothing below this comment needs to change#-------------------------------------------------------------------------------our %NAME = map { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;our %colOrderHash = map { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;our %colFilterTypeHash = map { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;our @allFields = sort byfield keys %NAME;our @displayFields = ();our @hideFields = ();my $QUERY_STRING;our %FORM;foreach (param()){$FORM{$_} = param($_); # Retrieve all of the FORM data submittedif ((/^filter/) and ($FORM{$_} ne '')) # Build a set of filters to apply{my ($filter,$field) = split /-/, $_;$FILTER->{$field} = $FORM{$_};}elsif ($FORM{$_} eq "true") # Compile list of fields to display{ push @displayFields, $_; }}if (exists $FORM{autoload}) # If the FORM was submitted (i.e. the page is being redisplayed),{ # build the data for the cookie that remembers the page setupmy $disFields = join ":", @displayFields;my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{autoload};}if (!(exists $FORM{autoload})) # No FORM was submitted...{if (my $prefs = cookie($prefscookie)) # Check for cookies from previous visits.{my ($disF, $filts, $al) = split /&/,$prefs;@displayFields = split /:/,$disF;foreach $pair (split /:/, $filts){my ($key, $value) = split /=/, $pair;$FORM{"filter-$key"} = $value;$FILTER->{$key} = $value;}$FORM{autoload} = $al;$QUERY_STRING = $prefs;}else # Otherwise suppply a default list of columns.{ @displayFields = @defaultFields; }}# let's just make sure the columns are in the right order@displayFields = sort byfield @displayFields;# If the field isn't in the displayFields list, then add it to the hideFields list@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;# Process any filters provided in the form to pass to the databasemy @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;# Given the fields to display and the where conditions,# "getData" will return a reference to an array of# hash references of the results.my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE) };my $x = scalar @ProductList; # How many results were returned?# Set some cookie stuff...my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";my $queryCookie = cookie(-NAME=>$prefscookie,-VALUE=>"$QUERY_STRING",-PATH=>"$path",-EXPIRES=>'+365d');print header (-cookie=> [$queryCookie] );# print "<!-- FORM \n\n"; # Debug code to dump the FORM to a html comment# print "I'm catching updates!!!\n\n";# foreach $key (sort (keys %FORM)) # Must be done after the header is written!# { print "\t$key: $FORM{$key}\n"; }# print "--> \n\n";### print "<!-- ENV \n\n"; # Debug code to dump the ENV to a html comment# foreach $key (sort (keys %ENV)) # Must be done after the header is written!# { print "\t$key: $ENV{$key}\n"; }# print "--> \n\n";## print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";#------------------our ($onClick, $onChange);if ($FORM{autoload}) # Toggle the autoload fields within the table elements{ $onClick = "onClick='submit();'";$onChange = "onChange='submit();'"; }else{ $onClick = "";$onChange = ""; }print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );print start_form (-action => url (), -method => "POST", -name => "Req");print<<header;<TABLE><TR><TD><TABLE><TR><TD width=610 class="accent" height=60>headerprint h1 (' ', $pageTitle);print<<headercont;</TD><TD><img SRC="/images/headerblank.gif" NOSAVE height=38 width=165></TD></TR></TABLE></TD><TR><TD> </TD></TR><TR><TD><TABLE><TR><TD rowspan=2 align=left width=610><TABLE>headercont# Print the Hidden fields' check boxesmy $tc = 1;foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields){if ($tc == 1){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++;}elsif ($tc == 4){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;}else{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++;}}if ($FORM{autoload}){$trueChecked = "checked";$falseChecked = "";}else{$trueChecked = "";$falseChecked = "checked";}print<<header3;<TR><TD colspan=4 align=center><FONT size=1 color=saddlebrown><B>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</TD></TR></TABLE></TD><TD nowrap><A HREF='' onClick="window.document.Req.submit(); return false;"><IMG SRC='/images/refresh.button.gif' border=0></A><br></TD></TR><TR><TD align=left><B><FONT size=1><br>Display <A HREF='' onClick="window.document.Req.method = 'GET'; window.document.Req.submit(); return false;">Full URL</a> : <a href=/>[Go HOME]</a></TD></TR></TABLE></TD></TR><TR><TD> </TD></TR><TR><TD><TABLE cellspacing=2 cellpadding=4 width=100\%><TR>header3# Print the Column headingsforeach $f (@displayFields){ print "\t\t\t\t\t<TH><INPUT type=checkbox name=$f value=true checked $onClick class=accent>$NAME{$f}</TH>\n"; }print "\t\t\t\t</TR>\n\t\t\t\t<TR>\n";# and now the filter boxesforeach $f (@displayFields){print "\t\t\t\t\t<TD align=left bgcolor=#E6E6E6><FONT size=1>";print filter ($f);# print " ";print "</TD>\n";}print "\t\t\t\t</TR>\n";print end_form ();my $cw = scalar @displayFields;print<<header2;</TR><TR><TD colspan=$cw></TD></TR>header2my $co = '#FFFFFF';foreach $t (@ProductList) # Unt now we print the tickets!{print "\t\t\t\t<TR>\n";foreach $f (@displayFields){if (exists &{"modify_".$f}) {$t->{$f} = &{"modify_".$f} ($t);}print "\t\t\t\t\t<TD align=left valign=top bgcolor='$co'><FONT size=1>".$t->{$f}." </TD>\n";}print "\t\t\t\t</TR>\n";if ($co eq '#FFFFFF'){ $co = '#F9F9F9'; }else{ $co = '#FFFFFF'; }}print<<tail;</TABLE></TD></TR></TABLE><br><br><FONT size=2><B>$x Record(s) Displayed</font><BR><BR><FONT size=1><B>This page was displayed on $now<BR>Please direct questions, problems, and concerns to <FONT color=saddlebrown>noone\@gmail.com</FONT><SCRIPT language="JavaScript"><!--var ticket_window, severity_window, user_window;function NewWindow () {if ((ticket_window == null) || (ticket_window.closed == true))ticket_window = open(\"\",\"Details\",\"width=650,height=650,menubar,scrollbars,resizable\");ticket_window.focus();return true;}function SevWindow () {if ((severity_window == null) || (severity_window.closed == true))severity_window = open(\"\",\"SevDetails\",\"width=500,height=300,menubar\");severity_window.focus();return true;}function UserWindow () {if ((user_window == null) || (user_window.closed == true))user_window = open(\"\",\"UserDetails\",\"width=310,height=115,menubar\");user_window.focus();return true;}//--></SCRIPT>tailprint end_html;