--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fhiiqm/inc/ma_ldap_ac.inc.php Thu Sep 12 09:04:56 2013 +0200
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @author Bettina Schwarzer, Fritz-Haber-Institut
+ * @copyright 08/2013
+ *
+ * Autocomplete neue Mitarbeiter aus LDAP
+ */
+
+// header('Content-type: text/html; charset="iso-8859-1',true); //wg. jquery ui autocomplete
+ header('Content-type: text/html; charset="utf-8',true); //wg. jquery ui autocomplete und LDAP(utf-8 codiert)
+ error_reporting(E_ALL ^ E_NOTICE);
+
+ $q = strtolower($_GET["term"]); // wird in jquery in 'term' uebergeben, term UTF-8 codiert
+
+ $ldaphost = "ldap.rz-berlin.mpg.de"; // Ihr ldap servers
+ $ldapport = 389; // Die Portnummer ihres ldap servers
+ // Verbindung zu LDAP
+ $ldapconn = ldap_connect( $ldaphost, $ldapport )
+ or die( "Keine Verbindung zu {$ldaphost} möglich" );
+
+ if ($ldapconn)
+ {
+ $ldaprdn = "ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
+ ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
+ $ldapbind = @ldap_bind($ldapconn);
+ // $ldapbind = @ldap_bind($ldapconn);
+
+ $base="ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
+ if ($ldapbind)
+ {
+ $filter = "(sn=$q*)";
+ $afields = array ("uid","cn","givenName","sn","title","mail");
+ $afieldsort = array ("uid","givenName","sn");
+ // search active directory
+ if (!($search=@ldap_search($ldapconn,$base,$filter,$afields))) {
+ die("Unable to search ldap server");
+ }
+ foreach ($afieldsort as $esort)
+ {
+ if (in_array($esort, $afields)) { // making sure we don't accidentally try to sort against an inexisting field
+ ldap_sort($ldapconn, $search, $esort);
+ }
+ }
+ // Find out what we can see
+ $number_returned = ldap_count_entries($ldapconn,$search);
+ $info = ldap_get_entries($ldapconn, $search);
+ if ($number_returned)
+ {
+ for ($i=0; $i<$info["count"]; $i++)
+ {
+ $clist[] = "{\"label\": \"" . $info[$i]["sn"][0] . ", " . $info[$i]["givenname"][0]. "; " . $info[$i]["mail"][0]. "; " . $info[$i]["uid"][0].
+ "\",\"value\": \"" . $info[$i]["sn"][0].
+ "\",\"id\": \"" . $info[$i]["uid"][0]. "\",\"id2\": \"" . $info[$i]["givenname"][0]. "\",\"id3\": \"" . $info[$i]["mail"][0] . "\"}";
+ }
+ echo "[" . implode(", ", $clist) . "]"; // Format, das jquery source erwartet
+ }
+
+ }
+ }
+
+?>
\ No newline at end of file