I made a cgi calender program a while ago to display
events. I used Data::Calc, and CGI. The logic here is
probably not the cleanest, but I think it will do what
you want.
This prints the correct calendar for this month. The
print_calendar routine is dynamic depending on the input
paramaters of month, and year.
For your example I made a cheesy little flatfile (reserve.dat)
that contains: 2000:4:2 email@foo
2000:4:5 email@foo
2000:4:15 email@foo
2000:4:24 email@foo
which are the reserve dates and the email address associated
with them. You can elaborate. I agree that a flatfile is
not the best way to go. If it is a serious application use
a database (Mysql is free and fast). This program justs
prints the calender leaving already reserved dates blank.
The submit button does not do anything, so you will have to
write that, but this should be a good start:
#!/usr/bin/perl
use CGI qw(:standard);
use Date::Calc qw(:all);
print header();
print start_html();
&print_calender(4, 2000);
print end_html();
sub print_calender
{
my $month = shift;
my $year = shift;
my %res;
open(RES, "reserve.dat")||die;
while(($date,$email) = split(/\s/, <RES>))
{
$res{$date} = $email;
}
print "<center>\n";
print start_form(), "\n";
print "<table width=$tableWidth BORDER=1 VALIGN=\"MIDDLE\">\n";
print "<tr align=\"center\">", "\n";
$dow = 7;
for($i=1; $i<=7; $i++)
{
print "<td width=$width>", b(Day_of_Week_to_Text($dow)), "</td
+>\n";
$dow = $dow %7 + 1;
}
print "</tr>\n";
$day = 1;
while(check_date($year, $month, $day))
{
$weekday = Day_of_Week($year, $month, $day);
$weekday = $weekday % 7 + 1;
print "<tr>\n";
for($j=1;$j<$weekday;$j++)
{
print "<td width=$width height=$height>", br, "</td>", "\n
+";
}
for($j=$weekday;$j<8;$j++)
{
if(check_date($year, $month, $day))
{
print "<td width=$width height=$height valign=\"TOP\">
+", "\n";
print b($day), br, "\n";
unless( $res{"$year:$month:$day"} =~ /\S/ )
{
print checkbox(-name=>"$year:$month:$day", -label=
+>"Reserve");
}
print "</td>", "\n";
$day++;
}
else
{
print "<td width=$width height=$height>", br, "</td>",
+ "\n";
}
}
print "</tr>", "\n";
}
print "</table>\n";
print "Email Address: ", textfield(-name=>'email'), br;
print submit(-name=>'Make Reservation');
print "</form>\n";
print "</center>\n";
}
|