#!/usr/local/bin/perl
use CGI qw/:all/;
$| = 1;
my $q = new CGI;
my $action = $q->param('action');
# Read in all the variables set by the form
CGI::ReadParse(*input);
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
$month = $input{'month'};
$date = $input{'date'};
$year = $input{'year'};
#$action = param('action');
#print $action;
$numberoflines = &CountCurrentRecords('events.txt');
if($action eq "add_data"){
print "Your post was sucessful ";
#check_event();
add_data();
}
else{
#print "We are not in the Add sub-routine ";
#this is just an example fictitious default subroutine
}
if($action eq "preview"){
#print " Is this information correct? ";
preview();
}
else{
#print "We are not in the Preview sub-routine ";
#this is just an example fictitious default subroutine
}
############### BEGIN COUNTCURRENTRECORDS SUBROUTINE ########################
sub CountCurrentRecords {
$number = 1;
my($database) = ($_[0]);
open(DATABASE, "$database");
while ($line=) {
$number++;
}
$number = 0 if $number < 0;
close(DATABASE);
return $number;
}
#############################################################################
##
## Preview Data Section
##
############################################################################
############### sub preview ########
sub preview{
print "
$month $date, $year
$input{'title'}
$input{'message'}
$numberoflines
\n";
}
#############################################################################
##
## Add Data Section
##
############################################################################
############### sub add_data ########
sub add_data{
# Print out a content-type for HTTP/1.0 compatibility
$addfile = "events.txt";
print "$month";
print $month;
#print "We are in the add_data sub-routine \n";
# Open the file for appending
open (OUT, ">>$addfile") or die "Can't open $addfile\n";
$number = $numberoflines;
$message = $input{'message'};
$line = join '::', $number,$month,$date,$year,$title,$message;
print OUT "$line\n";
close OUT;
}