/**
  * append organizer name and email
  *
  * @param Syncroton_Model_Event $syncrotonEvent
  * @param Calendar_Model_Event $event
  */
 protected function _addOrganizer(Syncroton_Model_Event $syncrotonEvent, Calendar_Model_Event $event)
 {
     $organizer = NULL;
     if (!empty($event->organizer)) {
         try {
             $organizer = $event->resolveOrganizer();
         } catch (Tinebase_Exception_AccessDenied $tead) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " " . $tead);
             }
         }
     }
     if ($organizer instanceof Addressbook_Model_Contact) {
         $organizerName = $organizer->n_fileas;
         $organizerEmail = $organizer->getPreferedEmailAddress();
     } else {
         // set the current account as organizer
         // if organizer is not set, you can not edit the event on the Motorola Milestone
         $organizerName = Tinebase_Core::getUser()->accountFullName;
         $organizerEmail = Tinebase_Core::getUser()->accountEmailAddress;
     }
     $syncrotonEvent->organizerName = $organizerName;
     if ($organizerEmail) {
         $syncrotonEvent->organizerEmail = $organizerEmail;
     }
 }
 /**
  * get notification subject and method
  * 
  * @param Calendar_Model_Event $_event
  * @param string $_notificationLevel
  * @param string $_action
  * @param array $_updates
  * @param string $timezone
  * @param Zend_Locale $locale
  * @param Zend_Translate $translate
  * @param atring $method
  * @param Calendar_Model_Attender
  * @return string
  * @throws Tinebase_Exception_UnexpectedValue
  */
 protected function _getSubject($_event, $_notificationLevel, $_action, $_updates, $timezone, $locale, $translate, &$method, Calendar_Model_Attender $attender)
 {
     $startDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtstart, $timezone, $locale);
     $endDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtend, $timezone, $locale);
     switch ($_action) {
         case 'alarm':
             $messageSubject = sprintf($translate->_('Alarm for event "%1$s" at %2$s'), $_event->summary, $startDateString);
             break;
         case 'created':
             $messageSubject = sprintf($translate->_('Event invitation "%1$s" at %2$s'), $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_REQUEST;
             break;
         case 'booked':
             if ($attender->user_type !== Calendar_Model_Attender::USERTYPE_RESOURCE) {
                 throw new Tinebase_Exception_UnexpectedValue('not a resource');
             }
             $resource = Calendar_Controller_Resource::getInstance()->get($attender->user_id);
             $messageSubject = sprintf($translate->_('Resource "%1$s" was booked for "%2$s" at %3$s'), $resource->name, $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_REQUEST;
             break;
         case 'deleted':
             $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been canceled'), $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_CANCEL;
             break;
         case 'changed':
             switch ($_notificationLevel) {
                 case self::NOTIFICATION_LEVEL_EVENT_RESCHEDULE:
                     if (isset($_updates['dtstart']) || array_key_exists('dtstart', $_updates)) {
                         $oldStartDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_updates['dtstart'], $timezone, $locale);
                         $messageSubject = sprintf($translate->_('Event "%1$s" has been rescheduled from %2$s to %3$s'), $_event->summary, $oldStartDateString, $startDateString);
                         $method = Calendar_Model_iMIP::METHOD_REQUEST;
                         break;
                     }
                     // fallthrough if dtstart didn't change
                 // fallthrough if dtstart didn't change
                 case self::NOTIFICATION_LEVEL_EVENT_UPDATE:
                     $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been updated'), $_event->summary, $startDateString);
                     $method = Calendar_Model_iMIP::METHOD_REQUEST;
                     break;
                 case self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE:
                     if (!empty($_updates['attendee']) && !empty($_updates['attendee']['toUpdate']) && count($_updates['attendee']['toUpdate']) == 1) {
                         // single attendee status update
                         $attender = $_updates['attendee']['toUpdate']->getFirstRecord();
                         switch ($attender->status) {
                             case Calendar_Model_Attender::STATUS_ACCEPTED:
                                 $messageSubject = sprintf($translate->_('%1$s accepted event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_DECLINED:
                                 $messageSubject = sprintf($translate->_('%1$s declined event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_TENTATIVE:
                                 $messageSubject = sprintf($translate->_('Tentative response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_NEEDSACTION:
                                 $messageSubject = sprintf($translate->_('No response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                         }
                     } else {
                         $messageSubject = sprintf($translate->_('Attendee changes for event "%1$s" at %2$s'), $_event->summary, $startDateString);
                     }
                     // we don't send iMIP parts to organizers with an account cause event is already up to date
                     if ($_event->organizer && !$_event->resolveOrganizer()->account_id) {
                         $method = Calendar_Model_iMIP::METHOD_REPLY;
                     }
                     break;
             }
             break;
         default:
             $messageSubject = 'unknown action';
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " unknown action '{$_action}'");
             }
             break;
     }
     if ($attender->user_type === Calendar_Model_Attender::USERTYPE_RESOURCE) {
         $messageSubject = '[' . $translate->_('Resource Management') . '] ' . $messageSubject;
     }
     return $messageSubject;
 }
 /**
  * send notification to a single attender
  * 
  * @param Calendar_Model_Attender    $_attender
  * @param Calendar_Model_Event       $_event
  * @param Tinebase_Model_FullAccount $_updater
  * @param Sting                      $_action
  * @param String                     $_notificationLevel
  * @param array                      $_updates
  * @param array                      $attachs
  * @return void
  */
 public function sendNotificationToAttender($_attender, $_event, $_updater, $_action, $_notificationLevel, $_updates = NULL, $attachs = FALSE)
 {
     try {
         // find organizer account
         if ($_event->organizer && $_event->resolveOrganizer()->account_id) {
             $organizer = Tinebase_User::getInstance()->getFullUserById($_event->resolveOrganizer()->account_id);
         } else {
             // use creator as organizer
             $organizer = Tinebase_User::getInstance()->getFullUserById($_event->created_by);
         }
         // get prefered language, timezone and notification level
         $prefUser = $_attender->getUserAccountId();
         $locale = Tinebase_Translation::getLocale(Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::LOCALE, $prefUser ? $prefUser : $organizer->getId()));
         $timezone = Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::TIMEZONE, $prefUser ? $prefUser : $organizer->getId());
         $translate = Tinebase_Translation::getTranslation('Calendar', $locale);
         // check if user wants this notification
         $sendLevel = $prefUser ? Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::NOTIFICATION_LEVEL, $prefUser) : 100;
         $sendOnOwnActions = $prefUser ? Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::SEND_NOTIFICATION_OF_OWN_ACTIONS, $prefUser) : 0;
         // NOTE: organizer gets mails unless she set notificationlevel to NONE
         if ($prefUser == $_updater->getId() && !$sendOnOwnActions || $sendLevel < $_notificationLevel && ($prefUser != $organizer->getId() || $sendLevel == self::NOTIFICATION_LEVEL_NONE)) {
             return;
         }
         // get date strings
         $startDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtstart, $timezone, $locale);
         $endDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtend, $timezone, $locale);
         switch ($_action) {
             case 'alarm':
                 $messageSubject = sprintf($translate->_('Alarm for event "%1$s" at %2$s'), $_event->summary, $startDateString);
                 break;
             case 'created':
                 $messageSubject = sprintf($translate->_('Event invitation "%1$s" at %2$s'), $_event->summary, $startDateString);
                 $method = Calendar_Model_iMIP::METHOD_REQUEST;
                 break;
             case 'deleted':
                 $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been canceled'), $_event->summary, $startDateString);
                 $method = Calendar_Model_iMIP::METHOD_CANCEL;
                 break;
             case 'changed':
                 switch ($_notificationLevel) {
                     case self::NOTIFICATION_LEVEL_EVENT_RESCHEDULE:
                         $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been rescheduled'), $_event->summary, $startDateString);
                         $method = Calendar_Model_iMIP::METHOD_REQUEST;
                         break;
                     case self::NOTIFICATION_LEVEL_EVENT_UPDATE:
                         $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been updated'), $_event->summary, $startDateString);
                         $method = Calendar_Model_iMIP::METHOD_REQUEST;
                         break;
                     case self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE:
                         if (!empty($_updates['attendee']) && !empty($_updates['attendee']['toUpdate']) && count($_updates['attendee']['toUpdate']) == 1) {
                             // single attendee status update
                             $attender = $_updates['attendee']['toUpdate'][0];
                             switch ($attender->status) {
                                 case Calendar_Model_Attender::STATUS_ACCEPTED:
                                     $messageSubject = sprintf($translate->_('%1$s accepted event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                     break;
                                 case Calendar_Model_Attender::STATUS_DECLINED:
                                     $messageSubject = sprintf($translate->_('%1$s declined event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                     break;
                                 case Calendar_Model_Attender::STATUS_TENTATIVE:
                                     $messageSubject = sprintf($translate->_('Tentative response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                     break;
                                 case Calendar_Model_Attender::STATUS_NEEDSACTION:
                                     $messageSubject = sprintf($translate->_('No response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                     break;
                             }
                         } else {
                             $messageSubject = sprintf($translate->_('Attendee changes for event "%1$s" at %2$s'), $_event->summary, $startDateString);
                         }
                         // we don't send iMIP parts to organizers with an account cause event is already up to date
                         if ($_event->organizer && !$_event->resolveOrganizer()->account_id) {
                             $method = Calendar_Model_iMIP::METHOD_REPLY;
                         }
                         break;
                 }
                 break;
             default:
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " unknown action '{$_action}'");
                 }
                 break;
         }
         $view = new Zend_View();
         $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
         $view->translate = $translate;
         $view->timezone = $timezone;
         $view->event = $_event;
         $view->updater = $_updater;
         $view->updates = $_updates;
         $messageBody = $view->render('eventNotification.php');
         if (isset($method) && version_compare(PHP_VERSION, '5.3.0', '>=')) {
             $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
             $converter->setMethod($method);
             $vcalendar = $converter->fromTine20Model($_event);
             // in Tine 2.0 non organizers might be given the grant to update events
             // @see rfc6047 section 2.2.1 & rfc5545 section 3.2.18
             if ($method != Calendar_Model_iMIP::METHOD_REPLY && $_event->organizer !== $_updater->contact_id) {
                 foreach ($vcalendar->children() as $component) {
                     if ($component->name == 'VEVENT') {
                         if (isset($component->{'ORGANIZER'})) {
                             $component->{'ORGANIZER'}->add(new Sabre_VObject_Parameter('SEND-BY', 'mailto:' . $_updater->accountEmailAddress));
                         }
                     }
                 }
             }
             /* not yet supported
                // in Tine 2.0 status updater might not be updater
                if ($method == Calendar_Model_iMIP::METHOD_REPLY) {
                    
                }
                */
             $calendarPart = new Zend_Mime_Part($vcalendar->serialize());
             $calendarPart->charset = 'UTF-8';
             $calendarPart->type = 'text/calendar; method=' . $method;
             $calendarPart->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
             $attachment = new Zend_Mime_Part($vcalendar->serialize());
             $attachment->type = 'application/ics';
             $attachment->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
             $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
             $attachment->filename = 'event.ics';
             $attachments = array($attachment);
             if ($attachs) {
                 foreach ($attachs as $file) {
                     $stream = fopen($file['tempFile']['path'], 'r');
                     $part = new Zend_Mime_Part($stream);
                     $part->type = $file['tempFile']['type'];
                     $part->encoding = Zend_Mime::ENCODING_BASE64;
                     $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                     $part->filename = $file['tempFile']['name'];
                     $attachments[] = $part;
                 }
             }
         } else {
             $calendarPart = null;
             $attachments = null;
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " receiver: '{$_attender->getEmail()}'");
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " subject: '{$messageSubject}'");
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " body: {$messageBody}");
         }
         // NOTE: this is a contact as we only support users and groupmembers
         $contact = $_attender->getResolvedUser();
         $sender = $_action == 'alarm' ? $organizer : $_updater;
         Tinebase_Notification::getInstance()->send($sender, array($contact), $messageSubject, $messageBody, $calendarPart, $attachments);
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . " could not send notification :" . $e);
         return;
     }
 }
Пример #4
0
 /**
  * inspect before create/update
  * 
  * @TODO move stuff from other places here
  * @param   Calendar_Model_Event $_record      the record to inspect
  */
 protected function _inspectEvent($_record)
 {
     $_record->uid = $_record->uid ? $_record->uid : Tinebase_Record_Abstract::generateUID();
     $_record->originator_tz = $_record->originator_tz ? $_record->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     $_record->organizer = $_record->organizer ? $_record->organizer : Tinebase_Core::getUser()->contact_id;
     // external organizer (iTIP)
     if (!$_record->resolveOrganizer()->account_id && count($_record->attendee) > 1) {
         $ownAttendee = Calendar_Model_Attender::getOwnAttender($_record->attendee);
         $_record->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', $ownAttendee ? array($ownAttendee) : array());
     }
     $_record->setRruleUntil();
 }