Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

CGI Calandar

by raflach (Pilgrim)
on Apr 21, 2000 at 21:03 UTC ( [id://8396]=perlquestion: print w/replies, xml ) Need Help??

raflach has asked for the wisdom of the Perl Monks concerning the following question:

I am soon going to attempt to write a web based reservation system. It will allow vistors to the page to look at a graphical calandar with days that have been reserved marked appropriately, and then allow them to tenatively reserve a date for themselves. What I would really like is simply some pointers as to how I ought to attack the basic logic of the problem.

My current thoughts are to store reserved dates in a flatfile, which will be stripped of dates prior to the current date at each use, then load the list of dates into an array and build the table based on that array. I'll have another file where tenative reservations are stored, formatted in the same way, and second secure form, where the administrator can confirm the reservations thus transferring them to the other file.

After a person has made a reservation (which will require an e-mail address to be entered), I'll send periodic reminders about the reservation via e-mail, and will also need to track things like payment date, which would be a set number of days before the reservation. If payment is not made by that date, the script (or another script) should auto-remove the reservation. Can anyone tell me if I appear to be headed in the right direction? Is there a better way to do this than flat files? Your thoughts would be appreciated.

Replies are listed 'Best First'.
Re: CGI Calandar
by httptech (Chaplain) on Apr 22, 2000 at 00:11 UTC
    If you do not currently have access to a DBI compatible database you may want to look at using DBI and the DBD::CSV driver with your flatfiles. It will handle your file locking (assuming you're on a system that has flock()) and will allow you to take advantage of the ease of use of SQL when performing your operations.

    Then, when your project outgrows the use of flatfiles and you simply have to move it to a real database, porting the scripts should be fairly easy, since you built it around DBI from the start.

Re: CGI Calandar
by comatose (Monk) on Apr 21, 2000 at 22:43 UTC

    I would highly recommend against flat files if you are doing anything with any kind of volume. A tied DBM hash should be your last resort for if you don't have access to any database usable with DBI. With a flat file, you're going to have big locking issues.

    Beyond that and the obvious (like CGI.pm), one module you're definitely going to want to use is Date::Manip. It will save you a lot of time and energy in dealing with the various date formats people might put in.

RE: CGI Calandar
by genehack (Beadle) on Apr 21, 2000 at 21:34 UTC

    I would probably look at doing it with a more elaborate data structure, like a tied DBM hash, just because my guess would be that that will scale better over the long run.

    The other thing I would do if I were you is have a look over at Freshmeat; I know there are similar web calendar systems over there that you could probably either (a) adapt to your purposes or (b) scavenge code or ideas from.

    Good luck!
    john.


    <jacobs@genehack.org> = just another perl hacker
    <http://genehack.org> = not just another weblog
Re: CGI Calandar
by perlmonkey (Hermit) on Apr 21, 2000 at 23:01 UTC
    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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://8396]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-23 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found