- Timestamp:
- 05/27/11 15:02:52 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
r4353 r4538 115 115 function find($what, $rules=false, $other=false, $area=false, $recursive=false) 116 116 { 117 $restric_fields = $this->get_restrictions_without_branch($rules); 118 119 $trans_f = $this->translate_fields($what, $restric_fields); 120 121 foreach($trans_f as $orig => $field_a) 122 { 123 foreach($field_a as $field) 124 { 125 $fields[] = $field; 126 } 127 } 128 129 $fields = array_unique($fields); 130 131 //Testa se a busca foi realizada com aspas 132 $rules_search = $rules[3]['value']; 133 $rules_len = (strlen($rules_search)) -1; 134 135 if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){ 136 $rules_search = substr($rules_search,2,$rules_len-3); 137 $filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))"; 138 } 139 else{ 140 $filter = $this->process_restrictions($rules, $trans_f); 141 } 142 143 if ($area) 144 { 145 $obj = CreateObject('phpgwapi.config','contactcenter'); 146 $opts = $obj->read_repository(); 147 $filter = substr($filter,0,-1) .'(' . $opts['cc_ldap_atrib'] . '=*' . $area . '*))'; 148 $opts = null; 149 $obj = null; 150 } 151 // Find objects where 'mail' attribute is not null. 152 $filter = "(&".$filter."(mail=*))"; 153 117 $find = ''; 118 if($rules) 119 { 120 foreach ($rules as $rule) 121 { 122 if($rule['field'] == 'contact.names_ordered' && $find === '') 123 $find .= $rule['value']; 124 else if($rule['field'] == 'contact.names_ordered') 125 $find .= ' '.$rule['value']; 126 } 127 } 128 129 if(!((strlen($find) == 2 && substr($find, -1) == '%') || $find == '%' )) 130 return $this->findAddress($find,$other); 131 132 $restric_fields = $this->get_restrictions_without_branch($rules); 133 134 $trans_f = $this->translate_fields($what, $restric_fields); 135 136 foreach($trans_f as $orig => $field_a) 137 { 138 foreach($field_a as $field) 139 { 140 $fields[] = $field; 141 } 142 } 143 144 $fields = array_unique($fields); 145 146 //Testa se a busca foi realizada com aspas 147 $rules_search = $rules[3]['value']; 148 $rules_len = (strlen($rules_search)) -1; 149 150 if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){ 151 $rules_search = substr($rules_search,2,$rules_len-3); 152 $filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))"; 153 } 154 else{ 155 $filter = $this->process_restrictions($rules, $trans_f); 156 } 157 158 // Find objects where 'mail' attribute is not null. 159 $filter = "(&".$filter."(mail=*))"; 154 160 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 155 161 $result_r = $recursive ? ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']) : 156 157 158 if (!$result_r)162 ldap_list($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); 163 164 if (!$result_r) 159 165 { 160 166 return false; 161 167 } 162 163 164 165 166 167 } 168 169 170 168 169 if ($other['order']) 170 { 171 $sort_f = array($other['order']); 172 $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); 173 } 174 175 if ($ldap_sort_by) 176 { 171 177 if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) 172 178 { 173 return false; 174 } 175 } 176 177 $result_u = ldap_get_entries($ldap, $result_r); 178 // No entries found. 179 if(!$result_u) 180 return true; 181 182 $i = 0; 183 foreach ($result_u as $index => $result_p) 184 { 185 if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1')) 186 { 187 continue; 188 } 189 190 foreach ($trans_f as $orig => $trans) 191 { 192 $orig = substr($orig, strrpos($orig, '.')+1, strlen($orig)); 193 foreach ($trans as $f) 194 { 195 if ($f === 'dn') 196 { 197 $return[$i][$orig] = $result_p['dn']; 198 } 199 else if ($result_p[$f][0]) 200 { 201 $return[$i][$orig] = $result_p[$f][0]; 202 } 203 } 204 } 205 $i++; 206 } 207 if($return) 208 usort($return, array($this, "compareObjects")); 209 return $return; 210 } 179 return false; 180 } 181 } 182 183 $iTotalEntries = ldap_count_entries( $ldap, $result_r ); 184 185 if($iTotalEntries < 1 ) 186 return true; 187 188 $iEnd = $iTotalEntries; 189 190 $return = array(); 191 192 $rEntry = ldap_first_entry( $ldap, $result_r ); 193 for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++) 194 { 195 196 $result_p = ldap_get_attributes($ldap, $rEntry ); 197 198 if(!$this->external and $result_p['phpgwaccountvisible'][0] == '-1'){ 199 continue; 200 } 201 202 $returnTemp = array(); 203 $returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry); 204 $returnTemp['names_ordered'] = $result_p['cn']['0']; 205 206 array_push( $return, $returnTemp ); 207 $rEntry = ldap_next_entry( $ldap, $rEntry ); 208 209 } 210 211 212 usort($return, array($this, "compareObjects")); 213 return $return; 214 } 215 216 function findAddress($find, $other=false) 217 { 218 219 require_once $_SESSION['rootPath'].'/API/class.servicelocator.php'; 220 $ldapService = ServiceLocator::getService('ldap'); 221 $filter = $ldapService->getSearchFilter($find); 222 $fields = array('cn','dn'); 223 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 224 $result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields); 225 226 227 if (!$result_r) 228 { 229 return false; 230 } 231 232 if ($other['order']) 233 { 234 $sort_f = array($other['order']); 235 $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); 236 } 237 238 if ($ldap_sort_by) 239 { 240 if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) 241 { 242 return false; 243 } 244 } 245 246 $iTotalEntries = ldap_count_entries( $ldap, $result_r ); 247 248 if($iTotalEntries < 1 ) 249 return true; 250 251 $iEnd = $iTotalEntries; 252 253 $return = array(); 254 255 $rEntry = ldap_first_entry( $ldap, $result_r ); 256 for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++) 257 { 258 259 $result_p = ldap_get_attributes($ldap, $rEntry ); 260 261 $returnTemp = array(); 262 $returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry); 263 $returnTemp['names_ordered'] = $result_p['cn']['0']; 264 265 array_push( $return, $returnTemp ); 266 $rEntry = ldap_next_entry( $ldap, $rEntry ); 267 268 } 269 270 271 usort($return, array($this, "compareObjects")); 272 return $return; 273 } 274 211 275 // Compare function for usort. 212 276 function compareObjects($a, $b) {
Note: See TracChangeset
for help on using the changeset viewer.