added support for SIF encoded files(Sync4j)

added search support(needed for slowsync)
This commit is contained in:
Lars Kneschke 2006-03-21 13:19:38 +00:00
parent 995cc939e9
commit 2a8544edd3
2 changed files with 316 additions and 265 deletions

View File

@ -30,6 +30,286 @@
*/
function addVCard($_vcard, $_abID)
{
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);
}
}
/**
* return a vcard
*
* @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
*/
function getVCard($_id)
{
require_once(EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar/vcard.php');
$vCard =& new Horde_iCalendar_vcard;
if(!is_array($this->supportedFields))
{
$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))
{
//$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();
foreach($this->supportedFields as $vcardField => $databaseFields)
{
$options = array();
$value = '';
foreach($databaseFields as $databaseField)
{
$tempVal = ';';
if(!empty($databaseField))
{
#$tempVal = trim('value').';';
$tempVal = trim($entry[0][$databaseField]).';';
}
$value .= $tempVal;
}
// remove the last ;
$value = substr($value, 0, -1);
switch($vcardField)
{
// TODO handle multiple categories
case 'CATEGORIES':
$catData = ExecMethod('phpgwapi.categories.return_single',$value);
$value = $catData[0]['name'];
break;
case 'CLASS':
$value = ($value == 'private' ? 'PRIVATE' : 'PUBLIC');
break;
case 'BDAY':
if(!empty($value))
{
$dateParts = explode('/',$value);
$value = sprintf('%04d%02d%02dT000000Z',$dateParts[2],$dateParts[0],$dateParts[1]);
}
break;
}
$value = $GLOBALS['egw']->translation->convert($value,$sysCharSet,'utf-8');
// don't add the entry if it contains only ';'
if(strlen(str_replace(';','',$value)) != 0)
{
$vCard->setAttribute($vcardField, $value);
}
if(preg_match('/([\000-\012\015\016\020-\037\075])/',$value))
{
$options['ENCODING'] = 'QUOTED-PRINTABLE';
}
if(preg_match('/([\177-\377])/',$value))
{
$options['CHARSET'] = 'UTF-8';
}
$vCard->setParameter($vcardField, $options);
}
$result = $vCard->exportvCalendar();
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)) {
return false;
}
if($foundContacts = $this->read_entries(array('query' => $contact))) {
return $foundContacts[0][id];
}
return false;
}
function setSupportedFields($_productManufacturer='file', $_productName='')
{
$defaultFields[0] = array(
'ADR' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'CATEGORIES' => array('cat_id'),
'CLASS' => array('access'),
'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name',''),
'TEL;CELL' => array('tel_cell'),
'TEL;FAX' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
);
$defaultFields[1] = array(
'ADR;WORK' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'ADR;HOME' => array('','','adr_two_street','adr_two_locality','adr_two_region',
'adr_two_postalcode','adr_two_countryname'),
'BDAY' => array('bday'),
'CATEGORIES' => array('cat_id'),
'EMAIL;INTERNET;WORK' => array('email'),
'EMAIL;INTERNET;HOME' => array('email_home'),
'N' => array('n_family','n_given','n_middle','n_prefix','n_suffix'),
'NOTE' => array('note'),
'ORG' => array('org_name','org_unit'),
'TEL;CELL;WORK' => array('tel_cell'),
'TEL;FAX;WORK' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;PAGER;WORK' => array('tel_pager'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL;WORK' => array('url'),
);
$defaultFields[2] = array(
'ADR;HOME' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'BDAY' => array('bday'),
'CATEGORIES' => array('cat_id'),
'CLASS' => array('access'),
'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name',''),
'TEL;CELL;WORK' => array('tel_cell'),
'TEL;FAX;WORK' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL' => array('url'),
);
$defaultFields[3] = array(
'ADR;WORK' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'ADR;HOME' => array('','','adr_two_street','adr_two_locality','adr_two_region',
'adr_two_postalcode','adr_two_countryname'),
'BDAY' => array('bday'),
'EMAIL;INTERNET;WORK' => array('email'),
'EMAIL;INTERNET;HOME' => array('email_home'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name','org_unit'),
'TEL;CELL;WORK' => array('tel_cell'),
'TEL;FAX;WORK' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;PAGER;WORK' => array('tel_pager'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL;WORK' => array('url'),
);
switch(strtolower($_productManufacturer))
{
case 'nexthaus corporation':
switch(strtolower($_productName))
{
case 'syncje outlook edition':
default:
$this->supportedFields = $defaultFields[1];
break;
}
break;
// multisync does not provide anymore information then the manufacturer
// we suppose multisync with evolution
case 'the multisync project':
switch(strtolower($_productName))
{
default:
$this->supportedFields = $defaultFields[0];
break;
}
break;
case 'siemens':
switch(strtolower($_productName))
{
case 'sx1':
default:
$this->supportedFields = $defaultFields[3];
break;
}
break;
case 'sonyericsson':
switch(strtolower($_productName))
{
case 'd750i':
default:
$this->supportedFields = $defaultFields[2];
break;
}
break;
case 'synthesis ag':
switch(strtolower($_productName))
{
default:
$this->supportedFields = $defaultFields[0];
break;
}
break;
case 'file': // used outside of SyncML, eg. by the calendar itself ==> all possible fields
$this->supportedFields = $defaultFields[1];
break;
// the fallback for SyncML
default:
error_log("Client not found: $_productManufacturer $_productName");
$this->supportedFields = $defaultFields[0];
break;
}
}
function vcardtoegw($_vcard) {
if(!is_array($this->supportedFields))
{
$this->setSupportedFields();
@ -86,7 +366,7 @@
$rowNames[$rowName] = $key;
}
error_log('rowNames: '.print_r($rowNames,true));
#error_log('rowNames: '.print_r($rowNames,true));
// now we have all rowNames the vcard provides
// we just need to map to the right addressbook fieldnames
@ -249,266 +529,6 @@
$contact['tel_video'] = '';
}
if($_abID > 0)
{
// update entry
$contact['ab_id'] = $_abID;
return $this->update_entry($contact);
}
else
{
// add entry
return $this->add_entry($contact);
}
}
/**
* return a vcard
*
* @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
*/
function getVCard($_id)
{
require_once(EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar/vcard.php');
$vCard =& new Horde_iCalendar_vcard;
if(!is_array($this->supportedFields))
{
$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))
{
//$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();
foreach($this->supportedFields as $vcardField => $databaseFields)
{
$options = array();
$value = '';
foreach($databaseFields as $databaseField)
{
$tempVal = ';';
if(!empty($databaseField))
{
#$tempVal = trim('value').';';
$tempVal = trim($entry[0][$databaseField]).';';
}
$value .= $tempVal;
}
// remove the last ;
$value = substr($value, 0, -1);
switch($vcardField)
{
// TODO handle multiple categories
case 'CATEGORIES':
$catData = ExecMethod('phpgwapi.categories.return_single',$value);
$value = $catData[0]['name'];
break;
case 'CLASS':
$value = ($value == 'private' ? 'PRIVATE' : 'PUBLIC');
break;
case 'BDAY':
if(!empty($value))
{
$dateParts = explode('/',$value);
$value = sprintf('%04d%02d%02dT000000Z',$dateParts[2],$dateParts[0],$dateParts[1]);
}
break;
}
$value = $GLOBALS['egw']->translation->convert($value,$sysCharSet,'utf-8');
// don't add the entry if it contains only ';'
if(strlen(str_replace(';','',$value)) != 0)
{
$vCard->setAttribute($vcardField, $value);
}
if(preg_match('/([\000-\012\015\016\020-\037\075])/',$value))
{
$options['ENCODING'] = 'QUOTED-PRINTABLE';
}
if(preg_match('/([\177-\377])/',$value))
{
$options['CHARSET'] = 'UTF-8';
}
$vCard->setParameter($vcardField, $options);
}
$result = $vCard->exportvCalendar();
return $result;
}
if($this->xmlrpc)
{
$GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
}
return False;
}
function setSupportedFields($_productManufacturer='file', $_productName='')
{
$defaultFields[0] = array(
'ADR' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'CATEGORIES' => array('cat_id'),
'CLASS' => array('access'),
'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name',''),
'TEL;CELL' => array('tel_cell'),
'TEL;FAX' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
);
$defaultFields[1] = array(
'ADR;WORK' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'ADR;HOME' => array('','','adr_two_street','adr_two_locality','adr_two_region',
'adr_two_postalcode','adr_two_countryname'),
'BDAY' => array('bday'),
'CATEGORIES' => array('cat_id'),
'EMAIL;INTERNET;WORK' => array('email'),
'EMAIL;INTERNET;HOME' => array('email_home'),
'N' => array('n_family','n_given','n_middle','n_prefix','n_suffix'),
'NOTE' => array('note'),
'ORG' => array('org_name','org_unit'),
'TEL;CELL;WORK' => array('tel_cell'),
'TEL;FAX;WORK' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;PAGER;WORK' => array('tel_pager'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL;WORK' => array('url'),
);
$defaultFields[2] = array(
'ADR;HOME' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'BDAY' => array('bday'),
'CATEGORIES' => array('cat_id'),
'CLASS' => array('access'),
'EMAIL' => array('email'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name',''),
'TEL;CELL' => array('tel_cell'),
'TEL;FAX' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL' => array('url'),
);
$defaultFields[3] = array(
'ADR;WORK' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
'ADR;HOME' => array('','','adr_two_street','adr_two_locality','adr_two_region',
'adr_two_postalcode','adr_two_countryname'),
'BDAY' => array('bday'),
'EMAIL;INTERNET;WORK' => array('email'),
'EMAIL;INTERNET;HOME' => array('email_home'),
'N' => array('n_family','n_given','','',''),
'NOTE' => array('note'),
'ORG' => array('org_name','org_unit'),
'TEL;CELL;WORK' => array('tel_cell'),
'TEL;FAX;WORK' => array('tel_fax'),
'TEL;HOME' => array('tel_home'),
'TEL;PAGER;WORK' => array('tel_pager'),
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
'URL;WORK' => array('url'),
);
switch(strtolower($_productManufacturer))
{
case 'nexthaus corporation':
switch(strtolower($_productName))
{
case 'syncje outlook edition':
default:
$this->supportedFields = $defaultFields[1];
break;
}
break;
// multisync does not provide anymore information then the manufacturer
// we suppose multisync with evolution
case 'the multisync project':
switch(strtolower($_productName))
{
default:
$this->supportedFields = $defaultFields[0];
break;
}
break;
case 'siemens':
switch(strtolower($_productName))
{
case 'sx1':
default:
$this->supportedFields = $defaultFields[3];
break;
}
break;
case 'sonyericsson':
switch(strtolower($_productName))
{
case 'd750i':
default:
$this->supportedFields = $defaultFields[2];
break;
}
break;
case 'synthesis ag':
switch(strtolower($_productName))
{
default:
$this->supportedFields = $defaultFields[0];
break;
}
break;
case 'file': // used outside of SyncML, eg. by the calendar itself ==> all possible fields
$this->supportedFields = $defaultFields[1];
break;
// the fallback for SyncML
default:
error_log("Client not found: $_productManufacturer $_productName");
$this->supportedFields = $defaultFields[0];
break;
}
return $contact;
}
}

View File

@ -91,12 +91,44 @@
function importVTODO(&$_vcalData, $_taskID=-1)
{
if(!$taskData = $this->vtodotoegw($_vcalData)) {
return false;
}
if($_taskID>0)
$taskData['info_id'] = $_taskID;
#_debug_array($taskData);exit;
return $this->write($taskData);
}
function searchVTODO($_vcalData) {
if(!$egwData = $this->vtodotoegw($_calData)) {
return false;
}
$filter = array('col_filter' => $egwData);
if($foundItems = $this->search($filter)) {
if(count($foundItems) > 0) {
#error_log(__LINE__);
#error_log(print_r($foundItems, true));
$itemIDs = array_keys($foundItems);
#error_log($itemIDs[0]);
return $itemIDs[0];
}
}
return false;
}
function vtodotoegw($_vcalData) {
$vcal = &new Horde_iCalendar;
if(!$vcal->parsevCalendar($_vcalData))
{
return FALSE;
}
$components = $vcal->getComponents();
if(count($components) > 0)
{
$component = $components[0];
@ -148,10 +180,9 @@
break;
}
}
$taskData = $GLOBALS['egw']->translation->convert($taskData,'UTF-8');
$taskData = $GLOBALS['egw']->translation->convert($taskData, 'UTF-8');
#_debug_array($eventData);exit;
return $this->write($taskData);
return $taskData;
}
}
return FALSE;