iCal, SunBird, and new web Calendar

Yesterday at slashdot there was a post about the new alpa release of Mozilla Sunbird - coincidentally enough it's a calendaring program. The reason this is significant is because, like all of the Mozilla applications they are attempting to be standards compliant. In this case compliant with the iCal standard. The iCal standard in its' most basic form simply describes how to store event information an a predefined format so that other calendering applications can read, understand, and display the event accordingly.

As you probably know, I just added a new events calender feature to this website. However, the overall capabilities of the php based calender in place are fairly limited. For instance I can not define an event that repeats every monday, wednesday, and friday. In fact the recurring event functionality is kind of crappy. "So what?" you might be saying - how does a desktop application like Mozilla Sunbird help you fix the limitations imposed by your web application? Well, I'm glad you asked!

While I was looking for suitable web calendar programs written in php I came across a great little app called PHP iCalendar which is merely a display end for iCal compliant files which Sunbird (and a few other programs) can generate. This is all fine and dandy but without some nice, fairly seamless, method of "synchronizing" my calendar between work, web, and home, I honestly don't think either Lisa or I would be too keen on using it. Fortunatly, there are two solutions to this problem for some - however, I was forced to use the second, less elegant solution.

The first solution is Sunbird's inherent support for another great standard, WebDAV (Web Distributed Authoring and Versioning). WebDAV basically allows you to publish documents to a web address without having to ftp. However, your webserver needs to have webDAV enabled. For instance, if your running apache then you would need mod_dav installed. Sadly, my provider does not have this module running so I was forced to find another solution.

Luckilly for me the solution was pretty easy to find thanks in part to the fact that you can have multiple calendars active at one time in Sunbird and thanks to windows batch files and command line access to FTP! Windows command line FTP supports a few different switches; I am using -v, -i, and -s:filename.

-v
Suppresses display of remote server responses.
-i
Turns off interactive prompting during multiple file transfers.
-s:filename
Specifies a text file containing FTP commands; the commands will automatically run after FTP starts.
Thanks to the -s option I was able to create two files for each of my calendars; publish_cal_x.txt and get_cal_x.txt where 'x' is the name of the calendar. Then, using a one line batch file that takes in two arguments [method] [calendar_name] I am able to quickly synchronize my calendars to and from the web. Here is an example of one of the text files that contain the ftp commands:

[username]
[password]
cd [remote path to put file, ex: /wwwroot/calendar/]
put [calendar file name, ex: myCal.ics]
bye
exit

Here is my batch file titled sync_cal.bat

ftp -v -i -s:%1_%2.txt rawlinson.us
Argument 1 shown as %1 is the method, either get or publish and argument 2 shown as %2 is the name of the calendar. For instance I have two calendars, lisa and bill, which I want to publish. So I have a text file for each to publish such as publish_bill.txt. This way, when I call my batch file with the command: sync_cal.bat publish bill - the ftp command is called with the corresponding switches and it runs the ftp commands from the file publish_bill.txt due to the way windows batch files replace the %1 and %2 with the corresponding command line entries.

To get this all working, I then created four shortcuts to my batchfile and modified the properties of each shortcut to pass in the correct command line arguments (this way I don't actually have to type anything ever, so sync's are just one click away). The final piece to this puzzle is setting up sunbird so that I don't have to export entries (or import them) all the time. Instead they are auto-imported and auto-exported because I configured the calendars in Sunbird to point to the exact same files I'm FTPing up and down with the aforementioned batch file.

Now for the most important cautionary warning. Lisa should only edit her calendar and I should only edit mine. Plus we both have to use the same calendar naming convention. This way there is no chance that we will get duplicate entries from each other and neither of us will overwrite the others events by accident. Basically, Lisa should never run the batch file with "get lisa" as the arguments and I should never run "get bill" - this way the iCal file on our computers remains the master copy of the file. If you have any questions on how to get this setup working for you - don't hesitate to ask!