#!/usr/bin/perl
# "  "  " or use http://d...content-available-to-author-only...m.com/tools/smart-quotes.html to convert all smart quotes to straight #quotes
require "subparseform.lib";
use warnings;
use strict;
use CGI;


my $bgcolor = "green";
my $filledcellcolor = "yellow";
my $emptycellcolor = "pink";
my $tablecols = 3;
my $tablerows = 20;
my ($i,$j);

#opens file p04.txt for writing
open(MYFILE, "p04.txt") or die("\nError: cannot open file\n");

my @name = <MYFILE>;
chomp(@name);
close(MYFILE);


my $parseCount;


&Parse_Form;

#this needs to be in a for loop that runs through the elements in an array
#if($formdata{"text$parseCount"} eq ""){
#$table[$parseCount] = $formdata{"text$parseCount"};
#}

my $cgi = CGI->new;    #Instantiate a CGI class
print $cgi->header,

#begin html page
$cgi->start_html('Super Bowl Party'),

 
# create the Tag <h1>TEXT</h1>	
$cgi->h1("<center>Super Bowl Party Sign-up Sheet</center>"), 

#header
$cgi->h2("<center>Project p04</center>"),

#header
$cgi->h3("<center>Adam Knutson</center>"),
$cgi->start_form();
print "<center><TABLE BORDER=1>"; 


#creates 3 columns and 20 rows of text boxes
my $count = 0;
for ($j = 0; $j <$tablerows; $j++)
{
	print "<TR>";
	for ($i = 0;$i < $tablecols; $i++)
	{	
		if ( $name[$count] eq "" )
		{
		print "<TD BGCOLOR='".$filledcellcolor."' > <INPUT TYPE=TEXT NAME='text".$count."' SIZE=40 MAXLENGTH=50 VALUE=''  background-color:'".$emptycellcolor."'> </TD>";
		}
		else 
			{
		print "<TD> $name[$count]</TD>";
			}
$count++;
	}
	print "</TR>";
}


open (MYFILE, '>p04.txt');
my $newCount = 0;

#while conditions don't use 59, use number of columns*number of rows. 
while ($newCount <59){
print MYFILE "$name[$newCount] \n";
#print MYFILE "\n"; 
$newCount ++;
}
close (MYFILE);

#Creates submit and reset buttons at bottom of page
print "</TABLE> <INPUT TYPE=submit NAME=submitButton VALUE='Submit Form'>

<INPUT TYPE=reset NAME=resetButton VALUE='Clear Form'>
</center>";

#print $cgi->end_form();
$cgi->h2("<center>Project p04</center>"),
$cgi->end_html; #end of HTML

