2 require_once('init.php');
6 $ldapfilter = _makeldapfilter();
8 //check public addressbook
9 $sr = ldap_list($LDAP_CON,$conf[publicbook],$ldapfilter);
10 $result1 = ldap_get_binentries($LDAP_CON, $sr);
11 //check users private addressbook
12 if(!empty($_SESSION[ldapab][binddn])){
13 $sr = @ldap_list($LDAP_CON,
14 $conf[privatebook].','.$_SESSION[ldapab][binddn],
16 $result2 = ldap_get_binentries($LDAP_CON, $sr);
19 $result = array_merge($result1,$result2);
21 // select entry template
22 if($_REQUEST['export'] == 'csv'){
23 $entrytpl = 'export_list_csv_entry.tpl';
25 $entrytpl = 'list_entry.tpl';
29 if(count($result)==1 && $_REQUEST[search]){
30 //only one result on a search -> display page
31 header("Location: entry.php?dn=".$result[0][dn]);
33 }elseif(count($result)){
34 $keys = array_keys($result);
35 uksort($keys,"_namesort");
36 foreach($keys as $key){
37 tpl_entry($result[$key]);
38 $list .= $smarty->fetch($entrytpl);
44 tpl_markers(); //FIXME not needed anymore!?
48 $smarty->assign('list',$list);
49 $smarty->assign('filter',$_REQUEST['filter']);
50 $smarty->assign('marker',$_REQUEST['marker']);
51 $smarty->assign('search',$_REQUEST['search']);
53 if($_REQUEST['export'] == 'csv'){
54 header("Content-Type: text/csv");
55 header('Content-Disposition: Attachement; filename="ldapabexport.csv"');
56 $smarty->display('export_list_csv.tpl');
58 //save location in session
59 $_SESSION[ldapab][lastlocation]=$_SERVER["REQUEST_URI"];
61 header('Content-Type: text/html; charset=utf-8');
62 $smarty->display('list.tpl');
65 //------- functions -----------//
68 * callback function to sort entries by name
71 function _namesort($a,$b){
73 $x = $result[$a][sn][0].$result[$a][givenName][0];
74 $y = $result[$b][sn][0].$result[$b][givenName][0];
75 return(strcasecmp($x,$y));
80 * Creates an LDAP filter from given request variables search or filter
82 function _makeldapfilter(){
85 $filter = ldap_filterescape($_REQUEST['filter']);
86 $search = ldap_filterescape($_REQUEST['search']);
87 $org = ldap_filterescape($_REQUEST['org']);
88 $marker = ldap_filterescape($_REQUEST['marker']);
89 $categories = ldap_filterescape($_REQUEST['categories']);
90 $_SESSION[ldapab][filter] = $_REQUEST['filter'];
91 if(empty($filter)) $filter='a';
94 $ldapfilter = '(&(objectClass=contactPerson)';
95 $marker = explode(',',$marker);
96 foreach($marker as $m){
98 $ldapfilter .= "(marker=$m)";
101 }elseif(!empty($categories)){
102 $ldapfilter = "(&(objectClass=OXUserObject)(OXUserCategories=$categories))";
103 }elseif(!empty($search)){
104 $search = trim($search);
105 $words=preg_split('/\s+/',$search);
107 foreach($words as $word){
108 $filter .= "(|(|(sn=*$word*)(givenName=*$word*))(o=*$word*))";
110 $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
111 }elseif(!empty($org)){
112 $ldapfilter = "(&(objectClass=inetOrgPerson)(o=$org))";
113 }elseif($filter=='other'){
115 for ($i=ord('a');$i<=ord('z');$i++){
116 $other .= '(!(sn='.chr($i).'*))';
118 $ldapfilter = "(&(objectClass=inetOrgPerson)$other)";
119 }elseif($filter=='*'){
120 $ldapfilter = "(objectClass=inetOrgPerson)";
122 $ldapfilter = "(&(objectClass=inetOrgPerson)(sn=$filter*))";