Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
  #1 (permalink)  
Old 05-31-2006, 07:44 AM
phxmark phxmark is offline
Junior Member
 
Join Date: May 2006
Posts: 9
phxmark is on a distinguished road
Default PHP LDAP Address/Phone Book

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
Reply With Quote
  #2 (permalink)  
Old 05-31-2006, 07:52 AM
jholder's Avatar
jholder jholder is offline
Zimbra Employee
 
Join Date: Oct 2005
Location: San Mateo, CA
ZCS Version: 5.0.5 RHEL4 64-bit GA
Posts: 5,409
jholder is on a distinguished road
Send a message via Yahoo to jholder
Default

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
Reply With Quote
  #3 (permalink)  
Old 06-01-2006, 11:34 AM
phxmark phxmark is offline
Junior Member
 
Join Date: May 2006
Posts: 9
phxmark is on a distinguished road
Default PHP LDAP Address/Phonebook

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:

<html>
<head>
<title>Search</title>
</head>
<body>
<form action="search.php" method="POST">
First name
<br>
<input type="text" name="gn" length="30" value="*"><br>
Last name
<br>
<input type="text" name="sn" length="30" value="*"><br>
Email address
<br>
<input type="text" name="email" length="30" value="*"><br>
Site
<br>
<input type="text" name="comp" length="30" value="*"><br>
<br>
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>

search.php:

<html>
<head>
</head>
<body>

<table width="500" cellpadding="5" cellspacing="5" border="1">

<?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);

?>

<tr>
<td>Last Name</td>
<td>First Name</td>
<td>E-Mail Address</td>
<td>Site</td>
<td>Room</td>
<td>Phone</td>
<tf colspan=6>&nbsp;</td>
</tr>

<?php

// Sort Data by Company, Last Name and First Name
$attribs = array('company','sn','givenname');

for ($i=0; $i<$info["count"]; $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 "<ul>";
for ($i=0; $i<$info["count"]; $i++)
{
echo "<tr>";
echo "<td>".$info[$i]["sn"][0]."</td>";
echo "<td>".$info[$i]["givenname"][0]."</td>";
echo "<td>".$info[$i]["mail"][0]."</td>";
echo "<td>".$info[$i]["company"][0]."</td>";
echo "<td>".$info[$i]["physicaldeliveryofficename"][0]."</td>";
echo "<td>".$info[$i]["telephonenumber"][0]."</td>";
echo "</tr>";
}

// print number of entries found
echo "Number of entries found: " . ldap_count_entries($conn, $result) . "<p>";

// all done? clean up
ldap_close($conn);

?>

</table>
</body>
</html>
Reply With Quote
  #4 (permalink)  
Old 06-16-2006, 12:16 AM
geodrive geodrive is offline
Junior Member
 
Join Date: May 2006
Posts: 1
geodrive is on a distinguished road
Default What about the phpldapadmin project?

http://phpldapadmin.sourceforge.net/download.php

Probably not nescessary to reinvent the wheel, or wont this work toward zimbra?
Reply With Quote
  #5 (permalink)  
Old 06-16-2006, 07:01 AM
phxmark phxmark is offline
Junior Member
 
Join Date: May 2006
Posts: 9
phxmark is on a distinguished road
Default

This does work on Zimbra. I used it to help me with the script I am working on.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zimbra Install Problem - getDirectContext bsimzer Installation 27 07-19-2007 10:12 AM
3 testing: LDAP: 389 Failed when restore zimbra victorLeong Administrators 15 05-24-2007 06:45 AM
Mac OSX install: Java errors & LDAP CA error jefbear Installation 9 12-16-2006 02:39 PM
Can't get ride of Initializing ldap...FAILED (256) error jahaj Installation 4 11-15-2006 11:16 AM


freshmeat.net sourceforge.net The best Java IDE



 

Search Engine Optimization by vBSEO 3.0.0