One of the latest crazes on the 'net has recently been online calendars.
with the MCAL library and PHP,
writing calendar applications is now
easy and fully functional. The MCAL library is very similar to the c-client IMAP
library. It offers a common simple interface for accessing calendars that can be stored in
many different formats, both local and remote formats are supported.
In this tutorial, we will use the mstore calendar driver. The mstore calendar driver uses
a local file storage format. Another driver that can be used is the ICAP driver,
which allows access to remote calendar stores.
One things that makes the MCAL library very different than other libraries is that it
does not just handle "simple" calendaring. It is a feature rich calendaring library that
handles dates from year 1 to year 9999, incorporating the Gregorian calendar and extrapolating
back. This calendaring obviously contains events and many event objects. (It essentially uses
icalendar objects and properties).
Some of MCAL's supported object features are:
Alarms (triggers) which can be set to go off any number of minutes before the event.
Class values (Public/Private)
Start and End Dates
Recurrence (This event should re-occur every Thursday..etc..)
Enough about the capabilities, lets get coding!
The first thing we'll probably want to do is pull up a users calendar and display the month
view, and the event titles for any of their scheduled events:
To do this, we only need to use just a couple of mcal functions.
The first is mcal_open. mcal_open takes in a calendar string, a username and a password.
This function takes in a stream, and beginning and end dates. It returns a list of
event ID's for every event that is scheduled between the two dates.
Once we have this list of ID's, we need to loop through the events and find their actual dates.
while we are at it, we might as well store the title of the events since we will be
printing them out in the month view also:
Note, one thing we are doing is allowing people to add events by clicking on and day
in the calendar. If there is an event scheduled, it prints out the title, and by clicking
on the title, it displays all of the events information.
to display an events information, we use the same technique as the above, but just pull up the
events for that one day, and print out all information.
To do the actual adding of the event after the form is submitted,
we use a couple of new functions.
Every calendar stream has an internal event structure. This event
structure is used for storing and retreiving events.
So we simply set the internal event structure with the proper
information using the mcal_event_set functions.
Finally, we simply call mcal_store_event. This function takes
the current event and adds it to the calendar store.