Roundcube Community Forum
Release Support => Older Versions => Release Candidate 1 => Topic started by: em on May 30, 2007, 11:12:16 AM
-
Hello,
I would like that when user type in address field a ldap request was made(instead of personal addressbook), is it possible?
thanks for your answers
-
Yes, it is. I searched because I was in this same boat, and came across this. This has worked very well for me and beta2
http://trac.roundcube.net/trac.cgi/attachment/ticket/1483899/compose_391.inc.diff
-
thanks, this is not working with RC1 because ldap functions was changed, but I will try to adapt... If I found I will post the code here.
-
this is working for me on RC1.
changes have been made at the end of program/steps/mail/compose.inc
changes are between "//Add for LDAP search" and "//End of LDAP search"
/****** get contacts for this user and add them to client scripts ********/
require_once('include/rcube_contacts.inc');
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
$CONTACTS->set_pagesize(1000);
if ($result = $CONTACTS->list_records())
{
$a_contacts = array();
while ($sql_arr = $result->iterate())
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
//Add for LDAP search
foreach ($CONFIG['ldap_public'] as $ldapserv_config)
{
$ldapfields = array($ldapserv_config['mail_field'],$ldapserv_config['name_field']);
$cLdap = new rcube_ldap($ldapserv_config);
$cLdap->connect ();
$cLdap->bind($ldapserv_config['base_dn'],''); //second field is for password if required
$results = $cLdap->search ($ldapfields,
"mydomain", //field for search criteria, can't be empty,* is not a Wildcard character
true);
$cLdap->close ();
}
while ($ldap_arr = $results->next())
{
if ($ldap_arr['email'])
$a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
}
//End of LDAP search
$OUTPUT->set_env('contacts', $a_contacts);
}
parse_template('compose');
?>
-
Hi,
a cleaned up diff version of the above, modified slightly, with current (RC1) version of config parameters:
--- compose.inc.orig 2007-05-18 15:11:22.000000000 +0200
+++ compose.inc 2007-05-31 15:57:50.000000000 +0200
@@ -867,6 +867,7 @@ $OUTPUT->add_handlers(array(
/****** get contacts for this user and add them to client scripts ********/
require_once('include/rcube_contacts.inc');
+require_once('include/rcube_ldap.inc');
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
$CONTACTS->set_pagesize(1000);
@@ -877,7 +878,23 @@ if ($result = $CONTACTS->list_records())
while ($sql_arr = $result->iterate())
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
-
+
+ foreach ($CONFIG['ldap_public'] as $ldapserv_config)
+ {
+ $ldapfields = array($ldapserv_config['email_field'],$ldapserv_config['name_field']);
+ $cLdap = new rcube_ldap($ldapserv_config);
+ $cLdap->connect ();
+ $cLdap->bind($ldapserv_config['bind_dn'], $ldapserv_config['bind_pass']);
+ $results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
+ $cLdap->close ();
+ }
+
+ while ($ldap_arr = $results->next())
+ {
+ if ($ldap_arr['email'])
+ $a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
+ }
+
$OUTPUT->set_env('contacts', $a_contacts);
}
-
Thanks, this helps. Will try it out.
-
in the composer, I have only the 10 first address found in the ldap:( in adress book I can see all my ldap entries
anyone have an idea?
-
this is this variable that limits the list...
in "include/rcube_ldap.inc"
var $page_size = 10;
I change to 100 and I've got all the addresses but I don't know if there was other effect...
-
little improvement : sorting the list
add before this line
$results = $cLdap->search.......
this :
$cLdap->sort_col = 'mail';
change 'mail' by the ldap field you want ;)
-
i too try this...
but not work
-
What did you try? give me more informations, if I can help you....
-
I'm trying to implement this ldap-autofill too, but without success.
my code of compose.inc looks like this at the end.
/****** get contacts for this user and add them to client scripts ********/
require_once('include/rcube_contacts.inc');
require_once('include/rcube_ldap.inc');
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
$CONTACTS->set_pagesize(1000);
if ($result = $CONTACTS->list_records())
{
$a_contacts = array();
while ($sql_arr = $result->iterate())
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
//Add for LDAP search
foreach ($CONFIG['ldap_public'] as $ldapserv_config)
{
$ldapfields = array($ldapserv_config['email_field'],$ldapserv_config['name_field']);
$cLdap = new rcube_ldap($ldapserv_config);
$cLdap->connect ();
$cLdap->bind($ldapserv_config['bind_dn'], $ldapserv_config['bind_pass']);
$results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
$cLdap->close ();
}
while ($ldap_arr = $results->next())
{
if ($ldap_arr['email'])
$a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
}
//End of LDAP search
$OUTPUT->set_env('contacts', $a_contacts);
}
parse_template('compose');
the ldap-addressbook is working fine
but if I type in the to: filed some names no email appears except the one address of the normal addressbook.
any idea what's wrong?
btw: if I change to the ldap-addressbook RC shows "loading..." but nothing will be displayed, I have to use the search for seeing some addresses. is this normal? or could this be a similar problem?
thanks for any help
jay
-
sorry, no ideas... perhaps look in ldap logs
which version of RC do you use? I test this code on RC1, now I use on svn version of the 18 june
for me in ldap-addressbook nothing is displaying whereas I make a search
-
I found where it's not working!! on this line
$results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
I never get a result. If I replace "@" with some text e.g. the beginning of a name there is a result. I don't know why but the email field is not searchable (see also my post http://roundcubeforum.net/forum/index.php?topic=2084.0).
Do you have an idea why the email field is not searchable?
BTW:
1) In main.inc.php I configured the ldap email filed like this
'email_field' => 'mail', // this field represents the contact's e-mail
2) I installed the latest roundcube svn version (675)
Thanks
jay
-
I try with "@" and it is working for me... I use my domain name in search criteria because I only have users of my network into my ldap.
maybe "@" doesn't work for you because of your character encoding is your file compose.inc, your web server and your browser use the same character encoding? For me I install roundcube on a Debian with Apache and all character encoding is UTF8.
-
Hi all...I was working on this and noticed that the ldap query appears as soon as you compose. I had similar problems with the addresses since it would not search the email field. Then I figured since it has to grab the whole list and do a search later based on type in, then why even use search? It appears the the regular address book uses the list_records() instead of search()
So..
I replaced this in the compose.inc file mentioned above:
$results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
with:
$results = $cLdap->list_records();
bingo...it works great. hope this helps.