How to add a notification in a calendar

Lennart Ericson
Lennart Ericson used Ask the Experts™
on
I've got a booking script. I'd like to get a notification in the bookers calendar, being it MS Outlook calendar, Google Calendar or any other popular caledar. I have very little experience in this field and seek basic "how to" information".
Serverside language: php.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
There is a calendar standard called hCalendar that implements RFC2445.  Some other keywords of interest are iCal and vCal.  These use the iCalendar file format which is the defacto standard for calendar information interchange.  

You may be able to use PHP to force a download of a file with the ics file suffix.  The client's computer may associate the .ics files with a calendar program.  This file extension is used for calendaring and scheduling information.

The MIME type for iCalendar data is text/calendar.

I've done this in the past with an "add this event to my calendar" link.  The link went to a PHP script and it had a URL parameter giving a key to the calendar entry.  The PHP script used the key to locate the event row in the calendar database table.  It generated an iCalendar object, which is a simple text file like this (thanks, Wikipedia)
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR

Open in new window

If I can find a code example for this, I'll post it here and update these articles about handling date and time in PHP.
http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL-Procedural-Version.html
http://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
Most Valuable Expert 2011
Top Expert 2016
Commented:
Here's the only example I can find, and it probably dates from about 15 years ago!  The code should be refactored (obviously) but the iCalendar object works correctly.  You can probably guess the calendar table structure from the variable names.  The "poc" means "point of contact."
<?php 
require_once('common.php');
error_reporting(E_ALL ^ E_NOTICE);

$_key = $_GET["k"];
if (!integer_string($_key)) die("Bad Key");

$filename = "LBBEvent" . $_key . ".vcs";
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: inline; filename=$filename");

$sql = "SELECT * FROM calendar "WHERE _key = $_key LIMIT 1";
if (!$res = mysql_query($sql)) { query_error($sql); }
$num_rows = mysql_num_rows($res);

if ($num_rows == 0) {
    echo "Sorry, the <b>Event Key $_key</b> is not found in the calendar.<br /><br />\n";
    echo "Please report this error to the curator.<br /><br />\n";
    die("Sorry, Unable to add to your calendar.");
}
if ($num_rows != 1) {
    echo "SQL $sql<br>";
    echo "RESULT $result<br><br>";
    echo "The <b>Event Key $_key</b> appears to have $num_rows data base entries in the calendar (yikes!)<br />\n";
    echo "Please report this error to the curator.<br /><br />\n";
    die("Sorry, Unable to add to your calendar.");
}

$calendar_array = mysql_fetch_assoc($res);
extract($calendar_array);

$loc = trim($location);
if ($loc  != '') { $loc  = '=0D=0A=Location: ' . $loc; }

$poc1 = trim($poc1_name .' '. $poc1_phone .' '. $poc1_email);
if ($poc1 != '') { $poc1 = '=0D=0A=Contact: ' . $poc1; }

$poc2 = trim($poc2_name .' '. $poc2_phone .' '. $poc2_email);
if ($poc2 != '') { $poc2 = '=0D=0A=Contact: ' . $poc2; }

$pocw = trim($poc_url);
if ($pocw != '') { $pocw = '=0D=0A=WWW: ' . $pocw; }

$poc = $poc1 . $poc2 . $pocw;

// CALENDAR TOLERATES END TIMESTAMPS WRONG OR OMITTED - VCAL DOES NOT
$vcal_dtstart = date('Y-m-d H:i:sO', strtotime($start));
$vcal_dtend   = date('Y-m-d H:i:sO', strtotime($end));
if ($vcal_dtend < $vcal_dtstart) { $vcal_dtend = $vcal_dtstart; }


?>BEGIN:VCALENDAR
VERSION:1.0
PRODID:LBB Online Calendar
BEGIN:VEVENT
SUMMARY:<?php echo "$title" . "\n"; ?>
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:<?php echo "$details" . "$loc" . "$poc" . "\n"; ?>
DTSTART:<?php echo $vcal_dtstart . "\n"; ?>
DTEND:<?php echo $vcal_dtend . "\n"; ?>
END:VEVENT
END:VCALENDAR

Open in new window

Author

Commented:
Thank you! Sorry for not having responded eaarlier.
Regards
Lennart

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial