X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=ajax.php;h=7e16b2f362d974e83880650600bb9ebea1739c09;hb=664038cd66746a147e0b71b31a7f9bc1d6a27d3b;hp=564e59d36e1e427174b3c5ab94ebb9943781e104;hpb=e5e982801086e26aaacd4e9706b2854972ae264c;p=contagged diff --git a/ajax.php b/ajax.php index 564e59d..7e16b2f 100644 --- a/ajax.php +++ b/ajax.php @@ -1,15 +1,20 @@ -require_once('init.php'); +require_once('inc/init.php'); ldap_login(); -header('Content-Type: text/html; charset=utf-8'); - -if($_REQUEST['taglookup']){ - ajax_taglookup($_REQUEST['taglookup']); -}elseif($_REQUEST['addnote']){ - ajax_addnote($_REQUEST['addnote'],$_REQUEST['note']); -}elseif($_REQUEST['settags']){ - ajax_settags($_REQUEST['settags'],$_REQUEST['tags']); +$FIELD = preg_replace('/entry\[/','',$_REQUEST['field']); +$FIELD = preg_replace('/\W+/','',$FIELD); + +if($_REQUEST['dn'] && $_REQUEST['addnote']){ + ajax_addnote($_REQUEST['dn'],$_REQUEST['addnote']); +}elseif($_REQUEST['dn'] && $_REQUEST['settags']){ + ajax_settags($_REQUEST['dn'],$_REQUEST['settags']); +}elseif($_REQUEST['dn'] && $_REQUEST['loadtags']){ + ajax_loadtags($_REQUEST['dn'],$_REQUEST['loadtags']); +}elseif($FIELD == 'marker'||$FIELD == 'markers'){ + ajax_taglookup($_REQUEST['value']); +}else{ + ajax_lookup($FIELD,$_REQUEST['value']); } /** @@ -18,37 +23,43 @@ if($_REQUEST['taglookup']){ function ajax_addnote($dn,$note){ global $conf; global $LDAP_CON; + global $FIELDS; + + header('Content-Type: text/html; charset=utf-8'); // fetch the existing note - $result = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array('description')); + $result = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array($FIELDS['note'])); if(ldap_count_entries($LDAP_CON,$result)){ $result = ldap_get_binentries($LDAP_CON, $result); } - $note = $note."\n\n".$result[0]['description'][0]; + $note = $note."\n\n".$result[0][$FIELDS['note']][0]; $note = preg_replace("!\n\n\n+!","\n\n",$note); - $entry['description'] = $note; + $entry[$FIELDS['note']] = $note; ldap_modify($LDAP_CON,$dn,$entry); - require_once(dirname(__FILE__).'/smarty/plugins/modifier.noteparser.php'); + require_once(dirname(__FILE__).'/inc/smarty/plugins/modifier.noteparser.php'); print smarty_modifier_noteparser($note); } /** - * Sett tags for a contact + * Set tags for a contact */ function ajax_settags($dn,$tags){ global $conf; global $LDAP_CON; - if(!$conf['extended']) return; + global $FIELDS; + if(!$FIELDS['_marker']) return; + + header('Content-Type: text/html; charset=utf-8'); $tags = explode(',',$tags); $tags = array_map('trim',$tags); $tags = array_unique($tags); $tags = array_diff($tags, array('')); //strip empty ones - $entry['marker'] = $tags; + $entry[$FIELDS['_marker']] = $tags; ldap_mod_replace($LDAP_CON,$dn,$entry); foreach ($tags as $tag){ @@ -60,25 +71,56 @@ function ajax_settags($dn,$tags){ } } +/** + * Load current tags of an entry + */ +function ajax_loadtags($dn,$type='plain'){ + global $conf; + global $LDAP_CON; + global $FIELDS; + if(!$FIELDS['_marker']) return; + + header('Content-Type: text/html; charset=utf-8'); + + $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array($FIELDS['_marker'])); + if(!ldap_count_entries($LDAP_CON,$sr)) return false; + $result = ldap_get_binentries($LDAP_CON, $sr); + $entry = $result[0]; + + if($type == 'plain'){ + echo join(', ',$entry[$FIELDS['_marker']]); + }else{ + foreach ($entry[$FIELDS['_marker']] as $tag){ + echo ''; + echo htmlspecialchars($tag); + echo ' '; + } + } +} + /** * Find all tags (markers) starting with the given * string */ function ajax_taglookup($tag){ + header('Content-Type: text/xml; charset=utf-8'); global $conf; global $LDAP_CON; - if(!$conf['extended']) return; + global $FIELDS; + if(!$FIELDS['_marker']) return; $search = ldap_filterescape($tag); - $filter = "(&(objectClass=contactPerson)(marker=$search*))"; - $result = ldap_queryabooks($filter,'marker'); + $filter = "(&(objectClass=inetOrgPerson)(".$FIELDS['_marker']."=$search*))"; + $result = ldap_queryabooks($filter,$FIELDS['_marker']); if(!count($result)) return; $tags = array(); foreach ($result as $entry){ - if(count($entry['marker'])){ - foreach($entry['marker'] as $marker){ + if(count($entry[$FIELDS['_marker']])){ + foreach($entry[$FIELDS['_marker']] as $marker){ if(preg_match('/^'.preg_quote($tag,'/').'/i',$marker)){ array_push($tags, strtolower($marker)); } @@ -89,11 +131,53 @@ function ajax_taglookup($tag){ $tags = array_unique($tags); sort($tags,SORT_STRING); - print '