backport syncML fixes

This commit is contained in:
Cornelius Weiß 2007-07-04 19:13:00 +00:00
parent c4a17cf53f
commit b6cd1ee9e6
3 changed files with 30 additions and 22 deletions

View File

@ -443,7 +443,10 @@ class bocontacts extends socontacts
if (($old = $this->read($contact['id']))) // --> try reading the old entry and set it from there
{
$contact['owner'] = $old['owner'];
$contact['private'] = $old['private'];
if(!isset($contact['private']))
{
$contact['private'] = $old['private'];
}
}
else // entry not found --> create a new one
{

View File

@ -243,11 +243,17 @@ class socontacts_sql extends so_sql
$owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null);
// fix cat_id filter to search in comma-separated multiple cats and return subcats
if ((int)$filter['cat_id'])
if (($cats = $filter['cat_id']))
{
$filter[] = $this->_cat_filter($filter['cat_id']);
if ($filter['cat_id']{0} == '!')
{
$filter['cat_id'] = substr($filter['cat_id'],1);
$not = 'NOT';
}
$filter[] = $this->_cat_filter((int)$filter['cat_id'],$not);
unset($filter['cat_id']);
}
// add filter for read ACL in sql, if user is NOT the owner of the addressbook
if (isset($this->grants) && !(isset($filter['owner']) && $filter['owner'] == $GLOBALS['egw_info']['user']['account_id']))
{
@ -349,7 +355,7 @@ class socontacts_sql extends so_sql
* @param int $cat_id
* @return string sql to filter by given cat
*/
function _cat_filter($cat_id)
function _cat_filter($cat_id, $not='')
{
if (!is_object($GLOBALS['egw']->categories))
{
@ -357,9 +363,14 @@ class socontacts_sql extends so_sql
}
foreach($GLOBALS['egw']->categories->return_all_children((int)$cat_id) as $cat)
{
$cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'";
$cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'";
}
return '('.implode(' OR ',$cat_filter).')';
$cfilter = '('.implode(' OR ',$cat_filter).')';
if(!empty($not))
{
$cfilter = "( $cfilter OR cat_id IS NULL )";
}
return $cfilter;
}
/**
@ -530,4 +541,4 @@ class socontacts_sql extends so_sql
return $this->db->row(true);
}
}
}

View File

@ -15,6 +15,7 @@ require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php';
class vcaladdressbook extends bocontacts
{
/**
* import a vard into addressbook
*
@ -91,7 +92,8 @@ class vcaladdressbook extends bocontacts
}
// don't add the entry if it contains only ';'
if(strlen(str_replace(';','',$value)) != 0) {
// 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)) {
@ -103,18 +105,7 @@ class vcaladdressbook extends bocontacts
$vCard->setParameter($vcardField, $options);
}
// add the full name of the contact; this is a required field
$value = $GLOBALS['egw']->translation->convert($entry['n_fn'], $sysCharSet, 'utf-8');
$vCard->setAttribute('FN', $value);
$options = array();
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('FN', $options);
$result = $vCard->exportvCalendar();
return $result;
@ -564,7 +555,7 @@ class vcaladdressbook extends bocontacts
break;
case 'private':
$contact[$fieldName] = (int) $vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE';
(int)$contact[$fieldName] = $vcardValues[$vcardKey]['values'][$fieldKey] == 'PRIVATE';
break;
case 'cat_id':
@ -581,6 +572,10 @@ class vcaladdressbook extends bocontacts
$contact[$fieldName] = $cat_id;
}
break;
case 'note':
// note may contain ','s but maybe this needs to be fixed in vcard parser...
$contact[$fieldName] = trim($vcardValues[$vcardKey]['value']);
break;
default:
$contact[$fieldName] = trim($vcardValues[$vcardKey]['values'][$fieldKey]);
break;
@ -591,7 +586,6 @@ class vcaladdressbook extends bocontacts
}
$contact['n_fn'] = trim($contact['n_given'].' '.$contact['n_family']);
return $contact;
}