Ok, so I was bored.. Attached below is a PHP script that will connect to
Outlook via COM and go through all the items in the Calendar, displaying
the appointment name, location, FROM and TO date/times (adjusting for
the weird assed MS timestamp..  Apparently # of seconds since some time
in 1970), and whether it's recurring and/or all-day.

I didn't snag the information about recurrence, but you can probably
figure it out.

Here's the MS Data Model for Outlook.   Semi-helpful, although not
organized very well:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000
/html/olobjApplication.asp

Also, excuse the sloppy coding, just wanted to see if I could do this
real quick.  I have multiple mailboxes on my Outlook at work here, so I
have it cycle through all mailboxes and all folders until it finds the
right mailbox and correct calendar.  There's probably a more direct way
to do this.  But this doesn't really add much overhead, so "if it works,
it works" eh?  Feel free to share any better way you might find.

Code attached to the bottom

-TG

> -----Original Message-----
> From: Shaun [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, August 25, 2004 11:17 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Communicate with Outlook
> 
> 
> Hi,
> 
> Is it possible for a PHP application to communicate with an Outlook
> calendar? I would like to create a web based application that 
> shows staff
> availability...
> 
> Thanks for any advice offered.


<?php
$comobjOutlook = new COM("outlook.application") or die("Unable to
instantiate outlook");
$comobjOutlook -> Activate;

$targetmailboxname = "Mailbox - LastName, FirstName";
$targetfoldername = "Calendar";

$objNamespace = $comobjOutlook->GetNameSpace("MAPI");
$objFolders = $objNamespace->Folders();
$mailboxcount = $objFolders -> Count();

$foundmailbox = FALSE;
for ($i=1; $i<=$mailboxcount; $i++) {
  $folderitem = $objFolders ->Item($i);
  if ($folderitem -> Name == $targetmailboxname) {
    $objMailbox = $folderitem;
    $foundmailbox = TRUE;
  }
}

$foundcal = FALSE;
if ($foundmailbox) {
  $objFolders = $objMailbox->Folders();
  $foldercount = $objFolders -> Count();

  for ($i=1; $i<=$foldercount; $i++) {
    $folderitem = $objFolders -> Item($i);
    if ($folderitem -> Name == $targetfoldername) {
      $objCalendar = $folderitem;
      $foundcal = TRUE;
    }
  }

  if ($foundcal) {
    $objItems = $objCalendar->Items();
    $itemcount = $objItems->Count();

    for ($i=1; $i<=$itemcount; $i++) {
      $apptitem = $objItems -> Item($i);
      $apptstart = $apptitem -> Start();
      $apptend = $apptitem -> End();
      $apptallday = $apptitem -> AllDayEvent();
      $apptrecur = $apptitem -> IsRecurring();
      $apptsubject = $apptitem -> Subject();
      $apptlocation = $apptitem -> Location();

      $secondsadj = $apptstart - 14400;
      $startadj = date("m/d/Y H:i:s", mktime(0,0,$secondsadj,1,1,1970));

      $secondsadj = $apptend - 14400;
      $endadj = date("m/d/Y H:i:s", mktime(0,0,$secondsadj,1,1,1970));

      if($apptallday) { $allday = "All Day"; } else { $allday = ""; }
      if($apptrecur) { $recurring = "Recurring"; } else { $recurring =
""; }

      echo "$apptsubject @ $apptlocation\r\nFrom: $startadj To:
$endadj\r\n";
      if ($allday <> "" OR $recurring <> "") echo "$allday
$recurring\r\n";
      echo "\r\n\r\n";
    }

  } else {
    die ("Did not find calendar folder");
  }

} else {
  die("Did not find target mailbox: $targetmailboxname");
}
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to