From 455a96c8735281ab406e7642d4171862d02725d1 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 26 Apr 2006 14:02:17 +0000 Subject: [PATCH] changed to use the bocontacts instead of boaddressbook, need to be tested --- addressbook/inc/class.sifaddressbook.inc.php | 187 +++++++----------- addressbook/inc/class.vcaladdressbook.inc.php | 140 ++++--------- 2 files changed, 110 insertions(+), 217 deletions(-) diff --git a/addressbook/inc/class.sifaddressbook.inc.php b/addressbook/inc/class.sifaddressbook.inc.php index 405eabfbdc..ef9b9305b3 100644 --- a/addressbook/inc/class.sifaddressbook.inc.php +++ b/addressbook/inc/class.sifaddressbook.inc.php @@ -18,8 +18,8 @@ { var $sifMapping = array( 'Anniversary' => '', - 'AssistantName' => '', - 'AssistantTelephoneNumber' => '', + 'AssistantName' => 'assistent', + 'AssistantTelephoneNumber' => 'tel_assistent', 'BillingInformation' => '', 'Birthday' => 'bday', 'Body' => 'note', @@ -27,13 +27,13 @@ 'BusinessAddressCity' => 'adr_one_locality', 'BusinessAddressCountry' => 'adr_one_countryname', 'BusinessAddressPostalCode' => 'adr_one_postalcode', - 'BusinessAddressPostOfficeBox' => '', + 'BusinessAddressPostOfficeBox' => 'adr_one_street2', 'BusinessAddressState' => 'adr_one_region', 'BusinessAddressStreet' => 'adr_one_street', 'BusinessFaxNumber' => 'tel_fax', 'BusinessTelephoneNumber' => 'tel_work', 'CallbackTelephoneNumber' => '', - 'CarTelephoneNumber' => '', + 'CarTelephoneNumber' => 'tel_car', 'Categories' => 'cat_id', 'Children' => '', 'Companies' => '', @@ -47,17 +47,17 @@ 'Email2AddressType' => '', 'Email3Address' => '', 'Email3AddressType' => '', - 'FileAs' => '', + 'FileAs' => 'n_fileas', 'FirstName' => 'n_given', 'Hobby' => '', 'Home2TelephoneNumber' => '', 'HomeAddressCity' => 'adr_two_locality', 'HomeAddressCountry' => 'adr_two_countryname', 'HomeAddressPostalCode' => 'adr_two_postalcode', - 'HomeAddressPostOfficeBox' => '', + 'HomeAddressPostOfficeBox' => 'adr_two_street2', 'HomeAddressState' => 'adr_two_region', 'HomeAddressStreet' => 'adr_two_street', - 'HomeFaxNumber' => '', + 'HomeFaxNumber' => 'tel_fax_home', 'HomeTelephoneNumber' => 'tel_home', 'Importance' => '', 'Initials' => '', @@ -69,7 +69,7 @@ 'Mileage' => '', 'MobileTelephoneNumber' => 'tel_cell', 'NickName' => '', - 'OfficeLocation' => '', + 'OfficeLocation' => 'room', 'OrganizationalIDNumber' => '', 'OtherAddressCity' => '', 'OtherAddressCountry' => '', @@ -78,12 +78,12 @@ 'OtherAddressState' => '', 'OtherAddressStreet' => '', 'OtherFaxNumber' => '', - 'OtherTelephoneNumber' => '', + 'OtherTelephoneNumber' => 'tel_other', 'PagerNumber' => 'tel_pager', 'PrimaryTelephoneNumber' => '', - 'Profession' => '', + 'Profession' => 'role', 'RadioTelephoneNumber' => '', - 'Sensitivity' => 'access', + 'Sensitivity' => 'private', 'Spouse' => '', 'Subject' => '', 'Suffix' => 'n_suffix', @@ -93,7 +93,7 @@ 'YomiCompanyName' => '', 'YomiFirstName' => '', 'YomiLastName' => '', - 'HomeWebPage' => '', + 'HomeWebPage' => 'url_home', 'Folder' => '', ); @@ -137,10 +137,6 @@ foreach($this->contact as $key => $value) { $value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet); switch($key) { - case 'access': - $finalContact[$key] = ((int)$value > 0) ? 'private' : 'public'; - break; - case 'cat_id': if(!empty($value)) { $isAdmin = $GLOBALS['egw']->acl->check('run',1,'admin'); @@ -160,44 +156,41 @@ } break; - case 'bday': - if(!empty($value)) { - $bdayParts = explode('-',$value); - $finalContact[$key] = $bdayParts[1]. '/' .$bdayParts[2]. '/' .$bdayParts[0]; - } - break; - default: $finalContact[$key] = $value; break; } } - - $middleName = ($finalContact['n_middle']) ? ' '.trim($finalContact['n_middle']) : ''; - $finalContact['fn'] = trim($finalContact['n_given']. $middleName .' '. $finalContact['n_family']); - - return $finalContact; } - function search($_sifdata) { - if(!$contact = $this->siftoegw($_sifdata)) { + /** + * Search an exactly matching entry (used for slow sync) + * + * @param string $_sifdata + * @return boolean/int/string contact-id or false, if not found + */ + function search($_sifdata) + { + if(!$contact = $this->siftoegw($_sifdata)) + { return false; } - if($foundContacts = $this->read_entries(array('query' => $contact))) { + if(($foundContacts = $this->search($contact))) + { error_log(print_r($foundContacts,true)); - return $foundContacts[0][id]; + return $foundContacts[0]['id']; } - return false; } /** + * import a vard into addressbook + * * @return int contact id * @param string $_vcard the vcard * @param int $_abID the internal addressbook id - * @desc import a vard into addressbook */ function addSIF($_sifdata, $_abID) { @@ -208,17 +201,9 @@ return false; } - if($_abID > 0) - { - // update entry - $contact['ab_id'] = $_abID; - return $this->update_entry($contact); - } - else - { - // add entry - return $this->add_entry($contact); - } + if($_abID > 0) $contact['ab_id'] = $_abID; + + return $this->save($contact); } /** @@ -233,79 +218,59 @@ $fields = array_unique(array_values($this->sifMapping)); sort($fields); - if($this->check_perms($_id,EGW_ACL_READ)) + if(!($entry = $this->so->read_entry($_id))) { - $sifContact = ''; - //$data = array('id' => $_id, 'fields' => $fields); - $entry = $this->so->read_entry($_id,$fields); - $entry = $this->strip_html($entry); - if($this->xmlrpc) - { - $entry = $this->data2xmlrpc($entry); - } - #error_log(print_r($entry,true)); - $sysCharSet = $GLOBALS['egw']->translation->charset(); + return false; + } + $sifContact = ''; + #error_log(print_r($entry,true)); + $sysCharSet = $GLOBALS['egw']->translation->charset(); - foreach($this->sifMapping as $sifField => $egwField) - { - if(empty($egwField)) continue; - - #error_log("$sifField => $egwField"); - #error_log('VALUE1: '.$entry[0][$egwField]); - $value = $GLOBALS['egw']->translation->convert($entry[0][$egwField], $sysCharSet, 'utf-8'); - #error_log('VALUE2: '.$value); + foreach($this->sifMapping as $sifField => $egwField) + { + if(empty($egwField)) continue; + + #error_log("$sifField => $egwField"); + #error_log('VALUE1: '.$entry[0][$egwField]); + $value = $GLOBALS['egw']->translation->convert($entry[0][$egwField], $sysCharSet, 'utf-8'); + #error_log('VALUE2: '.$value); - switch($sifField) - { - // TODO handle multiple categories - case 'Categories': - if(!empty($value)) { - $egwCategories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'addressbook'); - $categories = explode(',',$value); - $value = ''; - foreach($categories as $cat_id) { - if($catData = $egwCategories->return_single($cat_id)) { - if(!empty($value)) $value .= '; '; - $value .= $catData[0]['name']; - } + switch($sifField) + { + // TODO handle multiple categories + case 'Categories': + if(!empty($value)) { + $egwCategories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'addressbook'); + $categories = explode(',',$value); + $value = ''; + foreach($categories as $cat_id) { + if(($catData = $egwCategories->return_single($cat_id))) + { + if(!empty($value)) $value .= '; '; + $value .= $catData[0]['name']; } } - $sifContact .= "<$sifField>$value"; - break; - - case 'Sensitivity': - $value = ($value == 'private' ? '2' : '0'); - $sifContact .= "<$sifField>$value"; - break; - - case 'Birthday': - if(!empty($value)) { - $dateParts = explode('/',$value); - $value = sprintf('%04-d%02-d%02',$dateParts[2],$dateParts[0],$dateParts[1]); - } - $sifContact .= "<$sifField>$value"; - break; - - case 'Folder': - # skip currently. This is the folder where Outlook stores the contact. - #$sifContact .= "<$sifField>/"; - break; - - default: - $sifContact .= "<$sifField>$value"; - break; - } + } + $sifContact .= "<$sifField>$value"; + break; + + case 'Sensitivity': + $value = 2 * $value; // eGW private is 0 (public) or 1 (private) + $sifContact .= "<$sifField>$value"; + break; + + case 'Folder': + # skip currently. This is the folder where Outlook stores the contact. + #$sifContact .= "<$sifField>/"; + break; + + default: + $sifContact .= "<$sifField>$value"; + break; } - $sifContact .= ""; - - return base64_encode($sifContact); } + $sifContact .= ""; - if($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); - } - return False; + return base64_encode($sifContact); } - } diff --git a/addressbook/inc/class.vcaladdressbook.inc.php b/addressbook/inc/class.vcaladdressbook.inc.php index abaf426818..885539c1cd 100644 --- a/addressbook/inc/class.vcaladdressbook.inc.php +++ b/addressbook/inc/class.vcaladdressbook.inc.php @@ -11,10 +11,10 @@ /* $Id$ */ - require_once EGW_SERVER_ROOT.'/addressbook/inc/class.boaddressbook.inc.php'; + require_once EGW_SERVER_ROOT.'/addressbook/inc/class.bocontacts.inc.php'; require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php'; - class vcaladdressbook extends boaddressbook + class vcaladdressbook extends bocontacts { #function vcaladdressbook() #{ @@ -30,27 +30,20 @@ */ function addVCard($_vcard, $_abID) { - if(!$contact = $this->vcardtoegw($_vcard)) { + if(!($contact = $this->vcardtoegw($_vcard))) + { return false; } - if($_abID > 0) - { - // update entry - $contact['ab_id'] = $_abID; - return $this->update_entry($contact); - } - else - { - // add entry - return $this->add_entry($contact); - } + if($_abID > 0) $contact['ab_id'] = $_abID; + + return $this->save($contact); } /** * return a vcard * - * @param int $_id the id of the contact + * @param int $_id the id of the contact * @param int $_vcardProfile profile id for mapping from vcard values to egw addressbook * @return string containing the vcard */ @@ -65,28 +58,10 @@ $this->setSupportedFields(); } - foreach($this->supportedFields as $databaseFields) - { - foreach($databaseFields as $databaseField) - { - if(!empty($databaseField)) - { - $fields[] = $databaseField; - } - } - } - #_debug_array($fields); - if($this->check_perms($_id,EGW_ACL_READ)) + if(($entry = $this->read($_id))) { - //$data = array('id' => $_id, 'fields' => $fields); - $entry = $this->so->read_entry($_id,$fields); - $entry = $this->strip_html($entry); - if($this->xmlrpc) - { - $entry = $this->data2xmlrpc($entry); - } #_debug_array($entry); $sysCharSet = $GLOBALS['egw']->translation->charset(); @@ -115,13 +90,13 @@ $value = $catData[0]['name']; break; case 'CLASS': - $value = ($value == 'private' ? 'PRIVATE' : 'PUBLIC'); + $value = $value ? 'PRIVATE' : 'PUBLIC'; break; case 'BDAY': if(!empty($value)) { - $dateParts = explode('/',$value); - $value = sprintf('%04d%02d%02dT000000Z',$dateParts[2],$dateParts[0],$dateParts[1]); + list($y,$m,$d) = explode('-',$value); + $value = sprintf('%04d%02d%02dT000000Z',$y,$m,$d); } break; } @@ -148,23 +123,26 @@ return $result; } - - if($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); - } return False; } - function search($_vcard) { - if(!$contact = $this->vcardtoegw($_vcard)) { + /** + * Search an exactly matching entry (used for slow sync) + * + * @param string $_vcard + * @return boolean/int/string contact-id or false, if not found + */ + function search($_vcard) + { + if(!($contact = $this->vcardtoegw($_vcard))) + { return false; } - - if($foundContacts = $this->read_entries(array('query' => $contact))) { - return $foundContacts[0][id]; + + if(($foundContacts = $this->search($contact))) + { + return $foundContacts[0]['id']; } - return false; } @@ -174,7 +152,7 @@ 'ADR' => array('','','adr_one_street','adr_one_locality','adr_one_region', 'adr_one_postalcode','adr_one_countryname'), 'CATEGORIES' => array('cat_id'), - 'CLASS' => array('access'), + 'CLASS' => array('private'), 'EMAIL' => array('email'), 'N' => array('n_family','n_given','','',''), 'NOTE' => array('note'), @@ -212,7 +190,7 @@ 'adr_one_postalcode','adr_one_countryname'), 'BDAY' => array('bday'), 'CATEGORIES' => array('cat_id'), - 'CLASS' => array('access'), + 'CLASS' => array('private'), 'EMAIL' => array('email'), 'N' => array('n_family','n_given','','',''), 'NOTE' => array('note'), @@ -309,7 +287,8 @@ } } - function vcardtoegw($_vcard) { + function vcardtoegw($_vcard) + { if(!is_array($this->supportedFields)) { $this->setSupportedFields(); @@ -335,8 +314,6 @@ foreach($vcardValues as $key => $vcardRow) { $rowName = $vcardRow['name']; - $mailtype = ';INTERNET'; - $tempVal = ';WORK'; if(isset($vcardRow['params']['INTERNET'])) { @@ -401,7 +378,7 @@ } break; - case 'CATEGORIESS': + case 'CATEGORIES': #cat_id = 7,8 $vcardData['category'] = array(); if ($attributes['value']) @@ -410,7 +387,7 @@ { if (!is_object($GLOBALS['egw']->categories)) { - $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$this->owner,'calendar'); + $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$this->owner,'addressbook'); } $this->cat =& $GLOBALS['egw']->categories; } @@ -447,15 +424,8 @@ { switch($fieldName) { - case 'access': - if($vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE') - { - $contact[$fieldName] = 'private'; - } - else - { - $contact[$fieldName] = 'public'; - } + case 'private': + $contact[$fieldName] = $vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE'; break; case 'cat_id': if (!is_object($this->cat)) @@ -487,48 +457,6 @@ #return true; /* _debug_array($contact);exit; */ - $contact['fn'] = trim($contact['n_given'].' '.$contact['n_family']); - if(!$contact['tel_work']) - { - $contact['tel_work'] = ''; - } - if(!$contact['tel_home']) - { - $contact['tel_home'] = ''; - } - if(!$contact['tel_voice']) - { - $contact['tel_voice'] = ''; - } - if(!$contact['tel_fax']) - { - $contact['tel_fax'] = ''; - } - if(!$contact['tel_msg']) - { - $contact['tel_msg'] = ''; - } - if(!$contact['tel_cell']) - { - $contact['tel_cell'] = ''; - } - if(!$contact['tel_pager']) - { - $contact['tel_pager'] = ''; - } - if(!$contact['tel_car']) - { - $contact['tel_car'] = ''; - } - if(!$contact['tel_isdn']) - { - $contact['tel_isdn'] = ''; - } - if(!$contact['tel_video']) - { - $contact['tel_video'] = ''; - } - return $contact; } }