2 require_once('init.php');
5 header('Content-Type: text/html; charset=utf-8');
7 if(!empty($_REQUEST['taglookup'])){
8 ajax_taglookup($_REQUEST['taglookup']);
9 }elseif(!empty($_REQUEST['addnote'])){
10 ajax_addnote($_REQUEST['addnote'],$_REQUEST['note']);
11 }elseif(!empty($_REQUEST['settags'])){
12 ajax_settags($_REQUEST['settags'],$_REQUEST['tags']);
16 * Add a note to the existing notes
18 function ajax_addnote($dn,$note){
23 // fetch the existing note
24 $result = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array($FIELDS['note']));
25 if(ldap_count_entries($LDAP_CON,$result)){
26 $result = ldap_get_binentries($LDAP_CON, $result);
28 $note = $note."\n\n".$result[0][$FIELDS['note']][0];
29 $note = preg_replace("!\n\n\n+!","\n\n",$note);
31 $entry[$FIELDS['note']] = $note;
32 ldap_modify($LDAP_CON,$dn,$entry);
35 require_once(dirname(__FILE__).'/smarty/plugins/modifier.noteparser.php');
36 print smarty_modifier_noteparser($note);
40 * Sett tags for a contact
42 function ajax_settags($dn,$tags){
46 if(!$FIELDS['_marker']) return;
48 $tags = explode(',',$tags);
49 $tags = array_map('trim',$tags);
50 $tags = array_unique($tags);
51 $tags = array_diff($tags, array('')); //strip empty ones
53 $entry[$FIELDS['_marker']] = $tags;
54 ldap_mod_replace($LDAP_CON,$dn,$entry);
56 foreach ($tags as $tag){
57 print '<a href="index.php?marker=';
58 print rawurlencode($tag);
59 print '" class="tag">';
60 print htmlspecialchars($tag);
66 * Find all tags (markers) starting with the given
69 function ajax_taglookup($tag){
72 if(!$FIELDS['_marker']) return;
74 $search = ldap_filterescape($tag);
75 $filter = "(&(objectClass=inetOrgPerson)('.$FIELDS['_marker'].'=$search*))";
76 $result = ldap_queryabooks($filter,$FIELDS['_marker']);
78 if(!count($result)) return;
81 foreach ($result as $entry){
82 if(count($entry[$FIELDS['_marker']])){
83 foreach($entry[$FIELDS['_marker']] as $marker){
84 if(preg_match('/^'.preg_quote($tag,'/').'/i',$marker)){
85 array_push($tags, strtolower($marker));
91 $tags = array_unique($tags);
92 sort($tags,SORT_STRING);
95 foreach($tags as $out){
96 print '<li>'.htmlspecialchars($out).'</li>';