formatting

This commit is contained in:
Miles Lott 2005-07-28 03:44:13 +00:00
parent 9a33b1f7be
commit b8bf4655fb

View File

@ -8,7 +8,7 @@
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License. *
\**************************************************************************/
/* $Id$ */
require_once EGW_SERVER_ROOT.'/addressbook/inc/class.boaddressbook.inc.php';
@ -54,46 +54,58 @@
require_once(EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php');
$vCard = Horde_iCalendar::newComponent('vcard', $container);
if (!$vCard->parsevCalendar($_vcard,'VCARD'))
if(!$vCard->parsevCalendar($_vcard,'VCARD'))
{
return False;
}
$vcardValues = $vCard->getAllAttributes();
#print "<pre>$_vcard</pre>";
#_debug_array($vcardValues);
foreach($vcardValues as $key => $vcardRow)
{
$rowName = $vcardRow['name'];
$mailtype = ';INTERNET';
$tempVal = ';WORK';
$rowName = $vcardRow['name'];
$mailtype = ';INTERNET';
$tempVal = ';WORK';
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';
}
$rowNames[$rowName] = $key;
}
#_debug_array($rowNames);
// 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
foreach($rowNames as $rowName => $vcardKey)
{
switch($rowName)
@ -104,16 +116,22 @@
case 'TEL;CELL':
case 'TEL;PAGER':
if(!isset($rowNames[$rowName.';WORK']))
{
$finalRowNames[$rowName.';WORK'] = $vcardKey;
}
break;
case 'EMAIL':
case 'EMAIL;WORK':
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;
case 'VERSION':
break;
@ -122,9 +140,9 @@
break;
}
}
#_debug_array($finalRowNames);
foreach($finalRowNames as $key => $vcardKey)
{
if(isset($vcardFields[$_vcardProfile][$key]))
@ -139,24 +157,54 @@
}
}
}
#_debug_array($contact);
#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'] = '';
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'] = '';
}
$GLOBALS['egw']->translation->convert($contact,'utf-8');
if($_abID > 0)
@ -184,22 +232,21 @@
require_once(EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar/vcard.php');
$vCard =& new Horde_iCalendar_vcard;
#if ($this->xmlrpc && !isset($data['fields']))
#if($this->xmlrpc && !isset($data['fields']))
#{
# $data['fields'] = array_keys(array_merge($this->so->contacts->non_contact_fields,$this->so->contacts->stock_contact_fields,$this->customfields()));
#}
#if ($data['id'] < 0)
#if($data['id'] < 0)
#{
# $entry = array($this->user_pseudo_entry(-$data['id']));
# if ($this->xmlrpc)
# if($this->xmlrpc)
# {
# $entry = $this->data2xmlrpc($entry);
# }
# return $entry;
#}
$vcardFields[0] = array(
'ADR;WORK' => array('','','adr_one_street','adr_one_locality','adr_one_region',
'adr_one_postalcode','adr_one_countryname'),
@ -235,7 +282,7 @@
'TEL;WORK' => array('tel_work'),
'TITLE' => array('title'),
);
$vcardFields[2] = array(
'N' => array('n_family','n_given','n_middle','n_prefix','n_suffix'),
'TEL;CELL' => array('tel_cell'),
@ -251,25 +298,27 @@
# 'ADR;HOME' => array('','','adr_two_street','adr_two_locality','adr_two_region',
# 'adr_two_postalcode','adr_two_countryname'),
);
# $_vcardProfile = 2;
foreach($vcardFields[$_vcardProfile] as $databaseFields)
{
foreach($databaseFields as $databaseField)
{
if(!empty($databaseField))
{
$fields[] = $databaseField;
}
}
}
#_debug_array($fields);
#_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)
if($this->xmlrpc)
{
$entry = $this->data2xmlrpc($entry);
}
@ -284,13 +333,15 @@
{
$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
@ -311,14 +362,20 @@
// 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);
}
# $options = array('CHARSET' => 'UTF-8', 'ENCODING' => 'QUOTED-PRINTABLE');
# $vCard->setParameter('SUMMARY', $options);
# $vCard->setParameter('DESCRIPTION', $options);
@ -331,11 +388,11 @@
# $vCard->setParameter('ORG', $options);
$result = $vCard->exportvCalendar();
return $result;
}
if ($this->xmlrpc)
if($this->xmlrpc)
{
$GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
}