3 require_once('inc/init.php');
6 // select entry template
7 if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){
8 $entrytpl = 'list_csv_entry.tpl';
9 }elseif(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'map'){
10 $entrytpl = 'list_map_entry.tpl';
12 $entrytpl = 'list_entry.tpl';
15 // check which fields are needed
16 $fields = get_fields_from_template($entrytpl);
20 $ldapfilter = _makeldapfilter();
23 $result = ldap_queryabooks($ldapfilter,$fields);
26 if(count($result)==1 && $_REQUEST['search']){
27 //only one result on a search -> display page
28 header("Location: entry.php?dn=".rawurlencode($result[0]['dn']));
30 }elseif(count($result)){
31 $keys = array_keys($result);
32 uksort($keys,"_namesort");
33 foreach($keys as $key){
34 tpl_entry($result[$key]);
35 $list .= $smarty->fetch($entrytpl);
41 if (empty($_REQUEST['filter'])) $_REQUEST['filter']='';
42 if (empty($_REQUEST['marker'])) $_REQUEST['marker']='';
43 if (empty($_REQUEST['search'])) $_REQUEST['search']='';
44 $smarty->assign('list',$list);
45 $smarty->assign('filter',$_REQUEST['filter']);
46 $smarty->assign('marker',$_REQUEST['marker']);
47 $smarty->assign('search',$_REQUEST['search']);
48 $smarty->assign('org',$_REQUEST['org']);
50 if(!empty($_REQUEST['export'])){
51 if ($conf['userlogreq'] && $user == ''){
52 header("HTTP/1.1 401 Access Denied");
53 echo '<h1>Access Denied</h1>';
57 if($_REQUEST['export'] == 'csv'){
58 header("Content-Type: text/csv");
59 header('Content-Disposition: Attachement; filename="contagged_export.csv"');
60 $smarty->display('list_csv.tpl');
62 }elseif($_REQUEST['export'] == 'map'){
63 require_once 'inc/Geocoder.php';
64 $geocoder = new Geocoder();
66 foreach ($result as $ldapEntry) {
67 tpl_entry($ldapEntry);
68 $entry = $smarty->get_template_vars('entry');
69 addCoords($coords, $entry, $geocoder);
71 $smarty->assign('coords', $coords);
73 header('Content-Type: text/html; charset=utf-8');
74 $smarty->display('list_map.tpl');
78 //save location in session
79 $_SESSION['ldapab']['lastlocation']=$_SERVER["REQUEST_URI"];
81 header('Content-Type: text/html; charset=utf-8');
82 $smarty->display('list.tpl');
85 //------- functions -----------//
88 * callback function to sort entries by name
91 function _namesort($a,$b){
94 if (empty($result[$a][$FIELDS['givenname']])) { $result[$a][$FIELDS['givenname']]=''; }
95 if (empty($result[$b][$FIELDS['givenname']])) { $result[$b][$FIELDS['givenname']]=''; }
96 $x = $result[$a][$FIELDS['name']][0].$result[$a][$FIELDS['givenname']][0];
97 $y = $result[$b][$FIELDS['name']][0].$result[$b][$FIELDS['givenname']][0];
98 return(strcasecmp($x,$y));
103 * Creates an LDAP filter from given request variables search or filter
105 function _makeldapfilter(){
109 //handle given filter
111 if (empty($_REQUEST['filter'])) { $_REQUEST['filter']=''; }
112 if (empty($_REQUEST['search'])) { $_REQUEST['search']=''; }
113 if (empty($_REQUEST['org'])) { $_REQUEST['org']=''; }
114 if (empty($_REQUEST['marker'])) { $_REQUEST['marker']=''; }
115 if(is_numeric($_REQUEST['search'])) $number = $_REQUEST['search'];
116 $filter = ldap_filterescape($_REQUEST['filter']);
117 $search = ldap_filterescape($_REQUEST['search']);
118 $org = ldap_filterescape($_REQUEST['org']);
119 $marker = ldap_filterescape($_REQUEST['marker']);
120 $_SESSION['ldapab']['filter'] = $_REQUEST['filter'];
121 if(empty($filter)) $filter='a';
125 $ldapfilter = '(&(objectClass=evolutionPerson)';
126 $marker = explode(',',$marker);
127 foreach($marker as $m){
129 $ldapfilter .= '('.$FIELDS['_marker'].'='.$m.')';
133 // Search by telephone number
135 // add wildcards between digits to compensate for any formatting
136 $length = strlen($number);
137 for($i=0; $i <$length; $i++){
138 $filter .= '*'.$number{$i};
142 '(objectClass=inetOrgPerson)'.
145 '('.$FIELDS['phone'].'='.$filter.')'.
146 '('.$FIELDS['homephone'].'='.$filter.')'.
148 '('.$FIELDS['mobile'].'='.$filter.')'.
151 }elseif(!empty($search)){
152 // Search name and organization
153 $search = trim($search);
154 $words=preg_split('/\s+/',$search);
156 foreach($words as $word){
158 foreach($conf['searchfields'] as $field) {
159 $wordfilter .= '('.$field.'=*'.$word.'*)';
161 for($i=0; $i <count($conf['searchfields']); $i++){
162 $wordfilter = '(|'.$wordfilter.')';
164 $filter .= '(&'.$wordfilter.')';
166 $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
167 }elseif(!empty($org)){
168 // List organization members
169 $ldapfilter = '(&(objectClass=inetOrgPerson)('.$FIELDS['organization']."=$org))";
170 }elseif($filter=='other'){
171 // Alphabetic listing of last names
173 for ($i=ord('a');$i<=ord('z');$i++){
174 $other .= '(!('.$FIELDS['name'].'='.chr($i).'*))';
176 $ldapfilter = "(&(objectClass=inetOrgPerson)$other)";
177 }elseif($filter=='\2a'){ //escaped asterisk
179 $ldapfilter = "(objectClass=inetOrgPerson)";
181 // Search by last name start
182 $ldapfilter = '(&(objectClass=inetOrgPerson)('.$FIELDS['name']."=$filter*))";