2005-07-20 14:14:39 +02:00
|
|
|
<?php
|
2006-07-09 01:02:30 +02:00
|
|
|
/**
|
|
|
|
* Addressbook - vCard / iCal parser
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Lars Kneschke <lkneschke@egroupware.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package addressbook
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
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 bocontacts
|
|
|
|
{
|
2007-06-30 13:20:31 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
/**
|
|
|
|
* import a vard into addressbook
|
|
|
|
*
|
|
|
|
* @param string $_vcard the vcard
|
2006-07-10 01:35:16 +02:00
|
|
|
* @param int/string $_abID=null the internal addressbook id or !$_abID for a new enty
|
2006-07-09 01:02:30 +02:00
|
|
|
* @return int contact id
|
|
|
|
*/
|
|
|
|
function addVCard($_vcard, $_abID)
|
2005-07-20 14:14:39 +02:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
if(!$contact = $this->vcardtoegw($_vcard)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-10 01:35:16 +02:00
|
|
|
if($_abID) {
|
2006-07-09 01:02:30 +02:00
|
|
|
// update entry
|
2006-07-09 15:29:19 +02:00
|
|
|
$contact['id'] = $_abID;
|
2005-07-20 14:14:39 +02:00
|
|
|
}
|
2006-07-10 00:59:22 +02:00
|
|
|
return $this->save($contact);
|
2006-07-09 01:02:30 +02:00
|
|
|
}
|
2005-07-20 14:14:39 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
/**
|
|
|
|
* return a vcard
|
|
|
|
*
|
|
|
|
* @param int/string $_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');
|
2005-07-20 14:14:39 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
$vCard =& new Horde_iCalendar_vcard;
|
2005-07-28 05:44:13 +02:00
|
|
|
|
2006-07-09 15:29:19 +02:00
|
|
|
if(!is_array($this->supportedFields)) {
|
2006-07-09 01:02:30 +02:00
|
|
|
$this->setSupportedFields();
|
|
|
|
}
|
|
|
|
$sysCharSet = $GLOBALS['egw']->translation->charset();
|
2005-07-28 05:44:13 +02:00
|
|
|
|
2006-07-09 15:29:19 +02:00
|
|
|
if(!($entry = $this->read($_id))) {
|
2006-07-09 01:02:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-01-23 18:34:24 +01:00
|
|
|
|
2007-10-13 13:00:47 +02:00
|
|
|
foreach($this->supportedFields as $vcardField => $databaseFields) {
|
2006-07-09 01:02:30 +02:00
|
|
|
$options = array();
|
2007-10-13 13:00:47 +02:00
|
|
|
$value = '';
|
|
|
|
foreach($databaseFields as $databaseField) {
|
|
|
|
$tempVal = ';';
|
|
|
|
if(!empty($databaseField)) {
|
|
|
|
$tempVal = trim($entry[$databaseField]).';';
|
2006-05-17 05:36:48 +02:00
|
|
|
}
|
2007-10-13 13:00:47 +02:00
|
|
|
$value .= $tempVal;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2007-10-13 13:00:47 +02:00
|
|
|
// 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' : 'PUBLIC';
|
|
|
|
break;
|
|
|
|
case 'BDAY':
|
|
|
|
if(!empty($value)) {
|
|
|
|
$value = str_replace('-','',$value).'T000000Z';
|
|
|
|
}
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2007-10-13 13:00:47 +02:00
|
|
|
|
|
|
|
if ($databaseField != 'jpegphoto') {
|
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't add the entry if it contains only ';'
|
|
|
|
// exeptions for mendatory fields
|
|
|
|
if( ( strlen(str_replace(';','',$value)) != 0 ) || in_array($vcardField,array('FN','ORG','N')) ) {
|
|
|
|
$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';
|
|
|
|
}
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
$vCard->setParameter($vcardField, $options);
|
|
|
|
}
|
2007-06-30 13:20:31 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
$result = $vCard->exportvCalendar();
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
return $result;
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
function search($_vcard)
|
|
|
|
{
|
2006-07-09 15:29:19 +02:00
|
|
|
if(!($contact = $this->vcardtoegw($_vcard))) {
|
2006-07-09 01:02:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-09 15:29:19 +02:00
|
|
|
unset($contact['private']);
|
|
|
|
unset($contact['note']);
|
|
|
|
unset($contact['n_fn']);
|
2007-01-23 18:34:24 +01:00
|
|
|
unset($contact['email']);
|
|
|
|
unset($contact['email_home']);
|
|
|
|
unset($contact['url']);
|
|
|
|
unset($contact['url_home']);
|
|
|
|
|
|
|
|
// some clients cut the values, because they do not support the same length of data like eGW
|
|
|
|
// at least the first 10 characters must match
|
|
|
|
$maybeCuttedFields = array('org_unit', 'org_name','title');
|
|
|
|
foreach($maybeCuttedFields as $fieldName) {
|
|
|
|
if(!empty($contact[$fieldName]) && strlen($contact[$fieldName]) > 10) {
|
|
|
|
$contact[$fieldName] .= '*';
|
|
|
|
}
|
|
|
|
}
|
2006-07-09 15:29:19 +02:00
|
|
|
|
2007-03-01 21:17:51 +01:00
|
|
|
//error_log(print_r($contact, true));
|
2007-01-23 18:34:24 +01:00
|
|
|
|
|
|
|
#if($foundContacts = parent::search($contact, true, '', '', '%')) {
|
2006-07-09 15:29:19 +02:00
|
|
|
if($foundContacts = parent::search($contact)) {
|
2006-07-09 01:02:30 +02:00
|
|
|
return $foundContacts[0]['id'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
function setSupportedFields($_productManufacturer='file', $_productName='')
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* ToDo Lars:
|
|
|
|
* + changes / renamed fields in 1.3+:
|
|
|
|
* - access --> private (already done by Ralf)
|
|
|
|
* - tel_msg --> tel_assistent
|
|
|
|
* - tel_modem --> tel_fax_home
|
|
|
|
* - tel_isdn --> tel_cell_private
|
|
|
|
* - tel_voice/ophone --> tel_other
|
|
|
|
* - address2 --> adr_one_street2
|
|
|
|
* - address3 --> adr_two_street2
|
|
|
|
* - freebusy_url --> freebusy_uri (i instead l !)
|
|
|
|
* - fn --> n_fn
|
|
|
|
* - last_mod --> modified
|
|
|
|
* + new fields in 1.3+:
|
|
|
|
* - n_fileas
|
|
|
|
* - role
|
|
|
|
* - assistent
|
|
|
|
* - room
|
|
|
|
* - calendar_uri
|
|
|
|
* - url_home
|
|
|
|
* - created
|
|
|
|
* - creator (preset with owner)
|
|
|
|
* - modifier
|
|
|
|
* - jpegphoto
|
|
|
|
*/
|
|
|
|
$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('private'),
|
|
|
|
'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'),
|
2006-07-09 15:29:19 +02:00
|
|
|
'ROLE' => array('role'),
|
2006-07-09 01:02:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$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('private'),
|
|
|
|
'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'),
|
2006-07-09 15:29:19 +02:00
|
|
|
'URL;WORK' => array('url'),
|
2006-07-09 01:02:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$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'),
|
|
|
|
);
|
|
|
|
|
2006-07-23 20:10:37 +02:00
|
|
|
$defaultFields[4] = 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',''),
|
|
|
|
'TEL;CELL;WORK' => array('tel_cell'),
|
|
|
|
'TEL;CELL;HOME' => array('tel_cell_private'),
|
|
|
|
'TEL;FAX;WORK' => array('tel_fax'),
|
|
|
|
'TEL;FAX;HOME' => array('tel_fax_home'),
|
|
|
|
'TEL;HOME' => array('tel_home'),
|
|
|
|
'TEL;PAGER;WORK' => array('tel_pager'),
|
|
|
|
'TEL;WORK' => array('tel_work'),
|
|
|
|
'TITLE' => array('title'),
|
|
|
|
'URL;WORK' => array('url'),
|
2006-08-15 14:46:26 +02:00
|
|
|
'URL;HOME' => array('url_home'),
|
2006-07-23 20:10:37 +02:00
|
|
|
);
|
|
|
|
|
2006-08-15 14:46:26 +02:00
|
|
|
$defaultFields[5] = 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','','n_prefix','n_suffix'),
|
|
|
|
'NOTE' => array('note'),
|
|
|
|
'ORG' => array('org_name',''),
|
|
|
|
'TEL;CELL;WORK' => array('tel_cell'),
|
|
|
|
'TEL;CELL;HOME' => array('tel_cell_private'),
|
|
|
|
'TEL;FAX;WORK' => array('tel_fax'),
|
|
|
|
'TEL;FAX;HOME' => array('tel_fax_home'),
|
|
|
|
'TEL;HOME' => array('tel_home'),
|
|
|
|
'TEL;PAGER;WORK' => array('tel_pager'),
|
|
|
|
'TEL;WORK' => array('tel_work'),
|
|
|
|
'TITLE' => array('title'),
|
|
|
|
'URL;WORK' => array('url'),
|
|
|
|
'URL;HOME' => array('url_home'),
|
|
|
|
);
|
2007-06-25 11:03:58 +02:00
|
|
|
|
|
|
|
$defaultFields[6] = array(
|
2007-10-13 13:00:47 +02:00
|
|
|
'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'),
|
|
|
|
'EMAIL' => array('email'),
|
|
|
|
'EMAIL;HOME' => array('email_home'),
|
|
|
|
'N' => array('n_family','n_given','','',''),
|
|
|
|
'NOTE' => array('note'),
|
|
|
|
'ORG' => array('org_name','org_unit'),
|
|
|
|
'TEL;CELL' => array('tel_cell'),
|
|
|
|
'TEL;HOME;FAX' => array('tel_fax'),
|
2007-06-25 11:03:58 +02:00
|
|
|
'TEL;HOME;VOICE' => array('tel_home'),
|
2007-10-13 13:00:47 +02:00
|
|
|
'TEL;PAGER' => array('tel_pager'),
|
2007-06-25 11:03:58 +02:00
|
|
|
'TEL;WORK;VOICE' => array('tel_work'),
|
2007-10-13 13:00:47 +02:00
|
|
|
'TITLE' => array('title'),
|
|
|
|
'URL;WORK' => array('url'),
|
|
|
|
'URL' => array('url_home'),
|
2007-06-25 11:03:58 +02:00
|
|
|
);
|
2006-08-15 14:46:26 +02:00
|
|
|
//error_log("Client: $_productManufacturer $_productName");
|
2006-07-09 01:02:30 +02:00
|
|
|
switch(strtolower($_productManufacturer))
|
|
|
|
{
|
2007-06-25 11:03:58 +02:00
|
|
|
case 'funambol':
|
2007-10-13 13:00:47 +02:00
|
|
|
switch(strtolower($_productName))
|
2007-06-25 11:03:58 +02:00
|
|
|
{
|
2007-10-13 13:00:47 +02:00
|
|
|
case 'fmz-thunderbird-plugin':
|
2007-06-25 11:03:58 +02:00
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[6];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'nexthaus corporation':
|
|
|
|
switch(strtolower($_productName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'syncje outlook edition':
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[1];
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
|
|
|
|
2006-07-23 20:10:37 +02:00
|
|
|
case 'nokia':
|
|
|
|
switch(strtolower($_productName))
|
|
|
|
{
|
2006-08-15 14:46:26 +02:00
|
|
|
case 'e61':
|
|
|
|
$this->supportedFields = $defaultFields[5];
|
|
|
|
break;
|
2006-07-23 20:10:37 +02:00
|
|
|
case '6600':
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[4];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
// multisync does not provide anymore information then the manufacturer
|
|
|
|
// we suppose multisync with evolution
|
|
|
|
case 'the multisync project':
|
|
|
|
switch(strtolower($_productName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[0];
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'siemens':
|
|
|
|
switch(strtolower($_productName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'sx1':
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[3];
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'sonyericsson':
|
|
|
|
switch(strtolower($_productName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'd750i':
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[2];
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'synthesis ag':
|
|
|
|
switch(strtolower($_productName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2007-01-23 18:34:24 +01:00
|
|
|
case 'sysync client pocketpc pro':
|
|
|
|
$this->supportedFields = $defaultFields[1];
|
|
|
|
#$this->supportedFields['PHOTO'] = array('jpegphoto');
|
|
|
|
break;
|
2006-07-09 01:02:30 +02:00
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields[0];
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
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:
|
2007-10-13 13:00:47 +02:00
|
|
|
error_log("Client not found: $_productManufacturer $_productName");
|
2006-07-09 01:02:30 +02:00
|
|
|
$this->supportedFields = $defaultFields[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function vcardtoegw($_vcard)
|
|
|
|
{
|
2006-08-15 14:46:26 +02:00
|
|
|
// the horde class does the charset conversion. DO NOT CONVERT HERE.
|
2006-07-09 01:02:30 +02:00
|
|
|
|
2006-08-15 14:46:26 +02:00
|
|
|
if(!is_array($this->supportedFields)) {
|
2006-07-09 01:02:30 +02:00
|
|
|
$this->setSupportedFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->supportedFields[0] = array(
|
|
|
|
);
|
|
|
|
|
|
|
|
require_once(EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php');
|
|
|
|
|
|
|
|
$vCard = Horde_iCalendar::newComponent('vcard', $container);
|
2007-01-23 18:34:24 +01:00
|
|
|
|
|
|
|
// Unfold any folded lines.
|
|
|
|
$vCardUnfolded = preg_replace ('/(\r|\n)+ /', ' ', $_vcard);
|
2006-07-09 01:02:30 +02:00
|
|
|
|
2007-01-23 18:34:24 +01:00
|
|
|
if(!$vCard->parsevCalendar($vCardUnfolded, 'VCARD')) {
|
2006-07-09 01:02:30 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$vcardValues = $vCard->getAllAttributes();
|
|
|
|
|
|
|
|
#print "<pre>$_vcard</pre>";
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-23 20:10:37 +02:00
|
|
|
#error_log(print_r($vcardValues, true));
|
2006-07-09 01:02:30 +02:00
|
|
|
|
|
|
|
foreach($vcardValues as $key => $vcardRow)
|
|
|
|
{
|
|
|
|
$rowName = $vcardRow['name'];
|
|
|
|
|
|
|
|
if(isset($vcardRow['params']['INTERNET']))
|
|
|
|
{
|
|
|
|
$rowName .= ";INTERNET";
|
|
|
|
}
|
|
|
|
if(isset($vcardRow['params']['CELL']))
|
|
|
|
{
|
|
|
|
$rowName .= ';CELL';
|
|
|
|
}
|
|
|
|
if(isset($vcardRow['params']['FAX']))
|
|
|
|
{
|
|
|
|
$rowName .= ';FAX';
|
|
|
|
}
|
|
|
|
if(isset($vcardRow['params']['PAGER']))
|
|
|
|
{
|
|
|
|
$rowName .= ';PAGER';
|
|
|
|
}
|
|
|
|
if(isset($vcardRow['params']['WORK']))
|
|
|
|
{
|
|
|
|
$rowName .= ';WORK';
|
|
|
|
}
|
|
|
|
if(isset($vcardRow['params']['HOME']))
|
|
|
|
{
|
|
|
|
$rowName .= ';HOME';
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
$rowNames[$rowName] = $key;
|
|
|
|
}
|
|
|
|
|
2006-07-09 15:29:19 +02:00
|
|
|
#error_log(print_r($rowNames, true));
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
// now we have all rowNames the vcard provides
|
|
|
|
// we just need to map to the right addressbook fieldnames
|
|
|
|
// we need also to take care about ADR for example. we do not
|
|
|
|
// support this. We support only ADR;WORK or ADR;HOME
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
foreach($rowNames as $rowName => $vcardKey)
|
|
|
|
{
|
|
|
|
switch($rowName)
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'ADR':
|
|
|
|
case 'TEL':
|
2006-07-09 15:29:19 +02:00
|
|
|
case 'URL':
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'TEL;FAX':
|
|
|
|
case 'TEL;CELL':
|
|
|
|
case 'TEL;PAGER':
|
|
|
|
if(!isset($rowNames[$rowName. ';WORK']))
|
|
|
|
{
|
|
|
|
$finalRowNames[$rowName. ';WORK'] = $vcardKey;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'EMAIL':
|
|
|
|
case 'EMAIL;WORK':
|
2006-07-09 15:29:19 +02:00
|
|
|
case 'EMAIL;INTERNET':
|
2006-07-09 01:02:30 +02:00
|
|
|
if(!isset($rowNames['EMAIL;INTERNET;WORK']))
|
|
|
|
{
|
|
|
|
$finalRowNames['EMAIL;INTERNET;WORK'] = $vcardKey;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'EMAIL;HOME':
|
|
|
|
if(!isset($rowNames['EMAIL;INTERNET;HOME']))
|
|
|
|
{
|
|
|
|
$finalRowNames['EMAIL;INTERNET;HOME'] = $vcardKey;
|
|
|
|
}
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2007-10-13 13:00:47 +02:00
|
|
|
case 'CATEGORIES':
|
|
|
|
#cat_id = 7,8
|
|
|
|
$vcardData['category'] = array();
|
|
|
|
if ($attributes['value'])
|
|
|
|
{
|
|
|
|
if (!is_object($this->cat))
|
|
|
|
{
|
|
|
|
if (!is_object($GLOBALS['egw']->categories))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$this->owner,'addressbook');
|
|
|
|
}
|
|
|
|
$this->cat =& $GLOBALS['egw']->categories;
|
|
|
|
}
|
|
|
|
foreach(explode(',',$attributes['value']) as $cat_name)
|
|
|
|
{
|
|
|
|
if (!($cat_id = $this->cat->name2id($cat_name)))
|
|
|
|
{
|
|
|
|
$cat_id = $this->cat->add( array('name' => $cat_name,'descr' => $cat_name ));
|
|
|
|
}
|
|
|
|
$vcardData['category'][] = $cat_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'VERSION':
|
|
|
|
break;
|
2006-07-09 15:29:19 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
default:
|
|
|
|
$finalRowNames[$rowName] = $vcardKey;
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 15:29:19 +02:00
|
|
|
#error_log(print_r($finalRowNames, true));
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
$contact = array();
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
foreach($finalRowNames as $key => $vcardKey)
|
|
|
|
{
|
|
|
|
if(isset($this->supportedFields[$key]))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
$fieldNames = $this->supportedFields[$key];
|
|
|
|
foreach($fieldNames as $fieldKey => $fieldName)
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
if(!empty($fieldName))
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 01:02:30 +02:00
|
|
|
switch($fieldName)
|
2006-03-21 14:19:38 +01:00
|
|
|
{
|
2006-07-09 15:29:19 +02:00
|
|
|
case 'bday':
|
2007-10-13 13:00:47 +02:00
|
|
|
if(!empty($vcardValues[$vcardKey]['values'][$fieldKey])) {
|
|
|
|
$contact[$fieldName] = date('Y-m-d', $vcardValues[$vcardKey]['values'][$fieldKey]);
|
2007-01-23 18:34:24 +01:00
|
|
|
}
|
2006-07-09 15:29:19 +02:00
|
|
|
break;
|
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'private':
|
2007-10-13 13:00:47 +02:00
|
|
|
(int)$contact[$fieldName] = $vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE';
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
2006-07-09 15:29:19 +02:00
|
|
|
|
2006-07-09 01:02:30 +02:00
|
|
|
case 'cat_id':
|
2007-10-13 13:00:47 +02:00
|
|
|
if (!is_object($this->cat)) {
|
|
|
|
if (!is_object($GLOBALS['egw']->categories)) {
|
|
|
|
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'addressbook');
|
|
|
|
}
|
|
|
|
$this->cat =& $GLOBALS['egw']->categories;
|
|
|
|
}
|
|
|
|
foreach(explode(',',$vcardValues[$vcardKey]['values'][$fieldKey]) as $cat_name) {
|
|
|
|
if (!($cat_id = $this->cat->name2id($cat_name))) {
|
|
|
|
$cat_id = $this->cat->add( array('name' => $cat_name, 'descr' => $cat_name ));
|
|
|
|
}
|
|
|
|
$contact[$fieldName] = $cat_id;
|
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
2007-07-02 15:11:13 +02:00
|
|
|
case 'note':
|
|
|
|
// note may contain ','s but maybe this needs to be fixed in vcard parser...
|
2007-10-13 13:00:47 +02:00
|
|
|
$contact[$fieldName] = trim($vcardValues[$vcardKey]['value']);
|
|
|
|
break;
|
2006-07-09 01:02:30 +02:00
|
|
|
default:
|
2007-10-13 13:00:47 +02:00
|
|
|
$contact[$fieldName] = trim($vcardValues[$vcardKey]['values'][$fieldKey]);
|
2006-07-09 01:02:30 +02:00
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-15 14:46:26 +02:00
|
|
|
|
2007-10-13 13:00:47 +02:00
|
|
|
$contact['n_fn'] = trim($contact['n_given'].' '.$contact['n_family']);
|
2006-07-09 01:02:30 +02:00
|
|
|
return $contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports some contacts: download or write to a file
|
|
|
|
*
|
|
|
|
* @param array $ids contact-ids
|
|
|
|
* @param string $file filename or null for download
|
|
|
|
*/
|
|
|
|
function export($ids,$file=null)
|
|
|
|
{
|
|
|
|
if (!$file)
|
|
|
|
{
|
|
|
|
$browser =& CreateObject('phpgwapi.browser');
|
|
|
|
$browser->content_header('addressbook.vcf','text/x-vcard');
|
|
|
|
}
|
|
|
|
if (!($fp = fopen($file ? $file : 'php://output','w')))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach($ids as $id)
|
|
|
|
{
|
|
|
|
fwrite($fp,$this->getVCard($id));
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
if (!$file)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
|
|
|
return true;
|
2005-07-20 14:14:39 +02:00
|
|
|
}
|
2006-07-09 01:02:30 +02:00
|
|
|
}
|