Fix contact group management using new libkolab

This commit is contained in:
Thomas B 2012-03-08 21:23:55 +01:00
parent c8696e278c
commit 67f3f91aac

View file

@ -249,6 +249,7 @@ class rcube_kolab_contacts extends rcube_addressbook
// list member of the selected group // list member of the selected group
if ($this->gid) { if ($this->gid) {
$this->_fetch_groups();
$seen = array(); $seen = array();
$this->result->count = 0; $this->result->count = 0;
foreach ((array)$this->distlists[$this->gid]['member'] as $member) { foreach ((array)$this->distlists[$this->gid]['member'] as $member) {
@ -256,8 +257,11 @@ class rcube_kolab_contacts extends rcube_addressbook
if (is_array($this->filter['ids']) && array_search($member['ID'], $this->filter['ids']) === false) if (is_array($this->filter['ids']) && array_search($member['ID'], $this->filter['ids']) === false)
continue; continue;
if ($this->contacts[$member['ID']] && !$seen[$member['ID']]++) $contact = $this->storagefolder->get_object($member['uid']);
if ($contact && !$seen[$member['ID']]++) {
$this->contacts[$member['ID']] = $this->_to_rcube_contact($contact);
$this->result->count++; $this->result->count++;
}
} }
$ids = array_keys($seen); $ids = array_keys($seen);
} }
@ -518,11 +522,11 @@ class rcube_kolab_contacts extends rcube_addressbook
$saved = $this->storagefolder->save($object, 'contact'); $saved = $this->storagefolder->save($object, 'contact');
if (PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error saving contact object to Kolab server:" . $saved->getMessage()), 'message' => "Error saving contact object to Kolab server"),
true, false); true, false);
} }
else { else {
@ -553,7 +557,7 @@ class rcube_kolab_contacts extends rcube_addressbook
$object = array_merge($old, $this->_from_rcube_contact($save_data)); $object = array_merge($old, $this->_from_rcube_contact($save_data));
$saved = $this->storagefolder->save($object, 'contact', $uid); $saved = $this->storagefolder->save($object, 'contact', $uid);
if (!$saved || PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
@ -563,6 +567,8 @@ class rcube_kolab_contacts extends rcube_addressbook
else { else {
$this->contacts[$id] = $this->_to_rcube_contact($object); $this->contacts[$id] = $this->_to_rcube_contact($object);
$updated = true; $updated = true;
// TODO: update data in groups this contact is member of
} }
} }
@ -717,16 +723,16 @@ class rcube_kolab_contacts extends rcube_addressbook
); );
$saved = $this->storagefolder->save($list, 'distribution-list'); $saved = $this->storagefolder->save($list, 'distribution-list');
if (PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error saving distribution-list object to Kolab server:" . $saved->getMessage()), 'message' => "Error saving distribution-list object to Kolab server"),
true, false); true, false);
return false; return false;
} }
else { else {
$id = md5($list['uid']); $id = $this->_uid2id($list['uid']);
$this->distlists[$id] = $list; $this->distlists[$id] = $list;
$result = array('id' => $id, 'name' => $name); $result = array('id' => $id, 'name' => $name);
} }
@ -748,11 +754,11 @@ class rcube_kolab_contacts extends rcube_addressbook
if ($list = $this->distlists[$gid]) if ($list = $this->distlists[$gid])
$deleted = $this->storagefolder->delete($list['uid']); $deleted = $this->storagefolder->delete($list['uid']);
if (PEAR::isError($deleted)) { if (!$deleted) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error deleting distribution-list object from the Kolab server:" . $deleted->getMessage()), 'message' => "Error deleting distribution-list object from the Kolab server"),
true, false); true, false);
} }
else else
@ -778,11 +784,11 @@ class rcube_kolab_contacts extends rcube_addressbook
$saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']); $saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']);
} }
if (PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error saving distribution-list object to Kolab server:" . $saved->getMessage()), 'message' => "Error saving distribution-list object to Kolab server"),
true, false); true, false);
return false; return false;
} }
@ -806,7 +812,6 @@ class rcube_kolab_contacts extends rcube_addressbook
$exists = array(); $exists = array();
$this->_fetch_groups(); $this->_fetch_groups();
$this->_fetch_contacts();
$list = $this->distlists[$gid]; $list = $this->distlists[$gid];
foreach ((array)$list['member'] as $i => $member) foreach ((array)$list['member'] as $i => $member)
@ -817,13 +822,14 @@ class rcube_kolab_contacts extends rcube_addressbook
foreach ($ids as $contact_id) { foreach ($ids as $contact_id) {
if ($uid = $this->_id2uid($contact_id)) { if ($uid = $this->_id2uid($contact_id)) {
$contact = $this->contacts[$contact_id]; $contact = $this->storagefolder->get_object($uid);
foreach ($this->get_col_values('email', $contact, true) as $email) { foreach ($this->get_col_values('email', $contact, true) as $email) {
$list['member'][] = array( $list['member'][] = array(
'uid' => $uid, 'uid' => $uid,
'display-name' => $contact['name'], 'mailto' => $email,
'smtp-address' => $email, 'name' => $contact['name'],
); );
break;
} }
$this->groupmembers[$contact_id][] = $gid; $this->groupmembers[$contact_id][] = $gid;
$added++; $added++;
@ -833,11 +839,11 @@ class rcube_kolab_contacts extends rcube_addressbook
if ($added) if ($added)
$saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']); $saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']);
if (PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error saving distribution-list to Kolab server:" . $saved->getMessage()), 'message' => "Error saving distribution-list to Kolab server"),
true, false); true, false);
$added = false; $added = false;
} }
@ -874,11 +880,11 @@ class rcube_kolab_contacts extends rcube_addressbook
$list['member'] = $new_member; $list['member'] = $new_member;
$saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']); $saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']);
if (PEAR::isError($saved)) { if (!$saved) {
raise_error(array( raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Error saving distribution-list object to Kolab server:" . $saved->getMessage()), 'message' => "Error saving distribution-list object to Kolab server"),
true, false); true, false);
} }
else { else {
@ -1048,7 +1054,7 @@ class rcube_kolab_contacts extends rcube_addressbook
// photo is stored as separate attachment // photo is stored as separate attachment
if ($record['photo'] && strlen($record['photo']) < 255 && ($att = $record['_attachments'][$record['photo']])) { if ($record['photo'] && strlen($record['photo']) < 255 && ($att = $record['_attachments'][$record['photo']])) {
// only fetch photo content if requested // only fetch photo content if requested
if ($rcmail = rcmail::get_instance()->action == 'photo') if (rcmail::get_instance()->action == 'photo')
$record['photo'] = $att['content'] ? $att['content'] : $this->storagefolder->get_attachment($record['uid'], $att['key']); $record['photo'] = $att['content'] ? $att['content'] : $this->storagefolder->get_attachment($record['uid'], $att['key']);
} }
@ -1064,13 +1070,6 @@ class rcube_kolab_contacts extends rcube_addressbook
if (!$contact['uid'] && $contact['ID']) if (!$contact['uid'] && $contact['ID'])
$contact['uid'] = $this->_id2uid($contact['ID']); $contact['uid'] = $this->_id2uid($contact['ID']);
/*
// format dates
if ($object['birthday'] && ($date = @strtotime($object['birthday'])))
$object['birthday'] = date('Y-m-d', $date);
if ($object['anniversary'] && ($date = @strtotime($object['anniversary'])))
$object['anniversary'] = date('Y-m-d', $date);
*/
$contact['email'] = array_filter($this->get_col_values('email', $contact, true)); $contact['email'] = array_filter($this->get_col_values('email', $contact, true));
$contact['website'] = array_filter($this->get_col_values('website', $contact, true)); $contact['website'] = array_filter($this->get_col_values('website', $contact, true));
$contact['im'] = array_filter($this->get_col_values('im', $contact, true)); $contact['im'] = array_filter($this->get_col_values('im', $contact, true));