Providing a calendar that is up-to-date can be quite a time- consuming task. As the months fly by, you don't want to always have to go back and regenerate a calendar for the current month. Using the small CGI script presented this week will allow you to present events for the current month, and any month, quickly and easily for visitors to your web site.
Let's say that you have a list of events in the following form:
12/25/1997,Christmas '97 12/25/1998,Christmas '98 1/1/1998,Happy New Year 11/25/1997,Oh no! Relatives for dinner!
This week's script will present you with a calendar that is always fresh and interesting.
You notice that the current day is highlighted in yellow any days with scheduled events marked in green. Red marks the day that you are currently viewing. Just click on a number to view the events for that day. Any number of events can be scheduled on a given day. In the example above, both "Christmas '97" and "Oh no! Relatives for dinner!" occur on the same day and will both be displayed when you click on December 25th.
All of the colors and formatting can be easily customized by you. In the source code you'll find the settings for the colors and the name of the text file that's used for setting the dates. Here's the code that specifies the location of the text file used for scheduling events. If you want to keep it in another directory or use a different name, this is where you set it:
# Path and name for the data file: $calfile="cal_sched.txt";
Upon starting, the calendar CGI loads that text file and converts all the dates into their corresponding Julian Day number. I chose to use this format because it's very easy to deal with dates in a uniform fashion. In the cal_sched.txt file, you can even specify the Julian Day number or the more conventional month, day and year (assuming $datefmnt=1):
12/25/1997,Christmas '97 2450808,This is Christmas '97, too.For more information on Julian Day numbers, check my previous calendar article.
Because the Web is indeed worldwide, there is a provision to handle other date formats in the input text file. In the United States, it is customary to use the month/day/year format. If you want to use another format in your text file, just change the following code:
# Date format, select one of the following: # 1 = month/day/year # 2 = day/month/year # 3 = year/month/day # $datefmt=1;
For example, to have 1997/31/10 represent October 31, 1997, use the following setting:
$datefmt=3;
Click below to download a .ZIP file with all the pieces you'll need to set up the CGI calendar:
Author: Doug Steinwand
Date: [10/14/97]
More articles about CGI
More articles by Doug Steinwand
Author Biography