public function __construct($certificate, $dontSkip = FALSE) { $config = Tinebase_Config::getInstance()->get('modssl'); if (is_object($config)) { $this->casfile = $config->casfile; $this->crlspath = $config->crlspath; } $this->status = array('isValid' => true, 'errors' => array()); $this->certificate = self::_fixPemCertificate($certificate); $c = openssl_x509_parse($this->certificate); // define certificate properties $this->serialNumber = $c['serialNumber']; $this->version = $c['version']; $this->subject = $c['subject']; $this->cn = $c['subject']['CN']; $this->issuer = $c['issuer']; $this->issuerCn = $c['issuer']['CN']; $this->hash = $this->_calcHash(); // $dateTimezone = new DateTimeZone(Tinebase_Core::getUserTimezone()); // $locale = new Zend_Locale($_translation->getAdapter()->getLocale()); // Date valid from $this->validFrom = Tinebase_Translation::dateToStringInTzAndLocaleFormat(new Tinebase_DateTime($c['validFrom_time_t'])); // Date valid to $this->validTo = Tinebase_Translation::dateToStringInTzAndLocaleFormat(new Tinebase_DateTime($c['validTo_time_t'])); $this->_parsePurpose($c['purposes']); $this->_parseExtensions($c['extensions']); if (strtolower($this->casfile) != 'skip') { $this->_validityCheck(); // skip validation, we trust the server's result } if (strtolower($this->crlspath) != 'skip' | $dontSkip) { $this->_testRevoked(); // skip test, } }
/** * do the rendering * * @param array $result */ protected function _onAfterExportRecords($result) { $templateProcessor = $this->getDocument(); // first step: generate layout $dayblock = $templateProcessor->cloneBlock('DAYBLOCK', 1, false); $seperator = $templateProcessor->cloneBlock('SEPARATOR', 1, false); $dayCount = count($this->_daysEventMatrix); $daysblock = $dayCount ? $dayblock : ''; for ($i = 1; $i < $dayCount; $i++) { $daysblock .= $seperator; $daysblock .= $dayblock; } $templateProcessor->replaceBlock('DAYBLOCK', $daysblock); $templateProcessor->deleteBlock('SEPARATOR'); // second step: render events foreach ($this->_daysEventMatrix as $dayString => $dayEvents) { $this->processDay($dayString, $dayEvents); } // third step: render generics if ($this->_from instanceof Tinebase_DateTime) { $templateProcessor->setValue('from', Tinebase_Translation::dateToStringInTzAndLocaleFormat($this->_from, null, null, $this->_config->dateformat)); } if ($this->_until instanceof Tinebase_DateTime) { $templateProcessor->setValue('until', Tinebase_Translation::dateToStringInTzAndLocaleFormat($this->_until->getClone()->subSecond(1), null, null, $this->_config->dateformat)); } parent::_onAfterExportRecords($result); }
/** * test csv export * * @return void * * @see 0007242: add customer address fields to lead csv export */ public function testExportCsv() { $this->_filename = $this->_instance->generate(); $export = file_get_contents($this->_filename); $translate = Tinebase_Translation::getTranslation('Crm'); $defaultContainerId = Tinebase_Container::getInstance()->getDefaultContainer('Crm')->getId(); $this->assertContains('"lead_name","leadstate_id","Leadstate","leadtype_id","Leadtype","leadsource_id","Leadsource","container_id","start"' . ',"description","end","turnover","probableTurnover","probability","end_scheduled","resubmission_date","tags","attachments","notes","seq","tags",' . '"CUSTOMER-org_name","CUSTOMER-n_family","CUSTOMER-n_given","CUSTOMER-adr_one_street","CUSTOMER-adr_one_postalcode","CUSTOMER-adr_one_locality",' . '"CUSTOMER-adr_one_countryname","CUSTOMER-tel_work","CUSTOMER-tel_cell","CUSTOMER-email",' . '"PARTNER","RESPONSIBLE","TASK"', $export, 'headline wrong: ' . substr($export, 0, 360)); $this->assertContains('"PHPUnit","1","' . $translate->_('open') . '","1","' . $translate->_('Customer') . '","1","' . $translate->_('Market') . '","' . $defaultContainerId . '"', $export, 'data #1 wrong'); $this->assertContains('"Metaways Infosystems GmbH","Kneschke","Lars","Pickhuben 4","24xxx","Hamburg","DE","+49TELWORK","+49TELCELL","*****@*****.**"' . ',"","","phpunit: crm test task"', $export, 'relations wrong'); $dateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat(NULL, NULL, NULL, 'date'); $this->assertContains($dateString, $export, 'note date wrong'); }
/** * test csv export * * @return void */ public function testExportCsv() { $csvFilename = $this->_instance->generate(); $export = file_get_contents($csvFilename); $translate = Tinebase_Translation::getTranslation('Crm'); $defaultContainerId = Tinebase_Container::getInstance()->getDefaultContainer('Crm')->getId(); $this->assertContains('"lead_name","leadstate_id","Leadstate","leadtype_id","Leadtype","leadsource_id","Leadsource","container_id","start"' . ',"description","end","turnover","probableTurnover","probability","end_scheduled","tags","notes","tags","CUSTOMER","PARTNER","RESPONSIBLE","TASK"', $export, 'headline wrong'); $this->assertContains('"PHPUnit","1","' . $translate->_('open') . '","1","' . $translate->_('Customer') . '","1","' . $translate->_('Market') . '","' . $defaultContainerId . '"', $export, 'data #1 wrong'); $this->assertContains('"Kneschke, Lars","","phpunit: crm test task"', $export, 'relations wrong'); $dateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat(NULL, NULL, NULL, 'date'); $this->assertContains($dateString, $export, 'note date wrong'); unlink($csvFilename); }
/** * add notes and activities to pdf * * @param array $record * @param Tinebase_Record_RecordSet $_notes */ protected function _addActivities($record, $_notes) { $translate = Tinebase_Translation::getTranslation('Tinebase'); if (!empty($_notes)) { $noteTypes = Tinebase_Notes::getInstance()->getNoteTypes(); $record[] = array('label' => $translate->_('Activities'), 'type' => 'separator'); foreach ($_notes as $note) { if ($note instanceof Tinebase_Model_Note) { $noteArray = $note->toArray(); $noteText = strlen($note->note) > 100 ? substr($note->note, 0, 99) . '...' : $note->note; $noteType = $noteTypes[$noteTypes->getIndexById($note->note_type_id)]; $time = Tinebase_Translation::dateToStringInTzAndLocaleFormat($note->creation_time); $createdBy = '(' . $noteArray['created_by'] . ')'; $record[] = array('label' => $time, 'type' => 'multiRow', 'value' => array(array('icon' => '/' . $noteType->icon), $noteText, $createdBy)); } } } return $record; }
/** * gets translated value * * NOTE: This is needed for values like Yes/No, Datetimes, etc. * * @param string $_field * @param mixed $_value * @param Zend_Translate $_translation * @param string $_timezone * @return string */ public static function getTranslatedValue($_field, $_value, $_translation, $_timezone) { if ($_value instanceof Tinebase_DateTime) { $locale = new Zend_Locale($_translation->getAdapter()->getLocale()); return Tinebase_Translation::dateToStringInTzAndLocaleFormat($_value, $_timezone, $locale, 'datetime', true); } switch ($_field) { case 'transp': return $_value && $_value == Calendar_Model_Event::TRANSP_TRANSP ? $_translation->_('No') : $_translation->_('Yes'); case 'organizer': if (!$_value instanceof Addressbook_Model_Contact) { $organizer = Addressbook_Controller_Contact::getInstance()->getMultiple($_value, TRUE)->getFirstRecord(); } return $organizer instanceof Addressbook_Model_Contact ? $organizer->n_fileas : ''; case 'rrule': if ($_value) { $rrule = $_value instanceof Calendar_Model_Rrule ? $_value : new Calendar_Model_Rrule($_value); return $rrule->getTranslatedRule($_translation); } default: return $_value; } }
/** * 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; } }
/** * create contact pdf * * @param Addressbook_Model_Contact $_contact contact data * * @return string the contact pdf */ public function generate(Addressbook_Model_Contact $_contact) { $locale = Tinebase_Core::get('locale'); $translate = Tinebase_Translation::getTranslation('Addressbook'); // set user timezone $_contact->setTimezone(Tinebase_Core::getUserTimezone()); $contactFields = array(array('label' => $translate->_('Business Contact Data'), 'type' => 'separator'), array('label' => $translate->_('Organisation / Unit'), 'type' => 'singleRow', 'value' => array(array('org_name', 'org_unit')), 'glue' => ' / '), array('label' => $translate->_('Business Address'), 'type' => 'multiRow', 'value' => array('adr_one_street', 'adr_one_street2', array('adr_one_postalcode', 'adr_one_locality'), array('adr_one_region', 'adr_one_countryname'))), array('label' => $translate->_('Email'), 'value' => array('email')), array('label' => $translate->_('Telephone Work'), 'value' => array('tel_work')), array('label' => $translate->_('Telephone Cellphone'), 'value' => array('tel_cell')), array('label' => $translate->_('Telephone Car'), 'value' => array('tel_car')), array('label' => $translate->_('Telephone Fax'), 'value' => array('tel_fax')), array('label' => $translate->_('Telephone Page'), 'value' => array('tel_pager')), array('label' => $translate->_('URL'), 'value' => array('url')), array('label' => $translate->_('Role'), 'value' => array('role')), array('label' => $translate->_('Room'), 'value' => array('room')), array('label' => $translate->_('Assistant'), 'value' => array('assistent')), array('label' => $translate->_('Assistant Telephone'), 'value' => array('tel_assistent')), array('label' => $translate->_('Private Contact Data'), 'type' => 'separator'), array('label' => $translate->_('Private Address'), 'type' => 'multiRow', 'value' => array('adr_two_street', 'adr_two_street2', array('adr_two_postalcode', 'adr_two_locality'), array('adr_two_region', 'adr_two_countryname'))), array('label' => $translate->_('Email Home'), 'value' => array('email_home')), array('label' => $translate->_('Telephone Home'), 'value' => array('tel_home')), array('label' => $translate->_('Telephone Cellphone Private'), 'value' => array('tel_cell_private')), array('label' => $translate->_('Telephone Fax Home'), 'value' => array('tel_fax_home')), array('label' => $translate->_('URL Home'), 'value' => array('url_home')), array('label' => $translate->_('Other Data'), 'type' => 'separator'), array('label' => $translate->_('Birthday'), 'value' => array('bday')), array('label' => $translate->_('Job Title'), 'value' => array('title'))); try { $tineImage = Addressbook_Controller::getInstance()->getImage($_contact->getId()); Tinebase_ImageHelper::resize($tineImage, 160, 240, Tinebase_ImageHelper::RATIOMODE_PRESERVANDCROP); $tmpPath = tempnam(Tinebase_Core::getTempDir(), 'tine20_tmp_gd'); $tmpPath .= $tineImage->getImageExtension(); file_put_contents($tmpPath, $tineImage->blob); $contactPhoto = Zend_Pdf_Image::imageWithPath($tmpPath); unlink($tmpPath); } catch (Exception $e) { // gif images are not supported yet by zf (or some other error) if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $e->__toString()); } $contactPhoto = NULL; } // build title (name) + subtitle + icon $nameFields = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix'); $titleArray = array(); foreach ($nameFields as $nameField) { if (!empty($_contact[$nameField])) { $titleArray[] = $_contact[$nameField]; } } $title = implode(' ', $titleArray); $subtitle = $_contact->org_name; $titleIcon = "/images/oxygen/32x32/apps/system-users.png"; // add data to array $record = array(); foreach ($contactFields as $fieldArray) { if (!isset($fieldArray['type']) || $fieldArray['type'] !== 'separator') { $values = array(); foreach ($fieldArray['value'] as $valueFields) { $content = array(); if (is_array($valueFields)) { $keys = $valueFields; } else { $keys = array($valueFields); } foreach ($keys as $key) { if ($_contact->{$key} instanceof Tinebase_DateTime) { $content[] = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_contact->{$key}, NULL, NULL, 'date'); } elseif (!empty($_contact->{$key})) { if (preg_match("/countryname/", $key)) { $content[] = Zend_Locale::getTranslation($_contact->{$key}, 'country', $locale); } else { $content[] = $_contact->{$key}; } } } if (!empty($content)) { $glue = isset($fieldArray['glue']) ? $fieldArray['glue'] : " "; $values[] = implode($glue, $content); } } if (!empty($values)) { $record[] = array('label' => $fieldArray['label'], 'type' => isset($fieldArray['type']) ? $fieldArray['type'] : 'singleRow', 'value' => sizeof($values) === 1 ? $values[0] : $values); } } elseif (isset($fieldArray['type']) && $fieldArray['type'] === 'separator') { $record[] = $fieldArray; } } // add notes $record = $this->_addActivities($record, $_contact->notes); //print_r($record); // tags $tags = isset($_contact['tags']) ? $_contact['tags'] : array(); // generate pdf $this->generatePdf($record, $title, $subtitle, $tags, $_contact->note, $titleIcon, $contactPhoto, array(), FALSE); }
/** * 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()); } } }
/** * 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; }
/** * test import * * @see 0006226: Data truncated for column 'adr_two_lon' * * TODO move import test to separate test class */ public function testImport() { $this->_testNeedsTransaction(); $result = $this->_importHelper(); $this->assertEquals(2, $result['totalcount'], 'dryrun should detect 2 for import.' . print_r($result, TRUE)); $this->assertEquals(0, $result['failcount'], 'Import failed for one or more records.'); $this->assertEquals('Müller, Klaus', $result['results'][0]['n_fileas'], 'file as not found'); // import again without dryrun $result = $this->_importHelper(array('dryrun' => 0)); $this->assertEquals(2, $result['totalcount'], 'Didn\'t import anything.'); $klaus = $result['results'][0]; $this->assertEquals('Import list (' . Tinebase_Translation::dateToStringInTzAndLocaleFormat(Tinebase_DateTime::now(), NULL, NULL, 'date') . ')', $klaus['tags'][0]['name']); // import with duplicates $result = $this->_importHelper(array('dryrun' => 0)); $this->assertEquals(0, $result['totalcount'], 'Do not import anything.'); $this->assertEquals(2, $result['duplicatecount'], 'Should find 2 dups.'); $this->assertEquals(1, count($result['exceptions'][0]['exception']['clientRecord']['tags']), '1 autotag expected'); // import again with clientRecords $klaus['adr_one_locality'] = 'Hamburg'; // check that empty filter works correctly, db only accepts NULL for empty value here $klaus['adr_two_lon'] = ''; $clientRecords = array(array('recordData' => $klaus, 'resolveStrategy' => 'mergeMine', 'index' => 0)); $result = $this->_importHelper(array('dryrun' => 0), $clientRecords); $this->assertEquals(1, $result['totalcount'], 'Should merge Klaus: ' . print_r($result, TRUE)); $this->assertEquals(1, $result['duplicatecount'], 'Fritz is no duplicate.'); $this->assertEquals('Hamburg', $result['results'][0]['adr_one_locality'], 'locality should change'); }
/** * add relation values from related records * * @param Tinebase_Record_Abstract $_record * @param string $_fieldName * @param string $_recordField * @return string */ protected function _addNotes(Tinebase_Record_Abstract $_record) { //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_record->notes->toArray(), true)); $resultArray = array(); foreach ($_record->notes as $note) { $date = Tinebase_Translation::dateToStringInTzAndLocaleFormat($note->creation_time); $resultArray[] = $date . ' - ' . $note->note; } $result = implode(';', $resultArray); return $result; }
/** * do substitutions in vacation message * * @param Expressomail_Model_Sieve_Vacation $vacation * @param string $message * @return string * * @todo get locale from placeholder (i.e. endDate-_LOCALESTRING_) * @todo get field from placeholder (i.e. representation-_FIELDNAME_) * @todo use html templates? * @todo use ZF templates / phplib tpl files? */ protected function _doMessageSubstitutions(Expressomail_Model_Sieve_Vacation $vacation, $message) { $timezone = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); $representatives = $vacation->contact_ids ? Addressbook_Controller_Contact::getInstance()->getMultiple($vacation->contact_ids) : array(); if ($vacation->contact_ids && count($representatives) > 0) { // sort representatives $representativesArray = array(); foreach ($vacation->contact_ids as $id) { $representativesArray[] = $representatives->getById($id); } } try { $ownContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId()); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $e); } $ownContact = NULL; } $search = array('{startDate-en_US}', '{endDate-en_US}', '{startDate-de_DE}', '{endDate-de_DE}', '{representation-n_fn-1}', '{representation-n_fn-2}', '{representation-email-1}', '{representation-email-2}', '{representation-tel_work-1}', '{representation-tel_work-2}', '{owncontact-n_fn}', '{signature}'); $replace = array(Tinebase_Translation::dateToStringInTzAndLocaleFormat($vacation->start_date, $timezone, new Zend_Locale('en_US'), 'date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($vacation->end_date, $timezone, new Zend_Locale('en_US'), 'date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($vacation->start_date, $timezone, new Zend_Locale('de_DE'), 'date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($vacation->end_date, $timezone, new Zend_Locale('de_DE'), 'date'), isset($representativesArray[0]) ? $representativesArray[0]->n_fn : 'unknown person', isset($representativesArray[1]) ? $representativesArray[1]->n_fn : 'unknown person', isset($representativesArray[0]) ? $representativesArray[0]->email : 'unknown email', isset($representativesArray[1]) ? $representativesArray[1]->email : 'unknown email', isset($representativesArray[0]) ? $representativesArray[0]->tel_work : 'unknown phone', isset($representativesArray[1]) ? $representativesArray[1]->tel_work : 'unknown phone', $ownContact ? $ownContact->n_fn : '', $vacation->signature ? Expressomail_Model_Message::convertHTMLToPlainTextWithQuotes(preg_replace("/\\r|\\n/", '', $vacation->signature)) : ''); $result = str_replace($search, $replace, $message); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $result); } return $result; }
/** * get linked objects for lead pdf (contacts, tasks, ...) * * @param Crm_Model_Lead $_lead lead data * @param Zend_Locale $_locale the locale * @param Zend_Translate $_translate * @return array the linked objects */ protected function getLinkedObjects(Crm_Model_Lead $_lead, Zend_Locale $_locale, Zend_Translate $_translate) { $linkedObjects = array(); // check relations if ($_lead->relations instanceof Tinebase_Record_RecordSet) { $_lead->relations->addIndices(array('type')); /********************** contacts ******************/ $linkedObjects[] = array($_translate->_('Contacts'), 'headline'); $types = array("customer" => "/images/oxygen/32x32/apps/system-users.png", "partner" => "/images/oxygen/32x32/actions/view-process-own.png", "responsible" => "/images/oxygen/32x32/apps/preferences-desktop-user.png"); foreach ($types as $type => $icon) { $contactRelations = $_lead->relations->filter('type', strtoupper($type)); foreach ($contactRelations as $relation) { try { //$contact = Addressbook_Controller_Contact::getInstance()->getContact($relation->related_id); $contact = $relation->related_record; $contactNameAndCompany = $contact->n_fn; if (!empty($contact->org_name)) { $contactNameAndCompany .= " / " . $contact->org_name; } $linkedObjects[] = array($contactNameAndCompany, 'separator', $icon); $postalcodeLocality = !empty($contact->adr_one_postalcode) ? $contact->adr_one_postalcode . " " . $contact->adr_one_locality : $contact->adr_one_locality; $regionCountry = !empty($contact->adr_one_region) ? $contact->adr_one_region . " " : ""; if (!empty($contact->adr_one_countryname)) { $regionCountry .= Zend_Locale::getTranslation($contact->adr_one_countryname, 'country', $_locale); } $linkedObjects[] = array($_translate->_('Address'), array($contact->adr_one_street, $postalcodeLocality, $regionCountry)); $linkedObjects[] = array($_translate->_('Telephone'), $contact->tel_work); $linkedObjects[] = array($_translate->_('Email'), $contact->email); } catch (Exception $e) { // do nothing so far } } } /********************** tasks ******************/ $taskRelations = $_lead->relations->filter('type', strtoupper('task')); if (!empty($taskRelations)) { $linkedObjects[] = array($_translate->_('Tasks'), 'headline'); foreach ($taskRelations as $relation) { try { $task = $relation->related_record; $taskTitle = $task->summary . " ( " . $task->percent . " % ) "; // @todo add big icon to db or preg_replace? if (!empty($task->status)) { $status = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->getById($task->status); $icon = "/" . $status['icon']; $linkedObjects[] = array($taskTitle, 'separator', $icon); } else { $linkedObjects[] = array($taskTitle, 'separator'); } // get due date if (!empty($task->due)) { $dueDate = new Tinebase_DateTime($task->due); $linkedObjects[] = array($_translate->_('Due Date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($dueDate, NULL, NULL, 'date')); } // get task priority $taskPriority = $this->getTaskPriority($task->priority, $_translate); $linkedObjects[] = array($_translate->_('Priority'), $taskPriority); } catch (Exception $e) { // do nothing so far Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' exception caught: ' . $e->__toString()); } } } /********************** products ******************/ $productRelations = $_lead->relations->filter('type', strtoupper('product')); if (!empty($productRelations)) { $linkedObjects[] = array($_translate->_('Products'), 'headline'); foreach ($productRelations as $relation) { try { $product = $relation->related_record; $quantity = isset($relation['remark']['quantity']) ? $relation['remark']['quantity'] : 1; $price = isset($relation['remark']['price']) ? $relation['remark']['price'] : $product->price; // @todo set precision for the price ? $price = Zend_Locale_Format::toNumber($price, array('locale' => $_locale)) . " €"; $description = isset($relation['remark']['description']) ? $relation['remark']['description'] : $product->description; $linkedObjects[] = array($product->name . ' - ' . $description . ' (' . $price . ') x ' . $quantity, 'separator'); } catch (Exception $e) { // do nothing so far Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' exception caught: ' . $e->__toString()); } } } } return $linkedObjects; }
/** * create notification message for task alarm * * @return string * * @todo should we get the locale pref for each single user here instead of the default? * @todo move lead stuff to Crm(_Model_Lead)? * @todo add getSummary to Addressbook_Model_Contact for linked contacts? */ public function getNotificationMessage() { // get locale from prefs $localePref = Tinebase_Core::getPreference()->getValue(Tinebase_Preference::LOCALE); $locale = Tinebase_Translation::getLocale($localePref); $translate = Tinebase_Translation::getTranslation($this->_application, $locale); // get date strings $timezone = $this->originator_tz ? $this->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); $dueDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($this->due, $timezone, $locale); // resolve values Tinebase_User::getInstance()->resolveUsers($this, 'organizer', true); $status = Tasks_Config::getInstance()->get(Tasks_Config::TASK_STATUS)->records->getById($this->status); $organizerName = $this->organizer ? $this->organizer->accountDisplayName : ''; //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($this->toArray(), TRUE)); $text = $this->summary . "\n\n" . $translate->_('Due') . ': ' . $dueDateString . "\n" . $translate->_('Organizer') . ': ' . $organizerName . "\n" . $translate->_('Description') . ': ' . $this->description . "\n" . $translate->_('Priority') . ': ' . $this->priority . "\n" . $translate->_('Status') . ': ' . $translate->_($status['value']) . "\n" . $translate->_('Percent') . ': ' . $this->percent . "%\n\n"; // add relations (get with ignore acl) $relations = Tinebase_Relations::getInstance()->getRelations(get_class($this), 'Sql', $this->getId(), NULL, array('TASK'), TRUE); foreach ($relations as $relation) { if ($relation->related_model == 'Crm_Model_Lead') { $lead = $relation->related_record; $text .= $translate->_('Lead') . ': ' . $lead->lead_name . "\n"; $leadRelations = Tinebase_Relations::getInstance()->getRelations(get_class($lead), 'Sql', $lead->getId()); foreach ($leadRelations as $leadRelation) { if ($leadRelation->related_model == 'Addressbook_Model_Contact') { $contact = $leadRelation->related_record; $text .= $leadRelation->type . ': ' . $contact->n_fn . ' (' . $contact->org_name . ')' . "\n" . (!empty($contact->tel_work) ? "\t" . $translate->_('Telephone') . ': ' . $contact->tel_work . "\n" : '') . (!empty($contact->email) ? "\t" . $translate->_('Email') . ': ' . $contact->email . "\n" : ''); } } } } //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $text); return $text; }
/** * replace some strings in autotags (name + description) * * @param array $_tagData * @return array */ protected function _doAutoTagReplacements($_tagData) { $result = $_tagData; $search = array('###CURRENTDATE###', '###CURRENTTIME###', '###USERFULLNAME###'); $now = Tinebase_DateTime::now(); $replacements = array(Tinebase_Translation::dateToStringInTzAndLocaleFormat($now, NULL, NULL, 'date'), Tinebase_Translation::dateToStringInTzAndLocaleFormat($now, NULL, NULL, 'time'), Tinebase_Core::getUser()->accountDisplayName); $fields = array('name', 'description'); foreach ($fields as $field) { if (isset($result[$field])) { $result[$field] = str_replace($search, $replacements, $result[$field]); } } return $result; }
/** * gets translated value * * NOTE: This is needed for values like Yes/No, Datetimes, etc. * * @param string $_field * @param mixed $_value * @param Zend_Translate $_translation * @param string $_timezone * @return string */ public static function getTranslatedValue($_field, $_value, $_translation, $_timezone) { if ($_value instanceof Tinebase_DateTime) { $locale = new Zend_Locale($_translation->getAdapter()->getLocale()); return Tinebase_Translation::dateToStringInTzAndLocaleFormat($_value, $_timezone, $locale); } switch ($_field) { case 'transp': return $_value ? $_translation->_('Yes') : $_translation->_('No'); default: return $_value; } }
/** * get formatted gmt date and time * * @return String */ private function getFormattedGmtDateTime() { // 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 . ')'; $dateTime = date('Y-m-d H:i:s'); $formattedDateTime = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($dateTime)); return $formattedDateTime . ' ' . $gmt; }
/** * set generic data * * @param array $result */ protected function _onAfterExportRecords($result) { $this->getDocument()->setValue('export_time', Tinebase_Translation::dateToStringInTzAndLocaleFormat(Tinebase_DateTime::now(), null, null, $this->_config->timeformat)); $this->getDocument()->setValue('export_date', Tinebase_Translation::dateToStringInTzAndLocaleFormat(Tinebase_DateTime::now(), null, null, $this->_config->dateformat)); $this->getDocument()->setValue('export_account', Tinebase_Core::getUser()->accountDisplayName); $this->getDocument()->setValue('export_account_n_given', Tinebase_Core::getUser()->accountFirstName); $this->getDocument()->setValue('export_account_n_family', Tinebase_Core::getUser()->accountLastName); }
/** * 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'); } }
/** * get cell value * * @param Zend_Config $_field * @param Tinebase_Record_Interface $_record * @param string $_cellType * @return string * * @todo check string type for translated fields? * @todo add 'config' type again? * @todo move generic parts to Tinebase_Export_Abstract */ protected function _getCellValue(Zend_Config $_field, Tinebase_Record_Interface $_record, &$_cellType) { $result = NULL; if (!(isset($_field->type) && $_field->separateColumns)) { if (in_array($_field->type, $this->_specialFields)) { // special field handling $result = $this->_getSpecialFieldValue($_record, $_field->toArray(), $_field->identifier, $_cellType); $result = $this->_replaceAndMatchvalue($result, $_field); return $result; } else { if (isset($field->formula) || !isset($_record->{$_field->identifier}) && !in_array($_field->type, $this->_resolvedFields) && !in_array($_field->identifier, $this->_getCustomFieldNames())) { // check if empty -> use alternative field if (isset($_field->empty)) { $fieldConfig = $_field->toArray(); unset($fieldConfig['empty']); $fieldConfig['identifier'] = $_field->empty; $result = $this->_getCellValue(new Zend_Config($fieldConfig), $_record, $_cellType); } // don't add value for formula or undefined fields return $result; } } } if ($_field->isMatrixField) { return $this->_getMatrixCellValue($_field, $_record); } switch ($_field->type) { case 'datetime': $result = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_record->{$_field->identifier}); // empty date cells, get displayed as 30.12.1899 if (empty($result)) { $result = NULL; } break; case 'date': $result = $_record->{$_field->identifier} instanceof DateTime ? $_record->{$_field->identifier}->toString('Y-m-d') : $_record->{$_field->identifier}; // empty date cells, get displayed as 30.12.1899 if (empty($result)) { $result = NULL; } break; case 'tags': $result = $this->_getTags($_record); break; case 'keyfield': $result = $this->_getResolvedKeyfield($_record->{$_field->identifier}, $_field->keyfield, $_field->application); break; case 'currency': $currency = $_field->currency ? $_field->currency : 'EUR'; $result = $_record->{$_field->identifier} ? $_record->{$_field->identifier} : '0'; $result = number_format($result, 2, '.', '') . ' ' . $currency; break; case 'percentage': $result = $_record->{$_field->identifier} / 100; break; case 'container_id': $result = $this->_getContainer($_record, $_field->field, $_field->type); break; /* case 'config': $result = Tinebase_Config::getOptionString($_record, $_field->identifier); break; */ /* case 'config': $result = Tinebase_Config::getOptionString($_record, $_field->identifier); break; */ case 'relation': $result = $this->_addRelations($_record, $_field->identifier, $_field->field, isset($_field->onlyfirst) ? $_field->onlyfirst : false); break; case 'notes': $result = $this->_addNotes($_record); break; default: if (in_array($_field->identifier, $this->_getCustomFieldNames())) { // add custom fields if (isset($_record->customfields[$_field->identifier])) { $result = $_record->customfields[$_field->identifier]; } } elseif (isset($_field->divisor)) { // divisor $result = $_record->{$_field->identifier} / $_field->divisor; } elseif (in_array($_field->type, $this->_userFields) || in_array($_field->identifier, $this->_userFields)) { // resolved user $result = $this->_getUserValue($_record, $_field); } else { if (is_object($_record->{$_field->identifier}) && method_exists($_record->{$_field->identifier}, '__toString')) { // call __toString $result = $_record->{$_field->identifier}->__toString(); } else { // all remaining $result = $_record->{$_field->identifier}; } } if (isset($_field->trim) && $_field->trim == 1) { $result = trim($result); } // set special value from params if (isset($_field->values)) { $values = $_field->values->value->toArray(); if (isset($values[$result])) { $result = $values[$result]; } } if (isset($_field->translate) && $_field->translate) { $result = $this->_translate->_($result); } $result = $this->_replaceAndMatchvalue($result, $_field); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' field def: ' . print_r($_field->toArray(), TRUE)); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' result: ' . $result); } return $result; }