]> git.sur5r.net Git - contagged/blob - ajax.php
changed multifield character from * to _
[contagged] / ajax.php
1 <?
2 require_once('init.php');
3 ldap_login();
4
5 header('Content-Type: text/html; charset=utf-8');
6
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']);
13 }
14
15 /**
16  * Add a note to the existing notes
17  */
18 function ajax_addnote($dn,$note){
19   global $conf;
20   global $LDAP_CON;
21   global $FIELDS;
22
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);
27   }
28   $note = $note."\n\n".$result[0][$FIELDS['note']][0];
29   $note = preg_replace("!\n\n\n+!","\n\n",$note);
30
31   $entry[$FIELDS['note']] = $note;
32   ldap_modify($LDAP_CON,$dn,$entry);
33
34
35   require_once(dirname(__FILE__).'/smarty/plugins/modifier.noteparser.php');
36   print smarty_modifier_noteparser($note);
37 }
38
39 /**
40  * Sett tags for a contact
41  */
42 function ajax_settags($dn,$tags){
43   global $conf;
44   global $LDAP_CON;
45   global $FIELDS;
46   if(!$FIELDS['_marker']) return;
47
48   $tags = explode(',',$tags);
49   $tags = array_map('trim',$tags);
50   $tags = array_unique($tags);
51   $tags = array_diff($tags, array('')); //strip empty ones
52
53   $entry[$FIELDS['_marker']] = $tags;
54   ldap_mod_replace($LDAP_CON,$dn,$entry);
55
56   foreach ($tags as $tag){
57     print '<a href="index.php?marker=';
58     print rawurlencode($tag);
59     print '" class="tag">';
60     print htmlspecialchars($tag);
61     print '</a> ';
62   }
63 }
64
65 /**
66  * Find all tags (markers) starting with the given
67  * string
68  */
69 function ajax_taglookup($tag){
70   global $conf;
71   global $LDAP_CON;
72   if(!$FIELDS['_marker']) return;
73
74   $search = ldap_filterescape($tag);
75   $filter = "(&(objectClass=inetOrgPerson)('.$FIELDS['_marker'].'=$search*))";
76   $result = ldap_queryabooks($filter,$FIELDS['_marker']);
77
78   if(!count($result)) return;
79
80   $tags = array();
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));
86         }
87       }
88     }
89   }
90
91   $tags = array_unique($tags);
92   sort($tags,SORT_STRING);
93
94   print '<ul>';
95   foreach($tags as $out){
96     print '<li>'.htmlspecialchars($out).'</li>';
97   }
98   print '</ul>';
99 }
100
101 ?>