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"; }

In reply to Re: CGI Calandar by perlmonkey
in thread CGI Calandar by raflach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.