#!/usr/bin/perl -w
#
# Floyd's RESULTS SCRIPT
#
use CGI qw(:cgi-lib :standard);
$query = new CGI;
 
$id=param('id');

unless ($id) {print redirect "http://allaboutfrogs.org";}

print header;


 open (DATA, "data/polls/$id.dat") || die "Couldn't open poll\n\n";
 flock DATA, 2; 
 @data=<DATA>;
 flock DATA, 8; 
 close(DATA);


foreach (@data) {
	 chomp;
	 unless ($i) {
 		($question, $total_votes) = split ?\|?, $_;
		$i++;
		next;
	 }
	(my $words, my $votes) = split ?\|?, $_;

	#$$words = $votes;
	$Votes[$x] = $votes;
	$Data[$x] = $words;
	$x++;
}

my $number_of_options = @Data;


print qq~<HTML>
<BODY BACKGROUND="/picts/frgbck.gif">
<CENTER>
<FONT FACE="COMIC SANS MS"><H1>Frog Poll Results</H1>
<HR>
<TABLE WIDTH=600 BORDER=0  cellpadding="5" BGCOLOR="#00CC33">
<TR>
<TD COLSPAN=3>
<FONT FACE="COMIC SANS MS" SIZE=5>
<CENTER><B>$question</B>
</FONT>
</TD>
</TR>

~;



foreach (@Data) {
        $i++;
	if ($i % 2 ) {
	$bgcolor="CCFFCC";
	}
	else {
	$bgcolor="FFFFCC";
	}
	my $precent = ($Votes[$i - 2] / $total_votes);
 	my $percent=sprintf("%.1f", 100*$precent);
	my $width = 3 * $percent;
	print qq~
	<TR BGCOLOR="$bgcolor">
	<TD><FONT FACE="COMIC SANS MS">$_</TD>
	<TD> <IMG SRC="/picts/pollbar.gif" height="20" WIDTH="$width"></TD>
	<TD><FONT FACE="COMIC SANS MS">$percent\%</TD> </FONT>
	</TR>
	~;

	
}
print qq~
<TR><TD COLSPAN=3>
<FONT FACE="COMIC SANS MS" SIZE=1><B>Total Votes: $total_votes </B>
</TD></TR></TABLE>
</CENTER>
<P>
<CENTER>
<FONT FACE="COMIC SANS MS" SIZE=2><B>
<A HREF="/funstuff/pastpolls/index.html">View Previous Surveys</A><P>
Got any good ideas for a future poll?  <A HREF="/mail.html">Mail me!</A>
</B>
</FONT>
<P>
</CENTER>
<font size="+2" FACE="COMIC SANS MS">Back to <A HREF="../froglnd.shtml">FROGLAND</A>.</font>

~;

 exit;
 



 



