/** * Imports the values for this event from a MS ActiveSync Message. * * @see Horde_ActiveSync_Message_Appointment */ public function fromASAppointment(Horde_ActiveSync_Message_Appointment $message) { /* New event? */ if ($this->id === null) { $this->creator = $GLOBALS['registry']->getAuth(); } if (strlen($title = $message->getSubject())) { $this->title = $title; } if ($message->getProtocolVersion() == Horde_ActiveSync::VERSION_TWOFIVE && strlen($description = $message->getBody())) { $this->description = $description; } elseif ($message->getProtocolVersion() > Horde_ActiveSync::VERSION_TWOFIVE) { if ($message->airsyncbasebody->type == Horde_ActiveSync::BODYPREF_TYPE_HTML) { $this->description = Horde_Text_Filter::filter($message->airsyncbasebody->data, 'Html2text'); } else { $this->description = $message->airsyncbasebody->data; } } if (strlen($location = $message->getLocation())) { $this->location = $location; } /* Date/times */ $tz = $message->getTimezone(); $dates = $message->getDatetime(); $this->start = clone $dates['start']; $this->start->setTimezone($tz); $this->end = clone $dates['end']; $this->end->setTimezone($tz); $this->allday = $dates['allday']; if ($tz != date_default_timezone_get()) { $this->timezone = $tz; } /* Sensitivity */ $this->private = $message->getSensitivity() == Horde_ActiveSync_Message_Appointment::SENSITIVITY_PRIVATE || $message->getSensitivity() == Horde_ActiveSync_Message_Appointment::SENSITIVITY_CONFIDENTIAL ? true : false; /* Busy Status */ $status = $message->getBusyStatus(); switch ($status) { case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY: $status = Kronolith::STATUS_CONFIRMED; break; case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_FREE: $status = Kronolith::STATUS_FREE; break; case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_TENTATIVE: $status = Kronolith::STATUS_TENTATIVE; break; // @TODO: not sure how "Out" should show in kronolith... // @TODO: not sure how "Out" should show in kronolith... case Horde_ActiveSync_Message_Appointment::BUSYSTATUS_OUT: $status = Kronolith::STATUS_CONFIRMED; default: // EAS Specifies default should be free. $status = Kronolith::STATUS_FREE; } $this->status = $status; /* Alarm */ if ($alarm = $message->getReminder()) { $this->alarm = $alarm; } /* Recurrence */ if ($rrule = $message->getRecurrence()) { /* Exceptions */ /* Since AS keeps exceptions as part of the original event, we need to * delete all existing exceptions and re-create them. The only drawback * to this is that the UIDs will change. */ $kronolith_driver = Kronolith::getDriver(null, $this->calendar); $this->recurrence = $rrule; if (!empty($this->uid)) { $search = new StdClass(); $search->start = $rrule->getRecurStart(); $search->end = $rrule->getRecurEnd(); $search->baseid = $this->uid; $results = $kronolith_driver->search($search); foreach ($results as $days) { foreach ($days as $exception) { $kronolith_driver->deleteEvent($exception->id); } } } $erules = $message->getExceptions(); foreach ($erules as $rule) { /* Readd the exception event, but only if not deleted */ if (!$rule->deleted) { $event = $kronolith_driver->getEvent(); $times = $rule->getDatetime(); $original = $rule->getExceptionStartTime(); $original->setTimezone($tz); $this->recurrence->addException($original->format('Y'), $original->format('m'), $original->format('d')); $event->start = $times['start']; $event->end = $times['end']; $event->start->setTimezone($tz); $event->end->setTimezone($tz); $event->allday = $times['allday']; $event->title = $rule->getSubject(); $event->title = empty($event->title) ? $this->title : $event->title; $event->description = $rule->getBody(); $event->description = empty($event->description) ? $this->description : $event->description; $event->baseid = $this->uid; $event->exceptionoriginaldate = $original; $event->initialized = true; if ($tz != date_default_timezone_get()) { $event->timezone = $tz; } $event->save(); } else { /* For exceptions that are deletions, just add the exception */ $exceptiondt = $rule->getExceptionStartTime(); $exceptiondt->setTimezone($tz); $this->recurrence->addException($exceptiondt->format('Y'), $exceptiondt->format('m'), $exceptiondt->format('d')); } } } /* Attendees */ $attendees = $message->getAttendees(); foreach ($attendees as $attendee) { switch ($attendee->status) { case Horde_ActiveSync_Message_Attendee::STATUS_ACCEPT: $response_code = Kronolith::RESPONSE_ACCEPTED; break; case Horde_ActiveSync_Message_Attendee::STATUS_DECLINE: $response_code = Kronolith::RESPONSE_DECLINED; break; case Horde_ActiveSync_Message_Attendee::STATUS_TENTATIVE: $response_code = Kronolith::RESPONSE_TENTATIVE; break; default: $response_code = Kronolith::RESPONSE_NONE; } switch ($attendee->type) { case Horde_ActiveSync_Message_Attendee::TYPE_REQUIRED: $part_type = Kronolith::PART_REQUIRED; break; case Horde_ActiveSync_Message_Attendee::TYPE_OPTIONAL: $part_type = Kronolith::PART_OPTIONAL; break; case Horde_ActiveSync_Message_Attendee::TYPE_RESOURCE: $part_type = Kronolith::PART_REQUIRED; } $this->addAttendee($attendee->email, $part_type, $response_code, $attendee->name); } /* Categories (Tags) */ $this->_tags = $message->getCategories(); // 14.1 if ($message->getProtocolVersion() >= Horde_ActiveSync::VERSION_FOURTEENONE) { $this->url = $message->onlinemeetingexternallink; } /* Flag that we are initialized */ $this->initialized = true; }
/** * Handle adding/editing exceptions from EAS 16.0 clients. * * @param Horde_ActiveSync_Message_Appointment $message * * @return boolean */ protected function _handleEas16Exception(Horde_ActiveSync_Message_Appointment $message) { if (!$this->recurs()) { return false; } $tz = $message->getTimezone(); $kronolith_driver = $this->getDriver(); // Do we already have an exception for this day? If so, remove the // bound exception (but don't need to remove it from the recurrence // object since we are just replacing it). $search = new StdClass(); $search->baseid = $this->uid; $results = $kronolith_driver->search($search); foreach ($results as $days) { foreach ($days as $exception) { if ($exception->exceptionoriginaldate->setTimezone('UTC')->format('Ymd\\THis\\Z') == $message->instanceid) { $kronolith_driver->deleteEvent($exception->id); break; } } } // Ensure the exception is added to the recurrence object. $original = new Horde_Date($message->instanceid, 'UTC'); $original->setTimezone($tz); $this->recurrence->addException($original->format('Y'), $original->format('m'), $original->format('d')); // Create the new exception event. $event = $kronolith_driver->getEvent(); if ($message->starttime) { $event->start = clone $message->starttime; $event->start->setTimezone($tz); } else { $event->start = clone $this->start; } if ($message->endtime) { $event->end = clone $message->endtime; $event->end->setTimezone($tz); } else { $event->end = clone $this->end; } $event->title = $message->subject ? $message->subject : $this->title; $event->description = $message->getBody(); $event->description = empty($event->description) ? $this->description : $event->description; $event->baseid = $this->uid; $event->exceptionoriginaldate = new Horde_Date($message->instanceid, 'UTC'); $event->exceptionoriginaldate->setTimezone($tz); $event->initialized = true; if ($tz != date_default_timezone_get()) { $event->timezone = $tz; } $event->save(); return true; }