kieranbarnes these are the things i learnt today

iCalendar Generation

Posted on July 20, 2007

One of my clients requested that the CRM applicationI wrote should interact with Outlook Calender.
For example, when adding a "Next Call Date" on the web based CRM application, the user's calendar is updated in Outlook so they are reminded even when not using the CRM application.

It should work for any VCalendar aware application, like Thunderbird & Lightning or Sunbird.
Heres how I did it, Create a file called make_calender.php

// Define the file as an iCalendar file
header("Content-Type: text/Calendar");

// Give the file a name and force download
header("Content-Disposition: inline; filename=calendar.ics");

// Header of ics file
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:PHP\n";
echo "METHOD:REQUEST\n";
echo "BEGIN:VEVENT\n";
echo "SUMMARY: PUT SUMMARY DETAILS HERE \n";
echo "DESCRIPTION: PUT DESCRIPTION DETAILS HERE";
echo "DTSTART:".DATE HERE."T090000\n";
echo "DTEND:".
DATE HERE."T090000\n";
echo "UID: ".rand()."\n";
echo "SEQUENCE:0\n";
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n";
echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT30M\n";
echo "REPEAT:1\n";
echo "ACTION:DISPLAY\n";
echo "END:VALARM\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";

You will need to populate the code with the following, presumably from a database record just before the above code.

Summary
echo "SUMMARY: PUT SUMMARY DETAILS HERE \n";

Description
echo "DESCRIPTION: PUT DESCRIPTION DETAILS HERE";

Date & Time
echo "DTSTART:".DATE HERE."T090000\n";
echo "DTEND:".
DATE HERE."T090000\n";

The code also produces a trigger, in Outlook terms, a reminder.
It will "alarm", in Outlook terms pop up a window, 30 minutes before the event.
This can be seen as

echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT30M\n";
echo "REPEAT:1\n";
echo "ACTION:DISPLAY\n";
echo "END:VALARM\n";

This code will generate an ICS file that the user will be prompted to Open. Once opened Outlook will save the event.

Its upto you how you call it.

Further reading

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. PHP Export as CSV
    A client recently requested an option to extract search results from their PHP application as...
  2. CAPTCHA Image Generation
    I couldn't find a very good CAPTCHA generation script in PHP, all the ones I...
  3. KB_CAPTCHA – CAPTCHA Image Generation in PHP
    Introduction KB_Captcha is a simple PHP script to generate reasonably safe CAPTCHA image to...
  4. The Microsoft Scalable Networking Fiasco
    I've just spent a few days diagnosing a strange Exchange 2003 issue for a client....
  5. Using Wordpress header and footers externally
    I needed to integrate a Wordpress header (header.php) and footer (footer.php) into an external application....

What this article useful to you?



Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the PHP category.

Filed under: PHP Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.