\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "\n\n"; return 0; } function my_fetch_search_input() { if (isset($_POST['action']) && $_POST['action'] == 'submitted') { my_form_print(); if ($_POST['search'] != "") { $ldap_query = "cn=*" . strtolower(htmlspecialchars($_POST['search'])) . "*"; } else { $ldap_query = "cn=*"; } } else { my_form_print(); $ldap_query = "cn=*"; } return $ldap_query; } function my_fetch_detail_of() { if (isset($_GET['detail_of'])) { return $detail_of = $_GET['detail_of']; } return; } function my_ldap($ldap_query) { global $LDAP_NAME, $LDAP_SERVER, $LDAP_ROOT_DN, $LDAP_SORT_BY; // Open Connection $connect_id = ldap_connect($LDAP_SERVER); if($connect_id) { // Authenticate ldap_bind($connect_id); // Search $search_id = ldap_search($connect_id, $LDAP_ROOT_DN, $ldap_query); if (!($search_id)) { die("

Unable to search LDAP server

"); } // Sort ldap_sort($connect_id, $search_id, $LDAP_SORT_BY); // Assign Result Set to an Array $result_array = ldap_get_entries($connect_id, $search_id); // Close Connection ldap_close($connect_id); } else { die("

Could not connect to LDAP server: $LDAP_SERVER

"); } return $result_array; } function my_process_results($result_array) { if($result_array) { for($i=0; $i"; print_r($format_array); echo ""; //DEBUG } else { echo "

Result set empty.

"; } return $format_array; } function my_make_result_list($format_array) { for($i=0; $i$LgivenName $Lsn\n"; } else { $result_list .= " $Lsn $LgivenName\n"; } // E-Mail if($Lmail && $Lmail2) { $result_list .= " $Lmail
$Lmail2\n"; } elseif($Lmail) { $result_list .= " $Lmail\n"; } else { $result_list .= " \n"; } // str_replace because we need to replace spaces to non-breaking-spaces in phone numbers // Mobile phone if($Lmobile && $Lmobile2) { $result_list .= " " . str_replace(" ", " ", $Lmobile) . "
" . str_replace(" ", " ", $Lmobile2) . "\n"; } else { $result_list .= " " . str_replace(" ", " ", $Lmobile) . "\n"; } // Phone (home) $result_list .= " " . str_replace(" ", " ", $LhomePhone) . "\n"; //// Phone (work) //$result_list .= " " . str_replace(" ", " ", $LtelephoneNumber) . "\n"; // End row $result_list .= " \n"; } } return $result_list; } function my_make_result_detail($format_array, $detail_of) { for($i=0; $i$Lmail
$Lmail2\n \n"; } elseif($Lmail) { $result_list .= " \n E-Mail\n $Lmail\n \n"; } else { $result_list .= " \n E-Mail\n \n \n"; } // Mobile phone if($Lmobile && $Lmobile2) { $result_list .= " \n Mobile phone\n $Lmobile
$Lmobile2\n \n"; } else { $result_list .= " \n Mobile phone\n $Lmobile\n \n"; } // Phone (home) $result_list .= " \n Phone (home)\n $LhomePhone\n \n"; // Phone (work) $result_list .= " \n Phone (work)\n $LtelephoneNumber\n \n"; // Fax $result_list .= " \n Fax\n $LfacsimileTelephoneNumber\n \n"; // Street $result_list .= " \n Street\n $Lstreet\n \n"; // City $result_list .= " \n City\n $Ll\n \n"; // State $result_list .= " \n State\n $Lst\n \n"; // Postal code $result_list .= " \n Postal code\n $LpostalCode\n \n"; // Company / Organisation $result_list .= " \n Company / Organisation\n $Lo\n \n"; // Preferred language $result_list .= " \n Preferred language\n $LpreferredLanguage\n \n"; return $result_list; } function my_print_list($result_list) { // Print table header echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; // Print results echo my_postprocess($result_list); // Print table footer echo " \n
NameE-MailMobile phonePhone (home)Phone (work)
\n\n"; return 0; } function my_print_detail($result_detail_list) { // Print table header echo "\n"; echo " \n"; echo " \n"; // Print results echo my_postprocess($result_detail_list); // Print table footer echo " \n
Contact details
\n\n"; return 0; } function my_postprocess($html_input) { // Workaround for empty-cells bug in Internet Explorer $ie_compatible = str_replace("", " ", $html_input); return $ie_compatible; } // "Main" $time_start = microtime(true); // Print html header echo "\n\n"; echo "\n\n"; echo "\n"; echo " \n"; echo " " . $OWNER . "'s address book\n"; echo " \n"; echo " \n"; echo "\n\n"; echo "\n\n"; echo "

Address book

\n\n"; $detail_of = my_fetch_detail_of(); $ldap_query = my_fetch_search_input(); $result_array = my_ldap($ldap_query); $format_array = my_process_results($result_array); if($detail_of) { // Detail requested, print detail $result_detail_list = my_make_result_detail($format_array, $detail_of); my_print_detail($result_detail_list); } elseif(!$format_array) { // Must be a search with no results... echo "

No contact found. Search was: \"$ldap_query\".

\n"; echo "

Listing all instead.

\n"; $ldap_query = "cn=*"; $result_array = my_ldap($ldap_query); $format_array = my_process_results($result_array); $result_list = my_make_result_list($format_array); my_print_list($result_list); } else { // Results found, print them $result_list = my_make_result_list($format_array); my_print_list($result_list); } // Print html footer $script_time = microtime(true) - $time_start; echo "

\n
\n " . sprintf("%4.4f", $script_time) . " seconds\n

\n\n"; echo "\n\n"; ?>