Fix GroupDAV/Addressbook categories issue

This commit is contained in:
Jörg Lehrke 2010-06-14 07:45:25 +00:00
parent a88fbb756f
commit 1431f149e2
2 changed files with 31 additions and 12 deletions

View File

@ -1606,17 +1606,17 @@ class addressbook_bo extends addressbook_so
*/
function find_or_add_categories($catname_list, $contact_id=null)
{
if($contact_id && $contact_id > 0)
if ($contact_id && $contact_id > 0)
{
// preserve categories without users read access
$old_contact = $this->read($contact_id);
$old_categories = explode(',',$old_contact['cat_id']);
$old_cats_preserve = array();
if(is_array($old_categories) && count($old_categories) > 0)
if (is_array($old_categories) && count($old_categories) > 0)
{
foreach($old_categories as $cat_id)
foreach ($old_categories as $cat_id)
{
if(!$this->categories->check_perms(EGW_ACL_READ, $cat_id))
if (!$this->categories->check_perms(EGW_ACL_READ, $cat_id))
{
$old_cats_preserve[] = $cat_id;
}
@ -1625,11 +1625,10 @@ class addressbook_bo extends addressbook_so
}
$cat_id_list = array();
foreach($catname_list as $cat_name)
foreach ((array)$catname_list as $cat_name)
{
$cat_name = trim($cat_name);
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
// some SyncML clients (mostly phones) add an X- to the category names
@ -1646,7 +1645,7 @@ class addressbook_bo extends addressbook_so
}
}
if(is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
if (is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
{
$cat_id_list = array_merge($cat_id_list, $old_cats_preserve);
}

View File

@ -250,6 +250,7 @@ class addressbook_groupdav extends groupdav_handler
}
$handler = self::_get_handler();
$options['data'] = $handler->getVCard($contact['id'],$this->charset,false);
// e.g. Evolution does not understand 'text/vcard'
$options['mimetype'] = 'text/x-vcard; charset='.$this->charset;
header('Content-Encoding: identity');
header('ETag: '.$this->get_etag($contact));
@ -276,6 +277,25 @@ class addressbook_groupdav extends groupdav_handler
$handler = self::_get_handler();
$vCard = htmlspecialchars_decode($options['content']);
$charset = null;
if (!empty($options['content_type']))
{
$content_type = explode(';', $options['content_type']);
if (count($content_type) > 1)
{
array_shift($content_type);
foreach ($content_type as $attribute)
{
trim($attribute);
list($key, $value) = explode('=', $attribute);
switch (strtolower($key))
{
case 'charset':
$charset = strtoupper(substr($value,1,-1));
}
}
}
}
if (is_array($oldContact))
{
@ -285,7 +305,7 @@ class addressbook_groupdav extends groupdav_handler
else
{
// new entry?
if (($foundContacts = $handler->search($vCard)))
if (($foundContacts = $handler->search($vCard, null, false, $charset)))
{
if (($contactId = array_shift($foundContacts)) &&
($oldContact = $this->bo->read($contactId)))
@ -307,15 +327,15 @@ class addressbook_groupdav extends groupdav_handler
}
}
$contact = $handler->vcardtoegw($vCard);
$contact = $handler->vcardtoegw($vCard, $charset);
if (is_array($contact['category']))
if (is_array($contact['cat_id']))
{
$contact['category'] = implode(',',$this->bo->find_or_add_categories($contact['category'], $contactId));
$contact['cat_id'] = implode(',',$this->bo->find_or_add_categories($contact['cat_id'], $contactId));
}
elseif ($contactId > 0)
{
$contact['category'] = $oldContact['category'];
$contact['cat_id'] = $oldContact['cat_id'];
}
if (is_array($oldContact))
{