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);
45 $smarty->assign('list',$list);
46 $smarty->assign('filter',$_REQUEST['filter']);
47 $smarty->assign('marker',$_REQUEST['marker']);
48 $smarty->assign('search',$_REQUEST['search']);
50 if($_REQUEST['export'] == 'csv'){
51 header("Content-Type: text/csv");
52 header('Content-Disposition: Attachement; filename="ldapabexport.csv"');
53 $smarty->display('export_list_csv.tpl');
55 //save location in session
56 $_SESSION[ldapab][lastlocation]=$_SERVER["REQUEST_URI"];
57 $smarty->display('header.tpl');
58 $smarty->display('list_filter.tpl');
59 $smarty->display('list.tpl');
60 $smarty->display('footer.tpl');
63 //------- functions -----------//
66 * callback function to sort entries by name
69 function _namesort($a,$b){
71 $x = $result[$a][sn][0].$result[$a][givenName][0];
72 $y = $result[$b][sn][0].$result[$b][givenName][0];
73 return(strcasecmp($x,$y));
78 * Creates an LDAP filter from given request variables search or filter
80 function _makeldapfilter(){
83 $filter = $_REQUEST['filter'];
84 $search = $_REQUEST['search'];
85 $org = $_REQUEST['org'];
86 $marker = $_REQUEST['marker'];
87 $_SESSION[ldapab][filter] = $filter;
88 if(empty($filter)) $filter='a';
91 $marker = utf8_encode($marker);
92 $ldapfilter = "(&(objectClass=contactPerson)(marker=$marker))";
93 }elseif(!empty($search)){
94 $search = trim($search);
95 $words=preg_split('/\s+/',$search);
97 foreach($words as $word){
98 $word = utf8_encode($word);
99 $filter .= "(|(|(sn=*$word*)(givenName=*$word*))(o=*$word*))";
101 $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
102 }elseif(!empty($org)){
103 $org = utf8_encode($org);
104 $ldapfilter = "(&(objectClass=inetOrgPerson)(o=$org))";
105 }elseif($filter=='other'){
107 for ($i=ord('a');$i<=ord('z');$i++){
108 $other .= '(!(sn='.chr($i).'*))';
110 $ldapfilter = "(&(objectClass=inetOrgPerson)$other)";
112 $filter = utf8_encode($filter);
113 $ldapfilter = "(&(objectClass=inetOrgPerson)(sn=$filter*))";