summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/kolab_addressbook/kolab_addressbook.php60
-rw-r--r--plugins/kolab_addressbook/rcube_kolab_contacts.php19
2 files changed, 41 insertions, 38 deletions
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php
index 9c8383e3d..da4f56ae7 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.php
+++ b/plugins/kolab_addressbook/kolab_addressbook.php
@@ -16,9 +16,10 @@ require_once(dirname(__FILE__) . '/rcube_kolab_contacts.php');
*/
class kolab_addressbook extends rcube_plugin
{
- private $abook_id = 'kolab';
- private $abook;
-
+ private $kolab;
+ private $folders;
+ private $sources;
+
/**
* Required startup method of a Roundcube plugin
*/
@@ -31,14 +32,6 @@ class kolab_addressbook extends rcube_plugin
$this->add_hook('addressbook_get', array($this, 'get_address_book'));
$this->add_hook('imap_init', array($this, 'imap_init'));
- // use this address book for autocompletion queries
- $config = rcmail::get_instance()->config;
- $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
- if (!in_array($this->abook_id, $sources)) {
- $sources[] = $this->abook_id;
- $config->set('autocomplete_addressbooks', $sources);
- }
-
// extend include path to load bundled Horde classes
$include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path');
set_include_path($include_path);
@@ -55,16 +48,37 @@ class kolab_addressbook extends rcube_plugin
*/
public function address_sources($p)
{
- // get single instance (for now)
- $abook = rcube_kolab_contacts::singleton();
-
- // maybe here we'll add more than one item
- $p['sources'][$this->abook_id] = array(
- 'id' => $this->abook_id,
- 'name' => 'Kolab',
- 'readonly' => $abook->readonly,
- 'groups' => $abook->groups,
- );
+ // setup Kolab backend
+ rcube_kolab::setup();
+
+ // get all folders that have "contact" type
+ $this->kolab = Kolab_List::singleton();
+ $this->folders = $this->kolab->getByType('contact');
+
+ if (PEAR::isError($this->folders)) {
+ raise_error(array(
+ 'code' => 600, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Failed to list contact folders from Kolab server:" . $this->folders->getMessage()),
+ true, false);
+ }
+ else {
+ foreach ($this->folders as $c_folder) {
+ // create instance of rcube_contacts
+ $abook_id = strtolower(asciiwords(strtr($c_folder->name, '/', '-')));
+ $abook = new rcube_kolab_contacts($c_folder->name);
+ $this->sources[$abook_id] = $abook;
+
+ // register this address source
+ $p['sources'][$abook_id] = array(
+ 'id' => $abook_id,
+ 'name' => $c_folder->name,
+ 'readonly' => $abook->readonly,
+ 'groups' => $abook->groups,
+ );
+ }
+ }
+
return $p;
}
@@ -74,8 +88,8 @@ class kolab_addressbook extends rcube_plugin
*/
public function get_address_book($p)
{
- if ($p['id'] === $this->abook_id) {
- $p['instance'] = rcube_kolab_contacts::singleton();
+ if ($this->sources[$p['id']]) {
+ $p['instance'] = $this->sources[$p['id']];
}
return $p;
diff --git a/plugins/kolab_addressbook/rcube_kolab_contacts.php b/plugins/kolab_addressbook/rcube_kolab_contacts.php
index 476202e33..f52512d27 100644
--- a/plugins/kolab_addressbook/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/rcube_kolab_contacts.php
@@ -28,25 +28,14 @@ class rcube_kolab_contacts extends rcube_addressbook
private $filter;
private $result;
private $imap_folder = 'INBOX/Contacts';
-
-
- /**
- * Singleton getter
- */
- public static function singleton()
- {
- if (!self::$instance)
- self::$instance = new rcube_kolab_contacts;
- return self::$instance;
- }
- public function __construct()
+ public function __construct($imap_folder = null)
{
- // setup Kolab backend
- rcube_kolab::setup();
+ if ($imap_folder)
+ $this->imap_folder = $imap_folder;
- // fetch objects from Cotnacts folder
+ // fetch objects from Contacts folder
$this->_kolab = Kolab_List::singleton();
$this->_folder = $this->_kolab->getFolder($this->imap_folder);
$this->_storage = $this->_folder->getData();