Beispiel #1
0
 public static function getFromContact(Addressbook_Model_Contact $contact)
 {
     $obj = new self($contact->__get('bank_account_number'), $contact->__get('bank_account_name'), $contact->__get('bank_name'), $contact->__get('bank_code'));
     $obj->setContactId($contact->getId());
     $countryCode = $contact->getLetterDrawee()->getPostalAddress()->getCountryCode('DE');
     $obj->setCountryCode($countryCode);
     if (trim($obj->getName()) == '') {
         $obj->setName($contact->__get('n_fileas'));
     }
     return $obj;
 }
 /**
  * testTriggerRebuildIfFatherRemovedChild
  */
 public function testTriggerRebuildIfFatherRemovedChild()
 {
     $contact = $this->testTriggerRebuildPathForRecords();
     // remove child relation from father and check paths of child records
     $father = Addressbook_Controller_Contact::getInstance()->get($this->_fatherRecord->getId());
     foreach ($father->relations as $relation) {
         if ($relation->related_degree === Tinebase_Model_Relation::DEGREE_CHILD) {
             $father->relations->removeRecord($relation);
             break;
         }
     }
     //workaround as _setRelatedData expects an array!?!
     $father->relations = $father->relations->toArray();
     Addressbook_Controller_Contact::getInstance()->update($father);
     $recordPaths = $this->_uit->getPathsForRecords($contact);
     $this->assertEquals(1, count($recordPaths));
     // check remaining path again
     $expectedPaths = array('/mother/tester');
     foreach ($expectedPaths as $expectedPath) {
         $this->assertTrue(in_array($expectedPath, $recordPaths->path), 'could not find path ' . $expectedPath . ' in ' . print_r($recordPaths->toArray(), true));
     }
 }
Beispiel #3
0
 /**
  * convert contact from xml to Addressbook_Model_Contact
  *
  * @param SimpleXMLElement $_data
  * @return Addressbook_Model_Contact
  */
 public function toTineModel(SimpleXMLElement $_data, $_entry = null)
 {
     if ($_entry instanceof Addressbook_Model_Contact) {
         $contact = $_entry;
     } else {
         $contact = new Addressbook_Model_Contact(null, true);
     }
     unset($contact->jpegphoto);
     $xmlData = $_data->children('uri:Contacts');
     $airSyncBase = $_data->children('uri:AirSyncBase');
     foreach ($this->_mapping as $fieldName => $value) {
         switch ($value) {
             case 'jpegphoto':
                 // do not change if not set
                 if (isset($xmlData->{$fieldName})) {
                     if (!empty($xmlData->{$fieldName})) {
                         $devicePhoto = base64_decode((string) $xmlData->{$fieldName});
                         try {
                             $currentPhoto = Tinebase_Controller::getInstance()->getImage('Addressbook', $contact->getId())->getBlob('image/jpeg', 36000);
                         } catch (Exception $e) {
                         }
                         if (isset($currentPhoto) && $currentPhoto == $devicePhoto) {
                             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                                 Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " photo did not change on device -> preserving server photo");
                             }
                         } else {
                             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                                 Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " using new contact photo from device (" . strlen($devicePhoto) . "KB)");
                             }
                             $contact->jpegphoto = $devicePhoto;
                         }
                     } else {
                         if ($_entry && !empty($_entry->jpegphoto)) {
                             $contact->jpegphoto = '';
                             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                                 Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Deleting contact photo on device request (contact id: ' . $contact->getId() . ')');
                             }
                         }
                     }
                 }
                 break;
             case 'bday':
                 if (isset($xmlData->{$fieldName})) {
                     $isoDate = (string) $xmlData->{$fieldName};
                     $contact->bday = new Tinebase_DateTime($isoDate);
                     if ($this->_device->devicetype == Syncope_Model_Device::TYPE_IPHONE && $this->_device->getMajorVersion() < 800 || preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $isoDate)) {
                         // iOS < 4 & webow < 2.1 send birthdays to the entered date, but the time the birthday got entered on the device
                         // acutally iOS < 4 somtimes sends the bday at noon but the timezone is not clear
                         // -> we don't trust the time part and set the birthdays timezone to the timezone the user has set in tine
                         $userTimezone = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
                         $contact->bday = new Tinebase_DateTime($contact->bday->setTime(0, 0, 0)->format(Tinebase_Record_Abstract::ISO8601LONG), $userTimezone);
                         $contact->bday->setTimezone('UTC');
                     }
                 } else {
                     $contact->bday = null;
                 }
                 break;
             case 'adr_one_countryname':
             case 'adr_two_countryname':
                 $contact->{$value} = Tinebase_Translation::getRegionCodeByCountryName((string) $xmlData->{$fieldName});
                 break;
             case 'adr_one_street':
                 if (strtolower($this->_device->devicetype) == 'palm') {
                     // palm pre sends the whole address in the <Contacts:BusinessStreet> tag
                     unset($contact->adr_one_street);
                 } else {
                     // default handling for all other devices
                     if (isset($xmlData->{$fieldName})) {
                         $contact->{$value} = (string) $xmlData->{$fieldName};
                     } else {
                         $contact->{$value} = null;
                     }
                 }
                 break;
             case 'email':
             case 'email_home':
                 // android send email address as
                 // Lars Kneschke <*****@*****.**>
                 if (preg_match('/(.*)<(.+@[^@]+)>/', (string) $xmlData->{$fieldName}, $matches)) {
                     $contact->{$value} = trim($matches[2]);
                 } else {
                     $contact->{$value} = (string) $xmlData->{$fieldName};
                 }
                 break;
             default:
                 if (isset($xmlData->{$fieldName})) {
                     $contact->{$value} = (string) $xmlData->{$fieldName};
                 } else {
                     $contact->{$value} = null;
                 }
                 break;
         }
     }
     // get body
     if (version_compare($this->_device->acsversion, '12.0', '>=') === true) {
         $contact->note = isset($airSyncBase->Body) ? (string) $airSyncBase->Body->Data : null;
     } else {
         $contact->note = isset($xmlData->Body) ? (string) $xmlData->Body : null;
     }
     // force update of n_fileas and n_fn
     $contact->setFromArray(array('n_given' => $contact->n_given, 'n_family' => $contact->n_family, 'org_name' => $contact->org_name));
     // contact should be valid now
     $contact->isValid();
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " contactData " . print_r($contact->toArray(), true));
     }
     return $contact;
 }
Beispiel #4
0
 /**
  * get test attendee
  *
  * @return Tinebase_Record_RecordSet
  */
 protected function _getAttendee()
 {
     return new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => $this->_testUserContact->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'status_authkey' => Tinebase_Record_Abstract::generateUID()), array('user_id' => $this->_personasContacts['sclever']->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'status_authkey' => Tinebase_Record_Abstract::generateUID())));
 }
 /**
  * add photo data to VCard
  * 
  * @param  Addressbook_Model_Contact $record
  * @param  \Sabre\VObject\Component  $card
  */
 protected function _fromTine20ModelAddPhoto(Addressbook_Model_Contact $record, \Sabre\VObject\Component $card)
 {
     if (!empty($record->jpegphoto)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__);
         try {
             $jpegData = $record->getSmallContactImage($this->_maxPhotoSize);
             $card->add('PHOTO', $jpegData, array('TYPE' => 'JPEG', 'ENCODING' => 'b'));
         } catch (Exception $e) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Image for contact {$record->getId()} not found or invalid: {$e->getMessage()}");
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
             }
         }
     }
 }
 /**
  * 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);
 }
 /**
  * update contact data(first name, last name, ...) of user in local sql storage
  * 
  * @param Addressbook_Model_Contact $contact
  * @return integer
  * @throws Exception
  */
 public function updateContactInSqlBackend(Addressbook_Model_Contact $_contact)
 {
     $contactId = $_contact->getId();
     $accountData = array($this->rowNameMapping['accountDisplayName'] => $_contact->n_fileas, $this->rowNameMapping['accountFullName'] => $_contact->n_fn, $this->rowNameMapping['accountFirstName'] => $_contact->n_given, $this->rowNameMapping['accountLastName'] => $_contact->n_family, $this->rowNameMapping['accountEmailAddress'] => $_contact->email);
     try {
         $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('contact_id') . ' = ?', $contactId));
         return $accountsTable->update($accountData, $where);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
 }
 /**
  * convert contact from xml to Addressbook_Model_Contact
  *
  * @param SimpleXMLElement $_data
  * @return Addressbook_Model_Contact
  */
 public function toTineModel(Syncroton_Model_IEntry $data, $entry = null)
 {
     if ($entry instanceof Addressbook_Model_Contact) {
         $contact = $entry;
     } else {
         $contact = new Addressbook_Model_Contact(null, true);
     }
     unset($contact->jpegphoto);
     foreach ($this->_mapping as $fieldName => $value) {
         if (!isset($data->{$fieldName})) {
             $contact->{$value} = null;
             continue;
         }
         switch ($value) {
             case 'jpegphoto':
                 if (!empty($data->{$fieldName})) {
                     $devicePhoto = $data->{$fieldName};
                     $contact->setSmallContactImage($devicePhoto);
                 } else {
                     if ($entry && !empty($entry->jpegphoto)) {
                         $contact->jpegphoto = '';
                         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                             Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Deleting contact photo on device request (contact id: ' . $contact->getId() . ')');
                         }
                     }
                 }
                 break;
             case 'bday':
                 $contact->{$value} = new Tinebase_DateTime($data->{$fieldName});
                 if ($this->_device->devicetype == Syncroton_Model_Device::TYPE_IPHONE && $this->_device->getMajorVersion() < 800) {
                     // iOS < 4 & webos < 2.1 send birthdays to the entered date, but the time the birthday got entered on the device
                     // actually iOS < 4 sometimes sends the bday at noon but the timezone is not clear
                     // -> we don't trust the time part and set the birthdays timezone to the timezone the user has set in tine
                     $userTimezone = Tinebase_Core::getUserTimezone();
                     $contact->{$value} = new Tinebase_DateTime($contact->bday->setTime(0, 0, 0)->format(Tinebase_Record_Abstract::ISO8601LONG), $userTimezone);
                     $contact->{$value}->setTimezone('UTC');
                 } elseif ($this->_device->devicetype == Syncroton_Model_Device::TYPE_BLACKBERRY && version_compare($this->_device->getMajorVersion(), '10', '>=')) {
                     // BB 10+ expects birthday to be at noon
                     $contact->{$value}->subHour(12);
                 }
                 break;
             case 'adr_one_countryname':
             case 'adr_two_countryname':
                 $contact->{$value} = Tinebase_Translation::getRegionCodeByCountryName($data->{$fieldName});
                 break;
             case 'adr_one_street':
                 if (strtolower($this->_device->devicetype) == 'palm') {
                     // palm pre sends the whole address in the <Contacts:BusinessStreet> tag
                     unset($contact->adr_one_street);
                 } else {
                     $contact->{$value} = $data->{$fieldName};
                 }
                 break;
             case 'email':
             case 'email_home':
                 // android sends email address as
                 // Lars Kneschke <*****@*****.**>
                 if (preg_match('/(.*)<(.+@[^@]+)>/', $data->{$fieldName}, $matches)) {
                     $contact->{$value} = trim($matches[2]);
                 } else {
                     $contact->{$value} = $data->{$fieldName};
                 }
                 break;
             case 'note':
                 // @todo check $data->$fieldName->Type and convert to/from HTML if needed
                 if ($data->{$fieldName} instanceof Syncroton_Model_EmailBody) {
                     $contact->{$value} = $data->{$fieldName}->data;
                 } else {
                     $contact->{$value} = null;
                 }
                 break;
             case 'url':
                 // remove facebook urls
                 if (!preg_match('/^fb:\\/\\//', $data->{$fieldName})) {
                     $contact->{$value} = $data->{$fieldName};
                 }
                 break;
             default:
                 $contact->{$value} = $data->{$fieldName};
                 break;
         }
     }
     // force update of n_fileas and n_fn
     $contact->setFromArray(array('n_given' => $contact->n_given, 'n_family' => $contact->n_family, 'org_name' => $contact->org_name));
     // either "org_name" or "n_family" must be given!
     if (empty($contact->org_name) && empty($contact->n_family)) {
         $contact->n_family = 'imported';
     }
     // contact should be valid now
     $contact->isValid();
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " contactData " . print_r($contact->toArray(), true));
     }
     return $contact;
 }
 /**
  * convert contact model to principal array
  * 
  * @param Addressbook_Model_Contact $contact
  * @return array
  */
 protected function _contactToPrincipal(Addressbook_Model_Contact $contact)
 {
     $principal = array('uri' => self::PREFIX_USERS . '/' . $contact->getId(), '{DAV:}displayname' => $contact->n_fileas, '{DAV:}alternate-URI-set' => array('urn:uuid:' . $contact->getId()), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-user-type' => 'INDIVIDUAL', '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}record-type' => 'users', '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}first-name' => $contact->n_given, '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}last-name' => $contact->n_family);
     if (!empty(Tinebase_Core::getUser()->accountEmailAddress)) {
         $principal['{http://sabredav.org/ns}email-address'] = $contact->email;
     }
     return $principal;
 }