#!/usr/bin/perl
require "cgi-lib218.pl";
print "Content-type: text/html\n";
print "\n";
print "
WXYC Playlist Formatting and Reporting Tool: Results";
# This procedure (from cgi-lib218.pl...see require statement at the
# top of the file) reads in the string of name/value information and
# parses it out into the associative array ValueOf. Afterwards, all
# form values can be referred to as $ValueOf{'name'}, where 'name'
# is the name of the form variable.
&ReadParse(*ValueOf);
$startdate = $ValueOf{'startmonth'}." ".$ValueOf{'startday'}.", ".$ValueOf{'startyear'};
$enddate = $ValueOf{'endmonth'}." ".$ValueOf{'endday'}.", ".$ValueOf{'endyear'};
# Format end-of-line characters.
$ValueOf{'topslist'} =~ s/
/\n/g;
$ValueOf{'addslist'} =~ s/
/\n/g;
# Format special charcters (single quotes).
$ValueOf{'topslist'} =~ s/³/'/g;
$ValueOf{'topslist'} =~ s/²/'/g;
$ValueOf{'topslist'} =~ s/¹/'/g;
$ValueOf{'topslist'} =~ s/Ò/'/g;
$ValueOf{'topslist'} =~ s/Õ/'/g;
$ValueOf{'topslist'} =~ s/Ó/'/g;
$ValueOf{'addslist'} =~ s/³/'/g;
$ValueOf{'addslist'} =~ s/²/'/g;
$ValueOf{'addslist'} =~ s/¹/'/g;
$ValueOf{'addslist'} =~ s/Ò/'/g;
$ValueOf{'addslist'} =~ s/Õ/'/g;
$ValueOf{'addslist'} =~ s/Ó/'/g;
@lines = split (/\n/, $ValueOf{'topslist'});
# Shift array over so first line is $lines[1], second line is $lines[2], etc.
unshift (@lines, "");
# Initialize line number counter before looping through each line.
$line_number = 0;
for $index (1..$#lines) {
$line_number++;
# Strip '$line' of beginning and ending sets of double quotes.
$lines[$index] =~ s/^"//;
$lines[$index] =~ s/"$//;
# Then put the four data components of '$line' into an array,
# removing all comma delimiters and extra double quotes in the process.
@lineparts = split (/","/, $lines[$index]);
# Replace old '$line' with a cleaner presentation of the first three data fields.
$lines[$index] = $lineparts[0]." - ".$lineparts[1]." (".$lineparts[2].")";
# Store fourth data field in a separate array for easy referencing.
$PlaysReceivedByReleaseNumber[$line_number] = $lineparts[3];
}
# Set by the user in the HTML form, the ceiling is the maximum
# number of releases that can be listed on the final playlist.
$ceiling = $ValueOf{'maximum_tops'};
# Since it is possible
# that this user-defined cutoff point occurs in the middle of a group of
# releases that all received the same number of plays, we compare the
# number of plays received by the last release to "make the cutoff" and
# the number of plays received by the first release to "miss the cutoff".
# If these numbers are the same, we throw out all releases that received
# that many plays. If they are different, we use that exact cutoff point.
while ($PlaysReceivedByReleaseNumber[$ceiling] == $PlaysReceivedByReleaseNumber[$ceiling+1]) {
$ceiling = $ceiling - 1;
}
print "WXYC's Top $ceiling Records from $startdate to $enddate
";
open MAIL, "|mail rosst\@email.unc.edu";
print MAIL "WXYC's Top $ceiling Records from $startdate to $enddate\n";
close MAIL;
print "\n
FORM_END
print "";