SyncML fixes

This commit is contained in:
Lars Kneschke 2006-05-17 03:36:48 +00:00
parent 73441f3ac3
commit 8cbca0bfd2

View File

@ -11,10 +11,10 @@
/* $Id$ */ /* $Id$ */
require_once EGW_SERVER_ROOT.'/addressbook/inc/class.bocontacts.inc.php'; require_once EGW_SERVER_ROOT.'/addressbook/inc/class.boaddressbook.inc.php';
require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php'; require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php';
class vcaladdressbook extends bocontacts class vcaladdressbook extends boaddressbook
{ {
#function vcaladdressbook() #function vcaladdressbook()
#{ #{
@ -30,14 +30,21 @@
*/ */
function addVCard($_vcard, $_abID) function addVCard($_vcard, $_abID)
{ {
if(!($contact = $this->vcardtoegw($_vcard))) if(!$contact = $this->vcardtoegw($_vcard)) {
{
return false; return false;
} }
if($_abID > 0) $contact['ab_id'] = $_abID; if($_abID > 0)
{
return $this->save($contact); // update entry
$contact['ab_id'] = $_abID;
return $this->update_entry($contact);
}
else
{
// add entry
return $this->add_entry($contact);
}
} }
/** /**
@ -58,10 +65,28 @@
$this->setSupportedFields(); $this->setSupportedFields();
} }
foreach($this->supportedFields as $databaseFields)
{
foreach($databaseFields as $databaseField)
{
if(!empty($databaseField))
{
$fields[] = $databaseField;
}
}
}
#_debug_array($fields); #_debug_array($fields);
if(($entry = $this->read($_id))) if($this->check_perms($_id,EGW_ACL_READ))
{ {
//$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); #_debug_array($entry);
$sysCharSet = $GLOBALS['egw']->translation->charset(); $sysCharSet = $GLOBALS['egw']->translation->charset();
@ -90,13 +115,13 @@
$value = $catData[0]['name']; $value = $catData[0]['name'];
break; break;
case 'CLASS': case 'CLASS':
$value = $value ? 'PRIVATE' : 'PUBLIC'; $value = ($value == 'private' ? 'PRIVATE' : 'PUBLIC');
break; break;
case 'BDAY': case 'BDAY':
if(!empty($value)) if(!empty($value))
{ {
list($y,$m,$d) = explode('-',$value); $dateParts = explode('/',$value);
$value = sprintf('%04d%02d%02dT000000Z',$y,$m,$d); $value = sprintf('%04d%02d%02dT000000Z',$dateParts[2],$dateParts[0],$dateParts[1]);
} }
break; break;
} }
@ -123,26 +148,23 @@
return $result; return $result;
} }
if($this->xmlrpc)
{
$GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
}
return False; return False;
} }
/** function search($_vcard) {
* Search an exactly matching entry (used for slow sync) if(!$contact = $this->vcardtoegw($_vcard)) {
*
* @param string $_vcard
* @return boolean/int/string contact-id or false, if not found
*/
function search($_vcard)
{
if(!($contact = $this->vcardtoegw($_vcard)))
{
return false; return false;
} }
if(($foundContacts = $this->search($contact))) if($foundContacts = $this->read_entries(array('query' => $contact))) {
{ return $foundContacts[0][id];
return $foundContacts[0]['id'];
} }
return false; return false;
} }
@ -152,7 +174,7 @@
'ADR' => array('','','adr_one_street','adr_one_locality','adr_one_region', 'ADR' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'), 'adr_one_postalcode','adr_one_countryname'),
'CATEGORIES' => array('cat_id'), 'CATEGORIES' => array('cat_id'),
'CLASS' => array('private'), 'CLASS' => array('access'),
'EMAIL' => array('email'), 'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''), 'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'), 'NOTE' => array('note'),
@ -190,7 +212,7 @@
'adr_one_postalcode','adr_one_countryname'), 'adr_one_postalcode','adr_one_countryname'),
'BDAY' => array('bday'), 'BDAY' => array('bday'),
'CATEGORIES' => array('cat_id'), 'CATEGORIES' => array('cat_id'),
'CLASS' => array('private'), 'CLASS' => array('access'),
'EMAIL' => array('email'), 'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''), 'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'), 'NOTE' => array('note'),
@ -287,8 +309,7 @@
} }
} }
function vcardtoegw($_vcard) function vcardtoegw($_vcard) {
{
if(!is_array($this->supportedFields)) if(!is_array($this->supportedFields))
{ {
$this->setSupportedFields(); $this->setSupportedFields();
@ -314,6 +335,8 @@
foreach($vcardValues as $key => $vcardRow) foreach($vcardValues as $key => $vcardRow)
{ {
$rowName = $vcardRow['name']; $rowName = $vcardRow['name'];
$mailtype = ';INTERNET';
$tempVal = ';WORK';
if(isset($vcardRow['params']['INTERNET'])) if(isset($vcardRow['params']['INTERNET']))
{ {
@ -424,8 +447,15 @@
{ {
switch($fieldName) switch($fieldName)
{ {
case 'private': case 'access':
$contact[$fieldName] = $vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE'; if($vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE')
{
$contact[$fieldName] = 'private';
}
else
{
$contact[$fieldName] = 'public';
}
break; break;
case 'cat_id': case 'cat_id':
if (!is_object($this->cat)) if (!is_object($this->cat))
@ -457,6 +487,48 @@
#return true; #return true;
/* _debug_array($contact);exit; */ /* _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; return $contact;
} }
} }