Has anyone successfully developed a PHP script to do an LDAP query to Zimbra OpenLDAP? We would like to use our Zimbra Server as the the main Address/Phonebook for our district. If you have, can you please send me the PHP scripts?
I found one online, but I am unable to make it work. I have very limited PHP knowledge.
Thanks,
Mark
PHP LDAP Address/Phone Book
PHP LDAP Address/Phone Book
Hi phxmark, and welcome.
We hope you enjoy the forums. As a note, please do not cross post in forums. As you can tell, we have a lot of posts. Because of this, we try to keep the level of confusion down when users search the forums.
I have removed your other post in the admin forum as it was a duplicate with this post.
Also, I have not heard anything thing on an LDAP Address book. I have an address book that runs on ASP that accesses an sql database, but it is in no way tied into zimbra.
Good luck!
john
We hope you enjoy the forums. As a note, please do not cross post in forums. As you can tell, we have a lot of posts. Because of this, we try to keep the level of confusion down when users search the forums.
I have removed your other post in the admin forum as it was a duplicate with this post.
Also, I have not heard anything thing on an LDAP Address book. I have an address book that runs on ASP that accesses an sql database, but it is in no way tied into zimbra.
Good luck!
john
PHP LDAP Address/Phone Book
OK. I have put together something that works. It is a work in progress, but it is close to doing what I want. It is a mish-mash of other PHP scripts found on the Internet.
The only issue I am having with it is that I cannot search by Site(Company) attribute. All else works.
This is programmed under PHP 5 and Apache Server.
pbform.html:
Search
First name
Last name
Email address
Site
search.php:
// specify the LDAP server to connect to
$conn = ldap_connect("yourzimbraserver.domain.com") or die("Could not connect to server");
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
// bind to the LDAP server specified above
$r = ldap_bind($conn) or die("Could not bind to server");
// create the search string
$query = "(&(givenname=" . $_POST['gn'] . ")(sn=" . $_POST['sn'] . ")(mail=" . $_POST['email'] . ")(company=" . $_POST['comp'] . "))";
echo $query;
// start searching
// specify both the start location and the search criteria
// in this case, start at the top and return all entries
$result = ldap_search($conn,"dc=domain,dc=com", $query) or die("Error in search query");
// get entry data as array
$info = ldap_get_entries($conn, $result);
?>
Last Name
First Name
E-Mail Address
Site
Room
Phone
// Sort Data by Company, Last Name and First Name
$attribs = array('company','sn','givenname');
for ($i=0; $i
{
$index = $info[$i];
$j=$i;
do {
//create comparison variables from attributes:
$a = $b = null;
foreach($attribs as $attrib){
$a .= $info[$j-1][$attrib][0];
$b .= $index[$attrib][0];
}
// do the comparison
if ($a > $b){
$is_greater = true;
$info[$j] = $info[$j-1];
$j = $j-1;
}else{
$is_greater = false;
}
} while ($j>0 && $is_greater);
$info[$j] = $index;
}
// iterate over array and print data for each entry
echo "";
for ($i=0; $i
{
echo "";
echo "".$info[$i]["sn"][0]."";
echo "".$info[$i]["givenname"][0]."";
echo "".$info[$i]["mail"][0]."";
echo "".$info[$i]["company"][0]."";
echo "".$info[$i]["physicaldeliveryofficename"][0]."";
echo "".$info[$i]["telephonenumber"][0]."";
echo "";
}
// print number of entries found
echo "Number of entries found: " . ldap_count_entries($conn, $result) . "";
// all done? clean up
ldap_close($conn);
?>
The only issue I am having with it is that I cannot search by Site(Company) attribute. All else works.
This is programmed under PHP 5 and Apache Server.
pbform.html:
Search
First name
Last name
Email address
Site
search.php:
// specify the LDAP server to connect to
$conn = ldap_connect("yourzimbraserver.domain.com") or die("Could not connect to server");
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
// bind to the LDAP server specified above
$r = ldap_bind($conn) or die("Could not bind to server");
// create the search string
$query = "(&(givenname=" . $_POST['gn'] . ")(sn=" . $_POST['sn'] . ")(mail=" . $_POST['email'] . ")(company=" . $_POST['comp'] . "))";
echo $query;
// start searching
// specify both the start location and the search criteria
// in this case, start at the top and return all entries
$result = ldap_search($conn,"dc=domain,dc=com", $query) or die("Error in search query");
// get entry data as array
$info = ldap_get_entries($conn, $result);
?>
Last Name
First Name
E-Mail Address
Site
Room
Phone
// Sort Data by Company, Last Name and First Name
$attribs = array('company','sn','givenname');
for ($i=0; $i
{
$index = $info[$i];
$j=$i;
do {
//create comparison variables from attributes:
$a = $b = null;
foreach($attribs as $attrib){
$a .= $info[$j-1][$attrib][0];
$b .= $index[$attrib][0];
}
// do the comparison
if ($a > $b){
$is_greater = true;
$info[$j] = $info[$j-1];
$j = $j-1;
}else{
$is_greater = false;
}
} while ($j>0 && $is_greater);
$info[$j] = $index;
}
// iterate over array and print data for each entry
echo "";
for ($i=0; $i
{
echo "";
echo "".$info[$i]["sn"][0]."";
echo "".$info[$i]["givenname"][0]."";
echo "".$info[$i]["mail"][0]."";
echo "".$info[$i]["company"][0]."";
echo "".$info[$i]["physicaldeliveryofficename"][0]."";
echo "".$info[$i]["telephonenumber"][0]."";
echo "";
}
// print number of entries found
echo "Number of entries found: " . ldap_count_entries($conn, $result) . "";
// all done? clean up
ldap_close($conn);
?>
PHP LDAP Address/Phone Book
Probably">http://phpldapadmin.sourceforge.net/download.php
Probably not nescessary to reinvent the wheel, or wont this work toward zimbra?
PHP LDAP Address/Phone Book
This does work on Zimbra. I used it to help me with the script I am working on.
PHP LDAP Address/Phone Book
this php script does work form me, but what i get are the mail accounts; i would get contacts but i dunno how can get them
i would use a ph script to feed aastra phones like you can find here
i would use a ph script to feed aastra phones like you can find here
PHP LDAP Address/Phone Book
What I'd like to see is a Zimlet that does the hover over lookups like the date zimlet- plugging that into the VOIP or other zimlets would be cool as well.