2 require_once('init.php');
5 header('Content-Type: text/html; charset=utf-8');
7 if($_REQUEST['taglookup']){
8 ajax_taglookup($_REQUEST['taglookup']);
9 }elseif($_REQUEST['addnote']){
10 ajax_addnote($_REQUEST['addnote'],$_REQUEST['note']);
11 }elseif($_REQUEST['settags']){
12 ajax_settags($_REQUEST['settags'],$_REQUEST['tags']);
16 * Add a note to the existing notes
18 function ajax_addnote($dn,$note){
22 // fetch the existing note
23 $result = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array('description'));
24 if(ldap_count_entries($LDAP_CON,$result)){
25 $result = ldap_get_binentries($LDAP_CON, $result);
27 $note = $note."\n\n".$result[0]['description'][0];
28 $note = preg_replace("!\n\n\n+!","\n\n",$note);
30 $entry['description'] = $note;
31 ldap_modify($LDAP_CON,$dn,$entry);
34 require_once(dirname(__FILE__).'/smarty/plugins/modifier.noteparser.php');
35 print smarty_modifier_noteparser($note);
39 * Sett tags for a contact
41 function ajax_settags($dn,$tags){
44 if(!$conf['extended']) return;
46 $tags = explode(',',$tags);
47 $tags = array_map('trim',$tags);
48 $tags = array_unique($tags);
49 $tags = array_diff($tags, array('')); //strip empty ones
51 $entry['marker'] = $tags;
52 ldap_mod_replace($LDAP_CON,$dn,$entry);
54 foreach ($tags as $tag){
55 print '<a href="index.php?marker=';
56 print rawurlencode($tag);
57 print '" class="tag">';
58 print htmlspecialchars($tag);
64 * Find all tags (markers) starting with the given
67 function ajax_taglookup($tag){
70 if(!$conf['extended']) return;
72 $search = ldap_filterescape($tag);
73 $filter = "(&(objectClass=contactPerson)(marker=$search*))";
74 $result = ldap_queryabooks($filter,'marker');
76 if(!count($result)) return;
79 foreach ($result as $entry){
80 if(count($entry['marker'])){
81 foreach($entry['marker'] as $marker){
82 if(preg_match('/^'.preg_quote($tag,'/').'/i',$marker)){
83 array_push($tags, strtolower($marker));
89 $tags = array_unique($tags);
90 sort($tags,SORT_STRING);
93 foreach($tags as $out){
94 print '<li>'.htmlspecialchars($out).'</li>';