3 require_once('inc/init.php');
7 $ldapfilter = _makeldapfilter();
9 //check public addressbook
10 $sr = ldap_list($LDAP_CON,$conf['publicbook'],$ldapfilter);
11 $result1 = ldap_get_binentries($LDAP_CON, $sr);
12 //check users private addressbook
13 if(!empty($_SESSION['ldapab']['binddn'])){
14 $sr = @ldap_list($LDAP_CON,
15 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
17 $result2 = ldap_get_binentries($LDAP_CON, $sr);
22 $result = array_merge((array)$result1,(array)$result2);
24 // select entry template
25 if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){
26 $entrytpl = 'list_csv_entry.tpl';
27 }elseif(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'map'){
28 $entrytpl = 'list_map_entry.tpl';
30 $entrytpl = 'list_entry.tpl';
34 if(count($result)==1 && $_REQUEST['search']){
35 //only one result on a search -> display page
36 header("Location: entry.php?dn=".$result[0]['dn']);
38 }elseif(count($result)){
39 $keys = array_keys($result);
40 uksort($keys,"_namesort");
41 foreach($keys as $key){
42 tpl_entry($result[$key]);
43 $list .= $smarty->fetch($entrytpl);
49 if (empty($_REQUEST['filter'])) $_REQUEST['filter']='';
50 if (empty($_REQUEST['marker'])) $_REQUEST['marker']='';
51 if (empty($_REQUEST['search'])) $_REQUEST['search']='';
52 $smarty->assign('list',$list);
53 $smarty->assign('filter',$_REQUEST['filter']);
54 $smarty->assign('marker',$_REQUEST['marker']);
55 $smarty->assign('search',$_REQUEST['search']);
57 if(!empty($_REQUEST['export'])){
58 if ($conf['userlogreq'] == 1 && $user == ''){
59 header("HTTP/1.1 401 ACCESS DENIED");
63 if($_REQUEST['export'] == 'csv'){
64 header("Content-Type: text/csv");
65 header('Content-Disposition: Attachement; filename="contagged_export.csv"');
66 $smarty->display('list_csv.tpl');
68 }elseif($_REQUEST['export'] == 'map'){
69 header('Content-Type: text/html; charset=utf-8');
70 $smarty->display('list_map.tpl');
74 //save location in session
75 $_SESSION['ldapab']['lastlocation']=$_SERVER["REQUEST_URI"];
77 header('Content-Type: text/html; charset=utf-8');
78 $smarty->display('list.tpl');
81 //------- functions -----------//
84 * callback function to sort entries by name
87 function _namesort($a,$b){
90 if (empty($result[$a][$FIELDS['givenname']])) { $result[$a][$FIELDS['givenname']]=''; }
91 if (empty($result[$b][$FIELDS['givenname']])) { $result[$b][$FIELDS['givenname']]=''; }
92 $x = $result[$a][$FIELDS['name']][0].$result[$a][$FIELDS['givenname']][0];
93 $y = $result[$b][$FIELDS['name']][0].$result[$b][$FIELDS['givenname']][0];
94 return(strcasecmp($x,$y));
99 * Creates an LDAP filter from given request variables search or filter
101 function _makeldapfilter(){
104 //handle given filter
106 if (empty($_REQUEST['filter'])) { $_REQUEST['filter']=''; }
107 if (empty($_REQUEST['search'])) { $_REQUEST['search']=''; }
108 if (empty($_REQUEST['org'])) { $_REQUEST['org']=''; }
109 if (empty($_REQUEST['marker'])) { $_REQUEST['marker']=''; }
110 $filter = ldap_filterescape($_REQUEST['filter']);
111 $search = ldap_filterescape($_REQUEST['search']);
112 $org = ldap_filterescape($_REQUEST['org']);
113 $marker = ldap_filterescape($_REQUEST['marker']);
114 $_SESSION['ldapab']['filter'] = $_REQUEST['filter'];
115 if(empty($filter)) $filter='a';
119 $ldapfilter = '(&(objectClass=contactPerson)';
120 $marker = explode(',',$marker);
121 foreach($marker as $m){
123 $ldapfilter .= '('.$FIELDS['_marker'].'='.$m.')';
126 }elseif(!empty($search)){
127 // Search name and organization
128 $search = trim($search);
129 $words=preg_split('/\s+/',$search);
131 foreach($words as $word){
132 $filter .= '(|(|('.$FIELDS['name'].'=*'.$word.'*)('.
133 $FIELDS['givenname'].'=*'.$word.'*))('.
134 $FIELDS['organization'].'=*'.$word.'*))';
136 $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
137 }elseif(!empty($org)){
138 // List organization members
139 $ldapfilter = '(&(objectClass=inetOrgPerson)('.$FIELDS['organization']."=$org))";
140 }elseif($filter=='other'){
141 // Alphabetic listing of last names
143 for ($i=ord('a');$i<=ord('z');$i++){
144 $other .= '(!('.$FIELDS['name'].'='.chr($i).'*))';
146 $ldapfilter = "(&(objectClass=inetOrgPerson)$other)";
147 }elseif($filter=='\2a'){ //escaped asterisk
149 $ldapfilter = "(objectClass=inetOrgPerson)";
151 // Search by last name start
152 $ldapfilter = '(&(objectClass=inetOrgPerson)('.$FIELDS['name']."=$filter*))";