/**
  * send notifications to a list a recipients
  *
  * @param Tinebase_Model_FullUser   $_updater
  * @param array                     $_recipients array of int|Addressbook_Model_Contact
  * @param string                    $_subject
  * @param string                    $_messagePlain
  * @param string                    $_messageHtml
  * @param string|array              $_attachments
  * @throws Tinebase_Exception
  * 
  * @todo improve exception handling: collect all messages / exceptions / failed email addresses / ...
  */
 public function send($_updater, $_recipients, $_subject, $_messagePlain, $_messageHtml = NULL, $_attachments = NULL)
 {
     $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $exception = NULL;
     $sentContactIds = array();
     foreach ($_recipients as $recipient) {
         try {
             if (!$recipient instanceof Addressbook_Model_Contact) {
                 $recipient = $contactsBackend->get($recipient);
             }
             if (!in_array($recipient->getId(), $sentContactIds)) {
                 $this->_smtpBackend->send($_updater, $recipient, $_subject, $_messagePlain, $_messageHtml, $_attachments);
                 $sentContactIds[] = $recipient->getId();
             }
         } catch (Exception $e) {
             $exception = $e;
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Failed to send notification message (recipient: ' . ($recipient instanceof Addressbook_Model_Contact ? $recipient->email : $recipient) . '. Exception: ' . $e);
             }
         }
     }
     if ($exception !== NULL) {
         // throw exception in the end when all recipients have been processed
         throw $exception;
     }
 }
示例#2
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $GLOBALS['Addressbook_Backend_SqlTest'] = array_key_exists('Addressbook_Backend_SqlTest', $GLOBALS) ? $GLOBALS['Addressbook_Backend_SqlTest'] : array();
     $this->_backend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Addressbook', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     $container = $personalContainer[0];
     $this->objects['initialContact'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'jpegphoto' => file_get_contents(dirname(__FILE__) . '/../../Tinebase/ImageHelper/phpunit-logo.gif'), 'note' => 'Bla Bla Bla', 'container_id' => $container->id, 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK'));
     $this->objects['updatedContact'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'note' => 'Bla Bla Bla', 'container_id' => $container->id, 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK'));
     return;
     $this->expectFailure['TestRecord']['testSetId'][] = array('2', '3');
     $this->expectFailure['TestRecord']['testSetId'][] = array('30000000', '3000000000000000000000000000');
     $this->expectSuccess['TestRecord']['testSetId'][] = array('2', '2');
     $this->expectFailure['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('2', '3');
     $this->expectFailure['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('30000000', '3000000000000000000000000000');
     $this->expectSuccess['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('2', '2');
     $this->expectSuccess['TestRecord']['testSetFromArray'][] = array(array('test_1' => '2', 'test_2' => NULL), 'test_1');
     $this->expectFailure['TestRecord']['testSetFromArrayException'][] = array('Tinebase_Exception_Record_Validation', array('test_2' => 'string'));
     $this->expectFailure['TestRecord']['testSetTimezoneException'][] = array('Exception', 'UTC');
     $dummy = array('test_id' => 2, 'test_2' => '', 'date_single' => $date->get(Tinebase_Record_Abstract::ISO8601LONG), 'date_multiple' => '');
     $this->expectSuccess['TestRecord']['testToArray'][] = array($dummy);
     $this->expectSuccess['TestRecord']['__set'][] = array('test_3', 4);
     $this->expectSuccess['TestRecord']['__get'][] = array('test_3', 4);
     $this->expectSuccess['TestRecord']['test__isset'][] = array('test_id');
     $this->expectFailure['TestRecord']['test__isset'][] = array('string');
     $this->expectFailure['TestRecord']['test__setException'][] = array('UnexpectedValueException', 'test_100');
     $this->expectFailure['TestRecord']['test__getException'][] = array('UnexpectedValueException', 'test_100');
     $this->expectFailure['TestRecord']['testOffsetUnset'][] = array('Tinebase_Exception_Record_NotAllowed', 'test_2');
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
     $this->_backend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Addressbook', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     $this->_container = $personalContainer[0];
 }
示例#4
0
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('bank_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_id', 'bank_id', 'id', new Billing_Backend_Bank());
     }
 }
 /**
  * Append contacts by foreign key (record embedding)
  * 
  * @param Tinebase_Record_Abstract $record
  * @return void
  */
 protected function appendDependentRecords($record)
 {
     Tinebase_User::getInstance()->resolveUsers($record, 'created_by_user');
     Tinebase_User::getInstance()->resolveUsers($record, 'processed_by_user');
     if ($record->__get('job_id')) {
         $this->appendForeignRecordToRecord($record, 'job_id', 'job_id', 'id', new Billing_Backend_BatchJob());
     }
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('debitor_id')) {
         $this->appendForeignRecordToRecord($record, 'debitor_id', 'debitor_id', 'id', new Billing_Backend_Debitor());
     }
 }
示例#6
0
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('price_group_id')) {
         $this->appendForeignRecordToRecord($record, 'price_group_id', 'price_group_id', 'id', new Billing_Backend_PriceGroup());
     }
     if ($record->__get('debitor_group_id')) {
         $this->appendForeignRecordToRecord($record, 'debitor_group_id', 'debitor_group_id', 'id', new Billing_Backend_DebitorGroup());
     }
     if ($record->__get('vat_id')) {
         $this->appendForeignRecordToRecord($record, 'vat_id', 'vat_id', 'id', new Billing_Backend_Vat());
     }
 }
 /**
  * do the import 
  */
 public function import()
 {
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' starting egw import for Adressbook');
     $this->_migrationStartTime = Tinebase_DateTime::now();
     $this->_tineRecordBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $estimate = $this->_getEgwRecordEstimate();
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . " found {$estimate} contacts for migration");
     $pageSize = 100;
     $numPages = ceil($estimate / $pageSize);
     for ($page = 1; $page <= $numPages; $page++) {
         $this->_log->info(__METHOD__ . '::' . __LINE__ . " starting migration page {$page} of {$numPages}");
         Tinebase_Core::setExecutionLifeTime($pageSize * 10);
         $recordPage = $this->_getRawEgwRecordPage($page, $pageSize);
         $this->_migrateEgwRecordPage($recordPage);
     }
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' ' . ($this->_importResult['totalcount'] - $this->_importResult['failcount']) . ' contacts imported sucessfully ' . ($this->_importResult['failcount'] ? " {$this->_importResult['failcount']} contacts skipped with failures" : ""));
 }
示例#8
0
 /**
  * the constructor
  *
  * don't use the constructor. use the singleton 
  */
 private function __construct()
 {
     $this->_applicationName = 'Addressbook';
     $this->_modelName = 'Addressbook_Model_Contact';
     $this->_backend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $this->_currentAccount = Tinebase_Core::getUser();
     $this->_purgeRecords = FALSE;
     $this->_resolveCustomFields = TRUE;
     $this->_duplicateCheckFields = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_DUP_FIELDS, array(array('n_given', 'n_family', 'org_name'), array('email')));
     // fields used for private and company address
     $this->_addressFields = array('locality', 'postalcode', 'street', 'countryname');
     $this->_setGeoDataForContacts = Tinebase_Config::getInstance()->getConfig(Tinebase_Config::MAPPANEL, NULL, TRUE)->value;
     if (!$this->_setGeoDataForContacts) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Mappanel/geoext/nominatim disabled with config option.');
         }
     }
 }
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('bank_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_id', 'bank_id', 'id', new Billing_Backend_Bank());
     }
     if ($record->__get('bank_account_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_account_id', 'bank_account_id', 'id', new Billing_Backend_BankAccount());
     }
     if ($record->__get('sepa_mandate_id')) {
         $this->appendForeignRecordToRecord($record, 'sepa_mandate_id', 'sepa_mandate_id', 'id', new Billing_Backend_SepaMandate());
     }
     if ($record->__get('membership_id')) {
         $this->appendForeignRecordToRecord($record, 'membership_id', 'membership_id', 'id', new Membership_Backend_SoMember());
     }
     if ($record->__get('regular_donation_id')) {
         $this->appendForeignRecordToRecord($record, 'regular_donation_id', 'regular_donation_id', 'id', new Donator_Backend_RegularDonation());
     }
 }
 /**
  * deletes user in tine20 db that no longer exist in sync backend
  *
  * @param Tinebase_Record_RecordSet $usersInSyncBackend
  */
 protected static function _syncDeletedUsers(Tinebase_Record_RecordSet $usersInSyncBackend)
 {
     $userIdsInSqlBackend = Tinebase_User::getInstance()->getAllUserIdsFromSqlBackend();
     $deletedInSyncBackend = array_diff($userIdsInSqlBackend, $usersInSyncBackend->getArrayOfIds());
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to delete / expire ' . count($deletedInSyncBackend) . ' users in SQL backend...');
     }
     foreach ($deletedInSyncBackend as $userToDelete) {
         $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $userToDelete, 'Tinebase_Model_FullUser');
         if (in_array($user->accountLoginName, self::getSystemUsernames())) {
             return;
         }
         // at first, we expire+deactivate the user
         $now = Tinebase_DateTime::now();
         if (!$user->accountExpires || $user->accountStatus !== Tinebase_Model_User::ACCOUNT_STATUS_DISABLED) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Disable user and set expiry date of ' . $user->accountLoginName . ' to ' . $now);
             }
             $user->accountExpires = $now;
             $user->accountStatus = Tinebase_Model_User::ACCOUNT_STATUS_DISABLED;
             Tinebase_User::getInstance()->updateUserInSqlBackend($user);
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' User already expired ' . print_r($user->toArray(), true));
             }
             // TODO make time span configurable?
             if ($user->accountExpires->isEarlier($now->subYear(1))) {
                 // if he or she is already expired longer than configured expiry, we remove them!
                 Tinebase_User::getInstance()->deleteUserInSqlBackend($userToDelete);
                 if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true && !empty($user->contact_id)) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deleting user contact of ' . $user->accountLoginName);
                     }
                     $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
                     $contactsBackend->delete($user->contact_id);
                 }
             } else {
                 // keep user in expiry state
             }
         }
     }
 }
 /**
  * delete contact associated with user
  * 
  * @param string  $_contactId
  */
 protected function _deleteContact($_contactId)
 {
     $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $contactsBackend->delete($_contactId);
 }
 /**
  * test purge deleted records
  *
  * @see 0010249: Tinebase.purgeDeletedRecords fails
  */
 public function testPurgeDeletedRecordsAllTables()
 {
     $opts = $this->_getOpts();
     $deletedContact = $this->_addAndDeleteContact();
     $deletedLead = $this->_addAndDeleteLead();
     // delete personal adb container and tag, too
     Tinebase_Container::getInstance()->deleteContainer($this->_getPersonalContainer('Addressbook')->getId());
     Tinebase_Tags::getInstance()->deleteTags($deletedContact->tags->getFirstRecord()->getId());
     ob_start();
     $this->_cli->purgeDeletedRecords($opts);
     $out = ob_get_clean();
     $this->assertContains('Removing all deleted entries before', $out);
     $this->assertContains('Cleared table addressbook (deleted ', $out);
     $this->assertContains('Cleared table metacrm_lead (deleted ', $out);
     $this->assertNotContains('Failed to purge', $out);
     $contactBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $contacts = $contactBackend->getMultipleByProperty($deletedContact->getId(), 'id', TRUE);
     $this->assertEquals(0, count($contacts));
     $leadsBackend = new Crm_Backend_Lead();
     $leads = $leadsBackend->getMultipleByProperty($deletedLead->getId(), 'id', TRUE);
     $this->assertEquals(0, count($leads));
 }
 /**
  * create or update contact in addressbook backend
  * 
  * @param  Tinebase_Model_FullUser $_user
  * @return Addressbook_Model_Contact
  */
 public function createOrUpdateContact(Tinebase_Model_FullUser $_user)
 {
     $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $contactsBackend->setGetDisabledContacts(true);
     if (empty($_user->container_id)) {
         $_user->container_id = $this->getDefaultInternalAddressbook();
     }
     try {
         if (empty($_user->contact_id)) {
             // jump to catch block
             throw new Tinebase_Exception_NotFound('contact_id is empty');
         }
         $contact = $contactsBackend->get($_user->contact_id);
         // update exisiting contact
         $contact->n_family = $_user->accountLastName;
         $contact->n_given = $_user->accountFirstName;
         $contact->n_fn = $_user->accountFullName;
         $contact->n_fileas = $_user->accountDisplayName;
         $contact->email = $_user->accountEmailAddress;
         $contact->type = Addressbook_Model_Contact::CONTACTTYPE_USER;
         $contact->container_id = $_user->container_id;
         // add modlog info
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
         $contact = $contactsBackend->update($contact);
     } catch (Tinebase_Exception_NotFound $tenf) {
         // add new contact
         $contact = new Addressbook_Model_Contact(array('n_family' => $_user->accountLastName, 'n_given' => $_user->accountFirstName, 'n_fn' => $_user->accountFullName, 'n_fileas' => $_user->accountDisplayName, 'email' => $_user->accountEmailAddress, 'type' => Addressbook_Model_Contact::CONTACTTYPE_USER, 'container_id' => $_user->container_id));
         // add modlog info
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'create');
         $contact = $contactsBackend->create($contact);
     }
     return $contact;
 }
示例#14
0
 /**
  * test purge deleted records
  */
 public function testPurgeDeletedRecordsAllTables()
 {
     $opts = $this->_getOpts();
     $deletedContact = $this->_addAndDeleteContact();
     $deletedLead = $this->_addAndDeleteLead();
     ob_start();
     $this->_cli->purgeDeletedRecords($opts);
     $out = ob_get_clean();
     $this->assertContains('Removing all deleted entries before', $out);
     $this->assertContains('Cleared table addressbook (deleted ', $out);
     $this->assertContains('Cleared table metacrm_lead (deleted ', $out);
     $contactBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $contacts = $contactBackend->getMultipleByProperty($deletedContact->getId(), 'id', TRUE);
     $this->assertEquals(0, count($contacts));
     $leadsBackend = new Crm_Backend_Lead();
     $leads = $leadsBackend->getMultipleByProperty($deletedLead->getId(), 'id', TRUE);
     $this->assertEquals(0, count($leads));
 }
 /**
  * create the search results dialogue
  *
  * @param string $mac the mac address of the phone
  * @param string $query the string to search the contacts for
  */
 public function searchContacts($mac, $query)
 {
     $baseUrl = $this->_getBaseUrl();
     // do nothing if search string is empty
     if (empty($query)) {
         $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
             <SnomIPPhoneText>
             <Title>Nothing found!</Title>
             <Text>Nothing found!</Text>
             <fetch mil="1000">' . $baseUrl . '?method=Phone.directory&TINE20SESSID=' . Tinebase_Session::getId() . '&mac=' . $mac . '</fetch>
             </SnomIPPhoneText>
         ');
         header('Content-Type: text/xml');
         echo $xml->asXML();
         return;
     }
     $this->_authenticate();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $mac . ' search for ' . $query);
     }
     $phone = Voipmanager_Controller_Snom_Phone::getInstance()->getByMacAddress($mac);
     $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $tbContainer = Tinebase_Container::getInstance();
     $readAbleContainer = array();
     foreach ($phone->rights as $right) {
         if ($right->account_type == Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) {
             $containers = $tbContainer->getContainerByACL($right->account_id, 'Addressbook', Tinebase_Model_Grants::GRANT_READ);
             $readAbleContainer = array_merge($readAbleContainer, $containers->getArrayOfIds());
         }
     }
     $readAbleContainer = array_unique($readAbleContainer);
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'query', 'operator' => 'contains', 'value' => $query), array('field' => 'container', 'operator' => 'in', 'value' => $readAbleContainer)));
     $contacts = $contactsBackend->search($filter, new Tinebase_Model_Pagination());
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' found ' . count($contacts) . ' contacts');
     }
     if (count($contacts) == 0) {
         $baseUrl = $this->_getBaseUrl();
         $xml = '<SnomIPPhoneText>
             <Title>Nothing found!</Title>
             <Text>Nothing found!</Text>
             <fetch mil="1000">' . $baseUrl . '?method=Phone.directory&TINE20SESSID=' . Tinebase_Session::getId() . '&mac=' . $mac . '</fetch>
         </SnomIPPhoneText>
         ';
     } else {
         $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
           <SnomIPPhoneDirectory>
             <Title>Directory</Title>
             <Prompt>Dial</Prompt>
           </SnomIPPhoneDirectory>
         ');
         foreach ($contacts as $contact) {
             if (!empty($contact->tel_work)) {
                 $directoryEntry = $xml->addChild('DirectoryEntry');
                 $directoryEntry->addChild('Name', $contact->n_fileas . ' Work');
                 $directoryEntry->addChild('Telephone', $contact->tel_work);
             }
             if (!empty($contact->tel_cell)) {
                 $directoryEntry = $xml->addChild('DirectoryEntry');
                 $directoryEntry->addChild('Name', $contact->n_fileas . ' Cell');
                 $directoryEntry->addChild('Telephone', $contact->tel_cell);
             }
             if (!empty($contact->tel_home)) {
                 $directoryEntry = $xml->addChild('DirectoryEntry');
                 $directoryEntry->addChild('Name', $contact->n_fileas . ' Home');
                 $directoryEntry->addChild('Telephone', $contact->tel_home);
             }
             if (!empty($contact->tel_cell_private)) {
                 $directoryEntry = $xml->addChild('DirectoryEntry');
                 $directoryEntry->addChild('Name', $contact->n_fileas . ' CellP');
                 $directoryEntry->addChild('Telephone', $contact->tel_cell_private);
             }
         }
         $xml = $xml->asXML();
     }
     header('Content-Type: text/xml');
     echo $xml;
 }
 /**
  * event handler function
  * 
  * all events get routed through this function
  *
  * @param Tinebase_Event_Abstract $_eventObject the eventObject
  * 
  * @todo    write test
  */
 protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . ' (' . __LINE__ . ') handle event of type ' . get_class($_eventObject));
     }
     switch (get_class($_eventObject)) {
         case 'Admin_Event_AddAccount':
             $this->createPersonalFolder($_eventObject->account);
             break;
         case 'Tinebase_Event_User_DeleteAccount':
             /**
              * @var Tinebase_Event_User_DeleteAccount $_eventObject
              */
             if ($_eventObject->deletePersonalContainers()) {
                 $this->deletePersonalFolder($_eventObject->account);
             }
             //make to be deleted accounts (user) contact a normal contact
             if ($_eventObject->keepAsContact()) {
                 $contact = Addressbook_Controller_Contact::getInstance()->get($_eventObject->account->contact_id);
                 $contact->type = Addressbook_Model_Contact::CONTACTTYPE_CONTACT;
                 Addressbook_Controller_Contact::getInstance()->update($contact);
             } else {
                 //or just delete it
                 $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
                 $contactsBackend->delete($_eventObject->account->contact_id);
             }
             break;
     }
 }
 /**
  * deletes user in tine20 db that no longer exist in sync backend
  *
  * @param Tinebase_Record_RecordSet $usersInSyncBackend
  */
 protected static function _syncDeletedUsers(Tinebase_Record_RecordSet $usersInSyncBackend)
 {
     $userIdsInSqlBackend = Tinebase_User::getInstance()->getAllUserIdsFromSqlBackend();
     $deletedInSyncBackend = array_diff($userIdsInSqlBackend, $usersInSyncBackend->getArrayOfIds());
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to delete ' . count($deletedInSyncBackend) . ' users in SQL backend...');
     }
     foreach ($deletedInSyncBackend as $userToDelete) {
         $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $userToDelete, 'Tinebase_Model_FullUser');
         Tinebase_User::getInstance()->deleteUserInSqlBackend($userToDelete);
         if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true && !empty($user->contact_id)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deleting user contact of ' . $user->accountLoginName);
             }
             $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
             $contactsBackend->delete($user->contact_id);
         }
     }
 }
示例#18
0
 /**
  * create contact in addressbook
  * 
  * @param Tinebase_Model_FullUser $user
  */
 public static function syncContact($user)
 {
     if (!Tinebase_Application::getInstance()->isInstalled('Addressbook')) {
         return;
     }
     $addressbook = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED);
     $contact = new Addressbook_Model_Contact(array('n_family' => $user->accountLastName, 'n_given' => $user->accountFirstName, 'n_fn' => $user->accountFullName, 'n_fileas' => $user->accountDisplayName, 'email' => $user->accountEmailAddress, 'type' => Addressbook_Model_Contact::CONTACTTYPE_USER, 'container_id' => $internalAddressbook->getId()));
     // add modlog info
     Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'create');
     $contact = $addressbook->create($contact);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Added contact " . $contact->n_given);
     }
     $user->contact_id = $contact->getId();
 }