troubleshooting Question

Ldap employee directory web page

Avatar of Christopher Casey
Christopher CaseyFlag for United States of America asked on
DatabasesWeb DevelopmentActive DirectoryHTMLPHP
4 Comments1 Solution786 ViewsLast Modified:
Hello i have been working on a employee directory web page i got a lot of help from here in the past and i hope i can get some more on this.

I put my all my code that i have so everyone can take a look at it. What it does is connect to my ldap and look thought it for people you searched for.

And then displays them. i have added a image of how it displays it works great pulls the info out of ldap. But i don't like how it displays on the page.

We have over 200 employee so if you did a search for all employee it list them all on the page.
What i want it to do is do a side by side.

So one table of the employee info on the left of the web page and other one right next to it on the right. Then a <br> and start the next two. This will save a lot of space so anyone looking at all the employee  doesn't have to scroll so much.

Also the button find next to the Manager is to do a find on that employee manager so you can quickly find that managers info.  

$myUsername = usernam;

$myPassword = password;

// specify the LDAP server to connect to
$conn = ldap_connect("") or die("Could not connect to server");

ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);

$bind2 = ldap_bind( $conn, $myUsername, $myPassword );

    if ($bind2) {
       // echo "LDAP bind successful...<br>" ;
    } else {
        echo "LDAP bind failed...";

$base_dn = 'OU=User-Dept,DC=ceo,DC=work,DC=tv';




$result = ldap_search($conn, $base_dn, $filter) or die ("ldap search error");

$info = ldap_get_entries($conn, $result);

//Puts the search in abc order from company then cm can be changed easly.

$attribs = array('company','cn','givenname');

for ($i=1; $i<$info["count"]; $i++)
$index = $info[$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;
$is_greater = false;
} while ($j>0 && $is_greater);

$info[$j] = $index;

echo "<form action='conect.php' method='POST'>";
echo "<select name='name'>";
echo "	<option value='cn' selected>First Name:</option>";
echo "	<option value='mail'>Email:</option>";
echo "	<option value='title'>Title:</option>";
echo "	<option value='descriptio'>Code:</option>";

echo "</select>";

echo " Look For <input type='text'  name='Key-name' length='30'><br><br>";

echo "<select name='department'>";
echo "	<option value='Information Technology'>IT:</option>";
echo "	<option value='' selected>All:</option>";
echo "	<option value='Development'>Development:</option>";
echo "	<option value='Fiscal Services'>Fiscal Services:</option>";
echo "	<option value='department'>Citrix:</option>";
echo "	<option value='Human Resources'>HR:</option>";
echo "	<option value='department'>Marketing:</option>";
echo "	<option value='department'>Recepionists:</option>";
echo "	<option value='department'>Admissions:</option>";
echo "	<option value='Clinical Support'>Clinical Support:</option>";
echo "	<option value='department'>Education:</option>";
echo "	<option value='department'>Home Care:</option>";
echo "	<option value='department'>Home:</option>";
echo "	<option value='department'>Long Care:</option>";
echo "	<option value='department'>Medicial Doctors:</option>";
echo "	<option value='Patient Care Services'>Palliative Care:</option>";
echo "	<option value='department'>Pediatrics:</option>";

echo "</select> ";

echo "<input type='submit' name='submit' value = 'Search'>";

echo "</form>";

// iterate over array and print data for each entry
echo "<html>";
echo "<head>";

echo "<style type=text/css>";
echo "<!--.text {color: #000}-->";
echo "</style>";
echo "<body bgcolor=#6d7f3f>";

for ($i=0; $i<$info["count"]; $i++)

echo "<form action=conect.php method=POST >";
echo "<input type=text style='display:none' size='1' height='1'  name=name   value= cn>";
echo "<bR>";
echo "<textarea type=text size='1' height='1' style='display:none' name=Key-name >". substr($info[$i]["manager"][0],3,stripos($info[$i]["manager"][0],",OU")-3)  ."</textarea> ";
echo "<bR>";
echo "<input type=text size='1' height='1'  style='display:none' name=department value=> ";

//echo "<input type=text size='1' height='1'  name=description value=". $info[$i]["description"][0] ."> ";

echo "<bR>";
echo "<table width=600  bgcolor=#cadba1 bordercolor=#000000 style=border-style:solid;color:#602860 align='center'>";

echo "<td align=center width=300>";

					//echo '<pre>' . print_r($info[$i]['memberof'], true) . '</pre>';
        			//echo "State is: ". $info[$i]["o"][0] ."<br>";
        			//echo "samaccountname: ". $info[$i]["samaccountname"][0] ."<br>";
        			//echo "mailNickname is: ". $info[$i]["mailnickname"][0] ."<br>";

echo "<strong>Manager is</strong>: <span class=text> ". substr($info[$i]["manager"][0],3,stripos($info[$i]["manager"][0],",OU")-3)  ."</a> <input type=submit name=submit value = Find></span><br>";


       			//echo "ou is: ". $info[$i]["ou"][0] ."<br>";

echo "<strong>Title is</strong>:<span class=text> ". $info[$i]["title"][0] ."</span><br>";
echo "<a href=http://laptop-vm/images/". $info[$i]["samaccountname"][0] .".jpg ><img hight=100px width=100px boards=0 src=http://laptop-vm/images/". $info[$i]["samaccountname"][0] .".jpg ></a>"."<br>";
echo "<span class=text>". $info[$i]["cn"][0] . "</span><strong> ". $info[$i]["description"][0] ."</strong><br>";

					//echo "Hair: ".  substr($info[$i]["whencreated"][0],0,stripos($info[$i]["whencreated"][0],",OU")-13) ."<br>";


echo "<td>";

					//echo "city is: ". $info[$i]["l"][0] ."<br>";

echo "<strong>Department is</strong>: <span class=text>". $info[$i]["department"][0] ."</span><br/>";
echo "<strong>Company is</strong>: <span class=text>". $info[$i]["company"][0] ."</span><br>";

    				//echo "Last Name is: ". $info[$i]["sn"][0] ."<br>";
					//echo "Last Name is: ". $info[$i]["description"][0] ."<br>";
   					//echo "Given Name is: ". $info[$i]["givenname"][0] ."<br>";
   					//echo "streetAddress is: ". $info[$i]["streetaddress"][0] ."<br>";
   					//echo "Zip is: ". $info[$i]["postalcode"][0] ."<br>";
   					//echo "st is: ". $info[$i]["st"][0] ."<br>";

echo "<strong>Extension</strong>: <span class=text>" . $info[$i]["telephonenumber"][0] ."</span><br>";
echo "<strong>Mobile number is</strong>: <span class=text>". $info[$i]["mobile"][0] ."</span><br>";
echo "<strong>Office Location</strong>:<span class=text> ". $info[$i]["physicaldeliveryofficename"][0] ."</span><br>";

					//echo "<strong>Member </strong>: <span class=text>". $info[$i]["memberof"] ."</span><br>";
					//echo "<strong>Members of</strong>: <span class=text>". substr($info[$i]["memberof"][0],3,stripos($info[$i]["memberof"][0],",OU")-3)  ."</span><br>";

echo "<strong>Email address is</strong>: <A href=mailto:".$info[$i]["mail"][0] .">".$info[$i]["mail"][0] ."</a>";

echo "</td>";
echo "</table>";
echo "</form>";


echo "</Body>";
echo "</html>";
echo "</head>";

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


Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros