package GigDate; use base 'CGI::Application'; use strict; use warnings; my $infile = "gigdates.txt"; my %gigdates; my @unsorteddates; my @sorteddatesmonth; my @sorteddates; my %fonts; my $count = 0; open(INFILEHANDLE, $infile) or die "Couldn't open $infile for reading: $! \n"; # read input file, skipping blank lines, dropping date=>place pairs in a hash and dates in an array for sorting while(){ next if /^(\s)*$/; my $date = $_; my $place = $_; my $font = $_; $font =~ s/^.+.\|//; $date =~ s/\/*\@.+//; $place =~ s/^.+.\@ //; $place =~ s/\|.+//; chomp($date); chomp($place); chomp($font); $unsorteddates[$count] = $date; $gigdates{$date} = $place; $fonts{$date} = $font; $count++; } # Transform dates Schwartzianly @sorteddatesmonth = map { $_->[0] } sort { $a->[2] <=> $b->[2] } map { [ $_, split /\// ] } @unsorteddates; @sorteddates = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, split /\// ] } @sorteddatesmonth; # Get todays date my ($day, $month, $today, $thismonth, $thisday, $showtoday); my @upcomingdates; my @pastdates; ($thisday, $thismonth) = (localtime)[3,4]; $thismonth++; # Based on the current date, index the upcoming shows and past show dates foreach(@sorteddates){ my ($month, $day) = split(/\//, $_); if (($month == $thismonth) && ($day == $thisday)) { $showtoday = $_; } elsif($month >= $thismonth && $day >= $thisday) { push(@upcomingdates, $_); } elsif($month > $thismonth && $day <= $thisday) { push(@upcomingdates, $_); } elsif($month <= $thismonth && $day < $thisday) { push(@pastdates, $_); } elsif($month < $thismonth && $day >= $thisday) { push(@pastdates, $_); } } unshift(@upcomingdates, $showtoday); close(INFILEHANDLE); sub setup { my $self = shift; $self->start_mode('mode1'); $self->mode_param('rm'); $self->run_modes( 'mode1' => 'upcomingshows', 'mode2' => 'previousshows', ); } sub upcomingshows { my $upcomingshow; my $output; foreach $upcomingshow (@upcomingdates) { if (exists $gigdates{$upcomingshow}) { $output .= "$upcomingshow @ $gigdates{$upcomingshow}

\n"; } $output = "
".$output."
"; } return $output; } sub previousshows { my $previousshow; my $output; foreach $previousshow (@pastdates) { if (exists $gigdates{$previousshow}) { $output .= "$previousshow @ $gigdates{$previousshow}

\n"; } $output = "
".$output."
"; } return $output; } 1; #### #!/usr/bin/perl -w use strict; use GigDate; my $webapp = GigDate->new(); $webapp->run(); #print STDERR $webapp->dump(); #debug #### #!/usr/bin/perl use strict; use warnings; use CGI; $|++; my $query = new CGI; print $query->header(); my $month = $query->param("month"); my $day = $query->param("day"); my $place = $query->param("place"); my $time = $query->param("time"); my $extra = $query->param("extra"); my $type = $query->param("type"); my $font = $query->param("font"); my $date = "$month\/$day" if ($month && $day); if($type == "add"){ my $outfile = "../gigdates.txt"; open (OUTFILEHANDLE, ">> $outfile") or die print "Couldn't open $outfile: $! \n"; my $newshow = "$date @ $place - $time - $extra | $font\n" if ($month && $day && $place); print OUTFILEHANDLE $newshow if ($newshow); close(OUTFILEHANDLE); } if(($type == "remove") && $date && !($place)){ # May need this in the future: #use Tie::File; #my @aFileLines; #my $sFileIn = "../gigdates.txt"; #tie (@aFileLines, 'Tie::File', $sFileIn) or die "$!"; #@aFileLines = grep{$_!~/Q$date/g;}@aFileLines; #untie @aFileLines or die "$!"; my $infile = "../gigdates.txt"; my $outfile = "../gigdates.txt"; open(IN,$infile) || die $!; my @contents = grep { !/$date/ } ; close(IN); open(OUT,">".$outfile) || die $!; print OUT @contents; close(OUT); } print < Gig Dates Admin
Previous Shows:
Upcoming Shows:


ADD A SHOW:

Date: Month: / Day:
Place:
Time:
Extra Info:
Select a font:



REMOVE A SHOW:

Date: Month: / Day:
END_HTML