Kieran Barnes / PHP / iCalendar Generation
iCalendar Generation
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
Related posts
- CAPTCHA Image Generation
I couldn't find a very good CAPTCHA generation script in PHP, all the ones I... - KB_CAPTCHA – CAPTCHA Image Generation in PHP
Introduction KB_Captcha is a simple PHP script to generate reasonably safe CAPTCHA image to secure... - CAPTCHA Image Generation Part 2
A quick morning hack - I added some random lines to try and confuse the... - Looping over dates in PHP
I recently had to loop over the difference between two dates. For example to create... - [Snippet] Setting the timezone for PHP 5.3
PHP 5.3 requires a time zone to be set if you do any kind of...
Posted by Kieran
Categories
- 4PSA VoIPNow (1)
- Apache (20)
- APC (1)
- Automotive (7)
- Client Sites (8)
- cPanel/WHM (22)
- CubeCart (23)
- Domains (1)
- Exchange (6)
- Geeky (32)
- General (22)
- Home (1)
- HTML, CSS, AJAX (23)
- IIS (1)
- Linux (79)
- MS SQL (4)
- Music (5)
- MySQL (19)
- nginx (4)
- Photography (17)
- PHP (93)
- phpBB (1)
- Reviews (4)
- Scalability (1)
- Search Engines (5)
- Security (6)
- Snippets (4)
- Software (4)
- Uncategorized (6)
- Vantegra (1)
- Virtualisation (1)
- VoIP (3)
- WHMCS (1)
- Windows (42)
- WordPress (64)
- Shopp (14)
- Xen (2)
Recent Comments
- Blue on Prevent images from displaying while loading with AnythingSlider
- jaysunn on MySQL 5.0 or 5.1 to 5.5 Upgrade Traumas on CentOS
- buy Synthroid on New Site: HSS Blog
- Minify CSS and JavaScript with nginx and embedded Perl on Minify CSS on the fly with nginx
- Yvo on MySQL: Can’t get hostname for your address
Kieran Barnes
Independent PHP, WordPress and CubeCart programmer and consultant in Manchester, UK.
I can offer programming and consultancy for your next WordPress, Ecommerce or PHP web application.
About Kieran
Kieran is a PHP developer with 15 years commercial experience. He has a niche for all things WordPress, CubeCart and other open sourcery. With expertise in most areas of Linux and Windows wrangling makes him a good choice for supporting and consulting your next web application.
Get in Touch



