Roundcube Community Forum

 

[help] Develop my own addressbook

Started by rodrigocarneiro, August 06, 2013, 08:48:08 AM

Previous topic - Next topic

rodrigocarneiro

Dear All,

I'm new to this forum, so hopefully I posted the question in the right place.

I created a new addressbook plugin from example_addressbook located inside the plugins folder in roundcube. I deduced a lot from other implementations and read something from the documentation, but I'm having a little problem when it relates to search within my addresbook.  Strangely the autocomplete on the screen to write the e-mail works fine.

I wonder if the masters have some literature to help me implement the plugin.

Thanks for any help!

SKaero

Haven't played with the address book functions to much so I may not be of to much help, but I'll try. What do you have set for address_book_type, and the autocomplete_addressbooks options in the main.inc.php?

rodrigocarneiro

Hello, thanks for the reply.

$rcmail_config['address_book_type'] = 'sql';
$rcmail_config['autocomplete_addressbooks'] = array('sql', 'my');

I already tried to set boot type to be equals to my autocomplete setting, but with the same result.

Note:
When i do a search in adressbook, it returns everytime the same values to my custom one, but bring correctly records of the buildin one.

SKaero

I'm not sure I understand what your saying its doing, did you code a custom search handler?

rodrigocarneiro

Hello again,

I'm developing a plugin that read some contacts from a custom table and presents them to users. A kind of global list. For this I started to develop on top of example_addressbook and added my code to make the magic happen. My problem is that I can not make a search in the contacts list works perfectly. Here's the code I modified from example_addressbook plugin, I hope I have been clearer now:

example_addressbook:
http://codepad.org/6mK7suxN

example_addressbook_backend:
http://codepad.org/d2rJi41o

SKaero

Looking at your code in the example_addressbook_backend file in the search function you have a custom chunk of sql in the $where variable which you pass to the list_records function but it never gets added to the actual sql query.

rodrigocarneiro

Sorry about that,

I modified the code to be able to show you, actually the where clause is added there, as I said earlier the autocoplete works on the page to write emails. So this is not my problem.

Thank you for your attention.

SKaero

Ok, I'm not sure what you mean by the following:

When i do a search in adressbook, it returns everytime the same values to my custom one, but bring correctly records of the buildin one.

Is it returning any records from your custom address book handler?

rodrigocarneiro

What i means is:

This piece of code:

$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);
}


Do the same of:

$rcmail_config['autocomplete_addressbooks'] = array('sql', 'my');


To bring result from the both addressbooks, i presume.

But, my custom addressbook, dont bring them correctly, although the sql bring. i think i forgot to implement some functioin on the class. This is why i first ask about a literature to help me to implement the plugin.

SKaero

Does the search work if you change the address_book_type in the main.inc.php to your custom address book handler?

rodrigocarneiro

No, i tried to put my addressbook name and a empty string:


// This indicates which type of address book to use. Possible choises:
// 'sql' (default), 'ldap' and ''.
// If set to 'ldap' then it will look at using the first writable LDAP
// address book as the primary address book and it will not display the
// SQL address book in the 'Address Book' view.
// If set to '' then no address book will be displayed or only the
// addressbook which is created by a plugin (like CardDAV).
$rcmail_config['address_book_type'] = '';

SKaero

Can you post your full code so I can test it myself?

rodrigocarneiro

This is all i have modified on the code. What you need is to active the plugin in config and create the table on your database with the fields:

id [int], login [varchar], nome [varchar], email [varchar], ramal [varchar], vinculo [varchar], lotacao [varchar], lista [varchar], lista_visivel [bool]

SKaero

You said that you had modified the code that you had posted before, since the search is obviously broken in that one.

rodrigocarneiro

Indeed, just change the code to accept the where clause, I will make the changes and repost for you.