+ echo '</ajaxresponse>'.NL;
+}
+
+/**
+ * Do a simple lookup in any simple field
+ */
+function ajax_lookup($field,$search){
+ header('Content-Type: text/xml; charset=utf-8');
+ global $conf;
+ global $LDAP_CON;
+ global $FIELDS;
+
+ if(!$FIELDS[$field]) return;
+ $field = $FIELDS[$field];
+
+ $search = ldap_filterescape($search);
+ $filter = "(&(objectClass=inetOrgPerson)($field=$search*))";
+ $result = ldap_queryabooks($filter,$field);
+ if(!count($result)) return;
+
+ $items = array();
+ foreach ($result as $entry){
+ if(isset($entry[$field]) && !empty($entry[$field])){
+ $items[] = $entry[$field][0];
+ }
+ }
+
+ $items = array_unique($items);
+ sort($items,SORT_STRING);
+
+ echo '<?xml version="1.0"?>'.NL;
+ echo '<ajaxresponse>'.NL;
+ foreach($items as $out){
+ echo '<item>'.NL;
+ echo '<value>'.htmlspecialchars($out).'</value>'.NL;
+ echo '<text>'.htmlspecialchars($out).'</text>'.NL;
+ echo '</item>'.NL;
+ }
+ echo '</ajaxresponse>'.NL;