I had a request to create an Intranet PhoneBook searchable via a browser...
Having Exchange 5.5 with the LDAP services running, I found some example code
on how to use the LDAP functions at php.net/ldap and started hacking...
took about 20min...
I didn't include the Search Form....
function phoneBook($person)
{
if(!$this-> person) {
print "You must search for something!!...";
print "< br> < A HREF=phonebook.php> Back to Form< /A> ";
die();
} else {
// Setup connection to server
// I'm using this function to connect to Exchange 5.5
$ds=ldap_connect(""); // must be a valid LDAP server!
$dn = "o=PCCS-Linux, c=US";
// We want to search for a person
// this can be any portion of the name first or last
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array( "ou", "sn", "givenname", "mail","telephonenumber");
// Execute the search
$sr=ldap_search($ds, $dn, $filter, $justthese);
// Put the results into an array called info
$info = ldap_get_entries($ds, $sr);
// Format the results that are returned
// $info[$1]["valuetoreturn"][0]
print "< center> ";
print "< H2> < font color=navy> ".$info["count"]."< /font> entries
returned< /H2> ";
print "< table border=0 cellpadding=2 cellspacing=1> ";
print "< tr> < th> < /th> < th align=left> Name< /th> <
th align=left> E-Mail< /th> < th align=left> Phone< /th> < /tr> ";
for($i=0; $i < count($info); $i++) {
if($info[$i]["givenname"][0] == "") {
//
} else {
print "< tr bgcolor=#FFFFFF> < td> ";
print "< a HREF=mailto:".$info[$i]["mail"][0]."> < img
src=".SITE_IMAGES."/sendemail.gif border=0> < /a> < /td> < td> ";
print $info[$i]["givenname"][0]." ".$info[$i]["sn"][0];
print "< /td> < td> ";
print $info[$i]["mail"][0];
print "< /td> < td> ";
print $info[$i]["telephonenumber"][0];
print "< /td> < /tr> ";
}
}
}
print "< /table> ";
print "< P> ";
print "< /center> ";
} // End phoneBook
>> Comments/FeedBack
|