]> git.sur5r.net Git - contagged/blob - ajax.php
added missing ajax.php
[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($_REQUEST['taglookup']){
8   ajax_taglookup($_REQUEST['taglookup']);
9 }elseif($_REQUEST['addnote']){
10   ajax_addnote($_REQUEST['addnote'],$_REQUEST['note']);
11 }
12
13 /**
14  * Add a note to the existing notes
15  */
16 function ajax_addnote($dn,$note){
17   global $conf;
18   global $LDAP_CON;
19
20   // fetch the existing note
21   $result = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array('description'));
22   if(ldap_count_entries($LDAP_CON,$result)){
23     $result = ldap_get_binentries($LDAP_CON, $result);
24   }
25   $note = $note."\n\n".$result[0]['description'][0];
26   $note = preg_replace("!\n\n\n+!","\n\n",$note);
27
28   $entry['description'] = $note;
29   ldap_modify($LDAP_CON,$dn,$entry);
30
31
32   require_once(dirname(__FILE__).'/smarty/plugins/modifier.noteparser.php');
33   print smarty_modifier_noteparser($note);
34 }
35
36 /**
37  * Find all tags (markers) starting with the given
38  * string
39  */
40 function ajax_taglookup($tag){
41   global $conf;
42   global $LDAP_CON;
43   if(!$conf[extended]) return;
44
45   $search = ldap_filterescape($tag);
46   $filter = "(&(objectClass=contactPerson)(marker=$search*))";
47   $result = ldap_queryabooks($filter,'marker');
48
49   if(!count($result)) return;
50
51   $tags = array();
52   foreach ($result as $entry){
53     if(count($entry['marker'])){
54       foreach($entry['marker'] as $marker){
55         if(preg_match('/^'.preg_quote($tag,'/').'/i',$marker)){
56           array_push($tags, strtolower($marker));
57         }
58       }
59     }
60   }
61
62   $tags = array_unique($tags);
63   sort($tags,SORT_STRING);
64
65   print '<ul>';
66   foreach($tags as $out){
67     print '<li>'.htmlspecialchars($out).'</li>';
68   }
69   print '</ul>';
70 }
71
72 ?>