PHP Calendar v1.4
This is a simple calendar script that allows you to view a calendar and add events. This calendar uses AJAX to improve performance by loading the new calendar components into the current document and uses a template system to produce the calendar.
Download
Using the calendar
To make the calendar you need to get the date and make an instance of the object:
require_once ('calendar_class.php');
$date = time();
if($_REQUEST['date']) $date = $_REQUEST['date'];
$calendar = new calendar($date);
This code includes the calendar class and makes a new calendar called 'calendar'.
object calendar( string date [boolean display events, boolean style] );
The first parameter is a date in the Unix timestamp format. The second is a boolean value that determines whether the events should be displayed with the calendar. The third value is a boolean that determines what style the calendar should be (this relates to how the empty columns in the table are displayed - see example 3).
Making a template
When making your own templates the following variables are available.
| Variable | Description |
|---|---|
| [DAY] | Day of the month (without leading zeros) |
| [MONTH_A] | Month of the year (full e.g. January) |
| [MONTH_N] | Month of the year (without leading zeros) |
| [YEAR] | Year (4 digits e.g. 2006) |
| [MONTH_3] | Month of the year (3 letter representation e.g. Jan) |
| [PREV_MONTH] | Unix time stamp for previous month |
| [NEXT_MONTH] | Unix time stamp for next month |
Adding events
Below is the signature of the add_event function.
add_event(string title, string description, int day, int month, int year, string duration, string start, string end);
The code below adds an event on day 22 of month 3 (22nd March) in 2006 only.
$calendar->add_event('Title 1','Description 1',22,3,2006,'1 hour','18:00','19:00');
This second event occurs on the 1st of February, every year.
$calendar->add_event('Title 3','Description 3',1,2,'ALL','1 hour','18:00','19:00');
This third event occurs on the 22nd of every month, every year.
$calendar->add_event('Title 2','Description 2',22,'ALL','ALL','1 hour','18:00','19:00');
Note that the word 'ALL' specifies that the event should be repeated in the field specified e.g. if put in the year then the event will repeat every year.
Loading events from a text file
The following code loads events from a text file.
$calendar->load_textfile_events('events.txt');
The text file must have the following structure.
Day|Month|Year|Title for event|Description for event|Duration|Start|End
The pipe symbol separates the data and each event must be on a new line.
Displaying the calendar
To display the calendar call the build_calendar function.
$calendar->build_calendar();
Licence / warranty
To use this script keep the comments in place. This script comes without warranty. Use at your own risk.