From c1bccb67c48ffb82e3e836a8f10e8c0dfb7430bc Mon Sep 17 00:00:00 2001 From: thomasb Date: Sun, 21 Nov 2010 16:47:51 +0000 Subject: Map more fields of the Kolab contact format (still read-only) git-svn-id: https://svn.roundcube.net/trunk@4244 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/kolab_addressbook/kolab_addressbook.php | 20 ++++++ plugins/kolab_addressbook/lib/rcube_kolab.php | 14 ++++ plugins/kolab_addressbook/rcube_kolab_contacts.php | 75 +++++++++++++++++++++- 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php index 27f30cb12..4c5a84e5f 100644 --- a/plugins/kolab_addressbook/kolab_addressbook.php +++ b/plugins/kolab_addressbook/kolab_addressbook.php @@ -29,6 +29,7 @@ class kolab_addressbook extends rcube_plugin $this->add_hook('addressbooks_list', array($this, 'address_sources')); $this->add_hook('addressbook_get', array($this, 'get_address_book')); + $this->add_hook('contact_form', array($this, 'contact_form')); // extend include path to load bundled Horde classes $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path'); @@ -112,5 +113,24 @@ class kolab_addressbook extends rcube_plugin return $this->sources; } + + + /** + * Plugin hook called before rendering the contact form or detail view + */ + public function contact_form($p) + { + // extend the list of contact fields to be displayed in the 'info' section + if (is_array($p['form']['info'])) { + $p['form']['info']['content']['initials'] = array('size' => 6); + $p['form']['info']['content']['anniversary'] = array('size' => 12, 'render_func' => 'rcmail_format_date_col'); + + // TODO: add more Kolab-specific fields + + // TODO: re-order fields + } + + return $p; + } } diff --git a/plugins/kolab_addressbook/lib/rcube_kolab.php b/plugins/kolab_addressbook/lib/rcube_kolab.php index 985691a51..94511e55d 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab.php @@ -1,6 +1,7 @@ array('limit' => 1), + 'firstname' => array('limit' => 1), + 'surname' => array('limit' => 1), + 'middlename' => array('limit' => 1), + 'prefix' => array('limit' => 1), + 'suffix' => array('limit' => 1), + 'nickname' => array('limit' => 1), + 'jobtitle' => array('limit' => 1), + 'organization' => array('limit' => 1), + 'department' => array('limit' => 1), + 'gender' => array('limit' => 1), + 'birthday' => array('limit' => 1), + 'email' => array(), + 'phone' => array(), + 'im' => array('limit' => 1), + 'website' => array('limit' => 1), + 'address' => array(), + 'notes' => array(), + // define additional coltypes + 'initials' => array('type' => 'text', 'size' => 6, 'limit' => 1), + 'anniversary' => array('type' => 'date', 'size' => 12, 'limit' => 1), + // TODO: define more Kolab-specific fields such as: office-location, profession, manager-name, assistant, spouse-name, children, language, latitude, longitude, pgp-publickey, free-busy-url + ); private $gid; private $imap; @@ -28,12 +52,19 @@ class rcube_kolab_contacts extends rcube_addressbook private $filter; private $result; private $imap_folder = 'INBOX/Contacts'; + private $gender_map = array(0 => 'male', 1 => 'female'); public function __construct($imap_folder = null) { if ($imap_folder) $this->imap_folder = $imap_folder; + + // extend coltypes configuration + $format = rcube_kolab::get_format('contact'); + $this->coltypes['phone']['subtypes'] = $format->_phone_types; + $this->coltypes['address']['subtypes'] = $format->_address_types; + $this->coltypes['anniversary']['label'] = rcube_label('anniversary'); // fetch objects from the given IMAP folder $this->contactstorage = rcube_kolab::get_storage($this->imap_folder); @@ -293,13 +324,53 @@ class rcube_kolab_contacts extends rcube_addressbook */ private function _to_rcube_contact($record) { - return array( + $out = array( 'ID' => md5($record['uid']), 'name' => $record['full-name'], 'firstname' => $record['given-name'], + 'middlename' => $record['middle-names'], 'surname' => $record['last-name'], - 'email' => $record['emails'], + 'prefix' => $record['prefix'], + 'suffix' => $record['suffix'], + 'nickname' => $record['nick-name'], + 'organization' => $record['organization'], + 'department' => $record['department'], + 'jobtitle' => $record['job-title'], + 'initials' => $record['initials'], + 'birthday' => $record['birthday'], + 'anniversary' => $record['anniversary'], + 'email' => array(), + 'phone' => array(), + 'notes' => $record['body'], ); + + if (isset($record['gender'])) + $out['gender'] = $this->gender_map[$record['gender']]; + + foreach ((array)$record['email'] as $i => $email) + $out['email'][] = $email['smtp-address']; + + foreach ((array)$record['phone'] as $i => $phone) + $out['phone:'.$phone['type']][] = $phone['number']; + + if ($record['im-address']) + $out['im:aim'] = array($record['im-address']); + if ($record['web-page']) + $out['website:work'] = array($record['web-page']); + + if ($record['addr-home-type']) { + $key = 'address:' . $record['addr-home-type']; + $out[$key][] = array( + 'street' => $record['addr-home-street'], + 'locality' => $record['addr-home-locality'], + 'zipcode' => $record['addr-home-postal-code'], + 'region' => $record['addr-home-region'], + 'country' => $record['addr-home-country'], + ); + } + + // remove empty fields + return array_filter($out); } private function _from_rcube_contact($contact) -- cgit v1.2.3