[2] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Written by: * |
---|
| 6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
| 7 | * ------------------------------------------------------------------------- * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | This class is responsible for manipulating the Global LDAP Contact Manager |
---|
| 16 | */ |
---|
| 17 | include_once('class.abo_catalog.inc.php'); |
---|
[400] | 18 | |
---|
[2] | 19 | class bo_global_ldap_catalog extends abo_catalog |
---|
| 20 | { |
---|
| 21 | var $ldap; |
---|
[400] | 22 | |
---|
[2] | 23 | var $src_info; |
---|
[400] | 24 | |
---|
[2] | 25 | var $trans_table; |
---|
[284] | 26 | // used to determine if a catalog is external |
---|
| 27 | var $external; |
---|
[2] | 28 | var $fields = array( |
---|
| 29 | 'id_contact' => true, |
---|
| 30 | 'status' => true, |
---|
| 31 | 'photo' => true, |
---|
| 32 | 'alias' => true, |
---|
| 33 | 'prefix' => true, |
---|
| 34 | 'given_names' => true, |
---|
| 35 | 'family_names' => true, |
---|
| 36 | 'account_type' => true, |
---|
| 37 | 'names_ordered' => true, |
---|
| 38 | 'suffix' => true, |
---|
| 39 | 'birthdate' => true, |
---|
| 40 | 'sex' => true, |
---|
| 41 | 'pgp_key' => true, |
---|
| 42 | 'notes' => true, |
---|
[400] | 43 | |
---|
[2] | 44 | /* Array fields */ |
---|
| 45 | 'companies' => true, |
---|
| 46 | 'relations' => true, |
---|
| 47 | 'addresses' => true, |
---|
| 48 | 'connections' => true |
---|
| 49 | ); |
---|
[400] | 50 | |
---|
[2] | 51 | /* |
---|
[400] | 52 | |
---|
[2] | 53 | @function global_ldap_catalog |
---|
| 54 | @abstract Constructor |
---|
| 55 | @author Raphael Derosso Pereira |
---|
[400] | 56 | @author Mário César Kolling (external catalogs) |
---|
[284] | 57 | |
---|
[2] | 58 | @param integer $id_source The ID of the LDAP source |
---|
[284] | 59 | @param string $context Ldap bind DN |
---|
| 60 | @param integer $external 0 = internal catalog, 1 = external catalog |
---|
[2] | 61 | */ |
---|
[284] | 62 | function bo_global_ldap_catalog ( $id_source, $context, $external = 0 ) |
---|
[2] | 63 | { |
---|
[284] | 64 | $this->external = $external; |
---|
[2] | 65 | if (!function_exists('ldap_search')) |
---|
| 66 | { |
---|
| 67 | exit('PHP LDAP support Unavailable!'); |
---|
| 68 | } |
---|
[400] | 69 | |
---|
[2] | 70 | $this->ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
[400] | 71 | |
---|
[284] | 72 | if ($this->external) |
---|
| 73 | { |
---|
| 74 | $all_src = $this->ldap->get_external_ldap_sources(); |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | { |
---|
| 78 | $all_src = $this->ldap->get_all_ldap_sources(); |
---|
| 79 | } |
---|
| 80 | |
---|
[2] | 81 | if (!$all_src[$id_source] or !$context) |
---|
| 82 | { |
---|
| 83 | exit('Unavailable LDAP source.'); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | $this->src_info = $all_src[$id_source]; |
---|
| 87 | $this->src_info['context'] = $context; |
---|
[284] | 88 | |
---|
| 89 | if ($this->external) |
---|
| 90 | { |
---|
| 91 | $this->trans_table = $this->ldap->get_external_ldap_fields_association($id_source); |
---|
| 92 | } |
---|
| 93 | else |
---|
[400] | 94 | { |
---|
[284] | 95 | $this->trans_table = $this->ldap->get_ldap_fields_association($id_source); |
---|
| 96 | } |
---|
[2] | 97 | } |
---|
[400] | 98 | |
---|
[2] | 99 | /* |
---|
[400] | 100 | |
---|
[2] | 101 | @function find |
---|
| 102 | @abstract Searches the LDAP directory for the specified fields with |
---|
| 103 | the specified rules and retuns an array containing all the DNs |
---|
| 104 | that matches the rules. |
---|
| 105 | @author Raphael Derosso Pereira |
---|
[400] | 106 | |
---|
[2] | 107 | @param array $what The fields to be taken |
---|
| 108 | @param array $rules The rules to be match. See class.abo_catalog.inc.php |
---|
| 109 | for reference |
---|
| 110 | @param array $other Other parameters: |
---|
| 111 | $return = array( |
---|
| 112 | 'limit' => (integer), |
---|
| 113 | 'offset' => (integer) [NOT IMPLEMENTED] |
---|
| 114 | ) |
---|
[400] | 115 | |
---|
[2] | 116 | */ |
---|
| 117 | function find($what, $rules=false, $other=false) |
---|
| 118 | { |
---|
| 119 | $restric_fields = $this->get_restrictions_without_branch($rules); |
---|
[400] | 120 | |
---|
[2] | 121 | $trans_f = $this->translate_fields($what, $restric_fields); |
---|
[400] | 122 | |
---|
[2] | 123 | foreach($trans_f as $orig => $field_a) |
---|
| 124 | { |
---|
| 125 | foreach($field_a as $field) |
---|
| 126 | { |
---|
| 127 | $fields[] = $field; |
---|
| 128 | } |
---|
| 129 | } |
---|
[400] | 130 | |
---|
[2] | 131 | $fields = array_unique($fields); |
---|
[400] | 132 | |
---|
[2] | 133 | $filter = $this->process_restrictions($rules, $trans_f); |
---|
[880] | 134 | // Find objects where 'mail' attribute is not null. |
---|
| 135 | $filter = "(&".$filter."(mail=*))"; |
---|
[314] | 136 | if("ou" === strtolower(substr($this->src_info['context'], 0, 2)) || |
---|
[880] | 137 | (trim($rules[0]['value']) == "phpgwAccount")) |
---|
[400] | 138 | { |
---|
[314] | 139 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); |
---|
[388] | 140 | $result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); |
---|
[285] | 141 | } |
---|
| 142 | else |
---|
[400] | 143 | { |
---|
[2] | 144 | return false; |
---|
| 145 | } |
---|
[400] | 146 | |
---|
[2] | 147 | |
---|
| 148 | if (!$result_r) |
---|
| 149 | { |
---|
| 150 | return false; |
---|
| 151 | } |
---|
[400] | 152 | |
---|
[2] | 153 | if ($other['order']) |
---|
| 154 | { |
---|
| 155 | $sort_f = array($other['order']); |
---|
| 156 | $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | if ($ldap_sort_by) |
---|
| 160 | { |
---|
| 161 | if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) |
---|
| 162 | { |
---|
| 163 | return false; |
---|
| 164 | } |
---|
| 165 | } |
---|
[400] | 166 | |
---|
[2] | 167 | $result_u = ldap_get_entries($ldap, $result_r); |
---|
[3134] | 168 | // No entries found. |
---|
| 169 | if(!$result_u) |
---|
| 170 | return true; |
---|
[400] | 171 | |
---|
[2] | 172 | $i = 0; |
---|
| 173 | foreach ($result_u as $index => $result_p) |
---|
| 174 | { |
---|
[284] | 175 | if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1')) |
---|
[2] | 176 | { |
---|
| 177 | continue; |
---|
| 178 | } |
---|
[400] | 179 | |
---|
[2] | 180 | foreach ($trans_f as $orig => $trans) |
---|
| 181 | { |
---|
| 182 | $orig = substr($orig, strrpos($orig, '.')+1, strlen($orig)); |
---|
| 183 | foreach ($trans as $f) |
---|
| 184 | { |
---|
| 185 | if ($f === 'dn') |
---|
| 186 | { |
---|
| 187 | $return[$i][$orig] = $result_p['dn']; |
---|
| 188 | } |
---|
| 189 | else if ($result_p[$f][0]) |
---|
| 190 | { |
---|
| 191 | $return[$i][$orig] = $result_p[$f][0]; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | $i++; |
---|
| 196 | } |
---|
[884] | 197 | usort($return, array($this, "compareObjects")); |
---|
[2] | 198 | return $return; |
---|
| 199 | } |
---|
[884] | 200 | // Compare function for usort. |
---|
| 201 | function compareObjects($a, $b) { |
---|
| 202 | return strnatcasecmp($a['names_ordered'], $b['names_ordered']); |
---|
| 203 | } |
---|
[400] | 204 | |
---|
[2] | 205 | /* |
---|
[400] | 206 | |
---|
[2] | 207 | @function translate_fields |
---|
| 208 | @abstract Return the LDAP objectClass fields that corresponds to the |
---|
| 209 | specified parameter fields |
---|
| 210 | @author Raphael Derosso Pereira |
---|
[400] | 211 | |
---|
[2] | 212 | @param array $fields The fields in the standard ContactCenter format |
---|
| 213 | @param array $rules The rules |
---|
[400] | 214 | |
---|
[2] | 215 | */ |
---|
| 216 | function translate_fields ( $fields, &$restric_fields ) |
---|
| 217 | { |
---|
| 218 | $return = array(); |
---|
[400] | 219 | |
---|
[2] | 220 | $i = 0; |
---|
| 221 | foreach ($fields as $field) |
---|
| 222 | { |
---|
| 223 | if (!array_key_exists($field,$this->trans_table) or !$this->trans_table[$field]) |
---|
| 224 | { |
---|
| 225 | continue; |
---|
| 226 | } |
---|
[400] | 227 | |
---|
[2] | 228 | if (!is_array($this->trans_table[$field])) |
---|
| 229 | { |
---|
| 230 | $reference = $this->trans_table[$field]; |
---|
[400] | 231 | |
---|
[2] | 232 | reset($restric_fields); |
---|
| 233 | while(list(,$field_r) = each($restric_fields)) |
---|
| 234 | { |
---|
| 235 | if ($field_r['field'] === $reference and array_key_exists($field_r['value'], $this->trans_table[$reference])) |
---|
| 236 | { |
---|
| 237 | array_push($return[$field], $this->trans_table[$reference][$field_r['value']]); |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | else |
---|
| 242 | { |
---|
| 243 | if (!is_array($return[$field])) |
---|
| 244 | { |
---|
| 245 | $return[$field] = $this->trans_table[$field]; |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
| 249 | array_push($return[$field], $this->trans_table[$field]); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | } |
---|
[400] | 253 | |
---|
[2] | 254 | if (count($return)) |
---|
| 255 | { |
---|
| 256 | return $return; |
---|
| 257 | } |
---|
[400] | 258 | |
---|
[2] | 259 | return false; |
---|
| 260 | } |
---|
[400] | 261 | |
---|
[2] | 262 | /* |
---|
[400] | 263 | |
---|
[2] | 264 | @function process_restrictions |
---|
| 265 | @abstract Returns a LDAP filter string that corresponds to the |
---|
| 266 | specified restriction rules |
---|
| 267 | @author Raphael Derosso Pereira |
---|
[400] | 268 | |
---|
[2] | 269 | @param string $rules The restriction rules |
---|
[400] | 270 | |
---|
[2] | 271 | */ |
---|
| 272 | function process_restrictions( $rules, &$trans_table, $join_type='&' ) |
---|
| 273 | { |
---|
| 274 | if (!is_array($rules) or !count($rules)) |
---|
| 275 | { |
---|
| 276 | return null; |
---|
| 277 | } |
---|
[400] | 278 | |
---|
[2] | 279 | foreach($rules as $rule_i => $rule) |
---|
| 280 | { |
---|
| 281 | $t = array(); |
---|
| 282 | switch($rule['type']) |
---|
| 283 | { |
---|
| 284 | case 'branch': |
---|
| 285 | switch(strtoupper($rule['value'])) |
---|
| 286 | { |
---|
| 287 | case 'OR': |
---|
| 288 | $join = '|'; |
---|
| 289 | break; |
---|
[400] | 290 | |
---|
[2] | 291 | case 'AND': |
---|
| 292 | $join = '&'; |
---|
| 293 | break; |
---|
[400] | 294 | |
---|
[2] | 295 | case 'NOT': |
---|
| 296 | $join = '!'; |
---|
| 297 | break; |
---|
[400] | 298 | |
---|
[2] | 299 | default: |
---|
| 300 | $join = $join_type; |
---|
| 301 | } |
---|
| 302 | $return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join); |
---|
| 303 | break; |
---|
[400] | 304 | |
---|
[2] | 305 | case '=': |
---|
| 306 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 307 | { |
---|
| 308 | foreach($trans_table[$rule['field']] as $field) |
---|
| 309 | { |
---|
| 310 | $t[] = '('.$field.'='.$rule['value'].')'; |
---|
| 311 | } |
---|
| 312 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 313 | } |
---|
| 314 | break; |
---|
[400] | 315 | |
---|
| 316 | case '!=': |
---|
[2] | 317 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 318 | { |
---|
| 319 | foreach($trans_table[$rule['field']] as $field) |
---|
| 320 | { |
---|
| 321 | $t[] = '(!('.$field.'='.$rule['value'].'))'; |
---|
| 322 | } |
---|
| 323 | $return_t[] = '(&'.implode(' ',$t).')'; |
---|
| 324 | } |
---|
| 325 | break; |
---|
[400] | 326 | |
---|
[2] | 327 | case '<=': |
---|
| 328 | case '<': |
---|
| 329 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 330 | { |
---|
| 331 | foreach($trans_table[$rule['field']] as $field) |
---|
| 332 | { |
---|
| 333 | $t[] = '('.$field.'<='.$rule['value'].')'; |
---|
| 334 | } |
---|
| 335 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 336 | } |
---|
| 337 | break; |
---|
[400] | 338 | |
---|
[2] | 339 | case '>': |
---|
| 340 | case '>=': |
---|
| 341 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 342 | { |
---|
| 343 | foreach($trans_table[$rule['field']] as $field) |
---|
| 344 | { |
---|
| 345 | $t[] = '('.$field.'>='.$rule['value'].')'; |
---|
| 346 | } |
---|
| 347 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 348 | } |
---|
| 349 | break; |
---|
[400] | 350 | |
---|
[2] | 351 | case 'NULL': |
---|
| 352 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 353 | { |
---|
| 354 | foreach($trans_table[$rule['field']] as $field) |
---|
| 355 | { |
---|
| 356 | $t[] = '(!('.$field.'=*'.'))'; |
---|
| 357 | } |
---|
| 358 | $return_t[] = '(&'.implode(' ',$t).')'; |
---|
| 359 | } |
---|
| 360 | break; |
---|
[400] | 361 | |
---|
[2] | 362 | case 'IN': |
---|
| 363 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 364 | { |
---|
| 365 | foreach($trans_table[$rule['field']] as $field) |
---|
| 366 | { |
---|
| 367 | foreach($rule['value'] as $value) |
---|
| 368 | { |
---|
| 369 | $t[] = '('.$field.'='.$value.')'; |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 373 | } |
---|
| 374 | break; |
---|
| 375 | |
---|
| 376 | case 'iLIKE': |
---|
| 377 | /* if (array_key_exists($rule['field'], $trans_table)) |
---|
| 378 | { |
---|
| 379 | $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); |
---|
| 380 | $value_2 = strtolower($value_1); |
---|
[400] | 381 | |
---|
[2] | 382 | foreach($trans_table[$rule['field']] as $field) |
---|
| 383 | { |
---|
| 384 | $t[] = '('.$field.'='.$value_1.')'; |
---|
| 385 | $t[] = '('.$field.'='.$value_2.')'; |
---|
| 386 | } |
---|
| 387 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 388 | } |
---|
| 389 | break; |
---|
[400] | 390 | |
---|
[2] | 391 | */ case 'LIKE': |
---|
| 392 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 393 | { |
---|
| 394 | $value = str_replace('%', '*', $rule['value']); |
---|
[400] | 395 | |
---|
[2] | 396 | foreach($trans_table[$rule['field']] as $field) |
---|
| 397 | { |
---|
| 398 | $t[] = '('.$field.'='.$value.')'; |
---|
| 399 | } |
---|
| 400 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 401 | } |
---|
| 402 | break; |
---|
[400] | 403 | |
---|
[2] | 404 | case 'NOT NULL': |
---|
| 405 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 406 | { |
---|
| 407 | foreach($trans_table[$rule['field']] as $field) |
---|
| 408 | { |
---|
| 409 | $t[] = '('.$field.'=*'.')'; |
---|
| 410 | } |
---|
| 411 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 412 | } |
---|
| 413 | break; |
---|
[400] | 414 | |
---|
[2] | 415 | case 'NOT IN': |
---|
| 416 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 417 | { |
---|
| 418 | foreach($trans_table[$rule['field']] as $field) |
---|
| 419 | { |
---|
| 420 | foreach($rule['value'] as $value) |
---|
| 421 | { |
---|
| 422 | $t[] = '('.$field.'='.$value.')'; |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | $return_t[] = '(!(|'.implode('',$t).'))'; |
---|
| 426 | } |
---|
| 427 | break; |
---|
| 428 | |
---|
| 429 | case 'NOT iLIKE': |
---|
| 430 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 431 | { |
---|
| 432 | $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); |
---|
| 433 | $value_2 = strtolower($value_1); |
---|
[400] | 434 | |
---|
[2] | 435 | foreach($trans_table[$rule['field']] as $field) |
---|
| 436 | { |
---|
| 437 | $t[] = '('.$field.'='.$value_1.')'; |
---|
| 438 | $t[] = '('.$field.'='.$value_2.')'; |
---|
| 439 | } |
---|
| 440 | $return_t[] = '(!(|'.implode(' ',$t).'))'; |
---|
| 441 | } |
---|
| 442 | break; |
---|
| 443 | |
---|
| 444 | case 'NOT LIKE': |
---|
| 445 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 446 | { |
---|
| 447 | $value = str_replace('%', '*', $rule['value']); |
---|
[400] | 448 | |
---|
[2] | 449 | foreach($trans_table[$rule['field']] as $field) |
---|
| 450 | { |
---|
| 451 | $t[] = '('.$field.'='.$value.')'; |
---|
| 452 | } |
---|
| 453 | $return_t[] = '(!(|'.implode(' ',$t).'))'; |
---|
| 454 | } |
---|
| 455 | break; |
---|
| 456 | } |
---|
| 457 | } |
---|
[400] | 458 | |
---|
[2] | 459 | if (count($return_t)) |
---|
| 460 | { |
---|
| 461 | $return = '('.$join_type; |
---|
| 462 | foreach ($return_t as $return_p) |
---|
| 463 | { |
---|
| 464 | $return .= $return_p; |
---|
| 465 | } |
---|
| 466 | $return .= ')'; |
---|
| 467 | } |
---|
| 468 | else |
---|
| 469 | { |
---|
| 470 | $return = null; |
---|
| 471 | } |
---|
| 472 | return $return; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | /*! |
---|
[400] | 476 | |
---|
[2] | 477 | @function get_restrictions_without_branch |
---|
| 478 | @abstract Returns an array containing the restrictions ignoring the |
---|
| 479 | branches |
---|
| 480 | @author Raphael Derosso Pereira |
---|
[400] | 481 | |
---|
[2] | 482 | @param array $restrictions The restrictions |
---|
[400] | 483 | |
---|
[2] | 484 | */ |
---|
| 485 | function get_restrictions_without_branch(&$restrictions) |
---|
| 486 | { |
---|
| 487 | if (!is_array($restrictions)) |
---|
| 488 | { |
---|
| 489 | return null; |
---|
| 490 | } |
---|
[400] | 491 | |
---|
[2] | 492 | $fields = array(); |
---|
[400] | 493 | |
---|
[2] | 494 | foreach ($restrictions as $restrict_data) |
---|
| 495 | { |
---|
| 496 | switch($restrict_data['type']) |
---|
| 497 | { |
---|
| 498 | case 'branch': |
---|
| 499 | $fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch'])); |
---|
| 500 | break; |
---|
[400] | 501 | |
---|
[2] | 502 | case '=': |
---|
[400] | 503 | case '!=': |
---|
[2] | 504 | case '<=': |
---|
| 505 | case '<': |
---|
| 506 | case '>': |
---|
| 507 | case '>=': |
---|
| 508 | case 'NULL': |
---|
| 509 | case 'IN': |
---|
| 510 | case 'LIKE': |
---|
| 511 | case 'iLIKE': |
---|
| 512 | case 'NOT NULL': |
---|
| 513 | case 'NOT IN': |
---|
| 514 | case 'NOT LIKE': |
---|
| 515 | case 'NOT iLIKE': |
---|
| 516 | array_push($fields, $restrict_data); |
---|
| 517 | break; |
---|
[400] | 518 | |
---|
[2] | 519 | default: |
---|
[400] | 520 | exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); |
---|
[2] | 521 | } |
---|
| 522 | } |
---|
[400] | 523 | |
---|
[2] | 524 | return $fields; |
---|
| 525 | } |
---|
[400] | 526 | |
---|
| 527 | |
---|
[2] | 528 | /*********************************************************************\ |
---|
| 529 | * Methods to Get Data * |
---|
| 530 | \*********************************************************************/ |
---|
[400] | 531 | |
---|
| 532 | |
---|
[2] | 533 | /*! |
---|
[400] | 534 | |
---|
[2] | 535 | @function get_single_entry |
---|
| 536 | @abstract Returns all information requested about one contact |
---|
| 537 | @author Raphael Derosso Pereira |
---|
[400] | 538 | |
---|
[2] | 539 | @param integer $id_contact The contact ID |
---|
| 540 | @param array $fields The array returned by get_fields with true |
---|
| 541 | on the fields to be taken. |
---|
[400] | 542 | |
---|
[2] | 543 | */ |
---|
[1419] | 544 | function get_single_entry ( $id_contact, $fields, $external=false ) |
---|
[2] | 545 | { |
---|
[400] | 546 | if (!is_array($fields)) |
---|
[2] | 547 | { |
---|
[400] | 548 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 549 | { |
---|
| 550 | $GLOBALS['phpgw']->log->message(array( |
---|
| 551 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 552 | 'line' => __LINE__, |
---|
| 553 | 'file' => __FILE__)); |
---|
[400] | 554 | |
---|
[2] | 555 | $GLOBALS['phpgw']->log->commit(); |
---|
| 556 | } |
---|
[400] | 557 | else |
---|
[2] | 558 | { |
---|
| 559 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 560 | } |
---|
| 561 | } |
---|
[400] | 562 | |
---|
[2] | 563 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); |
---|
[400] | 564 | |
---|
[2] | 565 | if (!$ldap) |
---|
| 566 | { |
---|
| 567 | return false; |
---|
| 568 | } |
---|
[1419] | 569 | if(!$external) |
---|
| 570 | $id_contact = preg_replace("/dc=(.*)/i",$this->src_info['dn'],$id_contact); |
---|
| 571 | |
---|
[314] | 572 | $resource = @ldap_read($ldap, $id_contact, 'objectClass='.$this->src_info['obj']); |
---|
| 573 | $n_entries = @ldap_count_entries($ldap, $resource); |
---|
[2] | 574 | if ( $n_entries > 1 or $n_entries < 1) |
---|
| 575 | { |
---|
| 576 | return false; |
---|
| 577 | } |
---|
[400] | 578 | |
---|
[2] | 579 | $first_entry = ldap_first_entry($ldap, $resource); |
---|
| 580 | $contact = ldap_get_attributes($ldap,$first_entry); |
---|
[400] | 581 | if($contact['jpegPhoto']){ |
---|
| 582 | $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); |
---|
[2] | 583 | } |
---|
| 584 | |
---|
[400] | 585 | |
---|
[1419] | 586 | |
---|
[2] | 587 | // $contact_data = $this->fields; |
---|
[400] | 588 | |
---|
[2] | 589 | foreach($fields as $field => $trueness) |
---|
| 590 | { |
---|
| 591 | if (!$trueness) |
---|
| 592 | { |
---|
| 593 | //unset($contact_data[$field]); |
---|
| 594 | continue; |
---|
| 595 | } |
---|
[400] | 596 | |
---|
[2] | 597 | switch ($field) |
---|
| 598 | { |
---|
| 599 | case 'companies': |
---|
| 600 | unset($l_fields); |
---|
| 601 | $l_fields['company_name'] = $this->trans_table['contact.company.company_name']; |
---|
| 602 | $l_fields['title'] = $this->trans_table['contact.business_info.title']; |
---|
| 603 | $l_fields['department'] = $this->trans_table['contact.business_info.department']; |
---|
| 604 | $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; |
---|
[400] | 605 | |
---|
[2] | 606 | $contact_data['companies'] = array(); |
---|
| 607 | foreach($l_fields as $l_field => $l_value) |
---|
| 608 | { |
---|
| 609 | if (!( $contact[$l_value[0]][0])) |
---|
| 610 | { |
---|
| 611 | continue; |
---|
| 612 | } |
---|
[400] | 613 | |
---|
[284] | 614 | $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 615 | } |
---|
[400] | 616 | |
---|
[2] | 617 | if (!(count($contact_data['companies']))) |
---|
| 618 | { |
---|
| 619 | unset($contact_data['companies']); |
---|
| 620 | } |
---|
| 621 | break; |
---|
[400] | 622 | |
---|
[2] | 623 | case 'relations': |
---|
| 624 | unset($l_fields); |
---|
| 625 | if (!$this->trans_table['contact.contact_related.names_ordered']) |
---|
| 626 | { |
---|
| 627 | unset($contact_data['relations']); |
---|
| 628 | } |
---|
[400] | 629 | |
---|
[2] | 630 | $contact_data['relations'] = array(); |
---|
| 631 | if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) |
---|
| 632 | { |
---|
| 633 | if (!($trans = $this->trans_table[$this->trans_table['contact.contact_related.names_ordered']])) |
---|
| 634 | { |
---|
| 635 | continue; |
---|
| 636 | } |
---|
[400] | 637 | |
---|
[2] | 638 | $i = 1; |
---|
| 639 | foreach($trans as $l_type => $l_type_fields) |
---|
| 640 | { |
---|
| 641 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 642 | { |
---|
| 643 | continue; |
---|
| 644 | } |
---|
[400] | 645 | |
---|
[2] | 646 | $contact_data['relations']['relation'.$i]['type'] = $l_type; |
---|
[284] | 647 | $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 648 | $i++; |
---|
| 649 | } |
---|
| 650 | } |
---|
[400] | 651 | |
---|
[2] | 652 | if (!(count($contact_data['relations']))) |
---|
| 653 | { |
---|
| 654 | unset($contact_data['relations']); |
---|
| 655 | } |
---|
| 656 | break; |
---|
[400] | 657 | |
---|
[2] | 658 | case 'addresses': |
---|
| 659 | unset($l_fields); |
---|
| 660 | $l_fields['address1'] = $this->trans_table['contact.address.address1']; |
---|
| 661 | $l_fields['address2'] = $this->trans_table['contact.address.address2']; |
---|
| 662 | $l_fields['complement'] = $this->trans_table['contact.address.complement']; |
---|
| 663 | $l_fields['address_other'] = $this->trans_table['contact.address.address_other']; |
---|
| 664 | $l_fields['postal_code'] = $this->trans_table['contact.address.postal_code']; |
---|
| 665 | $l_fields['po_box'] = $this->trans_table['contact.address.po_box']; |
---|
| 666 | $l_fields['id_city'] = $this->trans_table['contact.address.city.id_city']; |
---|
| 667 | $l_fields['city_name'] = $this->trans_table['contact.address.city.city_name']; |
---|
| 668 | $l_fields['city_timezone'] = $this->trans_table['contact.address.city.city_timezone']; |
---|
| 669 | $l_fields['city_geo_location'] = $this->trans_table['contact.address.city.city_geo_location']; |
---|
| 670 | $l_fields['id_state'] = $this->trans_table['contact.address.city.state.id_state']; |
---|
| 671 | $l_fields['state_name'] = $this->trans_table['contact.address.city.state.state_name']; |
---|
| 672 | $l_fields['state_symbol'] = $this->trans_table['contact.address.city.state.state_symbol']; |
---|
| 673 | $l_fields['id_country'] = $this->trans_table['contact.address.city.country.id_country']; |
---|
| 674 | $l_fields['country_name'] = $this->trans_table['contact.address.city.country.country_name']; |
---|
| 675 | $l_fields['address_is_default'] = $this->trans_table['contact.address.address_is_default']; |
---|
| 676 | |
---|
| 677 | $contact_data['addresses'] = array(); |
---|
| 678 | foreach($l_fields as $l_field => $l_value) |
---|
| 679 | { |
---|
| 680 | if (!is_array($l_value)) |
---|
| 681 | { |
---|
| 682 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 683 | { |
---|
| 684 | continue; |
---|
| 685 | } |
---|
[400] | 686 | |
---|
[2] | 687 | $i = 1; |
---|
| 688 | foreach($trans as $l_type => $l_type_fields) |
---|
| 689 | { |
---|
| 690 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 691 | { |
---|
| 692 | continue; |
---|
| 693 | } |
---|
[400] | 694 | |
---|
[2] | 695 | $contact_data['addresses']['address'.$i]['type'] = $l_type; |
---|
[284] | 696 | $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 697 | $i++; |
---|
| 698 | } |
---|
| 699 | } |
---|
| 700 | else |
---|
| 701 | { |
---|
[284] | 702 | $contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 703 | } |
---|
| 704 | } |
---|
[400] | 705 | |
---|
[2] | 706 | if (!(count($contact_data['addresses']))) |
---|
| 707 | { |
---|
| 708 | unset($contact_data['addresses']); |
---|
| 709 | } |
---|
| 710 | break; |
---|
[400] | 711 | |
---|
[2] | 712 | case 'connections': |
---|
| 713 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
| 714 | if (!is_array($preferences)) |
---|
| 715 | { |
---|
| 716 | $preferences['personCardEmail'] = 1; |
---|
| 717 | $preferences['personCardPhone'] = 2; |
---|
| 718 | } |
---|
| 719 | unset($l_fields); |
---|
| 720 | $l_fields['connection_name'] = $this->trans_table['contact.connection.connection_name']; |
---|
| 721 | $l_fields['connection_value'] = $this->trans_table['contact.connection.connection_value']; |
---|
| 722 | |
---|
| 723 | $contact_data['connections'] = array(); |
---|
| 724 | foreach($l_fields as $l_field => $l_value) |
---|
| 725 | { |
---|
| 726 | if (!is_array($l_value)) |
---|
| 727 | { |
---|
| 728 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 729 | { |
---|
| 730 | continue; |
---|
| 731 | } |
---|
[400] | 732 | |
---|
[2] | 733 | $i = 1; |
---|
| 734 | foreach($trans as $l_type => $l_type_fields) |
---|
| 735 | { |
---|
| 736 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 737 | { |
---|
| 738 | continue; |
---|
| 739 | } |
---|
[400] | 740 | |
---|
[2] | 741 | switch ($l_type) |
---|
| 742 | { |
---|
| 743 | case 'email': |
---|
| 744 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardEmail']; |
---|
| 745 | break; |
---|
| 746 | |
---|
| 747 | default: |
---|
| 748 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardPhone']; |
---|
| 749 | } |
---|
| 750 | $contact_data['connections']['connection'.$i]['type'] = $l_type; |
---|
[284] | 751 | $contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 752 | $i++; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | else |
---|
| 756 | { |
---|
[284] | 757 | $contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 758 | } |
---|
| 759 | } |
---|
[400] | 760 | |
---|
[2] | 761 | if (!(count($contact_data['connections']))) |
---|
| 762 | { |
---|
| 763 | unset($contact_data['connections']); |
---|
| 764 | } |
---|
| 765 | break; |
---|
[400] | 766 | |
---|
[2] | 767 | case 'prefix': |
---|
| 768 | unset($l_fields); |
---|
| 769 | $l_fields = $this->trans_table['contact.prefixes.prefix']; |
---|
| 770 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 771 | { |
---|
| 772 | unset($contact_data['prefix']); |
---|
| 773 | continue; |
---|
| 774 | } |
---|
[400] | 775 | |
---|
[284] | 776 | $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 777 | break; |
---|
[400] | 778 | |
---|
[2] | 779 | case 'suffix': |
---|
| 780 | unset($l_fields); |
---|
| 781 | $l_fields = $this->trans_table['contact.suffixes.suffix']; |
---|
| 782 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 783 | { |
---|
| 784 | unset($contact_data['suffix']); |
---|
| 785 | continue; |
---|
| 786 | } |
---|
[400] | 787 | |
---|
[284] | 788 | $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 789 | break; |
---|
[400] | 790 | |
---|
[2] | 791 | case 'status': |
---|
| 792 | unset($l_fields); |
---|
| 793 | $l_fields = $this->trans_table['contact.status.status_name']; |
---|
| 794 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 795 | { |
---|
| 796 | unset($contact_data['status']); |
---|
| 797 | continue; |
---|
| 798 | } |
---|
[400] | 799 | |
---|
[284] | 800 | $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 801 | break; |
---|
[400] | 802 | |
---|
[2] | 803 | case 'photo': |
---|
| 804 | unset($l_fields); |
---|
| 805 | $l_fields = $this->trans_table['contact.photo']; |
---|
| 806 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 807 | { |
---|
| 808 | unset($contact_data['photo']); |
---|
| 809 | continue; |
---|
| 810 | } |
---|
[400] | 811 | |
---|
[2] | 812 | $contact_data['photo'] = $contact[$l_fields[0]][0]; |
---|
[400] | 813 | break; |
---|
[2] | 814 | |
---|
| 815 | default: |
---|
| 816 | unset($l_fields); |
---|
| 817 | $l_fields = $this->trans_table['contact.'.$field]; |
---|
| 818 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 819 | { |
---|
| 820 | unset($contact_data[$field]); |
---|
| 821 | continue; |
---|
| 822 | } |
---|
[400] | 823 | |
---|
[2] | 824 | if(count($contact[$l_fields[0]]) > 1) |
---|
[284] | 825 | { |
---|
| 826 | $tmp = array(); |
---|
| 827 | foreach ($contact[$l_fields[0]] as $i => $j) |
---|
| 828 | { |
---|
| 829 | $tmp["$i"] = utf8_decode($j); |
---|
| 830 | } |
---|
| 831 | //$contact_data[$field] = $contact[$l_fields[0]]; |
---|
| 832 | $contact_data[$field] = $tmp; |
---|
| 833 | } |
---|
[2] | 834 | else |
---|
[284] | 835 | $contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 836 | |
---|
| 837 | break; |
---|
| 838 | } |
---|
| 839 | } |
---|
[400] | 840 | |
---|
[2] | 841 | if (!is_array($contact_data)) |
---|
| 842 | { |
---|
| 843 | return false; |
---|
| 844 | } |
---|
[400] | 845 | |
---|
[2] | 846 | return $contact_data; |
---|
| 847 | } |
---|
[285] | 848 | //SERPRO |
---|
[284] | 849 | /*! |
---|
| 850 | |
---|
| 851 | @function get_all_entries |
---|
| 852 | @abstract Returns all information requested about a bunch of contacts, usually a page |
---|
| 853 | @author Raphael Derosso Pereira |
---|
[400] | 854 | @author Mário César Kolling |
---|
[284] | 855 | |
---|
| 856 | @param string $filter Filter (returned by generate_filter). |
---|
| 857 | @param array $fields The array returned by get_fields with true |
---|
| 858 | on the fields to be taken. |
---|
| 859 | |
---|
| 860 | */ |
---|
| 861 | function get_all_entries($filter, $fields) |
---|
| 862 | { |
---|
| 863 | if (!is_array($fields)) |
---|
| 864 | { |
---|
| 865 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 866 | { |
---|
| 867 | $GLOBALS['phpgw']->log->message(array( |
---|
| 868 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 869 | 'line' => __LINE__, |
---|
| 870 | 'file' => __FILE__)); |
---|
| 871 | |
---|
| 872 | $GLOBALS['phpgw']->log->commit(); |
---|
| 873 | } |
---|
| 874 | else |
---|
| 875 | { |
---|
| 876 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 877 | } |
---|
| 878 | } |
---|
| 879 | |
---|
| 880 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); |
---|
| 881 | |
---|
| 882 | if (!$ldap) |
---|
| 883 | { |
---|
| 884 | return false; |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | $resource = @ldap_search($ldap, $this->src_info['dn'], $filter); |
---|
| 888 | $n_entries = @ldap_count_entries($ldap, $resource); |
---|
| 889 | |
---|
| 890 | ldap_sort($ldap, $resource, 'cn'); |
---|
| 891 | |
---|
| 892 | if ( $n_entries < 1) |
---|
| 893 | { |
---|
| 894 | return false; |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | $contacts = array(); |
---|
| 898 | |
---|
| 899 | for ($entry = ldap_first_entry($ldap, $resource); |
---|
| 900 | $entry != false; |
---|
| 901 | $entry = ldap_next_entry($ldap, $entry)) |
---|
| 902 | { |
---|
| 903 | $contact = ldap_get_attributes($ldap,$entry); |
---|
| 904 | if($contact['jpegPhoto']){ |
---|
| 905 | $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $entry, "jpegPhoto"); |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | foreach($fields as $field => $trueness) |
---|
| 909 | { |
---|
| 910 | if (!$trueness) |
---|
| 911 | { |
---|
| 912 | //unset($contact_data[$field]); |
---|
| 913 | continue; |
---|
| 914 | } |
---|
| 915 | |
---|
| 916 | switch ($field) |
---|
| 917 | { |
---|
| 918 | case 'companies': |
---|
| 919 | unset($l_fields); |
---|
| 920 | $l_fields['company_name'] = $this->trans_table['contact.company.company_name']; |
---|
| 921 | $l_fields['title'] = $this->trans_table['contact.business_info.title']; |
---|
| 922 | $l_fields['department'] = $this->trans_table['contact.business_info.department']; |
---|
| 923 | $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; |
---|
| 924 | |
---|
| 925 | $contact_data['companies'] = array(); |
---|
| 926 | foreach($l_fields as $l_field => $l_value) |
---|
| 927 | { |
---|
| 928 | if (!( $contact[$l_value[0]][0])) |
---|
| 929 | { |
---|
| 930 | continue; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | if (!(count($contact_data['companies']))) |
---|
| 937 | { |
---|
| 938 | unset($contact_data['companies']); |
---|
| 939 | } |
---|
| 940 | break; |
---|
| 941 | |
---|
| 942 | case 'relations': |
---|
| 943 | unset($l_fields); |
---|
| 944 | if (!$this->trans_table['contact.contact_related.names_ordered']) |
---|
| 945 | { |
---|
| 946 | unset($contact_data['relations']); |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | $contact_data['relations'] = array(); |
---|
| 950 | if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) |
---|
| 951 | { |
---|
| 952 | if (!($trans = $this->trans_table[$this->trans_table['contact.contact_related.names_ordered']])) |
---|
| 953 | { |
---|
| 954 | continue; |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | $i = 1; |
---|
| 958 | foreach($trans as $l_type => $l_type_fields) |
---|
| 959 | { |
---|
| 960 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 961 | { |
---|
| 962 | continue; |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | $contact_data['relations']['relation'.$i]['type'] = $l_type; |
---|
| 966 | $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 967 | $i++; |
---|
| 968 | } |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | if (!(count($contact_data['relations']))) |
---|
| 972 | { |
---|
| 973 | unset($contact_data['relations']); |
---|
| 974 | } |
---|
| 975 | break; |
---|
| 976 | |
---|
| 977 | case 'addresses': |
---|
| 978 | unset($l_fields); |
---|
| 979 | $l_fields['address1'] = $this->trans_table['contact.address.address1']; |
---|
| 980 | $l_fields['address2'] = $this->trans_table['contact.address.address2']; |
---|
| 981 | $l_fields['complement'] = $this->trans_table['contact.address.complement']; |
---|
| 982 | $l_fields['address_other'] = $this->trans_table['contact.address.address_other']; |
---|
| 983 | $l_fields['postal_code'] = $this->trans_table['contact.address.postal_code']; |
---|
| 984 | $l_fields['po_box'] = $this->trans_table['contact.address.po_box']; |
---|
| 985 | $l_fields['id_city'] = $this->trans_table['contact.address.city.id_city']; |
---|
| 986 | $l_fields['city_name'] = $this->trans_table['contact.address.city.city_name']; |
---|
| 987 | $l_fields['city_timezone'] = $this->trans_table['contact.address.city.city_timezone']; |
---|
| 988 | $l_fields['city_geo_location'] = $this->trans_table['contact.address.city.city_geo_location']; |
---|
| 989 | $l_fields['id_state'] = $this->trans_table['contact.address.city.state.id_state']; |
---|
| 990 | $l_fields['state_name'] = $this->trans_table['contact.address.city.state.state_name']; |
---|
| 991 | $l_fields['state_symbol'] = $this->trans_table['contact.address.city.state.state_symbol']; |
---|
| 992 | $l_fields['id_country'] = $this->trans_table['contact.address.city.country.id_country']; |
---|
| 993 | $l_fields['country_name'] = $this->trans_table['contact.address.city.country.country_name']; |
---|
| 994 | $l_fields['address_is_default'] = $this->trans_table['contact.address.address_is_default']; |
---|
| 995 | |
---|
| 996 | $contact_data['addresses'] = array(); |
---|
| 997 | foreach($l_fields as $l_field => $l_value) |
---|
| 998 | { |
---|
| 999 | if (!is_array($l_value)) |
---|
| 1000 | { |
---|
| 1001 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 1002 | { |
---|
| 1003 | continue; |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | $i = 1; |
---|
| 1007 | foreach($trans as $l_type => $l_type_fields) |
---|
| 1008 | { |
---|
| 1009 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 1010 | { |
---|
| 1011 | continue; |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | $contact_data['addresses']['address'.$i]['type'] = $l_type; |
---|
| 1015 | $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 1016 | $i++; |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | else |
---|
| 1020 | { |
---|
| 1021 | $contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 1022 | } |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | if (!(count($contact_data['addresses']))) |
---|
| 1026 | { |
---|
| 1027 | unset($contact_data['addresses']); |
---|
| 1028 | } |
---|
| 1029 | break; |
---|
| 1030 | |
---|
| 1031 | case 'connections': |
---|
| 1032 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
| 1033 | if (!is_array($preferences)) |
---|
| 1034 | { |
---|
| 1035 | $preferences['personCardEmail'] = 1; |
---|
| 1036 | $preferences['personCardPhone'] = 2; |
---|
| 1037 | } |
---|
| 1038 | unset($l_fields); |
---|
| 1039 | $l_fields['connection_name'] = $this->trans_table['contact.connection.connection_name']; |
---|
| 1040 | $l_fields['connection_value'] = $this->trans_table['contact.connection.connection_value']; |
---|
| 1041 | |
---|
| 1042 | $contact_data['connections'] = array(); |
---|
| 1043 | foreach($l_fields as $l_field => $l_value) |
---|
| 1044 | { |
---|
| 1045 | if (!is_array($l_value)) |
---|
| 1046 | { |
---|
| 1047 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 1048 | { |
---|
| 1049 | continue; |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | $i = 1; |
---|
| 1053 | foreach($trans as $l_type => $l_type_fields) |
---|
| 1054 | { |
---|
| 1055 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 1056 | { |
---|
| 1057 | continue; |
---|
| 1058 | } |
---|
| 1059 | |
---|
| 1060 | switch ($l_type) |
---|
| 1061 | { |
---|
| 1062 | case 'email': |
---|
| 1063 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardEmail']; |
---|
| 1064 | break; |
---|
| 1065 | |
---|
| 1066 | default: |
---|
| 1067 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardPhone']; |
---|
| 1068 | } |
---|
| 1069 | $contact_data['connections']['connection'.$i]['type'] = $l_type; |
---|
| 1070 | $contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 1071 | $i++; |
---|
| 1072 | } |
---|
| 1073 | } |
---|
| 1074 | else |
---|
| 1075 | { |
---|
| 1076 | $contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | |
---|
| 1080 | if (!(count($contact_data['connections']))) |
---|
| 1081 | { |
---|
| 1082 | unset($contact_data['connections']); |
---|
| 1083 | } |
---|
| 1084 | break; |
---|
| 1085 | |
---|
| 1086 | case 'prefix': |
---|
| 1087 | unset($l_fields); |
---|
| 1088 | $l_fields = $this->trans_table['contact.prefixes.prefix']; |
---|
| 1089 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1090 | { |
---|
| 1091 | unset($contact_data['prefix']); |
---|
| 1092 | continue; |
---|
| 1093 | } |
---|
| 1094 | |
---|
| 1095 | $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1096 | break; |
---|
| 1097 | |
---|
| 1098 | case 'suffix': |
---|
| 1099 | unset($l_fields); |
---|
| 1100 | $l_fields = $this->trans_table['contact.suffixes.suffix']; |
---|
| 1101 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1102 | { |
---|
| 1103 | unset($contact_data['suffix']); |
---|
| 1104 | continue; |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1108 | break; |
---|
| 1109 | |
---|
| 1110 | case 'status': |
---|
| 1111 | unset($l_fields); |
---|
| 1112 | $l_fields = $this->trans_table['contact.status.status_name']; |
---|
| 1113 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1114 | { |
---|
| 1115 | unset($contact_data['status']); |
---|
| 1116 | continue; |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1120 | break; |
---|
| 1121 | |
---|
| 1122 | case 'photo': |
---|
| 1123 | unset($l_fields); |
---|
| 1124 | $l_fields = $this->trans_table['contact.photo']; |
---|
| 1125 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1126 | { |
---|
| 1127 | unset($contact_data['photo']); |
---|
| 1128 | continue; |
---|
| 1129 | } |
---|
| 1130 | |
---|
| 1131 | $contact_data['photo'] = $contact[$l_fields[0]][0]; |
---|
| 1132 | break; |
---|
| 1133 | |
---|
| 1134 | default: |
---|
| 1135 | unset($l_fields); |
---|
| 1136 | $l_fields = $this->trans_table['contact.'.$field]; |
---|
| 1137 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1138 | { |
---|
| 1139 | unset($contact_data[$field]); |
---|
| 1140 | continue; |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | if(count($contact[$l_fields[0]]) > 1) |
---|
| 1144 | { |
---|
| 1145 | $tmp = array(); |
---|
| 1146 | foreach ($contact[$l_fields[0]] as $i => $j) |
---|
| 1147 | { |
---|
| 1148 | $tmp["$i"] = utf8_decode($j); |
---|
| 1149 | } |
---|
| 1150 | //$contact_data[$field] = $contact[$l_fields[0]]; |
---|
| 1151 | $contact_data[$field] = $tmp; |
---|
| 1152 | } |
---|
| 1153 | else |
---|
| 1154 | $contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1155 | |
---|
| 1156 | break; |
---|
| 1157 | |
---|
| 1158 | } |
---|
| 1159 | } |
---|
| 1160 | |
---|
| 1161 | if (is_array($contact_data)) |
---|
| 1162 | { |
---|
| 1163 | $contacts[ldap_get_dn($ldap, $entry)] = $contact_data; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | } |
---|
| 1167 | |
---|
| 1168 | return $contacts; |
---|
| 1169 | } |
---|
[400] | 1170 | |
---|
[1419] | 1171 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false, $external=false ) |
---|
[2] | 1172 | { |
---|
| 1173 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
| 1174 | { |
---|
[400] | 1175 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 1176 | { |
---|
| 1177 | $GLOBALS['phpgw']->log->message(array( |
---|
| 1178 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
| 1179 | 'line' => __LINE__, |
---|
| 1180 | 'file' => __FILE__)); |
---|
[400] | 1181 | |
---|
[2] | 1182 | $GLOBALS['phpgw']->log->commit(); |
---|
| 1183 | } |
---|
| 1184 | else { |
---|
| 1185 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 1186 | } |
---|
| 1187 | } |
---|
[400] | 1188 | |
---|
[285] | 1189 | foreach ($id_contacts as $id) |
---|
| 1190 | { |
---|
[1419] | 1191 | $contacts[$id] = $this->get_single_entry($id,$fields,$external); |
---|
[285] | 1192 | } |
---|
[400] | 1193 | |
---|
[285] | 1194 | return $contacts; |
---|
[284] | 1195 | |
---|
[285] | 1196 | // SERPRO |
---|
[400] | 1197 | |
---|
[285] | 1198 | /*$contacts = array(); |
---|
[400] | 1199 | |
---|
[2] | 1200 | if ($other_data) |
---|
| 1201 | { |
---|
| 1202 | //TODO |
---|
| 1203 | } |
---|
[284] | 1204 | |
---|
| 1205 | $filter = $this->generate_filter($id_contacts); |
---|
| 1206 | |
---|
| 1207 | //$teste = $this->get_all_entries($filter, $fields); |
---|
| 1208 | |
---|
[285] | 1209 | return $this->get_all_entries($filter, $fields);*/ |
---|
[400] | 1210 | |
---|
[284] | 1211 | } |
---|
| 1212 | |
---|
[285] | 1213 | // CELEPAR |
---|
[284] | 1214 | function generate_filter($id_contacts) |
---|
| 1215 | { |
---|
| 1216 | if (($size = count($id_contacts))) |
---|
[2] | 1217 | { |
---|
[285] | 1218 | $contacts[$id] = $this->get_single_entry($id,$fields); |
---|
| 1219 | } |
---|
[400] | 1220 | |
---|
[285] | 1221 | return $contacts; |
---|
| 1222 | } |
---|
[400] | 1223 | |
---|
[285] | 1224 | // SERPRO |
---|
| 1225 | /* |
---|
| 1226 | function generate_filter($id_contacts) |
---|
| 1227 | { |
---|
| 1228 | if (($size = count($id_contacts))) |
---|
| 1229 | { |
---|
[284] | 1230 | $filter = '(&(objectClass='.$this->src_info['obj'] . ')(|'; |
---|
| 1231 | for ($i = 0; $i < $size; $i++) |
---|
| 1232 | { |
---|
| 1233 | |
---|
[400] | 1234 | // |
---|
| 1235 | // Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro |
---|
[285] | 1236 | // componente da dn |
---|
[400] | 1237 | // |
---|
[284] | 1238 | preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn); |
---|
| 1239 | |
---|
[285] | 1240 | // |
---|
| 1241 | // Adicionados os str_replace para adicionar caracteres de escape em frente aos caracteres '(' e ')', |
---|
[400] | 1242 | // posteriormente poderá ser necessário substituir por uma expressão regular mais genérica. |
---|
[285] | 1243 | // |
---|
| 1244 | |
---|
[284] | 1245 | if ($cn[1]) |
---|
| 1246 | { |
---|
[285] | 1247 | // |
---|
[400] | 1248 | // Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada |
---|
| 1249 | // pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares, |
---|
| 1250 | // neste caso é mais apropriado colocar dentro de uma função. |
---|
[285] | 1251 | // |
---|
[284] | 1252 | //foreach($cn as $key=>$value){ |
---|
| 1253 | // $cn[$key]=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value); |
---|
| 1254 | //} |
---|
| 1255 | |
---|
| 1256 | $filter .= '(' . str_replace(')', '\)', str_replace('(','\(',$cn[1])) . ')'; |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | $filter .= '))'; |
---|
[2] | 1260 | } |
---|
[284] | 1261 | |
---|
| 1262 | return $filter; |
---|
| 1263 | |
---|
[2] | 1264 | } |
---|
[285] | 1265 | */ |
---|
[2] | 1266 | |
---|
| 1267 | function get_all_entries_ids () |
---|
| 1268 | { |
---|
| 1269 | $search_fields = array('contact.id_contact', 'contact.names_ordered'); |
---|
| 1270 | $search_rules = array( |
---|
| 1271 | 0 => array( |
---|
| 1272 | 'field' => 'contact.names_ordered', |
---|
| 1273 | 'type' => 'LIKE', |
---|
| 1274 | 'value' => '%' |
---|
| 1275 | ) |
---|
| 1276 | ); |
---|
| 1277 | $search_other = array('order' => 'contact.names_ordered'); |
---|
| 1278 | |
---|
| 1279 | $result_i = $this->find($search_fields, $search_rules, $search_other); |
---|
| 1280 | |
---|
| 1281 | if (is_array($result_i) and count($result_i)) |
---|
| 1282 | { |
---|
| 1283 | $result = array(); |
---|
| 1284 | foreach($result_i as $result_part) |
---|
| 1285 | { |
---|
| 1286 | $result[] = $result_part['id_contact']; |
---|
| 1287 | } |
---|
| 1288 | |
---|
| 1289 | return $result; |
---|
| 1290 | } |
---|
| 1291 | |
---|
| 1292 | return null; |
---|
| 1293 | } |
---|
[400] | 1294 | |
---|
[2] | 1295 | function get_relations ($id_contact,$extra=false) |
---|
| 1296 | { |
---|
| 1297 | } |
---|
[400] | 1298 | |
---|
[2] | 1299 | function get_addresses ( $id_contact,$extra=false ) |
---|
| 1300 | { |
---|
| 1301 | } |
---|
[400] | 1302 | |
---|
[2] | 1303 | function get_connections ( $id_contact,$extra=false ) |
---|
| 1304 | { |
---|
| 1305 | } |
---|
[400] | 1306 | |
---|
[2] | 1307 | function get_companies ( $id_contact, $extra=false ) |
---|
| 1308 | { |
---|
| 1309 | } |
---|
[400] | 1310 | |
---|
[2] | 1311 | function get_all_prefixes ( ) |
---|
| 1312 | { |
---|
| 1313 | } |
---|
[400] | 1314 | |
---|
[2] | 1315 | function get_all_suffixes ( ) |
---|
| 1316 | { |
---|
| 1317 | } |
---|
[400] | 1318 | |
---|
[2] | 1319 | function get_all_status ( ) |
---|
| 1320 | { |
---|
| 1321 | } |
---|
[400] | 1322 | |
---|
[2] | 1323 | function get_all_relations_types ( ) |
---|
| 1324 | { |
---|
| 1325 | } |
---|
[400] | 1326 | |
---|
[2] | 1327 | function get_all_addresses_types ( ) |
---|
| 1328 | { |
---|
| 1329 | } |
---|
[400] | 1330 | |
---|
[2] | 1331 | function get_all_connections_types ( ) |
---|
| 1332 | { |
---|
| 1333 | } |
---|
[400] | 1334 | |
---|
[2] | 1335 | function get_vcard ( $id_contact ) |
---|
| 1336 | { |
---|
| 1337 | } |
---|
[400] | 1338 | |
---|
| 1339 | |
---|
| 1340 | |
---|
| 1341 | |
---|
[2] | 1342 | function get_global_tree ( $root ) |
---|
| 1343 | { |
---|
| 1344 | } |
---|
[400] | 1345 | |
---|
[2] | 1346 | function get_actual_brach ( ) |
---|
| 1347 | { |
---|
| 1348 | } |
---|
[400] | 1349 | |
---|
[2] | 1350 | function set_actual_branch ( $branch ) |
---|
| 1351 | { |
---|
| 1352 | } |
---|
| 1353 | } |
---|
| 1354 | ?> |
---|