/** * testNotificationWithSpecialCharContactName */ public function testNotificationWithSpecialCharContactName() { $this->_mailer->flush(); // create contact with special chars $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'Hüßgen', 'n_given' => 'Silke', 'email' => Tinebase_Core::getUser()->accountEmailAddress)), FALSE); // send notification $subject = 'äöü unittest notification'; $text = 'unittest notification text'; Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), array($contact), $subject, $text); // check mail (encoding) $messages = $this->_mailer->getMessages(); $this->assertEquals(1, count($messages)); $headers = $messages[0]->getHeaders(); $this->assertEquals('=?UTF-8?Q?=C3=A4=C3=B6=C3=BC=20unittest=20notification?=', $headers['Subject'][0]); $this->assertEquals('"=?UTF-8?Q?Silke=20H=C3=BC=C3=9Fgen?=" <' . Tinebase_Core::getUser()->accountEmailAddress . '>', $headers['To'][0]); $this->assertEquals('UTF-8', $messages[0]->getCharset()); }
/** * Send the reading confirmation in a message who has the correct header and is not seen yet * * @return void */ public function sendReadingConfirmation() { if (!is_array($this->headers)) { $this->headers = Expressomail_Controller_Message::getInstance()->getMessageHeaders($this->getId(), NULL, TRUE); } if (array_key_exists('disposition-notification-to', $this->headers) && $this->headers['disposition-notification-to'] && !$this->hasSeenFlag() && !$this->hasReadFlag() && !$this->hasDraftFlag()) { $translate = Tinebase_Translation::getTranslation($this->_application); $from = Expressomail_Controller_Account::getInstance()->get($this->account_id); $arrRet = array(); preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $this->headers['disposition-notification-to'], $arrRet); $to = $arrRet[0]; if ($from->email === $to) { return; } // calculate timezone in "GMT-HH:MM" format $dtz = new DateTimeZone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE)); $time = new DateTime('now', $dtz); $offset = $dtz->getOffset($time); $sign = $offset < 0 ? "-" : "+"; $offset = abs($offset); $hours = floor($offset / 3600); $hours = $hours < 10 ? '0' . $hours : $hours; $minutes = offset % 60; $minutes = $minutes < 10 ? '0' . $minutes : $minutes; $gmt = '(GMT' . $sign . $hours . ":" . $minutes . ')'; $subject = $translate->_('Reading Confirmation:') . ' ' . $this->subject; $readTime = date('Y-m-d H:i:s'); $tzReadTime = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($readTime)); $tzReceived = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($this->received)); $messageBody = $translate->_('Your message:') . ' ' . $this->subject . "\n" . $translate->_('Received on') . ' ' . $tzReceived . ' ' . $gmt . "\n" . $translate->_('Was read by:') . ' ' . $from->from . ' <' . $from->email . '> ' . $translate->_('on') . ' ' . $tzReadTime . ' ' . $gmt; //$messageBody = Expressomail_Message::convertFromTextToHTML($messageBody); $readconf = array('to' => $to, 'subject' => $this->subject, 'received' => $this->received, 'from_name' => $from->from, 'from_email' => $from->email, 'read_time' => $readTime); $mailPart = new Zend_Mime_Part(serialize($readconf)); $mailPart->charset = 'UTF-8'; $mailPart->type = 'text/readconf;'; $mailPart->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE; $contact = new Addressbook_Model_Contact(array('email' => $to, 'n_fn' => $from->from), true); $result = Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), array($contact), $subject, $messageBody, $mailPart, NULL); Expressomail_Controller_Message_Flags::getInstance()->addFlags($this->getId(), (array) 'Read'); } }
/** * send deactivation email to user * * @param mixed $accountId */ public function sendDeactivationNotification($accountId) { if (!Tinebase_Config::getInstance()->get(Tinebase_Config::ACCOUNT_DEACTIVATION_NOTIFICATION)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deactivation notification disabled.'); } return; } try { $user = $this->getFullUserById($accountId); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Send deactivation notification to user ' . $user->accountLoginName); } $translate = Tinebase_Translation::getTranslation('Tinebase'); $view = new Zend_View(); $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views'); $view->translate = $translate; $view->accountLoginName = $user->accountLoginName; // TODO add this? //$view->deactivationDate = $user->deactivationDate; $view->tine20Url = Tinebase_Core::getHostname(); $messageBody = $view->render('deactivationNotification.php'); $messageSubject = $translate->_('Your Tine 2.0 account has been deactivated'); $recipient = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId(), true); Tinebase_Notification::getInstance()->send(null, array($recipient), $messageSubject, $messageBody); } catch (Exception $e) { Tinebase_Exception::log($e); } }
/** * send notification to a single attender * * @param Calendar_Model_Attender $_attender * @param Calendar_Model_Event $_event * @param Tinebase_Model_FullAccount $_updater * @param string $_action * @param string $_notificationLevel * @param array $_updates * @return void * * TODO this needs major refactoring */ public function sendNotificationToAttender(Calendar_Model_Attender $_attender, $_event, $_updater, $_action, $_notificationLevel, $_updates = NULL) { try { $organizer = $_event->resolveOrganizer(); $organizerAccountId = $organizer->account_id; $attendee = $_attender->getResolvedUser(); if ($attendee instanceof Addressbook_Model_List) { // don't send notification to lists as we already resolved the list members for individual mails if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Skip notification for list " . $attendee->name); } return; } $attendeeAccountId = $_attender->getUserAccountId(); $prefUserId = $attendeeAccountId ? $attendeeAccountId : ($organizerAccountId ? $organizerAccountId : $_event->created_by); try { $prefUser = Tinebase_User::getInstance()->getFullUserById($prefUserId); } catch (Exception $e) { $prefUser = Tinebase_Core::getUser(); $prefUserId = $prefUser->getId(); } // get prefered language, timezone and notification level $locale = Tinebase_Translation::getLocale(Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::LOCALE, $prefUserId)); $timezone = Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::TIMEZONE, $prefUserId); $translate = Tinebase_Translation::getTranslation('Calendar', $locale); $sendLevel = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::NOTIFICATION_LEVEL, $prefUserId); $sendOnOwnActions = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::SEND_NOTIFICATION_OF_OWN_ACTIONS, $prefUserId); $sendAlarms = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::SEND_ALARM_NOTIFICATIONS, $prefUserId); // external (non account) notification if (!$attendeeAccountId) { // external organizer needs status updates $sendLevel = is_object($organizer) && $_attender->getEmail() == $organizer->getPreferedEmailAddress() ? 40 : 30; $sendOnOwnActions = false; $sendAlarms = false; } $recipients = array($attendee); $this->_handleResourceEditors($_attender, $_notificationLevel, $recipients, $_action, $sendLevel, $_updates); // check if user wants this notification NOTE: organizer gets mails unless she set notificationlevel to NONE // NOTE prefUser is organizer for external notifications if ($attendeeAccountId == $_updater->getId() && !$sendOnOwnActions || $sendLevel < $_notificationLevel && (is_object($organizer) && method_exists($attendee, 'getPreferedEmailAddress') && $attendee->getPreferedEmailAddress() != $organizer->getPreferedEmailAddress() || is_object($organizer) && !method_exists($attendee, 'getPreferedEmailAddress') && $attendee->email != $organizer->getPreferedEmailAddress() || $sendLevel == self::NOTIFICATION_LEVEL_NONE)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Preferred notification level not reached -> skipping notification for {$_attender->getEmail()}"); } return; } if ($_action == 'alarm' && !$sendAlarms) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " User does not want alarm mails -> skipping notification for {$_attender->getEmail()}"); } return; } $method = NULL; // NOTE $method gets set in _getSubject as referenced param $messageSubject = $this->_getSubject($_event, $_notificationLevel, $_action, $_updates, $timezone, $locale, $translate, $method, $_attender); // we don't send iMIP parts to external attendee if config is active if (Calendar_Config::getInstance()->get(Calendar_Config::DISABLE_EXTERNAL_IMIP) && !$attendeeAccountId) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " External iMIP is disabled."); } $method = NULL; } $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'); $calendarPart = null; $attachments = $this->_getAttachments($method, $_event, $_action, $_updater, $calendarPart); 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}"); } $sender = $_action == 'alarm' ? $prefUser : $_updater; Tinebase_Notification::getInstance()->send($sender, $recipients, $messageSubject, $messageBody, $calendarPart, $attachments); } catch (Exception $e) { Tinebase_Exception::log($e); return; } }
/** * 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; } }
public function inviteUsersToJoin($roomId, $users, $moderator) { $translate = Tinebase_Translation::getTranslation('Webconference'); $fullUser = Tinebase_Core::getUser(); $recipients = array(); foreach ($users as $user) { //$userName = $user[n_fn]; $addressbook = new Addressbook_Model_Contact($user); $userEmail = $addressbook->getPreferedEmailAddress(); $userName = $addressbook->n_fn; $url = Webconference_Controller_BigBlueButton::getInstance()->joinRoom($roomId, $moderator, $userName, $userEmail)->bbbUrl->bbbUrl; $subject = $translate->_("Invite User To Join Webconference"); $messagePlain = null; $_messageHtml = sprintf($translate->_("The user %s is inviting you to a Webconference"), Tinebase_Core::getUser()->accountFullName); $_messageHtml .= "<br/><br/>"; $_messageHtml .= "<div>"; $_messageHtml .= "<span class=\"{$url}\" />"; $_messageHtml .= "<span class=\"tinebase-webconference-link\">"; $_messageHtml .= $translate->_("Log in to Webconference"); $_messageHtml .= "</span>"; $_messageHtml .= "</div>"; $recipient = array($addressbook); Tinebase_Notification::getInstance()->send($fullUser, $recipient, $subject, $messagePlain, $_messageHtml); array_push($recipients, $user); } return array('message' => $translate->_('Users invited successfully') . '!'); }
/** * send mail with related (imported) leads for responsibles * * @param Addressbook_Model_Contact $responsible * @param Tinebase_Record_RecordSet */ protected function _sendNotificationToResponsible($responsible, $leads) { if (count($leads) === 0) { // do nothing return; } $view = new Zend_View(); $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views'); $translate = Tinebase_Translation::getTranslation('Crm'); $containerName = Tinebase_Container::getInstance()->get($leads->getFirstRecord()->container_id)->name; $view->lang_importedLeads = sprintf($translate->_('The following leads have just been imported into lead list %s'), $containerName); $view->importedLeads = $leads; $plain = $view->render('importNotificationPlain.php'); $subject = sprintf($translate->_('%s new leads have been imported'), count($leads)); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . $plain); } try { Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), array($responsible), $subject, $plain); } catch (Exception $e) { Tinebase_Exception::log($e, false); } }
/** * send notification to owner * * @param $container * @param $note */ protected function _sendNotification($container, $note) { if (empty($note)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Empty note: do not send notification for container ' . $container->name); } return; } $ownerId = Tinebase_Container::getInstance()->getContainerOwner($container); if ($ownerId !== FALSE) { try { $contact = Addressbook_Controller_Contact::getInstance()->getContactByUserId($ownerId, TRUE); } catch (Tinebase_Exception_NotFound $tenf) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Do not send notification for container ' . $container->name . ': ' . $tenf); } return; } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Sending notification for container ' . $container->name . ' to ' . $contact->n_fn); } $translate = Tinebase_Translation::getTranslation('Admin'); $messageSubject = $translate->_('Your container has been changed'); $messageBody = sprintf($translate->_('Your container has been changed by %1$s %2$sNote: %3$s'), Tinebase_Core::getUser()->accountDisplayName, "\n\n", $note); try { Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), array($contact), $messageSubject, $messageBody); } catch (Exception $e) { Tinebase_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . ' Could not send notification :' . $e); } } }
/** * creates notification text and sends out notifications * * @todo: * - add changes to mail body * - find updater in addressbook to notify him * - add products? * - add notification levels * * @param Crm_Model_Lead $_lead * @param Tinebase_Model_FullUser $_updater * @param string $_action {created|changed} * @param Crm_Model_Lead $_oldLead * @return void */ protected function doSendNotifications(Crm_Model_Lead $_lead, Tinebase_Model_FullUser $_updater, $_action, $_oldLead = NULL) { $sendOnOwnActions = Tinebase_Core::getPreference('Crm')->getValue(Crm_Preference::SEND_NOTIFICATION_OF_OWN_ACTIONS); if (!$sendOnOwnActions) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Sending of Lead notifications disabled by user.'); return; } $view = new Zend_View(); $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views'); $translate = Tinebase_Translation::getTranslation('Crm'); $view->updater = $_updater; $view->lead = $_lead; $settings = Crm_Controller::getInstance()->getConfigSettings(); $view->leadState = $settings->getOptionById($_lead->leadstate_id, 'leadstates'); $view->leadType = $settings->getOptionById($_lead->leadtype_id, 'leadtypes'); $view->leadSource = $settings->getOptionById($_lead->leadsource_id, 'leadsources'); $view->container = Tinebase_Container::getInstance()->getContainerById($_lead->container_id); if (isset($_lead->relations)) { $customer = $_lead->relations->filter('type', 'CUSTOMER')->getFirstRecord(); if ($customer) { $view->customer = $customer->related_record->n_fn; if (isset($customer->related_record->org_name)) { $view->customer .= ' (' . $customer->related_record->org_name . ')'; } } } if ($_lead->start instanceof DateTime) { $view->start = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_lead->start, NULL, NULL, 'date'); } else { $view->start = '-'; } if ($_lead->end instanceof DateTime) { $view->leadEnd = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_lead->end, NULL, NULL, 'date'); } else { $view->leadEnd = '-'; } if ($_lead->end_scheduled instanceof DateTime) { $view->ScheduledEnd = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_lead->end_scheduled, NULL, NULL, 'date'); } else { $view->ScheduledEnd = '-'; } $view->lang_customer = $translate->_('Customer'); $view->lang_state = $translate->_('State'); $view->lang_type = $translate->_('Role'); $view->lang_source = $translate->_('Source'); $view->lang_start = $translate->_('Start'); $view->lang_scheduledEnd = $translate->_('Scheduled end'); $view->lang_end = $translate->_('End'); $view->lang_turnover = $translate->_('Turnover'); $view->lang_probability = $translate->_('Probability'); $view->lang_folder = $translate->_('Folder'); $view->lang_updatedBy = $translate->_('Updated by'); $view->lang_updatedFields = $translate->_('Updated Fields:'); $view->lang_updatedFieldMsg = $translate->_('%s changed from %s to %s.'); $plain = $view->render('newLeadPlain.php'); $html = $view->render('newLeadHtml.php'); if ($_action == 'changed') { $subject = sprintf($translate->_('Lead %s has been changed'), $_lead->lead_name); } else { if ($_action == 'deleted') { $subject = sprintf($translate->_('Lead %s has been deleted'), $_lead->lead_name); } else { $subject = sprintf($translate->_('Lead %s has been created'), $_lead->lead_name); } } // create pdf try { $pdfGenerator = new Crm_Export_Pdf(); $pdfGenerator->generate($_lead); $attachment = array('rawdata' => $pdfGenerator->render(), 'filename' => $_lead->lead_name . '.pdf'); } catch (Zend_Pdf_Exception $e) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' error creating pdf: ' . $e->__toString()); $attachment = NULL; } $recipients = $this->_getNotificationRecipients($_lead); // send notification to updater in any case! if (!in_array($_updater->contact_id, $recipients->getArrayOfIds())) { $updaterContact = Addressbook_Controller_Contact::getInstance()->get($_updater->contact_id); $recipients->addRecord($updaterContact); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . $plain); } try { Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), $recipients, $subject, $plain, $html, array($attachment)); } catch (Exception $e) { Tinebase_Core::getLogger()->warn(__CLASS__ . '::' . __METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__CLASS__ . '::' . __METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString()); } } }
/** * send notification to a single attender * * @param Webconference_Model_Event $_event * @param Tinebase_Model_FullAccount $_updater * @return void */ public function sendNotificationToAttender($users, $moderator, $roomName) { $translate = Tinebase_Translation::getTranslation('Webconference'); 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); // get date strings $startDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtstart, $timezone, $locale); $endDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtend, $timezone, $locale); $messageSubject = sprintf($translate->_('Attendee changes for event "%1$s" at %2$s' ), $_event->summary, $startDateString); */ $fullUser = Tinebase_Core::getUser(); foreach ($users as $user) { $userName = $user[n_fn]; $url = Webconference_Controller_BigBlueButton::getInstance()->joinRoom($roomName, $moderator, $userName)->bbbUrl->bbbUrl; //$webconfMail = new Webconference_Model_Invite($url, $roomName, $moderator, $fullUser, $userName); $webconfMail = new Webconference_Model_Invite(array('url' => $url, 'roomName' => $roomName, 'moderator' => $moderator, 'createdBy' => $fullUser, 'to' => $userName), true); $messageSubject = $translate->_("Webconference Invite"); $view = new Zend_View(); $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views'); $view->translate = $translate; //$view->timezone = $timezone; $view->url = $url; $view->fullUser = $fullUser; $method = 'Webconference'; $messageBody = $view->render('eventNotification.php'); $mailPart = new Zend_Mime_Part(serialize($webconfMail)); $mailPart->charset = 'UTF-8'; $mailPart->type = 'text/webconference; method=' . $method; $mailPart->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE; $attachments = null; $contact = new Addressbook_Model_Contact($user); $sender = $fullUser; $result = Tinebase_Notification::getInstance()->send($sender, array($contact), $messageSubject, $messageBody, $mailPart, $attachments); } } catch (Exception $e) { Tinebase_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . " could not send notification :" . $e); return array('message' => $e->getMessage(), 'result' => $translate->_('An error has occured inviting users')); } return array('success' => TRUE, 'message' => $translate->_('Users invited successfully') . '!'); }