Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create Event VCS File

Posted on 2011-04-20
4
Medium Priority
?
316 Views
Last Modified: 2013-12-13
I have the following code that writes out information on an event that someone selects from our website. How do I create a "Save to Outlook Calendar" link from this information?
<?PHP 
$listing_id = $_GET['listing_id'];

$sql = "SELECT * FROM Listings WHERE ID='$listing_id'";

$sql_query = mysql_query($sql);



if (mysql_num_rows($sql_query) == 0)

{

	echo "Listing ID does not exist<br>\n";

	exit;

}


$listing_row = mysql_fetch_assoc($sql_query);

$ListingID = $listing_row['ID'];

$ListingName = $listing_row['Name'];

$ListingStartDate = $listing_row['EventStartDate'];

$ListingStartHour = $listing_row['EventStartHour'];

$ListingStartMinute = $listing_row['EventStartMinute'];

$ListingStartAMorPM = $listing_row['EventStartAMorPM'];

$ListingEndHour = $listing_row['EventEndHour'];

$ListingEndMinute = $listing_row['EventEndMinute'];

$ListingEndAMorPM = $listing_row['EventEndAMorPM'];

$ListingVenue = $listing_row['Venue'];

$ListingVenueAddress = $listing_row['VenueAddress'];

?> 

  <?php 
	echo "$ListingName<br />";
	echo "$ListingStartDate<br />";
echo "$ListingStartHour:$ListingStartMinute $ListingStartAMorPM\n":
?>

Open in new window

0
Comment
Question by:katlees
  • 2
4 Comments
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 35436337
Not a PHP expert but you would need to redirect to a page that generates the text like the following and has a Content-Type MIME header of either text/x-vcalendar, text/calendar or application/hbs-vcs:

BEGIN:VCALENDAR
BEGIN:VEVENT
STATUS:TENTATIVE
DTSTART:20101230T033000Z
DTEND:20101230T043000Z
SUBJECT:Your Proposal Review
DESCRIPTION:Testing
CLASS:PRIVATE
END:VEVENT
END:VCALENDAR
0
 

Author Comment

by:katlees
ID: 35436551
Thanks Jim.. I saw that much just don't know how to convert my current code to show all of this...
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 35437200
At a pure guess, I'd say it might look like the following (although I expect an experienced PHP developer would pull it to pieces):
<?php
    header('Content-Type: text/x-vcalendar')
    header('Content-Disposition: attachment; filename="vcal.vcs"');

    $ListingStart = $ListingStartDate + ' ' + $ListingStartHour + ':' + $ListingStartMinute + ' ' + $ListingStartAMorPM;
    $ListingEnd = $ListingEndDate + ' ' + $ListingEndHour + ':' + $ListingEndMinute + ' ' + $ListingEndAMorPM;

    echo 'BEGIN:VCALENDAR\r\n';
    echo 'BEGIN:VEVENT\r\n';

    echo 'UID:';
    echo 'www.mysite.com-vcal-';
    echo $ListingID;
    echo '\r\n';

    echo 'DTSTART:'
    echo date("Ymd", strtotime($ListingStart))
    echo 'T'
    echo date('his', strtotime($ListingStart))
    echo 'Z\r\n'

    echo 'DTEND:'
    echo date('Ymd', strtotime($ListingEnd))
    echo 'T'
    echo date('his', strtotime($ListingEnd))
    echo 'Z\r\n'

    echo 'SUMMARY;ENCODING=QUOTED-PRINTABLE:'
    echo quoted_printable_encode($ListingName)
    echo '\r\n'

    echo 'LOCATION;ENCODING=QUOTED-PRINTABLE:'
    echo quoted_printable_encode($ListingVenue)
    echo '\r\n'

    echo 'DESCRIPTION;ENCODING=QUOTED-PRINTABLE:'
    echo quoted_printable_encode($ListingVenueAddress)
    echo '\r\n'

    echo 'END:VEVENT\r\n';
    echo 'END:VCALENDAR\r\n\r\n\r\n';
?>

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 35440818
Here is a very old example from one of my sites.  Sorry about the spacing.  It works.  Hopefully it can show you a design pattern you can adapt for your own calendar needs.  HTH, ~Ray
<?php // calendar_vcal.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); // NOTE WE DO NOT TRANSFER THE CATEGORY TO THE V-CAL
foreach ($calendar_array as $k => $v) { $$k = $v; }

$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\TH:i:sO', strtotime($start));
$vcal_dtend   = date('Y-m-d\TH: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

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question