php + owa 2003 calendar fun

Hi,
I’ve been recently playing with WEBDAV integration between OWA 2003 ( Microsoft Exchange Outlook Web Access) and php.
Looks like Troy Wolf has made an excellent work creating some classes to provide WEBDAV methods , xml parsing and also Exchange 2003 integration examples.

I had specific needs in calendar integration and I found some good extra work provided by Ryan Hadley.

Looks like he made an excellent implementation of exchange calendar to ics format conversion.
The small bit I still needed was the creation of appointments using WEBDAV, like it is explained here.
After applying all my google-fu I still could not find any php examples  so I had to adapt visual basic and other dialects to php….

this is a working example:

<?php

// Modify the path to this class file as needed.
require_once("class_http.php");

// Change these values for your Exchange Server.
$exchange_server = "http://exchange";
$admin_username = "exchadministrator";
$admin_password = "password";
$partecipants="user1,user2";
$exchange_username="user1";
// We use Troy's http class object to send the XML-formatted WebDAV request
// to the Exchange Server and to receive the response from the Exchange Server.
// The response is also XML-formatted.
$h = new http();
$h->headers["Content-Type"] = 'text/xml; charset="UTF-8"';
$h->headers["Depth"] = "0";
$h->headers["Translate"] = "f";

// Build the XML request.
// This section must be against the left margin.

$golemreq= <<<END
<?xml version="1.0"?>
<g:propertyupdate xmlns:g="DAV:"
xmlns:e="http://schemas.microsoft.com/exchange/"
xmlns:mapi="http://schemas.microsoft.com/mapi/"
xmlns:mapit="http://schemas.microsoft.com/mapi/proptag/" xmlns:x="xml:"
xmlns:cal="urn:schemas:calendar:"
xmlns:dt="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"
xmlns:header="urn:schemas:mailheader:" xmlns:mail="urn:schemas:httpmail:">
<g:set>
<g:prop>
<g:contentclass>urn:content-classes:appointment</g:contentclass>
<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>

END;

$strMailInfo = "<mail:subject>Test Appointment Subject</mail:subject>\n";
$strMailInfo .= "<mail:htmldescription>Lets meet here</mail:htmldescription>\n";

$strCalInfo = "<cal:location>meetappt Location</cal:location>\n";
$strCalInfo .="<cal:dtstart dt:dt=\"dateTime.tz\">2009-11-18T23:00:00.000Z</cal:dtstart>\n";
$strCalInfo .="<cal:dtend dt:dt=\"dateTime.tz\">2009-11-18T23:30:00.000Z</cal:dtend>\n";
$strCalInfo .="<cal:instancetype dt:dt=\"int\">0</cal:instancetype>\n";
$strCalInfo .="<cal:busystatus>BUSY</cal:busystatus>\n";
$strCalInfo .="<cal:meetingstatus>CONFIRMED</cal:meetingstatus>\n";
$strCalInfo .="<cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>\n";
$strCalInfo .="<cal:responserequested dt:dt=\"boolean\">1</cal:responserequested>\n";
$strCalInfo .="<cal:reminderoffset dt:dt=\"int\">900</cal:reminderoffset>\n";

$strHeaderInfo = "<header:to>".$partecipants."</header:to>\n";

$golemreq .= $strMailInfo . $strCalInfo . $strHeaderInfo ;
$golemreq .= "<mapi:finvited dt:dt=\"boolean\">1</mapi:finvited>\n";
$golemreq .= "</g:prop>\n</g:set>\n";
$golemreq .= "</g:propertyupdate>";

$h->xmlrequest = $golemreq;

// The http object's 'fetch' method does the work of sending and receiving the
// request. We use the WebDAV PROPPATCH method to create or update Exchange items.
//$url = $exchange_server."/public/Company%20Contacts/john%20doe.EML";
$url = $exchange_server."/exchange/$exchange_username/Calendar/testapp.eml";
if (!$h->fetch($url, 0, null, $admin_username, $admin_password, "PROPPATCH")) {
 echo "<h2>There is a problem with the http request!</h2>";
 echo $h->log;
 exit();
}

// You can print out the response to help troubleshoot.
echo "debug \n";
echo "<pre>".$h->header."</pre><hr />\n";
echo "<pre>".$h->body."</pre><hr />\n";

?>

It took a while to get the proper xml namespaces so I hope that might be of some use to someone else…
Btw the administrator account needs explicit permission to write into the user calendar, beware also that the calendar is created at the first time the user writes something into it and the name is dependant on the language used by the calendar ( “Calendar” is just for english users).

I am afraid all this will not work on recent ( exchange 2007 and over) versions because there is a new (and  maybe saner) web services interface to exchange.
Please let me know what you think….

About these ads

Tags: , ,

2 Responses to “php + owa 2003 calendar fun”

  1. Sumit morey Says:

    Hi there,

    The script provided here works flawlessly….was hunting for this since long time.

    And have done with most of the part except changing/accessing the “Label and label color” in Appointments. How to do that can you guide me through?

    Regards,
    Sumit

  2. golemwashere Says:

    I am afraid not every property is exposed through webdav, I don’t know if that’s feasable.
    As an extra tip check out PFDAVADMIN
    http://www.microsoft.com/downloads/details.aspx?FamilyId=635BE792-D8AD-49E3-ADA4-E2422C0AB424&displaylang=en

    It’s microsoft scriptable official tool to apply permission to public folders and calendars

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 274 other followers

%d bloggers like this: